Skip to content
ImagineWorld

Large Language Models and Cybersecurity

node_idnode-book_artificial-intelligence-for-cybersecurity_chapter-13-large-language-models-and-cybersecurity
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num13
chapter_titleLarge Language Models and Cybersecurity
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 13 — Large Language Models and Cybersecurity

Section titled “Chapter 13 — Large Language Models and Cybersecurity”

In the last few years, we have witnessed the rise of a new type of model, trained on large volumes of textual data. These models have been trained on terabytes of data by crawling text from the web, and they can have billions of parameters. This enables them to have improved natural language understanding abilities and to be used in various applications, from text classification to question-answering, chatbots, and similar. These models can be applied in cybersecurity as well, both by attackers and defenders. Additionally, systems with large language models themselves can be susceptible to various attacks.

In this chapter, we are going to cover the following main topics:

  • From traditional Natural Language Processing (NLP), methods to LLMs
  • LLMs for defensive security
  • The security of LLMs

The traditional machine learning methods of NLP, where we use feature extraction methods such as bag-of-words and n-grams to extract numerical features and apply classic machine learning methods, such as a neural network or Support Vector Machines (SVMs), can be a powerful way to automate the recognition of patterns and execution of tasks, such as document classification or clustering. However, these baseline methods often can’t handle long sequences with variable-range dependencies. One solution for this was the development of recurrent neural networks (RNNs). However, RNNs are trained with backpropagation through time, which still makes the training of long sequences inefficient. The next generation of models was Transformers, which are more efficient models and are currently used as the basis for many sequence models and all LLMs on the market.

Transformers are a special type of model that is based on the idea of self-attention. This means that a neural network learns to weigh different parts of a sequence during training. This is done in each training iteration by determining the importance of different parts of the sequence for pattern recognition tasks. Transformers use multiple neural network components for self-attention (attention heads) to learn different types of patterns at the same time. Furthermore, another feature of transformers is position encoding, which is used to model sequential dependencies without needing backpropagation through time as RNNs use.

Transformers have proven to be useful in various tasks such as machine translation, question-answering, and document summarization. This has initiated the question of whether neural networks such as transformers can be trained once to be used for multiple tasks. It turns out that transformers trained on sufficiently large datasets can indeed be pretrained and either used as-is or fine-tuned for multiple NLP tasks, with high performance metrics. Starting with a GPT model, the idea of a model that can execute multiple tasks has been developed through the years to models with billions of parameters that can be multimodal, performing various tasks that are based on generating textual output as a response to textual input (a prompt), sometimes also combined with an image.

LLMs are deep learning models based on the transformer architecture, trained with the goal of detecting patterns from large volumes of textual data and obtaining an amount of natural language understanding, enabling them to execute various generative tasks where they provide textual output on textual inputs from a user (prompts). They are trained using unsupervised learning and further supervised fine-tuning, with various strategies that have evolved in recent years. Currently, popular architectures are based on Reinforcement Learning from Human Feedback (RLHF), where we don’t only rely on unsupervised training with a large amount of data but also have a reward model, based on human ranking of answers. This reward model is continuously adjusted and used to train and tune an LLM, using reinforcement learning techniques. Combined with the initial pretrained language model, based on transformer architecture, we get a more accurate LLM.

The following figure illustrates the steps in RLHF model training.

Figure 13.1 – The steps in training an LLM using RLHF

Figure 13.1 – The steps in training an LLM using RLHF

We start by training a base LLM model, move on to fine-tuning the model using human annotations, and then continue improving the model using reinforcement learning techniques.

LLMs can also be used as part of a framework that enables calling different models and tools, using prompts and external inputs as an additional knowledge base or reference. One such popular framework is LangChain (https://www.langchain.com/), where it’s possible to create complex systems based on LLMs by creating interoperable components.

Textual input (prompts) is a way for a user to describe the context of a task and the task itself to the model. Prompts can be given in various forms, such as questions, instructions, and chains of thought. You can give example answers to questions or solutions to tasks in the scope of the prompt as well. If the user asks a question within a prompt without giving a question-answer pair as an example, this is called zero-shot prompting. However, for more complex questions or tasks, it is beneficial to give examples of solved questions or tasks within the prompt. If a few examples are given to guide a model, it’s called few-shot prompting. Prompt engineering is a new discipline that includes techniques on how to design and optimize prompts for best results from LLMs.

Note

You can read more on prompting here: https://www.promptingguide.ai/.

As LLMs are based on datasets used for training, they can have difficulties answering questions where key information for the answer is not contained in those datasets, and they can be sometimes prone to hallucination. An often-used solution to data gaps and hallucination is to use retrieval augmented generation, a technique where we can use external documents to access knowledge available after training. Furthermore, we can base a response to queries on a particular set of documents to ensure that the right sources of knowledge are used by LLMs.

In the next section, we will describe the application of LLMs in defensive security scenarios, showing where their use can add value to the work of cybersecurity teams.

LLMs are a powerful technology, as they are trained on a large volume of data, often including source code. This enables us to use them in some classical scenarios where we need to extract information from large volumes of data in different ways, as well as more advanced applications, including code analysis and generation.

In the following subsections, we will examine the different LLM applications in cybersecurity scenarios.

The advancement of technology and industry demand has enabled the development of increasingly complex software systems. This means that we have large-scale systems consisting of complex code bases, where hundreds or thousands of developers contribute by creating code modules that are interconnected and provide parts of system functionality. However, due to increasing complexity, time pressure, and other limiting factors, it is inevitable that there will be errors. Sometimes, these errors result in software systems being vulnerable to attacks.

Some traditional techniques for vulnerability discovery are as follows:

  • Static analysis: The analysis of the code of a program and possible execution paths (e.g. in searching for vulnerabilities) without executing it.
  • Dynamic analysis: Analyzing the results of a program by executing it with various inputs. Fuzzing is a type of dynamic analysis where we insert random inputs into a system and track the results of the execution.
  • Symbolic execution: Creating an abstraction over the possible execution paths by assigning symbolic variables, and introducing symbolic inputs to analyze a program based on how inputs influence execution paths.

These methods contain different approaches to tackle the complexity of software systems, where there could be many execution paths in programs that depend on variables and, ultimately, depend on other programs and user input.

LLMs can be a promising alternative to these methods, as they are trained with large volumes of data. Some models, such as GitHub Copilot, are trained on code and text from websites such as StackOverflow, which enables them to learn from these bases of code, questions, and answers posted by experts. Furthermore, LLMs can be used for code assistance to help programmers create better code, detect potential vulnerabilities, and suggest code changes.

In the previous part of the book, we described the challenges in threat intelligence when analyzing large volumes of data in search of valuable threat intelligence information. We also introduced AI methods as a solution for this problem, with an example of topic modeling. LLMs are a natural enhancement of this solution, as they can handle large-scale textual or code datasets, and we can use an LLM model for different tasks. For instance, LLMs can be useful in the following scenarios:

  • Extracting information and artifacts from multiple data sources: In threat intelligence, we can benefit from technologies such as LLM to get information about entities, such as IP, domain, malware, and threat actors, from various data sources. This information can come from data that is fed into public LLM services, such as ChatGPT or Perplexity, or it can be refined by fine-tuning LLM models, using dedicated threat intelligence data sources, or by using RAG methods to index documents. Having the ability to track different data sources of various data formats and languages and provide succinct information can be a crucial capability for a successful cyber-threat intelligence organization.
  • Creating summaries and reports of findings: Cyber-threat intelligence tasks often depend on retrieving information from large volumes of data. However, it’s often not enough to just retrieve this information; it also needs to be shown in an understandable and/or standardized manner to various stakeholders, such as security operations teams or even a Chief Information Security Officer (CISO). LLMs can be an important tool for this, as one of their key features is generating natural language responses to various queries about data. Furthermore, they can generate responses with a specific length and phrasing, driven by the purpose described in the natural language prompt. For instance, we can use LLM to create a report about what the trends in ransomware threats are and what the rising threat actors are. Another example is to instruct an LLM to create a report for stakeholders about vulnerabilities in their organization’s IT systems, with the highest reported risk score. As these reports can be used in decision-making, when generating them, we need to make sure that they don’t contain hallucinations, which is possible when using LLMs. Specifying settings such as temperature and using an appropriate model can help minimize this possibility, but it is also advised to review reports before they get sent out to the relevant stakeholders.

In the previous part of the book, we described the problem of spam and phishing detection and introduced AI solutions to this problem. It’s a problem that fits very well with the typical classification methods of machine learning, and ML methods are already quite well established as a solution. However, the recent rise of LLMs has provoked the question of whether we can improve spam and phishing detection using LLM capabilities. If LLMs can store patterns from a large amount of text data and recognize any anomalous content in emails, they can be an important enhancement.

There are already multiple research papers investigating this direction. For example, Labone and Moran from JP Morgan Chase investigate the use of models such as RoBERTa, SetFit, and Flan-T5 and test them on various spam detection benchmark datasets. They report significant improvements over baseline ML methods, such as XGBoost or K-nearest neighbor method. Furthermore, in the work of Koide et al., the authors investigate the use of GPT-4 and email content as a prompt and report a strong accuracy of over 99% on spam detection. Considering the generative nature of LLMs, there is a possibility of not just classifying messages but also generating explanations or reports about detected phishing and spam.

Note

You can read more about spam-detecting datasets in Maxime, Labonne and Moran, Sean, ” Spam-t5: Benchmarking large language models for few-shot email spam detection”. arXiv preprint arXiv:2304.01238. 2023. and spam detection by Koide, Takashi, et al, “Chatspamdetector: Leveraging large language models for effective phishing email detection”. arXiv preprint arXiv:2402.18093. 2024.

A Security Operation Center (SOC) is an important part of a cybersecurity department in every organization. This is the place where cybersecurity alerts are handled, confirmed as incidents, and processed and an adequate incident response is executed (if needed). Usually, in large-scale organizations, the SOC needs to handle a large number of potential incidents, and the time to detect and process an incident is crucial to optimize in order to keep the SOC running and protecting an organization effectively. Usually, SOC has defined performance metrics such as Time to Detect, Time to Resolve, and Time to Respond, which are continuously measured and tracked to capture any changes in performance.

LLMs can be helpful to improve these metrics and make an SOC more efficient and effective. One way that LLMs could help is to summarize all the relevant data about an incident in an understandable manner, helping SOC analysts to focus on the important information, find the root cause, and solve the incident faster. Furthermore, it can help engineers create recommendations for a customer on how to remediate the incident. Finally, given the skills gap in cybersecurity, including the SOC, LLMs can be used to help SOC analysts interact with data and a system easily and train them to improve their skills.

In the next section, we will explore the use of LLM for offensive security scenarios, where security teams investigate a system from an attacker’s point of view.

Offensive security is a set of techniques where security teams use attacker techniques to assess the security of an organization and, in turn, strengthen the defenses. LLMs can be introduced to offensive security teams as well to boost their productivity and enable them to be more efficient. For instance, they can use LLMs to generate messages for testing the vulnerability of the organization to social engineering attacks. Another example is using LLMs to find vulnerabilities in an organization that can be exploited or finding ways for better automation of penetration testing. LLMs have the potential to be used by attackers to improve the efficiency of their attacks, and offensive security teams can use them similarly, only with the benign purpose of testing the limits of cybersecurity defenses.

LLMs are an increasingly popular technology, as they can be used for various purposes and provide benefits in automating tasks and improving workflows. Therefore, many organizations add them as tools to their IT systems, and many software products have LLM components included to enable natural language generation features, such as chatbots or report generation.

However, LLMs have their own vulnerabilities that can be exploited by attackers. Security experts must be aware of these vulnerabilities to advise and implement secure integration of LLMs.

The Open Worldwide Application Security Project (OWASP) is an international organization dedicated to cybersecurity – mainly, web application security. Considering the rising popularity of LLMs, OWASP has created a taxonomy of the top 10 security threats when applying LLMs:

  • Prompt injection: LLMs are used by providing queries to them in the form of a textual prompt and obtaining a textual response. The modeling and response generation process usually includes guardrails that safeguard them from providing responses that are inappropriate or leak sensitive information. However, it was shown that an attacker can create a specially crafted prompt that can make LLMs ignore the guardrails and provide an unwanted response.
  • Insecure output handling: The output of LLMs can be natural language text but it can also be created in a specific format that can be used to execute malicious code and compromise the security of an IT system where LLM is integrated.
  • Training data poisoning: LLMs are trained with large-scale data, and in a high number of use cases, the data is gathered from public sources. There is a potential threat that the data that is used for training can be manipulated to change a model to provide results that benefit attackers.
  • Model denial of service: LLMs are large-scale models and can require a high number of computational resources to operate and serve responses to queries from a potentially large user base. Attackers can intentionally create an overwhelmingly large volume of requests to overwhelm a system where an LLM is running and cause disruptions.
  • Supply chain vulnerabilities: The functionality of LLMs involves reliance on various other software components, which can be vulnerable to malicious updates or other changes. Furthermore, systems that involve LLMs as components can be vulnerable to inauthentic LLM models being provided.
  • Sensitive information disclosure: LLMs are trained on large volumes of data, which can easily include Personally Identifiable Data (PII) or other sensitive organizational information. Without proper guardrails, this information can be provided within generated responses, possibly to users who shouldn’t have permission to see this data.
  • Insecure plugin design: LLMs are often added to existing software as plugins to enable features such as chatbots and various text generation capabilities. However, since LLMs accept user input and output can be forwarded to other components, vulnerabilities can be introduced to allow exploits such as remote code execution or SQL injection.
  • Excessive agency: The responses of LLMs often contain very impressive textual responses and can provide formulation in the desired form. However, making them a fully autonomous component should be carefully considered, as problems such as hallucinations can cause problems with their reliability and reduce user trust.
  • Overreliance: Building on the previous point, we need to consider when we can rely on LLM responses and under what conditions. There needs to be enough awareness of LLM functionality and limitations, as well as enough testing, to be highly confident that LLMs are reliable in particular use cases.
  • Model theft: LLM models can be trained on confidential data, and their use by unauthorized persons can create problems for organizations. Therefore, LLM models need to be protected from unauthorized access and being moved and copied to locations where they can be used by attackers.

Since the introduction of LLMs, there have been security considerations regarding emerging threats when using this technology. However, there have been new defensive approaches developed to counter these threats. One example is an AI firewall, which is a type of product that analyzes input and output to LLMs to enable defense from some of the aforementioned threats, such as prompt injection or the extraction of sensitive data. Conversely, some threats, such as supply chain vulnerability and denial of service, were well known before the introduction of LLMs and there are already established defensive approaches that can be used for LLM-based architectures as well.

In this chapter, we explored LLMs and their usage in cybersecurity applications. We begin by introducing LLMs as a new AI technology and presenting example applications in cybersecurity scenarios, both in defensive and offensive security. Furthermore, we discussed security considerations when using LLMs in software systems, common vulnerabilities, and defensive approaches. As LLMs are a fast-growing area and finding applications in various types of use cases and industries, having foundational knowledge in this area is important to be able to use them better, improving security and securing their usage in your organization.

In the next part of the book, we will examine common problems and considerations when applying AI in cybersecurity scenarios, so in the next chapter, we will first look at data quality and its usage in AI and LLMs.

  • Zhou, Xin, Sicong Cao, Xiaobing Sun, and David Lo. “Large Language Model for Vulnerability Detection and Repair: Literature Review and the Road Ahead.” preprint arXiv:2404.02525 (2024).
  • Hu, Sihao, Tiansheng Huang, Fatih İlhan, Selim Furkan Tekin, and Ling Liu. “Large language model-powered smart contract vulnerability detection: New perspectives.” In 2023 5th IEEE International Conference on Trust, Privacy and Security in Intelligent Systems and Applications (TPS-ISA), pp. 297-306. IEEE, 2023.
  • Purba, Moumita Das, Arpita Ghosh, Benjamin J. Radford, and Bill Chu. “Software vulnerability detection using large language models.” In 2023 IEEE 34th International Symposium on Software Reliability Engineering Workshops (ISSREW), pp. 112-119. IEEE, 2023.
  • Koide, Takashi, Naoki Fukushi, Hiroki Nakano, and Daiki Chiba. “Chatspamdetector: Leveraging large language models for effective phishing email detection.” arXiv preprint arXiv:2402.18093 (2024).
  • Labonne, Maxime, and Sean Moran. “Spam-t5: Benchmarking large language models for few-shot email spam detection.” arXiv preprint arXiv:2304.01238 (2023).
  • GitHub - jpmorganchase/llm-email-spam-detection: LLM for Email Spam Detection
  • Noever, David. “Can large language models find and fix vulnerable software?.” arXiv preprint arXiv:2308.10345 (2023).
  • GitHub - git-disl/GPTLens: Large Language Model-Powered Smart Contract Vulnerability Detection: New Perspectives (TPS23)
  • https://github.com/git-disl/GPTLens
  • https://www.bu.edu/peaclab/files/2023/08/USENIX_23_Poster.pdf
  • https://towardsdatascience.com/detecting-insecure-code-with-llms-8b8ad923dd98
  • https://github.com/jpmorganchase/llm-email-spam-detection