Repository navigation
feat: [cape_sandbox] add sample submission and report enrichment - #1065
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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.") |
There was a problem hiding this comment.
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 👍 / 👎.
| 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()) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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 👍 / 👎.
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.69swithpytest -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.