The Problem
Reverse engineering stripped binaries is time-consuming due to the loss of context—function names, type information, and variable names—that makes code readable. The manual process of recovering this context through pattern matching is tedious and repetitive, even for relatively small binaries with a few hundred functions. Existing tools require significant manual intervention, making the process inefficient and error-prone.
What This Does
Kong is an autonomous reverse engineering pipeline that automates the mechanical aspects of binary analysis. It integrates with Ghidra (via kong/ghidra/client.py) to perform a full analysis pipeline, including triaging functions, building call-graph context, recovering types and symbols through LLM-guided decompilation, and writing results back into Ghidra's program database. The key components are:
- Agentic Deobfuscation Pipeline: Located in
kong/agent/deobfuscator.py, this module handles deobfuscation of stripped binaries. - LLM Orchestration: Managed by
kong/llm/client.pyandkong/llm/openai_client.py, this component uses LLMs to infer function names, types, and structures from decompiled code. - Call-Graph Analysis: Implemented in
kong/agent/analyzer.py, this module ensures functions are analyzed in dependency order, leveraging already-resolved context for callees.
The pipeline is designed to be fully autonomous, requiring minimal manual intervention.
How It Is Wired
Execution starts with kong/__main__.py, which orchestrates the entire pipeline. Key control flows include:
- Initialization: The
kong/config.pyfile handles configuration, whilekong/db.pymanages database interactions. - Ghidra Integration: The
kong/ghidra/client.pyfile runs Ghidra's analysis engine in-process, providing direct access to the program database. - Function Analysis: The
kong/agent/analyzer.pyfile performs bottom-up analysis from the call graph, naming leaf functions first. - LLM Interaction: The
kong/llm/client.pyandkong/llm/openai_client.pyfiles handle LLM prompts and responses, enriching the decompiled code with context from cross-references, string references, and caller/callee signatures. - Post-Analysis Synthesis: The
kong/agent/supervisor.pyfile unifies naming conventions and resolves inconsistencies between independently analyzed functions.
The most critical files in terms of blast radius are kong/agent/analyzer.py and kong/llm/client.py, as they are central to the analysis pipeline and LLM interaction.
How To Use It
Setup
To set up Kong, clone the repository and install dependencies:
git clone https://github.com/moses-y/kong
cd kong
pip install -e .
Configuration
Configure Ghidra and LLM credentials in kong/config.py. Ensure you have the necessary environment variables set for API keys and database connections.
Running It
Invoke the main script to start the analysis:
python -m kong <binary_path>
Replace <binary_path> with the path to the binary you want to analyze.
Real-World Use
Kong is particularly useful in scenarios where quick reverse engineering of stripped binaries is required. For example, security researchers can use Kong to analyze malware samples or proprietary binaries, quickly recovering function names and types to understand the code's behavior.
Code Health & Issues
- Tests: 29 test files found, covering various components of the pipeline.
- Documentation: 3 doc files found, providing basic setup and usage information.
- Code Quality: No structural red flags detected. Tests, CI, license, and lockfile are present where expected.
The Bottom Line
Kong provides a valuable solution for automating the tedious aspects of reverse engineering stripped binaries. Its integration with Ghidra and use of LLMs for context-aware analysis makes it a powerful tool for security researchers and reverse engineers. However, the project is still in its early stages, with some components requiring further refinement and testing.