Adversarial AI Attacks, Mitigations, and Defense Strategies
local graph
Adversarial AI Attacks, Mitigations, and Defense Strategies
Section titled “Adversarial AI Attacks, Mitigations, and Defense Strategies”chapter_01
Section titled “chapter_01”node-book_adversarial-ai-defense-strategies_chapter-01-getting-started-with-ai — Getting Started with AI
chapter_02
Section titled “chapter_02”node-book_adversarial-ai-defense-strategies_chapter-02-building-our-adversarial-playground — Building Our Adversarial Playground
chapter_03
Section titled “chapter_03”node-book_adversarial-ai-defense-strategies_chapter-03-security-and-adversarial-ai — Security and Adversarial AI
chapter_04
Section titled “chapter_04”node-book_adversarial-ai-defense-strategies_chapter-04-poisoning-attacks — Poisoning Attacks
chapter_05
Section titled “chapter_05”node-book_adversarial-ai-defense-strategies_chapter-05-model-tampering-with-trojan-horses-and-model-reprogramming — Model Tampering with Trojan Horses and Model Reprogramming
chapter_06
Section titled “chapter_06”node-book_adversarial-ai-defense-strategies_chapter-06-supply-chain-attacks-and-adversarial-ai — Supply Chain Attacks and Adversarial AI
chapter_07
Section titled “chapter_07”node-book_adversarial-ai-defense-strategies_chapter-07-evasion-attacks-against-deployed-ai — Evasion Attacks against Deployed AI
chapter_08
Section titled “chapter_08”node-book_adversarial-ai-defense-strategies_chapter-08-privacy-attacks-stealing-models — Privacy Attacks – Stealing Models
chapter_09
Section titled “chapter_09”node-book_adversarial-ai-defense-strategies_chapter-09-privacy-attacks-stealing-data — Privacy Attacks – Stealing Data
chapter_10
Section titled “chapter_10”node-book_adversarial-ai-defense-strategies_chapter-10-privacy-preserving-ai — Privacy-Preserving AI
chapter_11
Section titled “chapter_11”node-book_adversarial-ai-defense-strategies_chapter-11-generative-ai-a-new-frontier — Generative AI – A New Frontier
chapter_12
Section titled “chapter_12”node-book_adversarial-ai-defense-strategies_chapter-12-weaponizing-gans-for-deepfakes-and-adversarial-attacks — Weaponizing GANs for Deepfakes and Adversarial Attacks
chapter_13
Section titled “chapter_13”node-book_adversarial-ai-defense-strategies_chapter-13-llm-foundations-for-adversarial-ai — LLM Foundations for Adversarial AI
chapter_14
Section titled “chapter_14”node-book_adversarial-ai-defense-strategies_chapter-14-adversarial-attacks-with-prompts — Adversarial Attacks with Prompts
chapter_15
Section titled “chapter_15”node-book_adversarial-ai-defense-strategies_chapter-15-poisoning-attacks-and-llms — Poisoning Attacks and LLMs
chapter_16
Section titled “chapter_16”node-book_adversarial-ai-defense-strategies_chapter-16-advanced-generative-ai-scenarios — Advanced Generative AI Scenarios
chapter_17
Section titled “chapter_17”node-book_adversarial-ai-defense-strategies_chapter-17-secure-by-design-and-trustworthy-ai — Secure by Design and Trustworthy AI
chapter_18
Section titled “chapter_18”node-book_adversarial-ai-defense-strategies_chapter-18-ai-security-with-mlsecops — AI Security with MLSecOps
chapter_19
Section titled “chapter_19”node-book_adversarial-ai-defense-strategies_chapter-19-maturing-ai-security — Maturing AI Security
Preface
Section titled “Preface”The rise of AI is a new revolution in the making, transforming our lives. Alongside the phenomenal opportunities, new risks and threats are emerging, especially in the area of security, and new skills are demanded to safeguard AI systems. This is because some of these threats manipulate the very essence of how AI works to trick AI systems. We call this adversarial AI, and this book will walk you through techniques, examples, and countermeasures. We will explore them from both offensive and defensive perspectives; we will act as an attacker, staging attacks to demonstrate the threats and then discussing how to mitigate them.
Understanding adversarial AI and defending against it poses new challenges for cybersecurity professionals because they require an understanding of AI and Machine Learning (ML) techniques. The book assumes you have no ML or AI expertise, which will be true for most cybersecurity professionals. Although it will not make you a data scientist, the book will help you build a foundational hands-on understanding of ML and AI, enough to understand and detect adversarial AI attacks and defend against them.
AI has evolved. Its first wave covered predictive (or discriminative) AI with models classifying or predicting values from inputs. This is now mainstream, and we use it every day on our smartphones, for passport checks, at hospitals, and with home assistants. We will cover attacks on this strand of AI before we move to the next frontier of AI, generative AI, which creates new content. We will cover Generative Adversarial Networks (GANs), deepfakes, and the new revolution of Large Language Models (LLMs) such as ChatGPT.
The book strives to be hands-on, but adversarial AI is an evolving research topic. Thousands of research papers have been published detailing experiments in lab conditions. We will try to group this research into concrete themes while providing plenty of references for you to dive into for more details.
We will wrap up our journey with a methodology for secure-by-design AI with core elements such as threat modeling and MLSecOps, while looking at Trustworthy AI.
The book is detailed and demanding at times, asking for your full attention. The reward, however, is high. You will gain an in-depth understanding of AI and its advanced security challenges. In our changing times, this is essential to safeguard AI against its abusers.
Who this book is for
Section titled “Who this book is for”The book is for cybersecurity professionals, such as security architects, analysts, engineers, ethical hackers, penetration testers, and incident responders, but also developers and engineers designing, building, and assuring AI systems.
A basic understanding of security concepts is beneficial, and a hacking and tinkering mindset, especially using Python, is the ideal background.
What this book covers
Section titled “What this book covers”Chapter 1, Getting Started with AI, covers key concepts and terms surrounding AI and ML to get us started with adversarial AI.
Chapter 2, Building Our Adversarial Playground, goes through the step-by-step setup of our environment and the creation of some basic models and our sample Image Recognition Service (ImRecS).
Chapter 3, Security and Adversarial AI, discusses how to apply traditional cybersecurity to our sample ImRecS and bypass it with a sample adversarial AI attack.
Chapter 4, Poisoning Attacks, covers poisoning data and models, and how to mitigate them with examples from our ImRecS.
Chapter 5, Model Tampering with Trojan Horses and Model Reprogramming, looks at changing models by embedding code-based Trojan horses and how to defend against them.
Chapter 6, Supply Chain Attacks and Adversarial AI, covers traditional and new AI supply chain risks and mitigations, including building our own private package repository.
Chapter 7, Evasion Attacks against Deployed AI, explores fooling AI systems with evasion attacks and how to defend against them.
Chapter 8, Privacy Attacks – Stealing Models, looks at model extraction attacks to replicate models and how to mitigate these attacks, including watermarking.
Chapter 9, Privacy Attacks – Stealing Data, looks at model inversion and inference attacks to reconstruct or infer sensitive data from model responses.
Chapter 10, Privacy-Preserving AI, discusses techniques for preserving privacy in AI, including anonymization, differential privacy, homomorphic encryption, federated learning, and secure multi-party computations.
Chapter 11, Generative AI – A New Frontier, provides a hands-on introduction to generative AI with a focus on GANs.
Chapter 12, Weaponizing GANs for Deepfakes and Adversarial Attacks, provides an exploration of how to use GANs to support adversarial attacks, including deepfakes, and how to mitigate these attacks.
Chapter 13, LLM Foundations for Adversarial AI, provides a hands-on introduction to LLMs using the OpenAI API and LangChain to create our sample Foodie AI bot with RAG.
Chapter 14, Adversarial Attacks with Prompts, explores prompt injections against LLMs and how to mitigate them
Chapter 15, Poisoning Attacks and LLMs, looks at poisoning attacks with RAG, embeddings, and fine-tuning, using Foodie AI as an example, and appropriate defenses.
Chapter 16, Advanced Generative AI Scenarios, looks at poisoning the open source LLM Mistral with fine-tuning on Hugging Face, model lobotomization, replication, and inversion and inference attacks on LLMs.
Chapter 17, Secure by Design and Trustworthy AI, explores a methodology using standards-based taxonomies, threat modeling, and risk management to build secure AI with a case study combining predictive AI and LLMs.
Chapter 18, AI Security with MLSecOps, looks at MLSecOps patterns with examples of how to apply them using Jenkins, MLflow, and custom Python scripts.
Chapter 19, Maturing AI Security, discusses applying AI security governance and evolving AI security at an enterprise level.
To get the most out of this book
Section titled “To get the most out of this book”To follow along with the code, you will need a computer running Windows 10 or 11, macOS, or Linux with at least 16 GB of RAM. Windows users should use the Windows Subsystem for Linux 2 (WSL2) and Ubuntu 20.04. Alternatively, cloud solutions such as Colab or AWS SageMaker notebook instances will provide the processing power you will need. In all cases, you should have a basic understanding of a Bash command-line environment.
Most examples use Python 3.x, virtual environments, pip packages, and Jupyter notebooks. Chapter 2 will take you step by step through setting up the Python environments. Additionally, we will use Docker custom image files and Docker Compose files but we will provide detailed commands and scripts.
To edit or run the examples, you must have a browser or an IDE that supports Jupyter Notebook, such as Visual Studio Code or IntelliJ PyCharm. Both are free and can be found at https://code.visualstudio.com and https://www.jetbrains.com/pycharm, respectively. A browser will be more than sufficient for the examples in this chapter.
| Software/hardware covered in the book | Operating system requirements |
|---|---|
| Python 3.x, TensorFlow 2.x with Keras | Windows, macOS, or Linux |
| OpenAI and Hugging Face APIs LangChain | |
| Docker |
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
Section titled “Download the example code files”Conventions used
Section titled “Conventions used”There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The random_state parameter allows us to reproduce the split.”
A block of code is set as follows:
from sklearn.model_selection import train_test_splitX_train, X_test, y_train, y_test = train_test_split(wine.data, wine.target, test_size=0.2, random_state=42)When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
# Make predictions on the test set and calculate the accuracyy_pred_tree = tree.predict(X_test)accuracy_tree = accuracy_score(y_test, y_pred_tree)Any command-line input or output is written as follows:
python -m ipykernel install --user --name=secure-ai --display-name="Secure AI"Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Navigate to API Keys and create a new key.”
Tips or important notes
Appear like this.