Skip to content

feat: [cape_sandbox] add sample submission and report enrichment - #1065

Merged
adulau merged 2 commits into
mainfrom
codex/enrich-cape_sandbox
Oct 30, 2026
Merged

adulau merged 2 commits into
mainfrom
codex/enrich-cape_sandbox

Conversation

@adulau

@adulau adulau commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Analysts can submit supplied files to CAPEv2 with explicit submit_samples configuration and retrieve completed reports by numeric task ID. Reports yield hashes, network indicators and extracted configurations. Submission receipts carry task IDs for later retrieval. Payload sizes, TLS verification, timeouts and sanitized error handling are covered.

Includes a usage guide and focused adapter tests.

Validation: 19 passed, 1 warning in 0.69s with pytest -q tests/test_cape_sandbox.py; flake8 passed for the module. The combined enrichment regression check passed 389 tests.

Authenticated provider API validation remains pending. Tests use sanitized fixtures; no provider credentials are included.

Review updates: Handle current MISP sample ZIP sidecars, verify declared MD5, preserve pipes in filenames, and classify sandbox reports with the CAPE provider relation.

Updated validation: 22 passed, 1 warning in 0.67s; module lint passed. Combined regression validation passed 409 tests.

Companion provider suggestions: MISP/misp-objects#552. The adapters use the existing sandbox-report relations.

@adulau
adulau marked this pull request as ready for review October 29, 2026 22:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-29T22:12:20.414475Z 0e98cd5 Draft marked ready
🔒 Security Review ✅ Completed 2026-10-29T22:15:44.806033Z 0e98cd5 Draft marked ready
ℹ️ 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: 0e98cd5630

ℹ️ 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".

Comment on lines +138 to +140
entries = [entry for entry in archive.infolist() if not entry.is_dir()]
if len(entries) != 1 or entries[0].file_size > limit:
raise ModuleError("A malware-sample archive must contain one file within max_size_mb.")

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 Accept current MISP malware-sample archives

Current MISP malware-sample ZIPs normally contain both the sample named by its MD5 and a <md5>.filename.txt metadata member (as handled by the existing bingraph and manalyze modules). Because every non-directory member is counted here, these standard two-member archives always fail len(entries) != 1, so the advertised malware-sample submission path rejects ordinary current MISP input. Ignore the filename metadata member and select the actual sample before enforcing the single-sample check.

Useful? React with 👍 / 👎.

Comment on lines +141 to +144
content = archive.read(entries[0], pwd=b"infected")
if not filename or not content or len(content) > limit:
raise ModuleError("The sample is empty or exceeds max_size_mb.")
return (filename, content, hashlib.sha256(content).hexdigest())

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 Verify the unpacked sample against its declared MD5

For a malware-sample whose ZIP data is stale, corrupted, or mismatched with its filename|md5 value, this code submits the unpacked bytes without ever checking the declared MD5. CAPE can therefore analyze a different binary while the resulting receipt remains referenced to the original MISP attribute; parse the digest from the composite value and reject the submission when it does not match the unpacked content.

Useful? React with 👍 / 👎.

if not isinstance(encoded, str) or len(encoded) > 2 * limit:
raise ModuleError("Missing or oversized base64 sample data.")
content = base64.b64decode(encoded, validate=True)
filename = attribute["value"].split("|", 1)[0].replace("\\", "/").rsplit("/", 1)[-1]

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 Preserve pipes in sample filenames

When a valid malware-sample filename itself contains | (for example sample|name.exe|<md5>), splitting at the first delimiter reduces the submitted filename to sample, losing its basename and extension. That can change CAPE's package selection or analysis behavior; split the malware-sample composite value at the final delimiter instead, while leaving attachment filenames intact.

Useful? React with 👍 / 👎.

@adulau
adulau merged commit fa46836 into main Oct 30, 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.

1 participant