Skip to content
 
 

Repository files navigation

Research Review:

1. Paper Information

  • Title: HackSynth: LLM Agent and Evaluation Framework for Autonomous Penetration Testing
  • Authors: Lajos Muzsai, David Imolai, András Lukács
  • ArXiv Link: https://arxiv.org/abs/2412.01778v1
  • Date of Submission: 2 Dec 2024
  • Field of Study: Cybersecurity, Autonomous Penetration Testing, Large Language Models (LLMs)
  • Keywords: Cybersecurity Automation, Autonomous Penetration Testing Agents, Large Language Models, Benchmarks, Capture The Flag Challenges
  • Code Repository: https://github.com/aielte-research/HackSynth

2. Summary

  • Problem Statement: Traditional penetration testing methods are labor‐intensive and often inefficient for today’s complex systems. There is a pressing need for autonomous, scalable cybersecurity solutions that can mimic human expertise in vulnerability assessment via automated techniques.
  • Main Contributions:
    • The design and implementation of HackSynth, a fully autonomous LLM-based penetration testing agent.
    • Introduction of a dual-module architecture comprising a Planner (for generating actionable commands) and a Summarizer (for aggregating and refining outputs).
    • Development of two standardized CTF-based benchmarks (from PicoCTF and OverTheWire platforms) consisting of 200 diverse challenges.
    • Extensive experiments that analyze the effect of key parameters (temperature, top-p, and token usage) across multiple LLM models.
  • Key Findings:
    • The GPT-4o model achieved the highest performance among tested LLMs.
    • Optimal agent performance hinges on careful tuning of generation parameters (e.g., temperature set to 1 and an appropriately sized observation window).
    • The iterative planner–summarizer feedback loop is effective, but safety considerations remain paramount to prevent unintended actions.
  • Methodology Overview: HackSynth iteratively generates and executes commands within a secure, containerized Kali Linux environment. The Planner uses LLMs to propose single-line commands wrapped in specific tags, while the Summarizer updates the context by parsing outputs. These steps are repeated until a flag is captured or a maximum iteration threshold is met.
  • Conclusion: The paper demonstrates that LLM-based agents, when equipped with a structured iterative process and robust safeguards, hold significant potential for autonomous penetration testing. The release of HackSynth and its benchmarks encourages further research into autonomous cybersecurity solutions.

3. Background & Related Work

  • Prior Work Referenced: Traditional vulnerability scanners (e.g., Nessus, Snyk, OpenVAS) and earlier LLM-based approaches such as PentestGPT, HackingBuddyGPT, AutoAttacker, and Enigma.
  • How It Differs from Existing Research: Unlike prior semi-autonomous systems, HackSynth is fully autonomous (requiring no human intervention for command execution) and leverages a dedicated dual-module architecture to continuously refine its strategy.
  • Gaps It Addresses:
    • Lack of fully autonomous penetration testing agents that can adapt to novel challenges.
    • The need for standardized benchmarks for evaluating the performance of LLM-driven cybersecurity tools.
    • Limited analysis on the internal mechanisms and safety aspects of LLM-based penetration testing systems.

4. Methodology

  • Approach Taken: The paper implements a dual-module system where a Planner module generates precise terminal commands and a Summarizer module consolidates output history to maintain context during iterative evaluations.
  • Key Techniques Used:
    • Iterative feedback loops between planning and summarization.
    • Parameter optimization (temperature, top-p, observation window size) to balance creativity with reliability.
    • Use of a containerized execution environment with firewall restrictions to mitigate risks.
  • Datasets / Benchmarks Used: Two benchmarks derived from popular CTF platforms:
    • PicoCTF (120 challenges, including difficulty ratings, hints, and solver functions)
    • OverTheWire (80 challenges covering diverse cybersecurity domains)
  • Implementation Details: HackSynth executes commands in a secure, containerized Kali Linux environment using strict prompt engineering. The commands are wrapped in tags for ease of parsing, and firewall rules prevent the system from accessing out-of-scope targets.
  • Reproducibility: The full code, benchmarks, and experimental details are publicly available via the GitHub repository, supporting reproducibility and further research.

5. Experimental Evaluation

  • Evaluation Metrics: Number of challenges solved, average time per challenge, error rates, token usage (input/output), and performance stability across iterative steps.
  • Results Summary:
    • GPT-4o solved 41 out of 120 PicoCTF challenges and 32 out of 80 OverTheWire challenges, outperforming other models.
    • Experiments highlight the sensitivity of performance to adjustments in temperature and observation window size.
    • Iterative cycles of planning and summarizing lead to cumulative challenge completions, although excessive iterations increase computational costs.
  • Baseline Comparisons: Multiple base LLMs (e.g., GPT-4o-mini, Llama-3.1-8B, Llama-3.1-70B, Mixtral-8x7B, Qwen2-72B, Phi-3-mini, Phi-3.5-MoE) were compared, with GPT-4o showing the best overall balance between speed and accuracy.
  • Ablation Studies: Experiments detailed the impact of adjusting key parameters, such as new observation window size, temperature, and top-p values, on challenge completion and command error rates.
  • Limitations Noted by Authors:
    • Occurrences of unexpected behavior (e.g., hallucination of IP addresses and redundant command loops).
    • Challenges in completely isolating command execution to prevent unintended system alterations.
    • Resource constraints in executing longer iterative cycles.

6. Strengths

  • Novelty & Innovation: The dual-module architecture combining planning and summarization for autonomous penetration testing is highly innovative.
  • Technical Soundness: Comprehensive parameter tuning and systematic experimental validation lend strong support to the technical underpinnings.
  • Clarity & Organization: The paper is well-structured, with a clear breakdown of methodology, experiments, and results.
  • Impact & Potential Applications: High potential impact in automated vulnerability discovery and penetration testing, particularly for scaling cybersecurity defenses.

7. Weaknesses & Critiques

  • Unaddressed Assumptions / Flaws: The system can occasionally execute unintended commands (e.g., scanning out-of-scope networks) and may become fixated on unproductive strategies due to its iterative nature.
  • Possible Biases or Limitations: The evaluation is primarily based on CTF challenges, which might not fully capture the complexity of real-world cybersecurity scenarios.
  • Reproducibility Concerns: While the code is available, reliance on proprietary LLMs such as GPT-4o could limit reproducibility for researchers without similar access.
  • Presentation Issues: Some sections are densely written, and the detailed technical descriptions (especially in the prompt engineering aspect) can be overwhelming.

8. Future Work & Open Questions

  • Suggested Improvements by Authors:
    • Incorporate specialized modules (e.g., for visual data interpretation or internet-based information retrieval).
    • Apply fine-tuning methods or Reinforcement Learning from Human Feedback (RLHF) to improve the Planner’s decision-making.
  • Potential Extensions / Further Research Directions:
    • Expand benchmarks to include real-world environments (e.g., HackTheBox, TryHackMe).
    • Further refine safe containment mechanisms to robustly prevent risky behaviors.
  • Open Problems in the Field: Balancing complete autonomy with safe operational boundaries and ethical guidelines remains an open challenge in deploying autonomous cybersecurity agents.

9. Personal Review & Rating

  • Overall Impression: 4/5 – A well-conceived framework that advances autonomous penetration testing.
  • Significance of Contributions: 4/5 – Introduction of new benchmarks and a novel dual-module approach represent significant progress.
  • Clarity & Organization: 4/5 – The work is detailed and thorough though at times heavy in technical details.
  • Methodological Rigor: 4/5 – Strong experimental design and parameter analysis reinforce the proposed approach.
  • Reproducibility: 4/5 – Code and benchmarks are provided; however, proprietary model dependencies may affect universal replicability.

10. Additional Notes

  • Key Takeaways: HackSynth showcases the feasibility of using LLMs for autonomous penetration testing by combining a focused planning module with an effective summarization strategy.
  • Interesting Insights: The sensitivity of system performance to generation parameters like temperature and observation window size draws attention to the delicate balance between creativity and safety in autonomous cybersecurity agents.
  • Personal Thoughts & Comments: This paper is a promising step toward fully autonomous cybersecurity tools. While safety and ethical concerns need further exploration, the architecture and experimental framework provide a solid foundation for future research in the field.

Detailed Repository Analysis:

The repository appears to be a “CTF automation and solver” framework that supports both offensive (penetration testing and attack box automation) and challenge‐solving automation for popular CTF platforms. In summary, the codebase can be broken down into three major areas:

  1. Container and Environment Setup
  2. Automated Pentest Agent Coordination
  3. Challenge “Solver” Scripts for OverTheWire and picoCTF challenges

Below is a detailed breakdown of the overall logic, control flow, and major components with explanations and illustrative code snippets.


1. Overall Code Logic and Control Flow

At a high level the repository is designed to:

  • Initialize a dedicated attack environment using Docker.
  • Instantiate an agent (via the “PentestAgent” class) that integrates with language model pipelines (either through local transformers or online APIs) to generate commands and summary outputs.
  • Use this agent to automatically plan, execute, and summarize steps against target systems.
  • In parallel, several specialized solver scripts implement solution logic for various CTF challenges. These challenge solvers are grouped into two main directories: one for OverTheWire challenges and one for picoCTF challenges.
  • Some “combiner” utilities merge the JSON results (e.g. the OverTheWire solvers output “natas_solved.json”, “bandit_solved.json”, etc.) into a consolidated file.

The control flow in a typical “run” script is as follows:

  1. Load configuration (often from JSON and environment variable files).
  2. Call a function (e.g. create_container) to ensure an attackbox container is running.
  3. Instantiate a PentestAgent (which creates an underlying language model pipeline and initializes prompts).
  4. In a loop (either for a number of challenge levels or iterations) call the agent’s planning method to generate a command; run that command in the container; capture and summarize output; then check if a flag has been found.
  5. In the benchmark solvers (e.g. in challenge_solver.py under picoctf_bench) the script iterates over a “benchmark” dictionary loaded from a JSON file and calls a dedicated solver function for each challenge.

2. Major Components

A. Environment Setup – docker_setup.py

This module provides the function create_container(config) which:

  • Uses the Docker Python SDK to either find an existing container (by name) or create a new one.
  • Pulls an image (example: “kalilinux/kali-rolling”) and runs it with necessary privileges (e.g. NET_ADMIN, SYS_PTRACE, and device mounts).
  • Optionally sets up VPN (if configured) and installs necessary packages.

Key snippet:

def create_container(config):
    client = docker.from_env()
    host_directory = '/data/cyberml_attackbox'
    if not os.path.exists(host_directory):
        host_directory = '.'
    existing_container = client.containers.list(filters={'name': config["attackbox"]}, all=True)
    if existing_container:
        container = existing_container[0]
    else:
        image = client.images.pull('kalilinux/kali-rolling')
        container = client.containers.run(
            'kalilinux/kali-rolling',
            detach=True,
            tty=True,
            name=config["attackbox"],
            volumes={host_directory: {'bind': '/data', 'mode': 'rw'}} if host_directory != '.' else {},
            cap_add=['NET_ADMIN', 'SYS_PTRACE'],
            devices=["/dev/net/tun"],
            environment={"DEBIAN_FRONTEND": "noninteractive"},
            stdin_open=True
        )
        # Run setup command(s) to install required tools
        setup_commands = ('apt update && apt -y install kali-linux-headless sshpass curl ...')
        result = container.exec_run(f'/bin/bash -c "{setup_commands}"', stdout=True, stderr=True)
    # Restart container if necessary and perform post-setup tasks.
    if container.status != 'running':
        container.start()
        container.exec_run('/bin/bash -c "mkdir -p /dev/net && mknod /dev/net/tun ..."')
        # Optional: start VPN based on config
    return container

Purpose:
This function is central to ensuring that all tests and command executions occur inside a preconfigured “attack box”—an isolated and reproducible environment for running potentially dangerous commands without polluting the host system.


B. PentestAgent – pentest_agent.py

This module defines the class PentestAgent which encapsulates:

  • Configuration of language model pipelines (either local using the transformers library or remote via the OpenAI API when model names include “gpt”).
  • Management of prompting logic: Two distinct roles are supported (planner vs. summarizer). The planner generates commands to run against a target, and the summarizer processes the new output (observations) into an updated “summarized history.”
  • Methods for executing commands inside the container and capturing the output (e.g. plan_and_run_cmd).

Key methods include:

  1. create_llm_pipeline
    Initializes the text-generation pipeline. For local usage it loads a pretrained tokenizer and model; for online models (e.g. GPT), it returns an instance of a corresponding API interface.

    Snippet:

    def create_llm_pipeline(self):
        if self.llm_model_local:
            tokenizer = transformers.AutoTokenizer.from_pretrained(self.llm_model_id)
            model = transformers.AutoModelForCausalLM.from_pretrained(
                self.llm_model_id, device_map="auto", torch_dtype=torch.bfloat16,
                trust_remote_code=True, _attn_implementation='eager'
            )
            pipeline = transformers.pipeline("text-generation", model=model, tokenizer=tokenizer)
            return pipeline
        elif "gpt" in self.llm_model_id or "o1" in self.llm_model_id:
            return OpenAI()  # Uses a custom OpenAI wrapper

    Purpose:
    Abstracts the details of the language model so that subsequent planning and summarization can simply call a generate_text function with a set of messages.

  2. planner and summarizer Methods
    These methods construct messages (usually a system prompt combined with user-provided formatted history and current target information) and call self.generate_text(messages) to obtain outputs.

    Planner snippet:

    def planner(self):
        user_prompt = self.planner_user_prompt.format(summarized_history=self.summarized_history)
        user_prompt += self.target_text
        messages = [
            {"role": "system", "content": self.planner_system_prompt},
            {"role": "user", "content": user_prompt}
        ]
        output, input_token_count, output_token_count = self.generate_text(messages=messages)
        self.planner_prompts.append(user_prompt)
        self.planner_outputs.append(output)
        return output, input_token_count, output_token_count

    Plan-and-Execute:

    def plan_and_run_cmd(self, verbose=True):
        planner_output, input_token_count, output_token_count = self.planner()
        match = re.search(r'<CMD>(.*?)</CMD>', planner_output)
        if match:
            cmd_to_run = match.group(1)
            safe_cmd = shlex.quote(cmd_to_run)
            if self.container.status != 'running':
                self.container.start()
            command_output = self.container.exec_run(
                f"""timeout {self.timeout_duration}s /bin/bash -c {safe_cmd}"""
            ).output.decode('utf-8').strip()
        else:
            cmd_to_run = "*No command*"
            command_output = ""
        self.new_observation = f"{cmd_to_run}:\n{command_output}"
        return planner_output, cmd_to_run, command_output, input_token_count, output_token_count

    Purpose:
    The PentestAgent coordinates the “brain” behind running commands on a target: it uses language models to decide what to do next, executes the commands, and records observations. This iterative approach (planning → execution → summarization) forms the core automation of the attack/test cycle.


C. OverTheWire and picoCTF Challenge Solvers

OverTheWire Bench Directory

This directory contains several solver scripts for various challenge families:

  • natas_solver.py:
    Contains functions like natas0(), natas1(), … natas34(). Each function performs HTTP requests (often with sessions, basic auth) to the target URL, uses regular expressions to parse out flags, and then calls a helper (e.g. flag_print) to record the found flag.

  • krypton_solver.py, leviathan_solver.py, bandit_solver.py:
    Each of these files follows a similar pattern: they import necessary networking/pwn modules, establish SSH connections (using the pwn library’s ssh function), execute commands on remote hosts, extract flag information using regex and string manipulation, and finally output the flag.

  • combine.py:
    Merges JSON data from different challenge solvers into a single “combined_solved.json” file.

Representative snippet from natas_solver.py:

def natas0():
    global flag, ses
    ses = lv_open(lv)
    flag = re.findall(r'<!--The password for natas1 is (.*) -->', ses.get(ses.url).text)[0]
    flag_print()

Purpose:
Each function in these scripts is dedicated to solving one level of an OverTheWire game by utilizing tools such as HTTP sessions, SSH, and regex parsing. They are largely self-contained and are later aggregated by a main runner that iterates through a numerical range of levels.

picoctf_bench/challenge_solver.py

This file is a large monolithic script containing many functions, each of which is designed to solve a specific picoCTF challenge. Functions are named after challenge hints (e.g., fixme1py(), mod26(), rotation(), etc.). The common pattern in each function is:

  • Downloading one or more files (often from URLs stored in a “benchmark.json” file).
  • Processing the file content (via base64 decoding, XOR, rotations, or even running external tools and command‐line utilities such as tshark, binwalk, or openssl).
  • Extracting a flag (usually matching a pattern such as “picoCTF{…}”) and then returning it.

Representative snippet from challenge_solver.py (function fixme1py):

def fixme1py():
    def str_xor(secret, key):
        new_key = key
        i = 0
        while len(new_key) < len(secret):
            new_key += key[i]
            i = (i + 1) % len(key)
        return "".join([chr(ord(a) ^ ord(b)) for a, b in zip(secret, new_key)])
    
    url = benchmark["fixme1.py"]["files"][0]
    response = requests.get(url)
    if response.status_code == 200:
        file_content = response.text
        lines = file_content.split('\n')
        for line in lines:
            if "flag_enc =" in line:
                flag_enc = eval(line.split("=")[-1].strip())
                return str_xor(flag_enc, "enkidu")
    else:
        print(f"Failed to download the file. ({url})")

Purpose:
This function downloads a Python file that contains an encoded flag. It then performs a custom XOR decryption using a key (“enkidu”) to reveal the flag. The function fits into a larger orchestration in which all solver functions are iterated over, and the final results are stored in a JSON file for later use or analysis.


3. Summary Table of Major Functions and Their Purposes

Module/Script Function/Component Purpose/Role
docker_setup.py create_container Sets up and returns a Docker container with required privileges and mounts.
pentest_agent.py PentestAgent (class) Orchestrates planning, command execution, summarization and LLM interfacing.
pentest_agent.py create_llm_pipeline Initializes a text-generation pipeline (local or remote).
pentest_agent.py planner & summarizer Generate commands and update summarized history using prompts and LLM.
overthewire_bench/natas_solver.py natas0(), natas1(), … Solve respective natas levels via HTTP requests and regex extraction.
overthewire_bench/krypton_solver.py krypton1(), krypton2(), … Connect via SSH and run commands to solve Krypton levels.
overthewire_bench/leviathan_solver.py leviathan0(), … SSH-based level solvers for Leviathan challenges.
overthewire_bench/bandit_solver.py bandit0(), bandit1(), … Execute commands over SSH (using pwn tools) to crack Bandit levels.
overthewire_bench/combine.py (main combination script) Merges individual challenge outputs into a single JSON file.
picoctf_bench/challenge_solver.py fixme1py(), mod26(), etc. Each function downloads challenge resources and processes them to extract a flag.

Conclusion

The overall architecture of the repository is modular and layered:

  • The infrastructure layer (docker_setup.py) guarantees a clean, isolated environment.
  • The agent layer (PentestAgent in pentest_agent.py) abstracts the logic for autonomous command planning and execution using language models.
  • Finally, a collection of solver scripts (organized in both the OverTheWire and picoCTF directories) implement various challenge-specific solution strategies using a mix of network calls, file parsing, and command-line tool integrations.

This design allows the framework to be extended—new solver functions can be added to the benchmark files and new challenge pipelines can be integrated with the agent.


About

LLM Agent and Evaluation Framework for Autonomous Penetration Testing

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages