add-function-scope-call-chain-matching-across-call-graph - #2910
add-function-scope-call-chain-matching-across-call-graph#2910akshat4703 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances capa's capability to identify complex malicious behaviors by introducing "call-chain" rules. These rules allow analysts to define and detect sequences of API calls that occur across different functions within a program, leveraging the function call graph. This enables the detection of multi-stage attacks or sophisticated malware techniques that would be difficult to capture with single-function rules, thereby improving the accuracy and depth of threat intelligence. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
CHANGELOG updated or no update needed, thanks! 😄
There was a problem hiding this comment.
Code Review
This pull request introduces support for call-chain rules to detect behaviors spanning multiple functions. The implementation is well-structured, involving a two-pass analysis for static capabilities, a new CallChain feature and statement type, and logic for building a call graph and resolving call chains. The changes are accompanied by good tests. I've found one critical issue related to a merge conflict marker and one suggestion for improving type hints for better maintainability.
|
we're not going to consider major features like this without prior planning and research. |
Summary
Add support for call-chain rules that allow capa to detect behaviors
spread across multiple functions.
This PR introduces a new feature type that enables rules to match ordered
sequences of APIs across function boundaries using the program call graph.
This allows capa to detect multi-stage behaviors that are implemented across
several functions.
Example rule syntax:
features:
Motivation
Many malware capabilities are implemented across multiple functions.
For example, one function may decrypt data, another establish a network
connection, and a third execute a command. Individually these functions
may not trigger meaningful rules, but together they represent a clear
malicious capability.
This change enables capa rules to express such multi-function behavior
using ordered API sequences derived from the function call graph.
Implementation
This PR introduces the following changes:
Call-chain feature support
CallChainfeature type.Call graph construction
Call-chain resolution pipeline
The static capabilities pipeline is extended to:
This allows call-chain features to integrate naturally with existing
function-scope matching logic.
Rule Syntax
Example rule:
features:
This rule matches when the ordered API sequence appears across
reachable functions in the call graph.
Files Changed
Core changes:
Tests:
Validation
Executed the following test suite:
PYTHONPATH=. ./venv/bin/pytest -q
tests/test_engine.py
tests/test_rules.py
tests/test_call_chain.py
tests/test_capabilities.py
Result:
67 passed
Notes
The implementation integrates with the existing capa rule engine and
feature extraction pipeline without modifying existing rule behavior.
This change enables richer behavioral detection by allowing rules to
capture multi-function workflows present in real-world malware.