Skip to content

Add PCAP import module for files, email and network indicators - #1010

Merged
adulau merged 2 commits into
mainfrom
codex/pcap-import-397
Oct 26, 2026
Merged

adulau merged 2 commits into
mainfrom
codex/pcap-import-397

Conversation

@adulau

@adulau adulau commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Closes #397.

Adds pcap_import to import PCAP and PCAPNG captures into MISP. TShark handles offline decoding and TCP reassembly, including out-of-order segments and retransmissions. The module returns IPv4/IPv6 endpoints, DNS names and answers, HTTP URLs/hosts/user agents, and TLS SNI hostnames. Observed network attributes have to_ids disabled for analyst review.

HTTP payloads become file objects with hashes and data. Reassembled SMTP messages reuse email_import to produce email objects, attachments and body URLs; malformed messages are preserved as files. Also fixes the email importer's plain-text URL matching to retain paths, queries and fragments, while skipping malformed URLs that raise PyMISP parser exceptions.

Requires TShark >= 4.0 and PyMISP's email/fileobjects extras. Payload extraction requires complete, unencrypted HTTP/SMTP traffic; HTTPS provides visible TLS metadata only. Includes capture-size validation, configurable subprocess timeout, temporary-file cleanup, module documentation, and TShark installation in CI. JSON metadata, combined HTTP/SMTP exports, and diagnostic output are monitored every 50 ms while TShark runs; exceeding a limit kills and reaps the process. Checks also run after exit. Bursts can overshoot between polls, so this monitoring is not a filesystem quota.

Validation:

  • 55 focused tests passed, including real synthetic PCAP/PCAPNG captures, IPv4/IPv6, DNS, TLS SNI, HTTP file reassembly, SMTP attachments, malformed input and URLs, timeout cleanup, and live output limits. Regression tests use real child processes to verify termination/reaping and cleanup on metadata, HTTP, SMTP, combined-export, and diagnostic overflow; a real gzip-compressed HTTP capture verifies the decompression expansion case.
  • Live module-server smoke test confirmed discovery in /modules and successful capture import through /query.
  • Flake8, isort and diff whitespace checks passed; new Python files pass Black.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T09:28:04.331348Z e178209 PR opened
🔒 Security Review ✅ Completed 2026-10-26T09:30:53.630998Z e178209 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e178209652

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

else:
urls = re.findall(
r"https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+",
r"""https?://[^\s<>"']+""",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Catch parser errors from broadened URL matches

The broader pattern now matches common defanged or malformed text such as http://example[.]com and http://:, but URLObject can reject these with MISPObjectException rather than the currently caught ValueError. In an email containing such text, URL extraction therefore aborts the entire import and the module server returns its generic failure response instead of skipping the invalid URL; catch the PyMISP parser exception or validate these broader matches first.

Useful? React with 👍 / 👎.

Comment on lines +155 to +156
if report.stat().st_size > MAX_OUTPUT_SIZE:
raise ValueError("The capture's JSON metadata exceeds the 100 MiB limit.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce output caps while TShark is running

For a capture containing many small packets or highly compressed HTTP content, TShark can write far beyond 100 MiB to packets.json and the export directories before this check runs. TShark documents that --export-objects saves every object directly into the destination directory, so the later size checks do not actually protect the service filesystem from exhaustion; monitor and terminate the subprocess at the configured limit or run it under an enforced storage quota.

Useful? React with 👍 / 👎.

@adulau
adulau merged commit bc45722 into main Oct 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pcap import module

1 participant