23 May, 2023

AI in Penetration Testing: Exploitation Phase

Penetration Testing as a service (PTaaS)

Tests security measures and simulates attacks to identify weaknesses.

Penetration testing, also known as ethical hacking, is a crucial process that assesses the security of computer systems, networks, and applications. It involves simulating real-world attacks to identify vulnerabilities and weaknesses that malicious actors could exploit. As technology advances and cyber threats become more sophisticated, traditional methods of penetration testing may fall short in uncovering all potential risks. This is where artificial intelligence (AI) steps in to revolutionize the field. 

In the context of penetration testing, AI brings automation, adaptability, and intelligence to the exploitation phase. While human expertise remains crucial, AI augments the capabilities of security professionals by automating repetitive tasks, analyzing vast amounts of data, and generating more efficient and effective attack vectors. 

1.1 Overview of DeepExploit 

DeepExploit is an advanced penetration testing tool that combines the power of AI and automation to streamline the process of generating and launching exploits against target systems. It is designed to assist security professionals in identifying vulnerabilities, generating customized attack vectors, and conducting real-time attack simulations. DeepExploit’s AI algorithms learn from historical attack data, adapt to different environments, and optimize the exploit generation process to increase the success rate of attacks. 

1.2 Purpose and Significance of DeepExploit 

The primary purpose of DeepExploit is to enhance the efficiency and effectiveness of the exploitation phase in penetration testing. By automating the identification of vulnerabilities, generating targeted attack vectors, and adapting to changing environments, DeepExploit enables penetration testers to perform more comprehensive and efficient assessments. It saves valuable time and resources by automating repetitive tasks, allowing testers to focus on analyzing results, validating findings, and recommending mitigations. The significance of DeepExploit lies in its ability to augment human expertise, optimize exploit generation, and provide actionable insights to improve the overall security posture of organizations. 

1.3 Key Features of DeepExploit  

DeepExploit offers several key features that make it a powerful tool for penetration testing: 

1.3.1 AI-powered Exploit Generation: DeepExploit employs machine learning algorithms to analyze a vast amount of historical attack data and generate customized exploits. It can identify patterns, similarities, and vulnerabilities, enabling the tool to generate more effective and targeted attack vectors. 

1.3.2 Automated Attack Vectors: DeepExploit automates the process of generating attack vectors, includin 

g payload creation and customization. It adapts existing exploits to make them more potent, increasing the chances of successful exploitation. 

1.3.3 Real-time Attack Detection: DeepExploit includes real-time monitoring capabilities to detect ongoing attacks. It analyzes network traffic, system logs, and other data sources to identify suspicious activities and enable immediate response and mitigation. 

1.3.4 Comprehensive Reporting: DeepExploit generates detailed reports that provide penetration testers with valuable information about identified vulnerabilities, exploited systems, and recommended mitigations. The tool supports data visualization to aid in understanding the overall security posture of the target environment. 

1.2 Installation and Setup 

DeepExploit is compatible with Linux-based operating systems. It is recommended to use Ubuntu or Kali Linux for the installation. 

Step 1: Git Clone the DeepExploit Repository 

git clone https://github.com/13o-bbr-bbq/machine_learning_security.git 

Step 2: Get python3-pip 

apt-get install python3-pip 

Step 3: Install required python packages. 

cd machine_learning_security/DeepExploit 
pip3 install -r requirements.txt 

Note: If you encounter any errors during the installation process, you may need to modify the versions specified in the requirements file based on the guidance provided by the errors. If you come across an error indicating that the dependencies for freetype and png are missing, you can resolve this issue by installing the libfontconfig1-dev package using the apt-get package manager. By doing so, you will be able to overcome this specific error and proceed with the installation smoothly. 

Step 4: Edit config.ini of DeepExploit 

Match the server_host value with IP address of your Kali Linux. 

Step 5: Edit proxychains.conf 

Match the ProxyList info in the proxychains.conf with the proxy_host and proxy_port in the config.ini. 

proxychains.conf 

config.ini 

Step 6: Initialize Metasploit DB 

You initialize metasploit db (postgreSQL) using msfdb command. 

sudo msfdb init 

Step 7: Make your Current Distro Run Systemd  

By this installation, systemd is enabled in your WSL 2 distro. 

Download and run the latest installer script. 

curl -L -O “https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh” 
chmod +x install.sh 
sudo ./install.sh install 

Enable distrod in your distro and restart the shell. 

sudo /opt/distrod/bin/distrod enable 

Step 8: Launch Metasploit Framework 

Step 9: Launch RPC Server 

load msgrpc ServerHost=192.168.220.144 ServerPort=55553 User=test Pass=test1234 

1.3 Usage: 

Step 1: Train Deep Exploit: 

python3 DeepExploit.py -t <target-IP> -m train 

Step 2: Test using trained Deep Exploit 

python DeepExploit.py -t 192.168.184.129 -m test 

1.5 Benefits of DeepExploit 

The utilization of DeepExploit offers several benefits to both penetration testers and information security officers: 

Improved Test Efficiency: Penetration testers can significantly enhance the efficiency of their tests by leveraging DeepExploit’s automation capabilities. As DeepExploit learns from each test, it improves its exploitation methods, resulting in increased test accuracy over time. 

Rapid Vulnerability Identification: Information security officers can quickly identify vulnerabilities in their servers using DeepExploit. This enables proactive mitigation measures, preventing attackers from exploiting vulnerabilities and safeguarding the organization’s reputation. 

1.6 Limitations: 

While DeepExploit offers significant benefits, it is important to consider its scope and limitations. DeepExploit excels in automating and optimizing exploit generation, but it is not a substitute for human expertise. It requires skilled professionals to interpret results, validate findings, and make informed decisions. Additionally, DeepExploit’s effectiveness may vary depending on the complexity of the target environment and the availability of historical attack data. 

2.1 Other Similar Tool: PentestGPT 

PentestGPT is an innovative tool developed by “GreyDGL,” a Ph.D. student at Nanyang Technological University in Singapore. It is an automated penetration testing tool that utilizes the power of ChatGPT to guide penetration testers through the testing process. Built on top of ChatGPT, PentestGPT operates in an interactive mode, providing assistance and direction to testers in both overall progress and specific operations. To access PentestGPT, being a ChatGPT plus member is required, as it relies on the GPT-4 model for high-quality reasoning. While GPT-4 outperforms GPT-3.5 in penetration testing reasoning, using GPT-4 directly poses challenges in maintaining context during deeper tests. Therefore, PentestGPT employs a wrapper to utilize the ChatGPT session or allows direct usage of the GPT-4 API if available. Unlike AutoGPT, which is not designed for penetration testing and may engage in malicious operations, PentestGPT prioritizes an interactive approach to ensure safer and more controlled testing. 

By combining the power of ChatGPT and the expertise of penetration testers, PentestGPT aims to enhance the effectiveness and efficiency of penetration testing processes. One notable capability of PentestGPT is its ability to solve easy to medium-level challenges such as HackTheBox machines and other CTF (Capture the Flag) challenges. It demonstrates its effectiveness by showcasing an example where it successfully solves the HackTheBox challenge TEMPLATED, which is a web challenge. 

2.2 Prerequisites and Installation 

To install PentestGPT and configure the necessary settings, please follow the steps below: 

Clone the git repository using the command: 

git clone https://github.com/GreyDGL/PentestGPT.git 

Start by installing the required Python dependencies using pip. Open a terminal or command prompt and navigate to the PentestGPT project directory. Then, run the following command: 

pip install -r requirements.txt 

Next, configure the cookies in the config directory. You can use the provided sample configuration file as a template. In the terminal, run the following command to copy the sample configuration file: 

cp config/chatgpt_config_sample.py config/chatgpt_config.py 

Fill in the OpenAI API key in chatgpt_config.py 

To verify that the connection is configured properly, you may run python3 test_connection.py. You should see some sample conversation with ChatGPT. 

You’re connected with ChatGPT Plus cookie.  

To start PentestGPT, please use <python3 main.py –reasoning_model=gpt-4> 

## Test connection for OpenAI api (GPT-4) 

You’re connected with OpenAI API. You have GPT-4 access. To start PentestGPT, please use <python3 main.py –reasoning_model=gpt-4 –useAPI> 

## Test connection for OpenAI api (GPT-3.5) 

You’re connected with OpenAI API. You have GPT-3.5 access. To start PentestGPT, please use <python3 main.py –reasoning_model=gpt-3.5-turbo –useAPI> 

2.3 Usage of PentestGPT: 

To start using PentestGPT, run the main.py script with the necessary arguments. Use the –reasoning_model flag to specify the reasoning model you want to use, and the –useAPI flag if you want to utilize the OpenAI API. It is recommended to choose one of the following combinations suggested by the test_connection.py script: 

python3 main.py –reasoning_model=gpt-4 
python3 main.py –reasoning_model=gpt-4 –useAPI 
python3 main.py –reasoning_model=gpt-3.5-turbo –useAPI 

Once you have started PentestGPT, the tool operates similarly to msfconsole. It provides guidance and support during the penetration testing process. You can interact with PentestGPT by using various commands: 

help: Displays the help message. 

next: Provides the test execution result and proceeds to the next step. 

more: Requests PentestGPT to explain more details about the current step and potentially create a new sub-task to guide the tester. 

todo: Shows the list of tasks that need to be completed. 

discuss: Engages in a discussion with PentestGPT. 

google: Performs a search on Google (this function is still under development). 

quit: Exits the tool and saves the output as a log file (see the reporting section below). 

To input multiple lines, use <SHIFT + right arrow> to end your input. The TAB key can be used for command autocompletion. When presented with a dropdown selection list, navigate through the options using the cursor or arrow keys and press ENTER to select an item. Similarly, <SHIFT + right arrow> can be used to confirm the selection. 

During a sub-task handler initiated by the more command, additional commands are available for investigating specific problems: 

help: Displays the help message. 

brainstorm: Requests PentestGPT to generate possible solutions for the local task through brainstorming. 

discuss: Engages in a discussion with PentestGPT regarding the local task. 

google: Performs a search on Google (this function is still under development). 

continue: Exits the subtask and resumes the main testing session. 

These commands provide an interactive and iterative approach to guide penetration testers and enhance their testing process. 

2.4 Conclusion 

Overall, PentestGPT, with its integration of the GPT-4 model, interactive guidance, and user-friendly interface, has emerged as a game-changer in the penetration testing domain. By leveraging the power of AI alongside human expertise, it enhances the efficiency, effectiveness, and reliability of penetration testing efforts. PentestGPT empowers testers to perform comprehensive security assessments, solve challenges, and make informed decisions, ultimately strengthening the overall security posture of organizations. 

Other Services

Ready to secure?

Let's get in touch