Skip to content
ImagineWorld

Learning in a Changing and Adversarial Environment

node_idnode-book_artificial-intelligence-for-cybersecurity_chapter-17-learning-in-a-changing-and-adversarial-environment
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num17
chapter_titleLearning in a Changing and Adversarial Environment
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 17 — Learning in a Changing and Adversarial Environment

Section titled “Chapter 17 — Learning in a Changing and Adversarial Environment”

We will discuss and explore the topics of adversarial machine learning (AML) in the spirit of completing the big picture of AI/ machine learning (ML) by considering its security and privacy perspectives, which become more and more challenging and critical nowadays with the popularity of generative AI (GenAI). In previous chapters, we learned about the fundamentals of ML and a variety of applications in cybersecurity. However, the nature of ML brings native vulnerabilities that can be exploited by highly technical adversaries. Therefore, AML is a rising research area that draws a lot of attention from both academics and industries. Its objective is to study the vulnerabilities of ML proactively and to design and devise novel approaches that are more robust and reliable than traditional ML methods.

In this chapter, you will learn about the concepts and motivation of AML, and explore the differences between AML and traditional ML algorithms. It is important for you to know how adversaries attempt malicious activities and achieve their goals. Then we will introduce the taxonomy of AML and briefly present the state-of-art framework to describe the AML system. Furthermore, you will familiarize yourself with some offensive and defensive techniques in ML. To address recent advances in large language models (LLMs), we will discuss the particular aspects of adversarial prompt attacks on language models. In the spirit of practice, we will introduce some Python libraries that are used to exploit and evaluate ML models. Although it might seem to be an overload, we do encourage you to practice and learn how to use AML techniques to evaluate your models. This is essential to address some of the most concerning security and privacy issues in the advancement of AI.

In summary, here is the list of the topics that are covered in this chapter:

  • Learning about the concept and motivation of AML
  • Introduction to the taxonomy and state-of-the-art framework of AML
  • Learning about some common adversarial attack algorithms
  • Learning about some common defensive ML algorithms

What you will learn from this chapter is application-agnostic. However, it will be beneficial to use the knowledge gained from this chapter to enhance the security of your targeted ML applications.

For this chapter, the technical prerequisites are designed to equip you with the foundational knowledge required to navigate the complexities of this emerging field effectively. They are as follows:

  • A solid understanding of the core mechanics of ML is essential, encompassing the processes of training, testing, and evaluating models to ensure that they perform accurately and efficiently. This includes grasping the nuances of how data is split, how models are trained on one subset and tested on another, and how their performance is assessed through various metrics.
  • A deep comprehension of optimization in ML is crucial. This involves understanding the techniques and algorithms used to improve model accuracy and efficiency, such as gradient descent and its variants, which play a pivotal role in tuning models to achieve the best possible outcomes.
  • A basic familiarity with cybersecurity principles is necessary to understand the threats and vulnerabilities that AML seeks to exploit or defend against in modern digital systems. This knowledge is key to appreciating the context in which adversarial techniques are applied, as well as to understanding their implications for security.
  • Lastly, while not mandatory, programming skills in Python are highly beneficial for those looking to engage more practically with AML. With its extensive libraries and frameworks for ML, such as TensorFlow, PyTorch, and scikit-learn, Python is a preferred tool for developing and testing adversarial strategies.

This skill set enables a hands-on approach to experimenting with and implementing adversarial models, providing a more in-depth understanding of the concepts discussed in the chapter.

In the realm of ML, a unique subfield known as AML has emerged. This area focuses on learning from datasets that may be contaminated by adversarial samples. These samples are introduced by entities intent on undermining the integrity of ML processes for their own benefit. The unpredictability of predictions made by ML algorithms introduces a new layer of security risks in today’s data-centric systems. As data increasingly drives predictive services such as spam filters and voice assistants, the efficacy of a learning model becomes closely tied to the integrity of its data sources. Unfortunately, data source tampering is a common occurrence, whether through insider fraud, deliberate manipulation, or the natural degradation of devices, allowing adversarial entities to exploit these systems by altering their data inputs.

Nowadays, ML has become a crucial component in numerous IT systems. Despite its significant benefits, these systems can have inherent weaknesses, which malicious users might exploit for their gain. Recent advancements in adversarial learning have highlighted vulnerabilities in learning algorithms that were previously thought secure. These vulnerabilities can lead to the failure of their intended functions. For example, Deep Neural Networks (DNNs), known for their robustness in tasks such as image and voice recognition, can be surprisingly fallible. They may either miss critical nuances in data or misinterpret blatantly incorrect data. For instance, in one experiment, two original images—a school bus and a puppy—were correctly identified with high confidence. However, after slight, humanly imperceptible alterations, these images were misclassified with 0% accuracy (Szegedy et al., 2014). Conversely, heavily distorted images, unrecognizable to humans, were identified with 99% confidence as their original subjects (Nguyen et al., 2015). This demonstrates how deep networks can be misled by focusing on certain pixel-level features.

Another example focuses on spam filtering, which increasingly relies on ML algorithms such as naive Bayes classifiers. Adversaries often disguise spam as legitimate emails to bypass detection. They employ sophisticated obfuscation techniques to evade statistical spam filters, manipulating content to avoid classification as spam. In the following text, injecting a few “good” English words (in green boxes) makes the spam filter think that the emails are legitimate.

For instance, consider email text such as the following:

“Check this amazing discount on Apple products, everything is half-price until Monday, don’t hesitate!”

The attacker can take the preceding example and add text that could appear in a benign email to reduce the spam score of the message:

“Nice to see you yesterday, hope you had a good time! Check this amazing discount on Apple products, everything is half-price until Monday. I hope we can meet up soon and catch up. Don’t hesitate to take the offer!”

A recent and concerning development in adversarial attacks targets LLMs. These models, trained on vast datasets to understand and generate human-like text, are not immune to manipulation. For example, by carefully crafting input prompts, an adversary can subtly guide an LLM to generate biased or factually incorrect outputs, potentially spreading misinformation or bias. This vulnerability is particularly alarming given the widespread use of LLMs in applications ranging from customer service to content creation. Large models that are deployed in production are aligned to generate human desirable outputs using alignment techniques such as reinforcement learning with human feedback (RLHF). However, numerous prompt examples have shown that they can still be susceptible to adversarial prompts. namely to be \”helpful and harmless.\” These models should respond helpfully to user questions, but refuse to answer requests that could cause harm. However, adversarial users can construct inputs which circumvent attempts at alignment. In this work, we study to what extent these models remain aligned, even when interacting with an adversarial user who constructs worst-case inputs (adversarial examplesTherefore, the importance of understanding and developing countermeasures in AML cannot be overstated. As ML becomes more integrated into critical systems—spanning from security to communication—it is imperative to anticipate and mitigate these vulnerabilities. This not only ensures the reliability and safety of these systems but also protects against the exploitation of these technologies for harmful purposes. The ongoing study of, and advancement in, AML is crucial to building robust, trustworthy AI systems that are capable of withstanding the evolving landscape of cyber threats.

In the next section, we will walk through the foundation of AML by introducing the taxonomy and theoretic framework of the adversarial learning threat model in detail.

In previous chapters of this book, you learned about the general concepts and methodology of ML. While the information you saw gives enough technical background for approaching any learning problem, it does not suffice to tackle the security issues of ML models. We will therefore start with a discussion about the realistic setup of AML, which focuses on model security. In the interest of brevity, we will start by discussing an arms race problem in the context of cybersecurity.

In the area of cybersecurity, a scenario reminiscent of an arms race frequently unfolds. This involves strategic competition among various entities, each vying for dominance over specific assets to fulfill their unique objectives. Classic examples of this dynamic include the ongoing struggle between malware developers and antivirus software engineers, as well as the contest between spammers and anti-spam technologies. This paradigm is also reflected in the field of AML, which characteristically involves a minimum of two participants: the learner, who develops the ML model, and the adversary, who seeks to undermine or simply exploit it. This interaction often triggers a reactive arms race, predominantly instigated by sophisticated and adaptable adversaries. In this scenario, reactive denotes the learners’ initial unawareness, adhering to static assumptions until the adversary capitalizes on certain weaknesses in their algorithmic design. It is imperative for learners to promptly detect and address these adversarial maneuvers, typically through methods such as retraining the model with untainted data or modifying particularly susceptible features to prevent further attacks. However, even the swiftest and most effective counteractions are hindered by inherent delays, affording adversaries a crucial timeframe to achieve their objectives.

In a contrasting approach, which is prevalent in areas such as cryptography, security by obscurity is a common practice. This method involves safeguarding information within a cryptographic veil, effectively barring adversaries from gaining access. While this remains a valuable tactic in adversarial learning, our exploration diverges toward a proactive strategy in securing learning systems during their initial design phase. This approach, which aligns with the security by design philosophy, necessitates that learners account for potential deviations from initial assumptions and pre-emptively contemplate possible attacks. This proactive security method offers enhanced safeguards by addressing potential weaknesses ahead of algorithm development, subsequently imposing greater challenges for adversaries attempting to breach these systems and bolstering their robustness with minimal reliance on human intervention.

The illustration of an arms race in Figure 17*.1* contrasts the reactive and proactive arms race models, which are integral to the understanding of adversarial learning. The reactive model, depicted on the left, progresses through four stages: adversaries identify vulnerabilities in a learning system for specific motives and formulate and execute an attack, which is then detected by the learner, prompting the latter to modify their system accordingly. In contrast, the proactive model, shown on the right, involves learners assuming the presence of adversaries and modeling potential attacks in advance, thereby assessing their potential impact and fortifying the system’s security at the design stage.

Figure 17.1 – The reactive and proactive arms race concepts

Figure 17.1 – The reactive and proactive arms race concepts

This arms race in the adversarial learning landscape is inherently iterative and dynamic. The conceptual diagram captures the complete cycle of adversarial learning, indicating that interactions between the learner and adversary can manifest as either one-shot games or ongoing, iterative engagements. Although the importance of equilibrium in this game-theoretic framework is undeniable, our current focus is on dissecting the one-shot game as a foundational approach to achieving balance. Prior research, notably by Brückner and Scheffer (2009) delved into the properties of Nash equilibrium in prediction models, demonstrating that under certain conditions, a distinctive Nash equilibrium emerges between the adversary and the learner. However, the exploration of iterative games and the equilibrium dynamics across diverse adversarial contexts remain fertile ground for future research. In this section, we aim to dissect and delve into the following key areas:

  • In-depth analysis of the targeted learner process: This involves a meticulous examination and analysis of the learner process, such as a classifier or generator, to model potential adversaries. This process emphasizes the in-depth understanding and theoretical properties of the learning algorithm.
  • Comprehensive adversary modeling: This stage entails the conceptualization of potential attacks specifically designed to target a particular learner process. The focus is on assessing the potential impact and efficacy of these attacks.
  • Strategic design of countermeasures: This involves the integration of strategies and countermeasures against adversarial attacks at the very inception of the design phase. It ensures that learning algorithms are not only robust and resilient but also designed to adapt to dynamic data distributions and shifts in concepts, thereby enhancing their effectiveness and reliability in uncertain and evolving data environments.

In the next section, we will see what a typical learning process will look like in terms of data flow. This is essential for you to understand in order to proceed to the topic of adversarial modeling.

Data plays a central role in any ML algorithm. Both training data and test data can be susceptible to changes or manipulations, which are sometimes malignant. As we will learn in the rest of this chapter, most adversarial attacks aim at data manipulation such that they can achieve their goals. Therefore, we will first depict the learning process in terms of data flow. As we will see, the data flow is model-agnostic, which means that it is compatible with almost all state-of-the-art learning models.

The learning process always starts from a data generation process, which is typically unknown. For instance, images downloaded online can be created by consumer cameras, mobile phones, CCTVs, and so on, which can be further processed or transformed and ultimately uploaded to the web. Although the general process of constructing a digital image within a photographic device is not mysterious, it is not possible to fully reassemble the generation of all images. Another example of the data generation process is in natural language. A sentence is spoken, triggering billions of biological reactions of neurons in a human brain. In humans, this process is unknown or only partially interpretable. In Chapter 4, we flagged the difference between statistics and ML, that is, ML has a strong focus on learning the data generation process while statistics focus more on studying the distributional properties of generated data. This is especially true in the frontier of GenAI, as a generative model learns to generate data to conform with the observations that were originally generated.

In practice, only observations are available, such as text or images from the web, which are collected as training data. Based on the learning problem definition, a subset of learning models is selected and trained with the observations. The trained models are normally much smaller than the training dataset. For a simple approach to understanding this, we can consider the models as some sort of lossy compression algorithms. However, one characteristic of ML models is that the training data and model are interwoven. It is not possible to modularize the data and model once they are trained. Therefore, the so-called Change-Anything-Change-Everything (CACE) pattern causes the major vulnerability of any ML model.

On the other hand, once the model is trained and deployed in production, test data samples will be fed to the model, and model outputs will be generated without changing the model itself. For simplicity, any ML model can be considered as a function that takes compatible inputs and generates outputs that meet certain criteria. Depending on the functionality of the model, both input and output can take multiple data types (multi-modal), for example, text and image. Multi-modal has gained more attention nowadays and has become a new medium of marching toward more generic AI capability. However, this incentivizes adversaries to target the models for multi-factual assets, such as personally identifiable information (PII), confidential business reports, and so on. Have a look at the following figure:

Figure 17.2 – Data flow for any learning process

Figure 17.2 – Data flow for any learning process

In Figure 16*.2*, we have depicted the data flow that represents the learning process. Note that the model itself is also of interest to adversaries. Therefore, every component in this diagram is an asset that needs proper security guardrails.

Next, we will start to play the role of an adversary, which will help us understand various learning scenarios under adversarial settings.

As described in the context of the arms race problem, it is usually a best practice to conduct threat analysis in a proactive way, such that security practitioners play the role of an adversary and perform a comprehensive analysis of the learning models. Therefore, we will show the threat modeling in the context of AML, as well as the taxonomy of various sorts of adversarial attacks on ML models, in this section.

In the context of adversarial learning, it’s important to consider an adversary as a smart and adaptable entity that interacts with the learning system. This adversary has the ability to make changes to the data that the system learns from. These changes can be made either during the system’s training phase (when it’s learning and developing its abilities) or during the testing phase (when its performance is being evaluated). Such alterations by the adversary can shift the way the original data is structured or behaves, which is problematic because the learning system usually expects the data to remain consistent or stationary. Imagine teaching someone to recognize apples, but then halfway through, you start showing them oranges without telling them—their learning would be affected.

By strategically changing parts of the data, either in the training or testing stages, the adversary aims to confuse the learning system. This confusion benefits the adversary, leading them to achieve their goal, which is usually to misguide the system to a certain degree. In order to effectively prepare for and counteract these challenges in adversarial learning, experts create models that anticipate the adversary’s actions. These models are designed with the understanding that the adversary is trying to reach their goal in the most effective way possible. This approach helps in building more robust and secure learning systems that can better resist these intentional disruptions.

Definition of ML adversary

An ML adversary is defined as an actor that is parameterized by three major components. Let us denote it as, where is an optimal subset of adversarial data samples causing the targeted model to behave in a way that is desired by the attacker. represents the attacker’s knowledge about the model.

We will learn how the adversary achieves their goal by modeling various kinds of attack, though it is important to understand each component of the definition.

Adversarial data samples could be the only way that an attacker interferes with the system (model) most times, as the model usually only provides interfaces that receive users’ inputs (data) without exposing the details about the algorithm and training data. Therefore, an adversary attempts to create a set of adversarial samples, usually by another ML model, which causes the system to behave differently than it normally would. For instance, in the example of a spam filter, an adversary might change the content of an email by injecting “good” words, which results in a spam email bypassing spam detection. In this case, the particularly designed email is an adversarial example. It is straightforward to understand this scenario, as the attacker confuses the spam classifier. In the most recent scenarios (for instance, ChatGPT), adversaries could prompt the chatbot to generate toxic or unethical content, which is normally disallowed by the model through the enforcement of security policies. This is called an adversarial prompt in the context of GenAI. It sounds a bit more intriguing than it is. However, it is technically the same as the spam detection example. The only difference is in the model output. One is to predict a label on the email, another is to generate text based on instructions.

Targeted model more generally refers to the system that is mainly driven by some AI models. We need to stress the fact that the major difference between traditional software systems and these systems is that AI systems are normally probabilistic, while traditional software systems are deterministic. In AML, the targeted model is the attacker’s hunting object. Depending on what the goal is, the model can be compromised in a different way. We will explore the attack taxonomy in depth in the next section.

The attacker’s knowledge represents how much information the adversary knows about the targeted model, which can include what the model and the parameters are, as well as potential access to the training data. In the worst case, the adversary has full visibility of the targeted model and the data. Thus, the system can be extremely vulnerable. However, most of the time, we would expect that the adversary only has limited or even zero knowledge about the target. Like any other system, the more information that is exposed externally, the higher the risk will be. From a defensive aspect, keeping the model and data information confidential could be a key to success. However, the recent trend is leaning more toward pre-trained models. This is because training a large model can be extremely expensive, and therefore, it is usually not financially feasible for most small and medium organizations. This suggests an increasing risk of models being more targeted, as there are tons of applications being built on top of pre-trained models.

To continue our discussion, we recommend that you recap some fundamental ML algorithms from Chapter 5, but think of the modeling process from an adversary’s perspective. In the next section, we will give a taxonomy of various types of adversarial attacks. Again, this is in the interest of being proactive against those attacks. We do not encourage any attempt to apply any of these attacks on real-world production systems.

In the study of adversarial learning, a key concept is the classification, or taxonomy, of different types of adversarial attacks. This taxonomy helps us understand these attacks by categorizing them based on their characteristics and the specific ways they impact the learning system. The purpose of creating this taxonomy is twofold. First, it provides a clearer understanding of the strategies used by attackers. By categorizing the attacks, we can see patterns and commonalities in how these disruptions are carried out. Second, this organization aids in the development of effective strategies to counter the attacks. By knowing the type and nature of an attack, we can create more targeted and effective defenses against it. In essence, this approach to categorizing adversarial attacks is like creating a detailed guidebook. It helps those working in the field of adversarial learning to quickly identify the type of attack they’re dealing with, understand its potential impact, and apply the most appropriate countermeasures to protect the learning system. This structured understanding is crucial in enhancing the security and effectiveness of these systems. We will build the taxonomy based on the attacker model introduced in the previous section. We will also define a simple categorization in three dimensions, namely security violation, adversarial capability, and adversarial influence.

First, from a defender’s perspective, understanding the attacker’s objectives is crucial, especially as these often relate to compromising the security of targeted systems. For example, consider an email spam filter. In this scenario, attackers might create a series of spam emails that are designed to bypass detection, thereby undermining the integrity of the email system. When these types of malicious attacks successfully deceive the learning systems (the learners), they result in security breaches. To effectively address and counter these threats, it’s essential to first define what the attacker is aiming to achieve in terms of security violations. These violations can fall into various categories, such as breaches of integrity (such as in the spam email example), availability (where the system’s ability to operate is impacted), or privacy (where confidential information is accessed). Furthermore, we can categorize these attacks based on how they impact the targeted system. Some attacks are targeted, meaning that they are designed to compromise a specific part or function of the system. Others are indiscriminate, where the aim is to disrupt the system as a whole, without a specific focus. Sometimes, whether the attack is targeted or indiscriminate can be referred to as attacker specificity. This categorization helps in understanding the nature of the threat and in developing more precise defensive strategies.

Integrity violation occurs when an attacker manages to carry out harmful activities without disrupting the normal operations of the system. A classic example is in a situation involving a classifier, such as a spam filter. An attacker could design spam emails that are not detected as spam by the classifier, yet this might not affect the classifier’s ability to correctly identify legitimate emails. In such cases, the integrity of the classifier is compromised because it allows malicious content to pass undetected, but its function on legitimate content remains unaffected.

Availability violation attacks impact the system’s functionality, leading to a denial of service. In more technical terms, they damage the reliability of the predictive service offered by the system. In the context of ML, where predictions inherently involve some uncertainty, the reliability of these predictions is crucial. For classification and clustering systems, such attacks could lead to significant errors in classification or major alterations in the clustering process. The overall effect of these attacks is a degradation in the predictive services offered by the system, affecting its availability.

A privacy violation is a type of attack that is concerned with extracting information about the system or its users. An attacker might reverse-engineer the system to gain insights into the data or the workings of the classifier. To mitigate this risk, it’s important to limit the information available to potential attackers. This includes data used in the learning process, as well as user input and even the system’s responses to legitimate queries. All these elements should be treated as private and protected accordingly.

Lastly, the specificity of an attack can be categorized as either targeted or indiscriminate. A targeted attack focuses on a specific subset of information, whereas an indiscriminate attack affects a broader range of data or functionality. Understanding these distinctions is vital for developing effective countermeasures and safeguarding the system against various adversarial threats. Note that the categorization of attacks based on their security violation is aligned with the traditional cybersecurity principles of Confidentiality, Integrity, and Availability (CIA). However, we only emphasize on model-related threats, rather than a classic threat scenario such as a DDoS attack, which might be a rising risk associated with LLMs, as a flood of requests may incur a significant jump in computational cost.

Knowing an adversary’s objective, as described in the preceding section, is essential. From a cybersecurity perspective, it is usually impossible to reduce the risk to zero, which is why we have to resort to increasing the cost for an attack to be successful. When the cost outweighs the gain, the adversary may give up the act. Thus, a second dimension of the taxonomy is to analyze the adversary’s capability, as this is a limiting factor on how much it costs to conduct an attack successfully. Now, we can categorize the adversarial attack based on the level of knowledge the attacker has about the system they are targeting.

This knowledge can vary greatly and is typically divided into three key areas:

  • Knowledge of the training data: The attacker might have access to all, some, or none of the training data used by the system. If they don’t have direct access, they might try to use a substitute dataset, which is as similar as possible to the original training data. An example of this is using honeypots to gather malware samples for studying how a malware detection system was trained. Nowadays, LLMs are typically trained on a huge number of web-scale text datasets, which are commonly available to everyone. It is therefore quite difficult to keep the training data confidential, as a substitute dataset is almost “free.”
  • Knowledge of the feature set: This refers to how much the attacker knows about the features (characteristics) that the system uses to make decisions or classifications. As ML becomes more standardized, it’s becoming easier for attackers to understand and predict these features. For example, in text processing, a common method to convert documents into a format that is understandable by machines is the tf-idf statistical measure.
  • Knowledge of the learning algorithm: The attacker may also know which learning algorithm the system uses, and what criteria it uses for making decisions. Some algorithms are more common in certain applications, such as deep learning networks for image recognition or Naive Bayes for document classification. For tabular datasets, XGBoost or other tree-like algorithms are almost always the first choice. Most recently, pre-trained models such as GPT-2, LLaMA, and other open source large models are serving as a fundamental building block of many AI systems. It is not difficult to guess which model family is being used in an application. Open source models have accelerated AI development vastly, inadvertently opening the gate for those bad actors as well.

Now, with the attacker’s level of knowledge, adversarial attacks can be further classified into three types:

  • Perfect knowledge (PK) attacks: These are also called white-box attacks, which are defined as being straightforward. In this worst-case scenario, the attacker has complete knowledge of the system (model, features, and data). This situation allows researchers to understand the maximum possible impact an attack could have on a system, and usually, this gives a lower bound on a model’s robustness. It represents how well the model can still perform under white-box attacks.
  • Limited knowledge (LK) attacks: These attacks are more common in real-world scenarios. Here, the attacker only has partial knowledge about the training data, the feature set, or the learning algorithm. They use this limited information to mimic the system’s behavior and create attack samples to test against the targeted system. The objective for the attacker is to gather as much information as possible, so they can simulate the attacks to generate adversarial samples. Note that adversarial samples show a feature of transferability. This means that the adversary doesn’t necessarily gain everything to be successful. It is sometimes enough for them to just conduct attacks on a surrogate model or dataset.
  • Zero-knowledge (ZK) attacks: These are also called black-box attacks. In contrast to PK attacks, the attacker has no information about the system at all with ZK attacks. In this case, attackers will have to conduct attacks using heuristic approaches, or by using a surrogate (substitute) model and data as in LK attacks, then transferring the attacks to the real system. The next figure shows a depiction of steps in a black-box attack with a substitute model: Figure 17.3 – Steps of a black-box attack with a substitute model: training of a substitute model (left) and attack execution (right)

Figure 17.3 – Steps of a black-box attack with a substitute model: training of a substitute model (left) and attack execution (right)

Nowadays, AI applications are typically offered as web services or APIs (for example, ChatGPT). Users do not have knowledge about their internal mechanisms (black-box), but attacks are still possible, such as adversarial prompting by heuristics. This type of attack may increase in terms of volume and complexity. Similar to white-box attacks, black-box attacks can give an upper bound on the model’s robustness. If an adversary can compromise the model with black-box attacks to a certain degree, the model will be even worse under PK and LK attacks. Have a look at the following figure:

Figure 17.4 – Attacker’s knowledge scale on target model and the associated robustness bounds

Figure 17.4 – Attacker’s knowledge scale on target model and the associated robustness bounds

For practitioners, there is always debate about how realistic PK and LK attacks are. However, it’s generally safer to overestimate rather than underestimate an attacker’s capabilities. This approach ensures that security measures are robust enough to protect against a wide range of potential threats.

Adversarial influence refers to how and to what extent an attacker can affect the learning process. This influence can manifest in different ways, where the attacker can impact the training phase, the testing phase, or both. Typically, we can classify the adversarial influence into two main categories depending on whether the attacks cause a model change or not. They are causative and exploratory attacks, though many call them poisoning and evasion attacks. We will use the latter to stay aligned with others:

  • Poisoning attacks: These attacks occur during the training phase. The attacker manages to insert a certain percentage of carefully designed, malicious data into the training set. This manipulation can involve changing both the features (the characteristics of the data) and the labels (the categories or classifications assigned to the data). The attacker’s goal is to subtly alter the training data in a way that causes the system to learn incorrectly, leading to a less effective predictive function. An example is inserting malware into a dataset that is wrongly labeled as secure by antivirus software, thereby poisoning the training data and misleading the classifier.
  • Evasion attacks: These occur during the test phase, where the attacker modifies malicious data to avoid detection by the system. The challenge for the attacker is to alter the data in such a way that it still performs its malicious function, but is no longer recognized by the classifier. For example, malware code might be obfuscated such that it evades detection without losing its harmful capabilities. Attackers are essentially probing the boundaries of the classifier’s detection abilities in this scenario, attempting to create data that is ambiguous enough to be misclassified and thus evade detection. Figure 17.5 – Illustration of both poisoning and evasion attacks on a simple classifier

Figure 17.5 – Illustration of both poisoning and evasion attacks on a simple classifier

In the preceding figure, we illustrate the difference between these two types of attacks on a simple classifier. Note how the classification boundary changes in the poisoning scenario. Both types of attacks present significant challenges. Poisoning attacks compromise the learning process itself, leading to the system forming a flawed understanding. Evasion attacks, on the other hand, test the system’s ability to correctly identify and respond to new, altered forms of known threats. Understanding these adversarial influences is crucial for developing robust defense mechanisms in ML systems.

You might wonder about the effective impact of adversarial attacks on real-world models, as the attacker seems to only have limited or zero knowledge of the target most of the time. In other words, the attacker seems to only have access to APIs (ML-as-a-Service). Black-box attacks may look less worrying until we realize the transferability of adversarial samples. Much research has explicitly shown that knowledge can be transferred from one model to another as long as the learning task stays the same. In practice, an attacker can design and train a substitute model as a proxy to the target model by querying input-output pairs from the real system. This shows that adversarial samples that are crafted against the substitute model are largely effective against the target model as well. Even if the substitute model is completely different from the target, the attacks can still be effective. It is argued that the adversarial property of ML models is loosely related to the model itself, but closely tied up with the feature space.

Have a look at the following figure:

Figure 17.6 – An adversarial attack’s transferability from black-box attacks on substitute models to target models

Figure 17.6 – An adversarial attack’s transferability from black-box attacks on substitute models to target models

In the figure, we illustrate the process of a black-box attack by training a substitute model, where the generated adversarial samples can be transferred to the target system. The attacker first sends queries to the target system to collect a set of input-output pairs, which are then used as a training dataset for the substitute model. After the substitute model is trained, the attacker launches adversarial attacks on the substitute model and generates adversarial samples. These samples are then sent to the target system to achieve the attacker’s goal due to the transferability of adversarial samples.

Now we want to conclude this section by summarizing the adversarial attack taxonomy. The following table presents an overview of attack taxonomy. It is recommended that you get familiar with the definitions and how the attacks are categorized:

Security violation

Influence

Specificity

Integrity

Availability

Privacy

Poisoning

Targeted

Training data is compromised that changes model behavior to, for instance, misclassify samples as a particular class or generate a specific content.

Training data is compromised that changes the model and degrades the model’s functionality on a particular task. For instance, the model might be quite bad at predicting spam.

The model is compromised and changed such that the model exposes confidential or private information in the training data.

Indiscriminate

This is the same as for targeted. However, the model misbehaves in general rather than on a particular set of samples.

The model is changed, and performance is degraded in general, rather than just being poor at certain tasks.

This is the same as for targeted. However, the model does not have a preference for what confidential information is generated.

Evasion

Targeted

The attack happens at test time and does not change the model itself. Instead, the attack targets a particular sample being misclassified or generated.

A targeted subset of samples can evade the model’s classification or be generated unfaithfully. The model itself is unchanged, but it performs poorly on the selected samples.

Attacks cause the model to leak specific data or information that is confidential or private, while the model stays unchanged.

Indiscriminate

This is the same as for targeted but the attacker does not have a preference for which sample should be misclassified. It is of interest to misclassify data or generate unfaithful content in general.

Attacks cause random samples to be misclassified or generated unfaithfully. It does not change the model itself. However, the model performs poorly in general.

This is the same as for targeted, but the attacks do not have a preference for which confidential data is leaked.

Table 17.1 – Adversarial attack taxonomy

In the next section, we will introduce different techniques to enhance model security, namely covering the defensive mechanisms that exist to increase a model’s robustness.

In the previous sections, we have learned about a general framework for adversarial threat modeling and various types of attacks. Those attacks are naturally grouped toward the adversary’s security objectives, namely the violation of confidentiality (privacy), integrity, and availability. This aligns well with the common strategy of the cybersecurity process, which moves across different stages, building and strengthening the system. Therefore, we will adopt a similar approach to design and develop defensive mechanisms as in traditional cybersecurity. However, we will restrict the scope of discussion to the realm of ML models. The systematic approach toward securing and hardening AI systems is beyond our discussion.

AI model security involves a dynamic and ongoing process aimed at safeguarding the integrity, confidentiality, and availability of AI systems. This process is not a one-time goal but a continuous journey that evolves and strengthens over time. AI model security encompasses a variety of strategies and actions, which can be broadly categorized into three main phases: prevention, detection, and response.

In the prevention phase, the focus is on implementing novel and robust AI models that can cope with the adversarial attacks described in previous sections, such that various types of attacks make little or neglectable impact on the targeted model. This is only feasible when we adopt a proactive approach (see the arms race problem) to explore both the lower and upper bound of model robustness and take actions to design more reliable models that take those attacks into account. Prevention typically happens at the model training phase, although it is not always effective in highly dynamic threat scenarios. In classic security terms, we also need to take measures to protect AI models from potential cyber threats and vulnerabilities. This could involve encrypting data, securing data pipelines, and ensuring robust access controls. The aim is to create a solid foundation that minimizes the risk of unauthorized access or manipulation of AI models.

It is imprudent if the defense strategy relies solely on prevention, as the threats are ever-changing. Therefore, we need a second set of guardrails with a detection capability. The detection phase is crucial for identifying any unusual or malicious activities that may indicate a security breach or attempt to compromise the AI model. This involves continuously monitoring the system, employing anomaly detection algorithms on adversarial samples or inputs, and setting up alerts for suspicious behavior. The sooner a potential threat is detected, the more effectively it can be addressed. Thus, we can imagine that detection-based countermeasures usually happen during the testing or prediction phase.

Upon the detection of adversarial attacks, alerts will be created with a collection of threat contexts such as the source of the attack, anomalous input samples, indicators of compromise, and so on. Alerts should trigger the next stage for incident response, wherein security analysts investigate the adversarial attacks and take appropriate actions to mitigate the impact of any security incidents that have been detected. This could include isolating affected systems, conducting thorough investigations to understand the nature and extent of the adversarial attacks, and implementing fixes to prevent similar attacks in the future. As we can observe, this feeds back to the prevention stage and closes a cyclic defensive pattern. We depict the defensive cycle as seen in the following figure:

Figure 17.7 – Defensive cycle in AML

Figure 17.7 – Defensive cycle in AML

The landscape of threats against AI models is ever-changing, necessitating timely updates and adjustments to the strategies employed in all three phases. A proactive approach in the prevention phase can significantly influence the effectiveness of detection and response mechanisms. Similarly, insights gained during the response phase can inform improvements in prevention and detection strategies. AI model security is a cyclical and adaptive process, constantly evolving in response to new challenges and threats. For successful management of this process, it’s crucial to design each phase with adequate capabilities and ensure diligent oversight to foster the continuous development and maturation of these capabilities. The overarching goal of AI model security is to ensure that AI systems remain reliable, trustworthy, and resilient against adversarial attacks or data manipulation, thereby protecting the vital attributes of confidentiality, integrity, and availability.

In the rest of this section, we will discuss some common state-of-the-art defense approaches in AML for each of the defensive stages. Although it is difficult to be comprehensive, we will mainly focus on the primary idea behind the methods rather than the algorithmic details. Note that this is an active research area, and the problem is yet to be solved. Therefore, the methodological landscape may change over time.

As in prevention, we aim to construct AI models that are robust against adversarial samples, which typically happen at the model training phase. Most countermeasures at this stage tackle the problem from both a data and a model perspective. In some literature, defense mechanisms are broadly categorized into data sanitation and model modification.

Data sanitation is straightforward to understand. Assuming the existence of adversarial samples in training data, that is, considering a data poisoning scenario, it is desirable to identify and remove the adversarial samples before or during model training. Although this is different from detection at the test stage, the general idea behind it is that the poisonous data samples represent themselves in a relatively low-density area in the data space. Therefore, they increase the training entropy, which can be detectable during the training phase. For instance, we could construct a second training set by selecting a candidate sample from the original dataset, and then observe how the model performance changes. Nevertheless, this is not ideal for scenarios wherein the adversarial samples are difficult to identify. We also expect the training cost to boost significantly when it comes to large models.

Model modification is likely the best choice for prevention, as sanitizing training data could be costly and inefficient against dynamic attacks. The key behind model modification is the same as the core principle of designing any learning model: to increase model generalization. Instead of increasing generalization on unseen (legitimate) test samples, we modify the models to be generalized on adversarial samples. In lots of research, we have seen significant improvement in terms of reduction of the attacker’s success rate. One of the most popular methods is called defensive distillation, which is based on the concept of knowledge distillation introduced by Geoff Hinton. Knowledge distillation involves transferring insights from a larger, more complex model to a smaller, more compact model while maintaining comparable performance. The fundamental concept of this method is to utilize the class probability vectors generated by an initial DNN as the training foundation for a second, smaller DNN. The goal is to achieve this without compromising the accuracy of the model, effectively ensuring that the distilled model can perform as well as its larger counterpart with reduced complexity. This has been proven to be effective against many gradient-based attacks. However, it is not quite successful in defending against strong attacks such as a Carlini & Wagner (CW) attack. In essence, defensive distillation is a gradient masking or obfuscation method. Since most adversarial attacks rely on gradient information to perturb the inputs, gradient masking or obfuscation can confound the attackers. However, even these defensive methods can be overcome, as shown in the work of Athalye et al., by advanced techniques for estimating gradients. There are other types of model modification, such as applying a non-differentiable pre-processor on training data and then training the model based on the pre-processed data. Another example is that we enforce randomized dropouts of neurons at inference, which can also increase robustness. Some ML systems use multiple-classifier systems, that is, ensembles to increase the non-smoothness of the model. Defense-GAN is another example that attaches an adversarial generator to the target classifier, such that the classifier learns how to differentiate normal and adversarial samples. They all fall in the broader category of strong regularization, which can increase the model generalization eventually.

Preventative measures act as the initial shield against adversarial attacks, offering a robust defense against known vulnerabilities and threats. They are the cornerstone of any security strategy, designed to thwart a wide array of attacks before they can inflict damage. However, the landscape of adversarial attacks is dynamic, with novel and sophisticated attack algorithms (e.g., 0 days) emerging regularly. These attacks exploit previously unknown vulnerabilities of models, making them particularly challenging for preventative measures to address effectively. To complement preventative strategies, a secondary line of defense is essential. This involves the deployment of advanced detection systems capable of identifying adversarial attacks swiftly and accurately. Such detection mechanisms come into play after the preventative measures, during the testing or prediction phases of system operation. The aim here is to catch any attack that slips past the initial defenses, ensuring a second layer of security.

Numerous algorithms and techniques have been developed to enhance the detection of adversarial examples. One practical method involves training an auxiliary classifier alongside the primary model. This secondary classifier is specifically designed to distinguish between legitimate inputs and adversarial examples, effectively acting as a dedicated sentinel for identifying malicious inputs. Proactive defense strategies also play a crucial role. By simulating adversarial attacks, defenders can gather critical data on potential threats, using this information to train models to recognize and counteract such attacks more effectively. This pre-emptive approach to security helps in fortifying systems against emerging threats.

Additionally, various statistical methods are employed to scrutinize the underlying structure of data for signs of adversarial tampering. Techniques such as Principal Component Analysis (PCA) can be instrumental in this regard. PCA, for instance, analyzes the large principal components of data, which adversarial attacks often exploit, thereby helping to pinpoint malicious samples. Other statistical methods assess the distributional characteristics of data to detect deviations indicative of adversarial manipulation.

Randomization techniques offer another layer of defense by introducing uncertainty into data handling processes. By applying random modifications, such as dropout techniques, to input data, these methods can expose the heightened variance in responses that is characteristic of adversarial examples compared to regular data. This variance serves as a tell-tale sign of potential adversarial interference, enabling more effective detection and response to such threats.

When an adversarial attack is identified, it’s critical to implement measures to mitigate the threat. A prevalent strategy for addressing this challenge is to incorporate the adversarial examples—those manipulated inputs designed to confuse the model—back into the model’s training cycle. This process, known as adversarial retraining, involves updating the model with these examples to improve its resilience against similar attacks in the future. Adversarial retraining is a proactive defense mechanism that can significantly enhance a model’s robustness.

This approach bears similarities to other defense strategies, such as Defense-GAN or secondary classification methods, which also aim to fortify models against attacks. However, adversarial retraining is distinct in that it is typically applied after an attack has been detected, necessitating further actions to secure the system. For instance, it might be necessary to isolate or quarantine the source of the suspicious queries to prevent further harm. Additionally, creating indicators of compromise based on the detected anomalies can help in identifying and responding to future threats more efficiently.

Beyond immediate remediation, it’s also essential to conduct a thorough investigation of the attack and share these insights with the team responsible for the model’s development. This collaboration enables the model’s developers to learn from the attack patterns and incorporate this knowledge into the creation of more secure and resilient models. By understanding the nature of the attacks and integrating these lessons into the model design and training process, the team can better prepare and protect against future adversarial challenges.

In conclusion, the exploration of adversarial threat modeling and various types of attacks has revealed the importance of a multi-layered defense strategy in protecting AI systems. This strategy mirrors the traditional cybersecurity approach, focusing on prevention, detection, and response, but it is tailored to the unique challenges of ML models. The goal is to safeguard the confidentiality, integrity, and availability of AI systems against an ever-evolving threat landscape.

For your convenience, the following table summarizes the defensive strategies in different stages:

StageExample defensive strategies
PreventionThe first line of defense aims to build AI models that are inherently robust against adversarial attacks. It includes the following: - Data sanitation to remove adversarial samples - Defensive distillation - Non-differentiable pre-processing - Randomized dropouts - Ensemble models - Defense-GANs
DetectionDetection mechanisms serve as a crucial second layer of defense. Examples include the following: - Auxiliary classifiers - Dimension reduction, such as PCA - Distributional detection, such as KDE and MMD - Randomization and tests of uncertainty
ResponseImmediate action is required to mitigate its impact. Examples include the following: - Adversarial retraining - Isolating the attack source - Creating Indicators of Compromise (IoCs)

Table 17.2 – Overview of defensive strategies against adversarial attacks

The dynamic nature of adversarial threats necessitates continuous updates and adjustments to these defensive strategies. By adopting a cyclical and adaptive process that encompasses prevention, detection, and response, AI model security can be significantly enhanced. Collaboration and knowledge sharing among model developers are also critical in developing more secure and resilient AI systems. While the field of AML defense is an active area of research with evolving methodologies, the primary focus remains on understanding and countering threats to ensure the long-term reliability and trustworthiness of AI systems.

Practical tools for testing on adversarial attacks

Section titled “Practical tools for testing on adversarial attacks”

As the area of AML is gaining practical significance, there have been tools developed to test AI systems and defenses against such attacks. In the following table, we have summarized some of them:

ToolDescriptionLink
CleverHansLibrary for constructing adversarial examples and defenses, plus benchmarkinghttps://github.com/cleverhans-lab/cleverhans
Adversarial Robustness ToolboxPython library for ML securityhttps://github.com/Trusted-AI/adversarial-robustness-toolbox
SecMLLibrary for security evaluation of ML algorithmshttps://github.com/pralab/secml

Table 17.3 – Examples of tools for adversarial attack testing and defense

All these libraries have a similar motivation, but slightly different focus. Depending on the use case, all of them can be useful for testing attacks and defenses on your ML system.

In this chapter, we were on an educational journey into the realm of AML, beginning with an engaging introduction that not only presented the subject matter but also underscored its significance in today’s digital age. The motivation behind this exploration was clearly articulated, highlighting the urgent need for robust defenses in AI systems against increasingly sophisticated cyber threats. The chapter thoughtfully guided you through the nuanced setup of learning environments, where the spotlight was firmly on ensuring the security and integrity of AI models amid a landscape fraught with potential adversarial exploits.

As the narrative progressed, the chapter delved deeper into the core of adversarial threat modeling. Here, you were equipped with a detailed understanding of the attacker’s methodology, encompassing a meticulously crafted taxonomy of adversarial attacks. This section was particularly enlightening, offering you a clear framework for categorizing and analyzing the myriad of threats that AI systems might face. The comprehensive breakdown served not only to inform but also to empower you with the knowledge to anticipate and recognize adversarial tactics.

Building on this foundation, the chapter transitioned into an extensive discussion on defensive mechanisms, thoughtfully categorized into three primary strategies: prevention, detection, and response. Each category was explored in depth, providing you with a clear understanding of the various tools and approaches available to safeguard AI systems. Through the lens of prevention, you learned about proactive measures designed to fortify AI models against intrusion. The detection segment shed light on the critical role of monitoring and identifying potential threats in real time, while the response section outlined effective countermeasures and remediation strategies to mitigate the impact of attacks.

By the conclusion of the chapter, you have not only been introduced to the complex world of AML but have also gained a comprehensive understanding of the strategies and mechanisms at your disposal to protect AI systems. This rich tapestry of knowledge, woven from the threads of theoretical frameworks and practical defensive techniques, leaves you well-equipped to navigate the challenges of securing AI models in an ever-evolving adversarial landscape. The chapter stands as a testament to the dynamic interplay between AI development and cybersecurity, offering a holistic view that is both educational and actionable. In the next chapter, we will introduce another important field for AI security and safety: challenges in privacy, ethics, explainability, and so on. These are the rising issues with the recent advance of GenAI.

  • Brückner, M., Scheffer, T., 2009. Nash Equilibria of Static Prediction Games. Presented at the Advances in Neural Information Processing Systems 22 - Proceedings of the 2009 Conference, pp. 171–179.
  • Carlini, N., Nasr, M., Choquette-Choo, C.A., Jagielski, M., Gao, I., Awadalla, A., Koh, P.W., Ippolito, D., Lee, K., Tramer, F., Schmidt, L., 2023. Are aligned neural networks adversarially aligned? https://doi.org/10.48550/arXiv.2306.15447
  • Nguyen, A., Yosinski, J., Clune, J., 2015. Deep neural networks are easily fooled: Hi gh confidence predictions for unrecognizable images, in: 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). Presented at the 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 427–436. https://doi.org/10.1109/CVPR.2015.7298640
  • Szegedy, C., Zaremba, W., Sutskever, I., Bruna, J., Erhan, D., Goodfellow, I., Fergus, R., 2014. Intriguing properties of neural networks. https://doi.org/10.48550/arXiv.1312.6199
  • Xiao, H., 2017. Adversarial and secure machine learning (Dissertation). Technische Universität München.
  • Athalye, Anish, Nicholas Carlini, and David Wagner. Obfuscated gradients give a false sense of security: Circumventing defenses to adversarial examples. In International conference on machine learning, pp. 274-283. PMLR, 2018.