Repository navigation
feat: [fortisandbox] add hash ratings and sample submissions - #1066
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: aac05f919b
ℹ️ 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".
| "/alert/ondemand/submit-file", | ||
| session, | ||
| type="file", | ||
| filename=sample[0], |
There was a problem hiding this comment.
Base64-encode filenames before submitting samples
When submit_samples reaches this branch, the FortiSandbox JSON API requires both file and filename to be base64-encoded; sending the plain attribute filename causes the appliance to return FILENAME_NOT_ENCODED, so compliant appliances reject every sample submission. The filename should be encoded just like the file contents. See the FortiSandbox JSON API Reference.
Useful? React with 👍 / 👎.
| if isinstance(payload, list): | ||
| payload = payload[0] if payload else {} | ||
| rating = payload.get("rating") if isinstance(payload, dict) else None | ||
| if rating is not None and str(rating).lower() not in ("unknown", ""): |
There was a problem hiding this comment.
Normalize rating arrays before deciding to submit
FortiSandbox returns rating as an array, including for a single file (for example, ["Unknown"]). Converting that array to a string produces "['unknown']", which is not equal to "unknown", so an unknown sample is incorrectly emitted as a completed sandbox report and the submit_samples branch is skipped. Inspect the array elements rather than stringifying the container. See the documented rating response.
Useful? React with 👍 / 👎.
| entries = [entry for entry in archive.infolist() if not entry.is_dir()] | ||
| if len(entries) != 1 or entries[0].file_size > limit: |
There was a problem hiding this comment.
Ignore MISP filename metadata when unpacking samples
Current MISP malware-sample archives normally contain the binary plus a <md5>.filename.txt metadata member, as handled in bingraph.py:79-86. Counting every non-directory member therefore rejects standard MISP samples with the “must contain one file” error before lookup or submission; exclude the metadata member and require one remaining payload.
Useful? React with 👍 / 👎.
| if kind in ("attachment", "malware-sample"): | ||
| sample = _binary(attribute, config) | ||
| kind, value = ("sha256", sample[2]) | ||
| _, report = _rpc(base, "get", "/scan/result/filerating", session, checksum=value, ctype=kind) |
There was a problem hiding this comment.
Route MD5 lookups through an endpoint that supports MD5
For an advertised md5 input, this sends ctype="md5" to /scan/result/filerating, but that endpoint's documented contract accepts only sha1 and sha256; affected appliances return INVALID_PARAM instead of an enrichment. FortiSandbox documents MD5 support on the separate multi-file verdict endpoint, so MD5 should use a compatible endpoint or be removed from the declared inputs. See the FortiSandbox filerating contract.
Useful? React with 👍 / 👎.
Analysts can query FortiSandbox ratings by hash using authenticated JSON-RPC. Supplied samples are hashed before lookup; explicit submit_samples configuration permits submission when the rating is unknown. The module returns provider results or a submission receipt, closes sessions after operations and performs no background polling.
Includes a usage guide and focused adapter tests.
Validation:
19 passed, 1 warning in 0.73swithpytest -q tests/test_fortisandbox.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: Encode submission filenames, handle rating arrays, accept current MISP sample archives with digest verification, and classify reports using the appliance provider relation. Remove MD5 from advertised inputs because the single-file rating endpoint supports SHA-1 and SHA-256.
Updated validation: 22 passed, 1 warning in 0.64s; module lint passed. Combined regression validation passed 409 tests.
Companion provider suggestions: MISP/misp-objects#552. The adapters use the existing sandbox-report relations.