<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Fetching PCAP via API in R80.30 JHF 111 in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71699#M4276</link>
    <description>&lt;P&gt;Howdy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With JHF 111 for R80.30 we can now fetch pcaps associated to threat prevention alerts (IPS/AB/etc) via API!&lt;/P&gt;
&lt;P&gt;Handy for SOCs and IR teams.&lt;/P&gt;
&lt;P&gt;Basically: &lt;BR /&gt;1. Log Exporter was modified to send an Attachment ID.&lt;BR /&gt;2. That Attachment ID can be leveraged via the get-attachment API call to fetch the goods.&lt;/P&gt;
&lt;P&gt;Wanted to share the attached python script (in .7z + screenshot) as an example.&lt;/P&gt;
&lt;P&gt;Tim Otis - Check Point Incident Response Team&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 20:41:56 GMT</pubDate>
    <dc:creator>Tim_Otis</dc:creator>
    <dc:date>2020-01-06T20:41:56Z</dc:date>
    <item>
      <title>Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71699#M4276</link>
      <description>&lt;P&gt;Howdy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With JHF 111 for R80.30 we can now fetch pcaps associated to threat prevention alerts (IPS/AB/etc) via API!&lt;/P&gt;
&lt;P&gt;Handy for SOCs and IR teams.&lt;/P&gt;
&lt;P&gt;Basically: &lt;BR /&gt;1. Log Exporter was modified to send an Attachment ID.&lt;BR /&gt;2. That Attachment ID can be leveraged via the get-attachment API call to fetch the goods.&lt;/P&gt;
&lt;P&gt;Wanted to share the attached python script (in .7z + screenshot) as an example.&lt;/P&gt;
&lt;P&gt;Tim Otis - Check Point Incident Response Team&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 20:41:56 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71699#M4276</guid>
      <dc:creator>Tim_Otis</dc:creator>
      <dc:date>2020-01-06T20:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71708#M4277</link>
      <description>&lt;P&gt;Pretty need. Thanks for sharing&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 05:26:19 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71708#M4277</guid>
      <dc:creator>Kim_Moberg</dc:creator>
      <dc:date>2020-01-07T05:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71780#M4280</link>
      <description>&lt;P&gt;Nice!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 15:17:47 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/71780#M4280</guid>
      <dc:creator>Jon_Goldman</dc:creator>
      <dc:date>2020-01-07T15:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/81081#M4681</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using a MDM-MLM setup.&lt;/P&gt;&lt;P&gt;If a pcap file must be fetched via an API, will the pcap request go to a particular CMA or a CLM?&lt;/P&gt;&lt;P&gt;/Norbert&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 07:33:19 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/81081#M4681</guid>
      <dc:creator>Norbert_Anderss</dc:creator>
      <dc:date>2020-04-07T07:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/81373#M4704</link>
      <description>Hi, It will be an API connection to the management server.</description>
      <pubDate>Wed, 08 Apr 2020 20:31:04 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/81373#M4704</guid>
      <dc:creator>Tim_Otis</dc:creator>
      <dc:date>2020-04-08T20:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/92525#M5061</link>
      <description>&lt;P&gt;Hello Tim, could you&amp;nbsp; specify on which version of python it is working? Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 13:09:57 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/92525#M5061</guid>
      <dc:creator>Tomas_Vobruba</dc:creator>
      <dc:date>2020-07-27T13:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/97664#M5189</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/23628"&gt;@Tim_Otis&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for sharing this script.&lt;/P&gt;&lt;P&gt;Could you confirm how would I get the "LOG_ATTACHMENT_UID".&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 02:34:04 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/97664#M5189</guid>
      <dc:creator>Lithin_Mathew</dc:creator>
      <dc:date>2020-09-28T02:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/97665#M5190</link>
      <description>&lt;P&gt;Believe it's in the log entry itself.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 02:48:49 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/97665#M5190</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2020-09-28T02:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching PCAP via API in R80.30 JHF 111</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/110922#M5587</link>
      <description>&lt;P&gt;Code reviewed to work with python3 and r80.40 API version 1.6&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#!/usr/bin/python
import requests, json, binascii, time, base64, email, shlex
user=""
password=""
mgmtServer=""
port="443"

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def api_call(command, json_payload, sid):
 url = 'https://' + mgmtServer  + ':' + port + '/web_api/' + command
 if sid == '':
  request_headers = {'Content-Type' : 'application/json'}
 else:
  request_headers = {'Content-Type' : 'application/json', 'X-chkp-sid' : sid}
 r = requests.post(url,data=json.dumps(json_payload), headers=request_headers, verify=False)
 return r.json()

def login(user,password):
 payload = {'user':user, 'password' : password}
 response = api_call('login',payload, '')
 return response["sid"]

# Login
print("Authenticating...")
sid = login(user,password)
print("Got Session id: " + sid)

# Get the log_attachment_uid, package up, call API and keep the TaskID
log_attachment_uid = ""
post_data = {} 
post_data['attachment-id'] = log_attachment_uid
print("Calling API for pcap with log_attachment_uid: " + log_attachment_uid)
taskID = api_call('get-attachment',post_data, sid)
print("Got TaskID: ",taskID)

# Define a function to parse the '.eml' message that contains the actual pcap
def parseEml(emlData):
 print("Parsing .eml formatted data...")
 mgs = base64.standard_b64decode(emlData)

 capMsg = email.message_from_bytes(mgs)


 contentTypeHdr = capMsg.get('Content-Type', '')
 hdrParts = shlex.split(contentTypeHdr,";")
 # print(contentTypeHdr)
 # print(hdrParts)
 # print(capMsg.get('attachment',''))
 for part in hdrParts:
  # print(part)
  if part.startswith('name'):
   longFilename = part.split("=")[1]
   filename = longFilename.split("/")[-1]
 pcapBase64 = capMsg.get_payload()
 return filename,pcapBase64

# Define a function to write the pcap data to disk using the filename defined in the .eml's content-type header
def writePcap(filename,pcapBase64):
  with open(filename, "wb") as fh:
   fh.write(base64.standard_b64decode(pcapBase64))
  print("Wrote pcap file :", filename)

# Check on our TaskID
# - 10 tries with a 5 second sleep betwixt each
for x in range(10):
 # Call the API and check for 'succeeded' status
 print("Calling API to check on taskID:", taskID)
 response = api_call('show-task',taskID, sid)
 #print response
 status = response['tasks'][0]['status']
 print("Status:", status)
 if status == "succeeded":
  print("Recieved packet data...")
  # The base64 blob in the log decodes to the standard '.eml' format, that .eml msg has a base64 email body which is the pcap content
  captureData = response['tasks'][0]['task-details'][0]['attachments'][0]['base64-data']
  # print(captureData)
  # print (type(captureData))
  captureData = str(captureData)
  filename,pcapBase64 = parseEml(captureData)
  writePcap(filename,pcapBase64)
  break
 time.sleep(5)

print("Done.")
print()
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 16 Feb 2021 14:08:13 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Fetching-PCAP-via-API-in-R80-30-JHF-111/m-p/110922#M5587</guid>
      <dc:creator>Martin_Valenta</dc:creator>
      <dc:date>2021-02-16T14:08:13Z</dc:date>
    </item>
  </channel>
</rss>

