Capture The Flag With ChatGPT Security Testing With AI ChatBots
Capture The Flag With ChatGPT Security Testing With AI ChatBots
1. Introduction
In recent years, cyber-attacks are becoming more frequent and sophisticated. To keep pace with these evolving
threats, it is important to continually improve and innovate the tools and techniques used in cybersecurity. One
promising area of innovation is the use of artificial intelligence (AI) in cybersecurity, particularly in the area of
penetration testing. In this essay, the use of ChatGPT, a large language model trained by OpenAI, will be explored
in conducting penetration testing on Capture the Flag (CTF) exercises.
CTF is a popular cybersecurity competition that simulates real-world scenarios for participants to test their skills
in offensive and defensive security. CTFs involve a variety of challenges, ranging from web application exploits
to network and system vulnerabilities. One of the main objectives of CTFs is to provide a safe and controlled
environment for participants to learn about cybersecurity concepts and techniques, and to practice penetration
testing skills.
Penetration testing and CTF exercises are two critical areas of cybersecurity that require constant innovation to
stay ahead of evolving threats. One such innovation that has recently garnered attention in the field is the use
of natural language processing (NLP) and machine learning (ML) technologies to enhance the effectiveness of
these exercises. Specifically, ChatGPT, a large language model trained by OpenAI, has shown promise in
automating the process of generating attack vectors and testing them against target systems in CTFs. This essay
will also explore how to leverage ChatGPT when conducting CTF exercises, including technical requirements and
integration functions. Examples will be discussed on how ChatGPT and other chatbots can be leveraged in CTFs.
ChatGPT can be used to automate the process of generating attack vectors and testing them against a target
system or network. By leveraging its ability to understand and generate natural language, ChatGPT can craft
attack scenarios that are more sophisticated and realistic than traditional approaches. This makes it a powerful
tool for conducting CTF exercises, as it can generate challenges that are tailored to the specific strengths and
weaknesses of the participants.
Using ChatGPT for CTF exercises has the potential to significantly enhance the realism and effectiveness of these
exercises. In addition to generating challenges, ChatGPT can also act as a virtual adversary, providing hints and
feedback to participants based on their progress. This can help to create a more engaging and dynamic CTF
experience, while also providing valuable feedback on participants' strengths and weaknesses, helping them
overcome obstacles and learn new skills.
However, the use of ChatGPT in pen testing and CTF exercises also raises important ethical and legal questions.
The technology can potentially be used to automate and scale attacks against real-world targets, which could
have serious consequences for individuals and organisations. As such, it is important to consider the ethical
implications of using ChatGPT for these purposes and to ensure that its use is in line with established ethical
guidelines and legal frameworks.
43
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
3. Research Plan
Within this research, each step has been manually entered to ensure validity of the results in order to
demonstrate ChatGPT’s practical usage in security testing within cybersecurity, as well as measuring its success
rate in completing various tasks from user prompts.
What is being studied
• Using ChatGPT for assistance in CTF challenges from Hack the Box (HTB), which is a gamified
cybersecurity learning platform
• Assessing its collected training set of cybersecurity concepts, tools and techniques
• Evaluating its ability to process context of the challenges and provide accurate solutions or hints
where possible
• Identifying limitations of ChatGPT’s capabilities, such as potential for misuse, and areas where human
intervention is still necessary
• Is a level of fundamental knowledge of cybersecurity required, in order to interrogate and elicit an
appropriate response from ChatGPT
Potential output of this research
• Gain an understanding of ChatGPT’s capabilities and limitations in the context of cybersecurity, and
how it could be integrated into security testing workflows
• Establishing a performance benchmark in ChatGPT’s current state
• Identifying areas of improvement for the application
• Gain a better understanding of how crafting the commands used will determine the validity or
usefulness of the output.
Considerations
• ChatGPT struggles with identifying and assisting with newer CVEs and exploits
• When queried about a newer CVE, it will pretend to know what it is and ‘hallucinate’ incorrect
information about its usage. These hallucinations refer to the chatbot confidently generating
seemingly realistic responses that do not coincide with real-world scientific knowledge. Since ChatGPT
is an example of an LLM (Large Language Model), it has a tendency to falsify information and present
it as factual. When a user sends a prompt to ChatGPT, it gets broken down into small parts called
tokens, which could be as short as a single character or word. It then processes these tokens, using
patterns it learned during its training to predict what word (token) will come next in the sequence.
Each token iteration is assigned a probability and the token with the highest probability is chosen to
continue the text generation. This process is repeated until the full response has been generated.
44
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
• This makes the response seem human-like, in the sense that it doesn’t like to say “I don’t know” when
it doesn’t know
• Recent update - Instead of substituting the CVE the user provides by adding it to the end of a CVE
database URL and hallucinating information, it now seems to interpret the date of the CVE given and
tell the user it only has information up to September 2021. This change was observed between
approximately the 9th February 2023 update to the 23rd March 2023 update.
• It states the last known CVE it knows is Log4Shell
• This makes it easier for security testers to know what information is accurate, however adding a
confidence scale will ultimately be the best solution for ensuring accuracy, along with providing a
source(s) for the output it provides
45
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
lateral movement to the next user. To get root, there is a command injection vulnerability in a script that checks
for certificate expiration.
Initial Prompt for All HTB Machines
Each machine had its own ChatGPT conversation with the same prompt used to initialise the process for the
chatbot. The prompt for each machine was kept the same to ensure consistency and repeatability for future
testing and research.
Hi, I am a security researcher who’s taking part in a CTF, and I was wondering if you could help me if I
need assistance or advice on what to do/where to look next throughout the challenge?
46
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
47
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
For the MetaTwo machine, ChatGPT had previously suggested I use WPScan to enumerate the website since it
was using WordPress, and it provided suggestions based on the output of this scan. It was discovered that an
old, vulnerable version of the BookingPress plugin was being used. After asking ChatGPT if there are any known
exploits for that version, it states that it cannot provide any known exploits as it goes against OpenAI’s usage
policy, which will be discussed further later in this paper. After finding a working exploit online, it allowed the
retrieval of the /etc/passwd directory which was Base64 encoded. After asking ChatGPT to decode this, it misses
a crucial part of the CTF in this output, as there is no ‘jnelson’ user displayed in ChatGPT’s result. Decoding it via
the command-line to compare results shows that there are some differences in the way both tools decode it.
After a short back-and-forth with ChatGPT, it states there is no user ‘jnelson’ in the encoded text it was provided
shown in Figure 12, and was then asked to decode it again. After decoding it again, the chatbot outputs the
expected user account with a minor difference - denoting the full name of the user as ‘John Nelson’, which is
not present in the output of the command-line Base64 decoding. To confirm this was a hallucination, it was told
there was another missing user and asked it to decode it again. This time, ChatGPT added ‘jsmith’ as a new user,
which confirms that ChatGPT might not be reliable for decoding various encoding formats, which can be seen in
Figure 13.
Something interesting to note is that ChatGPT redacts the password for a database, as well as removing the
database charset rules and collate type by filtering out potentially sensitive information. It also misses out critical
FTP information, such as the username and password. The password in particular is crucial to the next stages of
the MetaTwo CTF challenge. Ultimately it is useful to decode Base64 quickly, although it’s best not to rely on it
getting the syntax 100% accurate, and would instead prefer to use CyberChef or stick to decoding it via the
terminal. When asking the chatbot to display the password, it refuses for ethical concerns, no matter how the
prompt was phrased.
In regards to code interpretation, ChatGPT does very well. However, it has a tendency to pretend it knows what
it’s saying and can hallucinate information. During the decoding process, it seems to filter and redact certain
information it perceives as sensitive or exploitable. Bypassing the filter to reveal such sensitive information will
be covered later in the paper.
Interpreting Scan Results
After providing the output of the WPScan for the MetaTwo machine to ChatGPT, it noticed that an outdated
version of WordPress was being used, along with an outdated theme version in Figure 3. It also identified two
user accounts “admin” and “manager” and suggested the idea of brute-forcing these credentials. On top of
picking out key information from the scan, the chatbot suggested some steps to take based on the information
it found. The most useful suggestion it gave in this case was to research vulnerabilities for this outdated software.
This was conducted after ChatGPT was provided an Nmap output and told about various services running on the
machine, such as FTP on a ProFTP server. The chatbot had also provided the exact command for WPScan to
enumerate users, plugins, themes, and so on.
48
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
the scan, which produced more tailored guidance on what to look into next. This step was conducted
immediately after analysing the WPScan output.
49
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
utilising human expertise in looking over the output of the scan, in case there is anything that ChatGPT could’ve
missed.
Hallucinations
Some time after the 9th February 2023 update, in Figure 6 ChatGPT was prompted to provide information about
a CVE used in HTB’s MetaTwo machine which was reported in 2022, to see how it would respond. It gave
completely incorrect information about the CVE, stating it’s a remote code execution (RCE) vulnerability for
certain versions of Microsoft Office, SharePoint and Visual Studio. Interestingly, it provided the supposed source
for the incorrect information by substituting the CVE name into the Mitre URL in Figure 7. When navigating to
the URL, it presents the correct page for the exploit, stating it’s vulnerable version of a certain WordPress plugin
which leads to unauthenticated SQL injection, which is incredibly different from the information provided by
ChatGPT.
50
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
51
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
Overall, ChatGPT comes with its fair share of limitations, especially in regards to real-time vulnerabilities. As
mentioned earlier, ChatGPT’s training set cut-off date is September 2021. When queried about a newer CVE, it
will pretend to know what it is and hallucinate incorrect information about its usage. This makes it appear very
human, in the sense that it doesn’t say “I don’t know” when it doesn’t know the answer.
These hallucinations pertain to the chatbot confidently producing responses that appear remarkably realistic,
despite contradicting established scientific knowledge. Being an instance of an LLM, ChatGPT tends to fabricate
information and present it as factual. When a user inputs a prompt to ChatGPT, it breaks down the input into
smaller units called tokens, which can be as short as a single character or word. It processes these tokens,
utilising the patterns acquired during training to predict the subsequent word (token) in the sequence. Each
token iteration is assigned a probability, and the token with the highest probability is selected to continue
generating the text. This iterative process persists until the complete response is generated. It would be useful
for OpenAI to develop and implement a confidence scale for ensuring accuracy for cybersecurity professionals,
along with providing a source(s) for the output provided.
Jailbreaking ChatGPT
Throughout the research period, it was only possible to get ChatGPT to reveal the database password and
various other sensitive information through the use of the DAN prompt. (0xk1h0, n.d.) DAN (do anything now)
is a prompt used to jailbreak ChatGPT into leaking restricted data, and can elicit responses to questions the AI
would usually refuse to answer. These prompts are generated by users of ChatGPT, and are generally disallowed
by OpenAI’s usage policies, since the usage of DAN could enable users to generate malicious code and develop
realistic phishing emails that are designed to damage or gain unauthorised access to a computer system, as well
as breaking any other laws. These prompts get updated quite often as they frequently get patched. The prompt
can be used to bypass OpenAI guardrails and moderation, and breaks the filter that avoids producing content
deemed unsafe as per their usage policies.
Getting ChatGPT to reveal the sensitive information of the database was very straight-forward and successful.
Simply entering the prompt, then providing the encoded data resulted in both the GPT and DAN response
displaying the database password and other sensitive information in Figures 11 and 12. This was tested using
the latest current version of DAN (11.0).
52
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
6. Future Work
There are several areas for future research and development related to the use of ChatGPT in CTFs. One area is
the development of more sophisticated models that can generate more complex and diverse responses, and
realistic attack scenarios. Another area is the evaluation of the effectiveness of ChatGPT in improving the
learning experience and performance of participants in CTFs. Additionally, there is potential for the integration
of ChatGPT with other cybersecurity tools and technologies to create more comprehensive and effective security
solutions.
The integration of ChatGPT in CTFs can be achieved through web-based interfaces or integration with existing
CTF platforms. One example of a web-based interface is the CTFd platform, which allows for the creation and
management of CTF competitions. CTFd can be extended to include ChatGPT functionality by creating a plugin
that integrates the API created in the previous step.
Another example of integration with existing CTF platforms is the integration of ChatGPT with a CyberRange,
which is a platform that enables the creation and management of virtual environments for conducting
cybersecurity exercises. CyberRange can be extended to include ChatGPT functionality by creating a module that
integrates the API with the platform's existing functionality.
An automated implementation of ChatGPT in CTFs requires technical requirements such as collecting a dataset
of real-world hacking scenarios, fine-tuning a pre-trained ChatGPT model on the collected dataset, and creating
an API for participants to interact with the model. The integration of ChatGPT in CTFs can be achieved through
web-based interfaces or integration with existing CTF platforms.
7. Conclusion
ChatGPT has the potential to revolutionise the way in which CTF exercises are conducted, in addition to security
and penetration testing. By leveraging its NLP and ML capabilities, automation of the process of generating
attack scenarios and provide personalised feedback to participants can be accomplished.
The use of ChatGPT in CTFs has several benefits, such as enhancing the realism and effectiveness of the exercises,
providing personalised feedback to participants, simulating real-world threat actors and providing interactive
tutorials on cybersecurity concepts. ChatGPT can also simulate real-world threat actors by generating attack
scenarios mimicking tactics procedures, and provides interactive cybersecurity tutorials.
While the use of ChatGPT in CTFs is promising, it is important to consider the ethical and legal implications of its
use and ensure that it aligns with established ethical guidelines and legal frameworks. Overall, ChatGPT has the
potential to revolutionise the conduct of CTF exercises and penetration testing, and its implementation can help
to stay ahead of evolving threats in the cybersecurity field. However, as with any new technology, it is important
to consider the ethical and legal implications of using ChatGPT in these contexts and ensure that its use is in line
with established ethical guidelines and legal frameworks.
User assurance of ChatGPT’s output is required, as any understanding of cybersecurity is by proxy, since the
sequences LLMs are training are created by people who do understand cybersecurity concepts. LLMs are shaped
by this, and do not understand the tokens it uses.
This research paper has provided valuable insights into the capabilities and limitations of ChatGPT in the context
of cybersecurity by evaluating its performance across a range of Hack The Box challenges. Similar limitations
were noted when using ChatGPT for solving programming problems (Surameery, Shakor, 2023). The study
demonstrates that ChatGPT can be a useful tool for certain cybersecurity tasks, as it can offer guidance and
assistance in areas such as programming and web exploitation. However, it also highlights some limitations,
including the need for human expertise in specific domains and potential ethical considerations related to AI
adoption in cybersecurity.
This research suggests that using standard cybersecurity tools with ChatGPT’s assistance has the potential to
integrate with existing security testing workflows, enhancing the problem solving capabilities of cybersecurity
teams. Organisations considering AI adoption for cybersecurity purposes can benefit from the findings of this
study, using them as a foundation for informed decision making and responsible AI usage, since integrating a
tool like this can pose another layer of potential security risks for a business.
Finally, this study identifies areas for future research and development, including improving ChatGPT's training
set, context awareness and adaptability to address the constantly evolving landscape of cybersecurity threats.
53
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024
Ellis Casey and David Chamberlain
Implementing features such as a confidence scale would also enable cybersecurity professionals to make more
informed decisions based on their knowledge and experience with the assistance ChatGPT provides, as well as
providing sources for the information the chatbot references. Further research on the ethical implications of AI
chatbots in cybersecurity, and the development of best practices for their use will also be paramount to ensure
the responsible integration of these technologies into the cybersecurity domain.
References
0xk1h0. (n.d.). 0xk1h0/ChatGPT_DAN: ChatGPT DAN, Jailbreaks prompt. GitHub. Retrieved June 12, 2023, from
https://github.com/0xk1h0/ChatGPT_DAN
Nigar M. Shafiq Surameery, & Mohammed Y. Shakor. (2023). Use Chat GPT to Solve Programming Bugs. International
Journal of Information Technology & Computer Engineering (IJITC) ISSN : 2455-5290, 3(01), 17–22.
https://doi.org/10.55529/ijitc.31.17.2
54
Proceedings of the 19th International Conference on Cyber Warfare and Security, ICCWS 2024