๐ฌ LLM Vulnerability DetectionMay 28, 2026โ
Tests passing
Code Diff Exploit Simulator
This tool uses a single LLM to analyze differences between two versions of a codebase (e.g., pre- and post-commit) and predict whether the changes may introduce vulnerabilities. It can also attempt to simulate how an exploit would function based on the detected changes.
What It Does
- Analyze code differences between two directories containing code files.
- Use OpenAI's GPT model to predict potential vulnerabilities in the code changes.
- Generate a detailed vulnerability assessment report.
Installation
- Python 3.7+
openairich
Usage
python code_diff_exploit_simulator.py --old_version ./old_code --new_version ./new_code --output ./report.txtSource Code
import os
import difflib
import argparse
from rich.console import Console
from rich.table import Table
import openai
def analyze_code_diff(old_version_path, new_version_path):
"""
Analyze differences between two codebases and predict potential vulnerabilities.
Args:
old_version_path (str): Path to the old version of the codebase.
new_version_path (str): Path to the new version of the codebase.
Returns:
list: List of potential vulnerabilities detected.
"""
vulnerabilities = []
console = Console()
if not os.path.exists(old_version_path) or not os.path.exists(new_version_path):
console.print("[red]Error: One or both paths do not exist.[/red]")
return vulnerabilities
if os.path.isdir(old_version_path) and os.path.isdir(new_version_path):
old_files = {f: os.path.join(old_version_path, f) for f in os.listdir(old_version_path)}
new_files = {f: os.path.join(new_version_path, f) for f in os.listdir(new_version_path)}
common_files = set(old_files.keys()) & set(new_files.keys())
for file_name in common_files:
with open(old_files[file_name], 'r') as old_file, open(new_files[file_name], 'r') as new_file:
old_content = old_file.readlines()
new_content = new_file.readlines()
diff = difflib.unified_diff(old_content, new_content, lineterm='')
diff_text = '\n'.join(diff)
if diff_text:
response = predict_vulnerability(diff_text)
vulnerabilities.append((file_name, response))
else:
console.print("[red]Error: Both paths must be directories containing code files.[/red]")
return vulnerabilities
def predict_vulnerability(diff_text):
"""
Use OpenAI's API to predict vulnerabilities based on code diff.
Args:
diff_text (str): Unified diff text.
Returns:
str: Predicted vulnerability description.
"""
try:
response = openai.Completion.create(
model="text-davinci-003",
prompt=f"Analyze the following code diff and predict potential vulnerabilities:\n{diff_text}",
max_tokens=100
)
return response['choices'][0]['text'].strip()
except Exception as e:
return f"Error during vulnerability prediction: {e}"
def generate_report(vulnerabilities, output_path):
"""
Generate a vulnerability assessment report.
Args:
vulnerabilities (list): List of vulnerabilities detected.
output_path (str): Path to save the report.
"""
console = Console()
table = Table(title="Vulnerability Assessment Report")
table.add_column("File", style="cyan")
table.add_column("Vulnerability", style="red")
for file_name, vulnerability in vulnerabilities:
table.add_row(file_name, vulnerability)
if output_path:
with open(output_path, 'w') as report_file:
report_file.write(str(table))
console.print(f"[green]Report saved to {output_path}[/green]")
else:
console.print(table)
def main():
parser = argparse.ArgumentParser(description="Code Diff Exploit Simulator")
parser.add_argument('--old_version', required=True, help="Path to the old version of the codebase")
parser.add_argument('--new_version', required=True, help="Path to the new version of the codebase")
parser.add_argument('--output', help="Path to save the vulnerability assessment report")
args = parser.parse_args()
vulnerabilities = analyze_code_diff(args.old_version, args.new_version)
generate_report(vulnerabilities, args.output)
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- code_diff_exploit_simulator
- Category
- LLM Vulnerability Detection
- Generated
- May 28, 2026
- Tests
- Passing โ
- Fix Loops
- 2
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-05-28/code_diff_exploit_simulator cd generated_tools/2026-05-28/code_diff_exploit_simulator pip install -r requirements.txt 2>/dev/null || true python code_diff_exploit_simulator.py