🆕 The new HTB Certified Offensive AI Expert (HTB COAE) is officially here! Learn More

AI-Augmented Pentesting Foundations

This module provides a comprehensive introduction to the world of AI-augmented penetration testing. It covers the basic concepts and paradigms, including safe use, prompt engineering, and prompting techniques.

Created by vautia

Easy Offensive

Summary

Note: This module is a bring-your-own-API-key module. To complete the module, you need access to an LLM, for instance, through an API key from any popular LLM provider.

With the rapid advancement of Artificial Intelligence (AI), penetration testing engagements can benefit greatly from AI assistance, increasing efficiency and scalability. AI is a powerful tool that human testers need to learn to use to their advantage.

In this module, we will cover:

  • AI-augmented penetration testing: Foundations of AI assistance in offensive engagements, including benefits, risks, and integration into traditional workflows.
  • Governance: Safely using AI in corporate environments.
  • Prompt engineering: Crafting effective prompts for common penetration testing use cases.
  • Managing the context window: Dealing with large input data from artifacts such as tool outputs to avoid model performance degradation.
  • AI-augmented analysis: Using AI for artifact analysis and the importance of manual verification.

This module is broken into sections with accompanying hands-on exercises to practice each of the tactics and techniques we cover. The module ends with a practical hands-on skills assessment to gauge your understanding of the various topic areas.

You can start and stop the module at any time and pick up where you left off. There is no time limit or "grading", but you must complete all of the exercises and the skills assessment to receive the maximum number of cubes and have this module marked as complete in any paths you have chosen.

As an introductory module, there are no prerequisite modules. However, basic knowledge of Large Language Models (LLMs) is required.

The Role of AI in Penetration Testing


Artificial Intelligence (AI) is rapidly transforming how security professionals approach their work. While traditional methodologies still form the foundation of offensive security, AI introduces a new layer that enhances efficiency, scalability, and analytical capability in security assessments. While it cannot replace a human penetration tester, AI can serve as a powerful tool for processing large amounts of data, generating insights, and streamlining decision-making throughout an engagement. By combining human expertise with AI capabilities, security professionals can work more efficiently and scale their efforts more effectively.

In modern penetration testing, AI integrates into all stages of an engagement, including reconnaissance, enumeration, exploitation, post-exploitation, and reporting. During an engagement, large amounts of data and repetitive tasks are common, particularly when targeting massive corporate networks. When there is a large amount of data, the probability of missing important aspects increases, potentially leading a human tester to miss security misconfigurations or vulnerabilities. AI can be particularly helpful in sifting through noise to identify the most promising services or targets. In particular, AI can help parse and summarize large tool outputs, generating hypotheses about potential vulnerabilities, and helping correlate data from multiple sources and tools.


Modes of Testing

To better understand the value of AI in penetration testing, let us briefly explore three common approaches to security assessments.

Manual Testing

During manual testing, a human executes all tasks manually and makes all decisions. Thus, it is fully human-driven, with no automation, making it highly adaptable, as a human tester can easily pivot and react to unexpected circumstances or target behavior. For instance, if a target handles errors unexpectedly, uses uncommon software stacks, or implements custom authentication flows, human testers can adapt accordingly. Furthermore, an experienced penetration tester has exceptional contextual judgment for the business impact of specific vulnerabilities, as well as for scope constraints or risk trade-offs that may require a change in testing methodology. As such, a human can react to information on the fly and decide to stop probing further to avoid disrupting a service. Alternatively, the tester can decide to contact the client to request permission to proceed. For instance, let us assume we are tasked with performing a network scan of a client's production network. In these networks, we need to avoid disruptions and denial-of-service (DoS) scenarios at all costs to prevent financial harm to the client. Therefore, we should dynamically adjust our testing methodology if we notice that a target system reacts in a way that may indicate potential service disruption in response to our inputs. Manual work typically produces the strongest evidence, including clear reproduction steps and proof of compromise, resulting in a low probability of false positives.

However, manual work is very time- and labor-intensive, making it a slow and expensive process. Due to differences in the experience and skill level of different testers working on an engagement, there is also a higher variance in the results, potentially leading to inconsistencies across testers.

Generally, manual work is the best approach for complex application logic, multi-step workflows, or highly customized applications. It can produce high-quality results, even if careful testing is required.

Automated Testing

On the other hand, traditional automated testing involves predefined scripts and tools that execute certain repeatable tasks automatically. These tools can include scanners (such as Nmap), fuzzers (such as ffuf), and exploitation tools (such as sqlmap).

The advantages of automated testing include repeatability and scalability. It allows for fast execution of predefined tasks, covering a wide range of the penetration testing landscape. The output of automated tools allows for later analysis. However, automation can be brittle in edge cases where the target does not display standard behavior or additional security measures, such as rate-limiters, are implemented, preventing the effective utilization of automated tools. Furthermore, automated tools can produce high noise, including false positives or duplicate findings, requiring manual oversight to filter out useful results.

Overall, automation significantly reduces the time required to execute repetitive tasks during an engagement and enables fast, consistent execution. Ideal use cases for automation are baseline checks, such as TLS configuration, HTTP headers, or port scans that are not particularly prone to errors. The high scalability makes it easy to perform asset discovery and service identification even in large corporate networks. However, the results often require manual interpretation. As such, manual testing and automated testing go hand in hand.

AI-Augmented Testing

Lastly, AI-augmented testing combines the advantages of human expertise with automation by utilizing AI-driven analysis. As such, it bridges the gap between automated and manual testing. The human tester remains the operator but uses AI to accelerate certain tasks, thereby significantly reducing overhead. AI differs from traditional automation in that it can interpret, summarize, and reason about data, rather than simply executing predefined commands. This enables more intelligent workflows, where the output of one step can dynamically influence the next. Generally, AI-augmented testing adheres to the following principle: Automation executes. AI interprets. Humans decide.

When used effectively, AI is a powerful tool that can provide significant support to a human tester. It thrives at summarization of tool output to create structured notes, such as an overview of systems, services or software stacks, pattern recognition to match data-backed behavior to common types of issues, as well as planning and prioritization by proposing hypotheses and suggesting next steps based on tool outputs. Additionally, AI can help in the documentation process by drafting report sections, providing guidance on remediation, or writing executive summaries.

In contrast, AI tends to confidently invent details (hallucinations) such as endpoints, services, or CVEs that do not exist in the provided data. It also lacks environmental awareness as it has no inherent understanding of the target environment or operational security. Most importantly, the AI can never own risk or ethical responsibilities, which always lie with the human tester.

In practice, a good recommendation is to treat AI as a junior analyst that can propose possibilities and provide structured notes, but must be closely supervised and verified. Therefore, AI-augmented workflows must ensure that the human remains in control and the AI cannot autonomously perform actions in the client's network. On top of that, AI output should never be treated as a fact, but rather as a suggestion. Ideally, all AI claims should be tied to solid evidence, such as tool outputs, screenshots, HTTP requests or responses, or log data. We want the AI to generate hypotheses we can verify, rather than conclusions.

The following table provides a summarized overview of the strengths and weaknesses of the three modes of testing:

Mode Strengths Weaknesses Typical Outputs
Manual Testing Adaptability, contextual judgement, strong evidence Slow and time-consuming, inconsistent, low scalability Confirmed findings, detailed risk analysis
Automated Testing Fast, high scalability Noisy, low adaptability, not good with edge cases Scan results, enumeration
AI-Augmented Testing Speed, efficiency, pattern recognition Hallucinations, context drift Summaries, hypotheses, structured plans, draft reporting

AI Use Cases in an Engagement

AI can be most useful when compressing information to find the most relevant data, assisting in generating hypotheses, test cases, or deliverables, or translating information from and to different formats. Some of the most common use cases in an engagement include:

  • Summarizing tool output and generating structured output formats
  • Analyzing source code to identify potential bugs
  • Generating attack hypotheses from noisy enumeration data
  • Prioritizing targets
  • Drafting notes or deliverables, such as findings or remediation advice

Due to its versatility, it has a wide range of use cases across the different phases of a penetration test.

Reconnaissance

During the reconnaissance phase, AI can help convert raw artifacts from automated enumeration tools into structured, summarized data. Clustering and correlating data from different sources can provide a clearer overview of the target as a whole, enabling us to better understand the network or application and improve our ability to identify and exploit vulnerabilities. In this phase, AI's core strength is sifting through noise and extracting the most relevant information.

Testing

In the testing phase, we often have to deal with many different applications and artifacts that we need to interpret and process, for which we can use AI. For instance, in web application and API testing, AI can help interpret response patterns and suggest specific test cases based on observed functionality, identifying likely input points and sensitive endpoints, and assessing whether implemented protective measures, such as input sanitization, are effective. Furthermore, when assessing internal company networks, we typically obtain large amounts of artifacts, similar to those in the reconnaissance phase. These artifacts include BloodHound data, SMB shares, and AD information. By using AI to organize and summarize this information, we can identify repeated patterns, potentially revealing possible privilege escalation or lateral movement vectors. Lastly, AI can also help review source code and configuration files to identify misconfigurations and bugs, or summarize complex logic and unfamiliar patterns, enabling us to understand the target architecture better.

Hypothesis Generation & Attack-path Planning

Aggregating, correlating, and analyzing all information identified during an engagement to generate vulnerability hypotheses and plan attack paths is one of the most crucial tasks in any engagement. Similar to the reconnaissance phase, AI can analyze all artifacts and suggest next steps for potential privilege escalation vectors, assess access-control measures, and identify interesting source code paths worth further review. Furthermore, when dealing with large amounts of artifacts, we need to avoid becoming overwhelmed. AI can help compare data and potential findings, helping to distinguish between low- and high-impact issues. This can be particularly helpful when analyzing large AD environments, where a lack of data is often not an issue, but the challenge lies in effectively prioritizing targets. Keep in mind that all AI-generated hypotheses, plans, and prioritizations need to be verified manually.

Reporting

After the technical part of the engagement is complete, we can use AI to structure our notes or draft parts of the deliverables. Since these tasks are text-heavy, LLMs can provide consistent value. For instance, we can use them to draft finding descriptions, vulnerability impact, or remediation advice. However, human checking for technical accuracy, scope, and completeness is crucial to ensure high-quality deliverables.

AI-augmented reporting can improve consistency across a report when used responsibly. During an engagement, we often capture fragmented notes and evidence such as CLI output and screenshots. AI can draft standardized findings from these unstructured notes. Additionally, AI can generate appropriate remediation advice with the right level of detail, as we typically want to avoid generic advice like "Fix the vulnerability" and instead provide helpful, detailed guidance.

Lastly, as technically skilled testers, it can be difficult to tailor the tone for non-technical audiences. However, when writing executive summaries, it is crucial to convey the most important information about the engagement in a way that the target audience can understand it. In particular, technical teams typically need reproducible steps and command outputs, while executives need information about business impact and risk prioritization without technical details. AI can help adjust our writing style for different target audiences.

Sign Up / Log In to Unlock the Module

Please Sign Up or Log In to unlock the module and access the rest of the sections.