Boosting Black-box Attack to Deep Neural Networks with Conditional
  Diffusion Models
Existing black-box attacks have demonstrated promising potential in creating
adversarial examples (AE) to deceive deep learning models. Most of these
attacks need to handle a vast optimization space and require a large number of
queries, hence exhibiting limited practical impacts in real-world scenarios. In
this paper, we propose a novel black-box attack strategy, Conditional Diffusion
Model Attack (CDMA), to improve the query efficiency of generating AEs under
query-limited situations. The key insight of CDMA is to formulate the task of
AE synthesis as a distribution transformation problem, i.e., benign examples
and their corresponding AEs can be regarded as coming from two distinctive
distributions and can transform from each other with a particular converter.
Unlike the conventional \textit{query-and-optimization} approach, we generate
eligible AEs with direct conditional transform using the aforementioned data
converter, which can significantly reduce the number of queries needed. CDMA
adopts the conditional Denoising Diffusion Probabilistic Model as the
converter, which can learn the transformation from clean samples to AEs, and
ensure the smooth development of perturbed noise resistant to various defense
strategies. We demonstrate the effectiveness and efficiency of CDMA by
comparing it with nine state-of-the-art black-box attacks across three
benchmark datasets. On average, CDMA can reduce the query count to a handful of
times; in most cases, the query count is only ONE. We also show that CDMA can
obtain $>99\%$ attack success rate for untarget attacks over all datasets and
targeted attack over CIFAR-10 with the noise budget of $\epsilon=16$.
Renyang Liu, Wei Zhou, Tianwei Zhang, Kangjie Chen, Jun Zhao, Kwok-Yan Lam
# Boosting Black-box Attack to Deep Neural Networks with Conditional Diffusion Models

###### Abstract

Existing black-box attacks have demonstrated promising potential in creating adversarial examples (AE) to deceive deep learning models. Most of these attacks need to handle a vast optimization space and require a large number of queries, hence exhibiting limited practical impacts in real-world scenarios. In this paper, we propose a novel black-box attack strategy, Conditional Diffusion Model Attack (CDMA), to improve the query efficiency of generating AEs under query-limited situations. The key insight of CDMA is to formulate the task of AE synthesis as a distribution transformation problem, i.e., benign examples and their corresponding AEs can be regarded as coming from two distinctive distributions and can transform from each other with a particular converter. Unlike the conventional _query-and-optimization_ approach, we generate eligible AEs with direct conditional transform using the aforementioned data converter, which can significantly reduce the number of queries needed. CDMA adopts the conditional Denoising Diffusion Probabilistic Model as the converter, which can learn the transformation from clean samples to AEs, and ensure the smooth development of perturbed noise resistant to various defense strategies. We demonstrate the effectiveness and efficiency of CDMA by comparing it with nine state-of-the-art black-box attacks across three benchmark datasets. On average, CDMA can reduce the query count to a handful of times; in most cases, the query count is only ONE. We also show that CDMA can obtain \(>99\%\) attack success rate for untarget attacks over all datasets and targeted attack over CIFAR-10 with the noise budget of \(\epsilon=16\).

 Adversarial Example, Adversarial Attack, Black-box Attack, Generative-based Attack, Conditional Diffusion Model.

## I Introduction

In recent years, Deep Learning (DL) has experienced rapid development, and DL models are widely deployed in many real-world applications, such as facial recognition [1], autonomous driving [2], financial services [3], etc. However, existing DL models have been proven to be fragile that they can be easily fooled by adding elaborately calculated imperceptible perturbations to the benign inputs, known as adversarial examples (AEs). Therefore, the security of DL models has been attracting more and more attention from researchers.

Typically, adversarial attacks can be classified into two categories based on their settings. The first one is white-box attacks [4, 5], where the attacker has complete information of the victim models, including the model structure, weights, gradients, etc. Such information can assist the attacker to achieve a very high attack success rate. A variety of attack techniques have been proposed to effectively generate AEs under the white-box setting, e.g., FGSM [6], C&W [4], etc.

The second one is black-box attacks [7, 8, 9, 10, 11], which is more practical in the real world. The attacker is not aware of the victim model's information. He has to repeatedly query the victim model with carefully crafted inputs and adjust the perturbations based on the returned soft labels (prediction probability) or even hard labels [12, 13]. Many query-efficient and transfer-based attack methods have been proposed recently. However, they suffer from several limitations. First, these methods still need hundreds to thousands of queries to generate one AE [8]), especially in the targeted attack setting. This makes the attack costly in terms of computation resources, time and monetary expense, restricting their practicality in real-world scenarios. Besides, more queries can remarkably increase the risk of being detected [14]. Second, AEs generated by the noise-adding manner are easy to be identified or denoised, decreasing the attack performance to a large extent [15, 16]. Once the victim model is equipped with some defense mechanisms, the attacker needs to consume more model queries to optimize a new AE. Third, the quality of the generated AE highly depends on the similarity between the local surrogate model and the victim model, which normally cannot be guaranteed. This also limits the performance of existing attack methods.

Driven by the above drawbacks, the goal of this paper is to design new hard-label black-box attack approaches, which can generate AEs with limited queries for both untarget and targeted settings. This is challenging due to the restrictions of limited information about the victim model, and query budget. Our observation is that _clean samples and their corresponding AEs follow two adjacent distributions, connected by certain relationships_. This presents an opportunity to _build a converter, which can easily transfer each clean sample to its corresponding AE without complex optimization operations_. Following this hypothesis, we propose CDMA, a novel Conditional Diffusion Model Attack to attack black-box DL models efficiently. Different from prior attacks using the iterative query-and-optimization strategy, CDMA converts the AE generation task into an image translation task, and adopts a conditional diffusion model (i.e., the converter) to directly
synthesize high-quality AEs. In detail, we first execute the diffusion process to train a conditional diffusion model with pre-collected pair-wised clean-adversarial samples, where the AEs are generated with white-box attack methods from local shadow models. During the training, the clean images are used as the condition to guide the diffusion model to generate eligible AEs from a given unique input. Once the diffusion model is trained, we can execute the reverse process for the clean input to formulate corresponding AEs.

Compared to existing works, CDMA has the following advantages. (1) It significantly improves the attack effectiveness by conditional synthesis instead of query and optimization. (2) CDMA does not rely on the inherent attribute of the target model. It only requires the hard labels to verify whether the victim model has been attacked successfully. As a result, the pre-trained diffusion model has a high generalization ability to attack any DL models. (3) Once the diffusion model is well-trained, the attacker can batch-wisely sample sufficient candidate AEs, further improving the attack efficiency and scalability. (4) Benefiting from the smooth synthesizing processes, the formulated AEs are challenging to be purified and can keep high robustness against different defense mechanisms.

We evaluate CDMA on mainstream datasets (CIFAR-10, CIFAR-100 and Tiny-ImageNet-200), and compare it with state-of-the-art black-box attack methods, including pure black-box attacks (soft- and hard-label), query-based and transfer-based attacks. Extensive experiment results demonstrate our superior query efficiency. In all attack settings, CDMA achieves a comparable attack success rate to all baselines but with significantly reduced numbers of queries. Besides, AEs generated from CDMA exhibit higher robustness to several mainstream defense strategies. Finally, the empirical results of data-independent and model-independent attacks have validated our assumption, i.e., the clean and adversarial examples come from two disparate distributions, which can be transformed into each other, and the proposed CDMA can well learn this transformation relationship.

To summarize, our main contributions are as follows:

* We model the adversarial example generation as a distribution transform problem with a perfect data converter on certain conditions to achieve efficient black-box attacks.
* We build the data converter with a diffusion model and propose a novel diffusion model-based black-box attack named CDMA, which can directly formulate the corresponding AE by conditional sampling on the original clean image without the complex iterative process of query and optimization.
* CDMA can generate AEs with high attack ability and robustness. These AEs can be well transferred to different victim models and datasets.
* We perform extensive experiments to demonstrate the superiority of CDMA over state-of-the-art black-box methods, in terms of query efficiency, attack robustness and effectiveness in both untargeted and targeted settings.

The remainder of this paper is organized as follows: we briefly review the existing literature on adversarial attacks in Sec. II. We define our distribution transformation-based attack and propose the diffusion model-based CDMA method in Sec. III. In Sec. IV, we perform extensive experiments to show that CDMA is more efficient and effective than other baseline attacks under untarget and targeted situations. It can also successfully keep the high attack performance against different defense strategies. Finally, we conclude this paper in Sec. V.

## II Related Work

Adversarial attacks against deep learning models refer to the process of intentionally manipulating benign inputs to fool well-trained models. Based on the setting, existing attacks can be classified into two categories: in the _white-box_ setting, the attacker knows every detail about the victim model, based on which he creates the corresponding AEs. In the _black-box_ setting, the attacker does not have the knowledge of the victim model, and are only allowed to query the model for AE generation. In this paper, we focus on the black-box one, which is more practical but also more challenging.

There are three types of techniques to achieve black-box adversarial attacks. The first one is transfer-based attacks. Papernot et al. [17] proposed the pioneering work towards black-box attacks, which first utilizes Jacobian-based Dataset Augmentation to train a substitute model by iteratively querying the oracle model, and then attacking the oracle using the transferability of AEs generated from the substitute model. TREMBA [18] trains a perturbation generator and traverses over the low-dimensional latent space. ODS [19] optimizes in the logit space to diversify perturbations for the output space. GFCS [20] searches along the direction of surrogate gradients and falls back to ODS. CG-Attack [21] combines a well-trained c-glow model and CAM-ES to extend attacks. However, these transfer-based attacks heavily rely on the similarity between the substitute model and the oracle model.

The second type is score-based attacks. Ilyas et al. [13] proposed a bandit optimization-based algorithm to integrate priors, such as gradient priors, to reduce the query counts and improve the attack success rate. Chen et al. [22] proposed zeroth order optimization-based attacks (ZOO) to directly estimate the gradients of the target DNN for generating AEs. Although this attack achieves a comparable attack success rate, its coordinate-wise gradient estimation requires excessive evaluations of the target model and is hence not query-efficient. AdvFlow [8] combines a normalized flow model and NES to search the adversarial perturbations in the latent space to balance the query counts and distortion and accelerate the attack process.

The third type is decision-based attacks, which are specifically designed for the hard-label setting. Boundary attack [12] is the earliest one that starts from a large adversarial perturbation and then seeks to reduce the magnitude of perturbation while keeping it adversarial. Bayes_Attack [9] uses Bayesian optimization to find adversarial perturbations in the low-dimension subspace and maps it back to the original input space to obtain the final perturbation. NPAttack [11] considers the structure information of pixels in one image rather than individual pixels during the attack with the help of a pre-trained Neural Process model. Rays [7] introduces a Ray Searching Method to reformulate the continuous problem of
finding the nearest decision boundary as a discrete problem that does not require any zero-order gradient estimation, which significantly improves the previous decision-based attacks. Triangle Attack (TA) [10] optimizes the perturbation in the low-frequency space by utilizing geometric information for effective dimensionality reduction.

The above query-and-optimization black-box attacks are inefficient and uneconomical because they require thousands of queries on the target model. In this situation, the time and computational consumption could be very considerable. On the other hand, the performance of transfer-based black-box attacks is often limited by the similarity between the surrogate model and the oracle model. Besides, these attacks cannot extend to the data-independent or model-independent scenario or keep robustness to different defense strategies, which fades the attack capability to a considerable extent.

Therefore, it is necessary to have a method that can efficiently generate AEs within limited queries, which are effective against different models and datasets. We propose to use the diffusion model to achieve this goal. The diffusion model is an advanced technique for image translation tasks. We can train such a model to convert clean images to AEs against the black-box victim model. Our attack, CDMA, does not require a large number of queries or detailed information regarding the victim model in the attacking process and the formulated AEs can be resistant to most defense strategies.

## III Methodology

### _Problem Definition_

Given a well-trained DNN model \(\mathbf{\mathcal{M}}\) and an input \(\mathbf{x}\) with its corresponding label \(y\), we have \(\mathbf{\mathcal{M}}(\mathbf{x})=y\). The AE \(\mathbf{x}^{adv}\) is a neighbor of \(\mathbf{x}\) that satisfies \(\mathbf{\mathcal{M}}(\mathbf{x}^{adv})\neq y\) and \(\left\|\mathbf{x}^{adv}-\mathbf{x}\right\|_{p}\leq\epsilon\), where \(\mathbf{L}_{p}\) norm is used as the metric function and \(\epsilon\) is a small noise budget. With this definition, the problem of generating an AE becomes a constrained optimization problem:

\[\mathbf{x}_{adv}=\left.\begin{array}{l}arg\ max\mathcal{L}\left(\mathbf{\mathcal{M }}(\mathbf{x}^{adv})\neq y\right),\\ \end{array}\right. \tag{1}\]

where \(\mathcal{L}\) stands for a loss function that measures the confidence of the model outputs.

Existing attack methods normally utilize the information (e.g., the prediction results, model weights, etc.) obtained from the target model to optimize the above loss function. Different from them, in this paper, we convert the AE generation problem into an image-to-image task: an adversarial image \(\mathbf{x}_{adv}\) can be regarded as a particular transformation from its corresponding clean image \(\mathbf{x}\). These two different images (\(\mathbf{x}\) and \(\mathbf{x}_{adv}\)) can be mutually transformed from each other by a converter. We choose a rising star generative model, the diffusion model, as our image converter and propose a Conditional Diffusion Model-based Attack framework for synthesizing AEs.

### _Denoising Diffusion Probabilistic Models_

Unlike VAE or Flow models, diffusion models are inspired by non-equilibrium thermodynamics to learn through a fixed process. The latent space has a relatively high dimensionality. It first defines a Markov chain of diffusion steps and corrupts the training data by continuously adding Gaussian noise until it becomes pure Gaussian noise. Then it reverses the process by removing noise and reconstructing the desired data. Once the model is well-trained, it can generate data through the learned denoising process by inputting randomly sampled noise. Here, we briefly review the representative Denoising Diffusion Probabilistic Models (DDPM) [23].

In the forward progress (i.e., adding noise), given an image \(x_{0}\sim q(x)\), the diffusion process can obtain \(x_{1},x_{2},...,x_{T}\) by adding Gaussian noise \(T\) times, respectively. This process can be expressed as a Markov chain:

\[q(x_{t}|x_{t-1}) =\mathcal{N}(x_{t};\sqrt{1-\beta_{t}}x_{t-1},\beta_{t}\text{I}), \tag{2}\] \[q(x_{1:T}|x_{0}) =\prod_{t=1}^{T}q(x_{t}|x_{t-1})=\prod_{t=1}^{T}(x_{t};\sqrt{1- \beta_{t}}x_{t-1},\beta_{t}\text{I})\]

where \(t\in{1,2,...,T}\), \(\left\{\beta_{t}\in(0,1)\right\}_{t=1}^{T}\) is the hyper-parameter of the Gaussian distribution's variance. In this process, \(x_{t}\) tends to be pure Gaussian noise with the increase of \(t\). It finally becomes the Standard Gaussian noise \(\mathcal{N}(0,\text{I})\) when \(T\rightarrow\infty\).

Suppose \(\alpha_{t}:=1-\beta_{t}\) and \(\bar{\alpha}_{t}:=\prod_{i=1}^{T}\alpha_{i}\). Then \(x\) of arbitrary \(t\) can be written in the following closed form:

\[\begin{array}{l}q(x_{t}|x_{0})=\mathcal{N}(x_{t};\sqrt{\bar{\alpha}_{t}}x_ {0},(1-a_{t})\text{I}),\\ x_{t}=\sqrt{\bar{\alpha}_{t}}x_{0}+\sqrt{1-\bar{\alpha}_{t}}\delta\end{array} \tag{3}\]

Fig. 1: Overview of CDMA, \(\mathcal{D}\{X,X^{adv}\}\) is the collected pair-wised clean and adversarial dataset and \(X^{adv}_{t}\) is the adversarial example \(X^{adv}\) at the forward or reverse step \(t\). \(\epsilon\sim\mathcal{N}(0,\text{I})\) is the Gaussian noise and \(\mathcal{M}(\cdot)\) is the target victim model.
where \(\delta\sim\mathcal{N}(0,\text{I})\). \(x_{t}\) satisfies \(q(x_{t}|x_{0})=\mathcal{N}(x_{t}\sqrt{\bar{a}_{t}}x_{0},(1-\bar{a}_{t})\text{I})\).

The reverse process is the denoising of diffusion. If we can gradually obtain the reversed distribution \(q(x_{t-1}|x_{t})\), we can restore the original image \(x_{0}\) from the standard Gaussian distribution \(\mathcal{N}(0,\text{I})\).

As \(q(x_{t}|x_{t-1})\) is a Gaussian distribution and \(\beta_{t}\) is small enough, \(q(x_{t-1}|x_{t})\) is a Gaussian distribution. However, we do not have a simple way to infer \(q(x_{t-1}|x_{t})\). DDPM adopts a deep neural network, typically U-Net, to predict the mean and covariance of \(x_{t-1}\) of the given input \(x_{t}\). In this situation, the reverse process can be written as the parameterized Gaussian transitions:

\[\begin{split} p_{\theta}(X_{0:T})=P(x_{T})\prod_{t=1}^{T}p_{ \theta}(x_{t-1}|x_{t}),\\ P_{\theta}(x_{t-1}|x_{t})=\mathcal{N}(x_{t-1};\mu(x_{t},t),\sum_{ \theta}(x_{t},t))\end{split} \tag{4}\]

With Bayes's theorem, DDPM predicts the noise \(\delta_{\theta}(x_{t},t)\) instead and computes \(\mu(x_{t},t)\) as follows:

\[\mu(x_{t},t)=\frac{1}{\sqrt{\alpha_{t}}}(x_{t}-\frac{\beta_{t}}{\sqrt{1-\bar{ \alpha}_{t}}}\delta_{\theta}(x_{t},t)) \tag{5}\]

### _Conditional Diffusion Model Attack (CDMA)_

The whole framework of CDMA is illustrated in Figure 1, which can be split into the following three stages: training sample collection, model training (forward process), and AE generating (reverse process). Specifically, in **Stage I**, the attacker collects the clean-adversarial example pairs, where the adversarial examples are built from local shadow models using standard white-box attack techniques. In **Stage II**, the attacker trains a conditional diffusion model with the pair-wised \((\mathbf{x},\mathbf{x}_{adv})\) sampled from the pre-collocated dataset \(\mathcal{D}\{X,X^{adv}\}\). The conditional diffusion model is composed of a series of encoder-decoder-like neural networks (UNET [24] is adopted in this work). Once the model is well-fitted, the attacker can perform the attacks against the victim model in a sampling manner in **Stage III** instead of a query-and-optimization way. Below we give details of each stage.

#### Iii-C1 **Training Sample Collection**

Recall that our training data are paired with clean and adversarial samples, where the clean example is used as an inference image and concatenated with its corresponding adversarial example to compose the diffusion model's input. More specifically, for a given dataset, we first use typical white-box attack methods (e.g., PGD [25] and et al.) to attack the local shadow model and obtain the corresponding adversarial examples, which are then paired with the original clean examples to formulate the training dataset \(\mathcal{D}=\{X,X^{adv}\}\) of our diffusion model.

#### Iii-C2 **Conditional Diffusion Model Training**

The core of training a diffusion model is to make it predict reliable noise \(\delta\). Unlike [23], we need to consider the additional conditional variable \(x\). We use \(\delta\) to represent the real noise added to \(x^{adv}\) at each step \(t\), and use \(\tilde{\delta}_{\theta}\) to represent the noise predicted by model \(f(\cdot)\) (U-NET in this paper). Then the final objective function can be written as:

\[\mathcal{L}=E_{t,\{x,\tilde{\sigma}_{0}^{adv}\},\hat{\delta}}\left\|\delta- \hat{\delta}_{\theta}(x_{t}^{adv},t,x)\right\|_{p} \tag{6}\]

where \(t\sim[1,2,...,T],\{x,x_{0}^{adv}\}\sim\mathcal{D}\{x,x^{adv}\},x_{t}^{adv} \sim q(x_{t}^{adv}|x_{0}^{adv},x)\), \(\delta\sim\mathcal{N}(0,\text{I})\), \(\|\cdot\|_{p}\) represents the \(L_{p}\)-norm and \(p\in\{0,1,2,L_{\infty}\}\). As demonstrated in [26], \(L_{1}\) yields significantly lower sample diversity compared to \(L_{2}\). Since we aim to generate diversified adversarial examples, we also adopt \(L_{2}\), i.e., MSE, as our loss function to constrain the true noise \(\delta\) and the predicted noise \(\hat{\delta}_{\theta}\).

```
0:\(\{x,x^{adv}\}\): the clean image and adversarial image pair; \(t\sim\mathcal{U}(1,...,T)\): The time-steps belong to Uniform distribution.
0: The well-trained model \(M(\cdot)\).
1:repeat
2: Take the gradient step on \(\mathcal{L}=E_{t,\{x,x_{0}^{adv}\},\hat{\delta}}\left\|\hat{\delta}-\hat{ \delta}_{\theta}(x_{t}^{adv},t,x)\right\|_{p}\).
3:until converged
```

**Algorithm 1** Conditional Diffusion Model Training

#### Iii-C3 **Generate Adversarial Examples.**

In CDMA, the attacker generates adversarial examples for benign images by sampling from the well-trained conditional diffusion model. Our generation process becomes sampling from the conditional distribution \(P(x_{0}^{adv}|c)\), where \(c\) is the clean image \(x\). As the aforementioned sampling process of DDPM [23, 27] (Eq. 4), the conditional sampling can be written as follows:

\[\begin{split} p_{\theta}(x_{0}^{adv}|x)=\int p_{\theta}(x_{0:T}^{ adv}|x)dx_{1:T}^{adv}\\ p_{\theta}(x_{0}^{adv}|x)=p(x_{T}^{adv})\prod_{t=1}^{T}p_{ \theta}(x_{t-1}^{adv}|x_{t}^{adv},x)\end{split} \tag{7}\]

Here each transition \(p_{\theta}(x_{t-1}^{adv}|x_{t}^{adv},x)\) in the sampling process depends on the condition \(x\), i.e., the clean image. The sampling (Eq.4) in the conditional version is re-written as:
\[p_{\theta}(x_{t-1}^{adv}|x_{t}^{adv},x)=\mathcal{N}(x_{t-1}^{adv};\mu_{\theta}(x_{ t}^{adv},t,x),\sum_{\theta}(x_{t}^{adv},t,x)) \tag{8}\]

As shown in Eq. 8, CDMA generates the adversarial example \(\mathbf{x}^{adv}\) via the diffusion model's reverse Markov process and starts from \(\mathbf{x}_{0}^{adv}=\epsilon\sim\mathcal{N}(0,\text{I})\) with the conditional clean image \(x\). To make the final adversarial examples meet the similarity requirements, we impose the extra \(clip(\cdot)\) constraints on \(L_{\infty}\)-norm as:

\[\mathbf{x}_{final}^{adv}=clip(clip(\mathbf{x}_{0}^{adv},x-\epsilon,x+\epsilon),0,1) \tag{9}\]

where \(\epsilon\) is the adversarial perturbation budget.

The training and attacking algorithms of CDMA are listed in Alg. 1 and Alg. 2, respectively, which could help readers to re-implement our method step-by-step.

## IV Evaluation

We present the experimental results of CDMA. We first compare it with other black-box attack baselines in untarget and targeted scenarios. Then we measure the attack effectiveness against state-of-the-art defenses. Next, we show the results of data-independent and model-independent attacks. Finally, we show the ablation study results to explore the attack ability of CDMA under different settings.

### _Experimental Setup_

**Implementation.** We set the maximum number of queries as \(Q_{max}=1000\) to simulate a realistic attack scenario. We stop the attack once a specific input is mispredicted by the victim model successfully. We set the noise budget as \(\epsilon=8/255\). and \(\epsilon=16/255\)., which is shortened as \(\epsilon=8\) and \(\epsilon=16\) for all attacks. To train the diffusion model in CDMA, the total number of diffusion steps is \(T=2000\). The number of training epochs is \(E=1e8\) with the batch size of \(B=256\). The noise scheduler is "linear" starting from \(1e-6\) and ending with \(0.01\). All the experiments are conducted on a GPU server with 4*NVIDIA Tesla A100 40GB GPU, 2*Xeon Glod 6112 CPU and RAM 512GB.

**Datasets.** We verify the performance of CDMA on three benchmark datasets for computer vision task, named CIFAR-101 [28], CIFAR-1002 [28] and Tiny-ImageNet-2003 [29]. In detail, CIFAR-10 contains 50,000 training images and 10,000 testing images with the size of \(3\times 32\times 32\) from 10 classes; CIFAR-100 has 100 classes, including the same number of training and testing images as the CIFAR-10; Tiny-ImageNet-200 has 200 categories, containing about 1.3M samples for training and 50,000 samples for validation. In our experiments, we first generate adversarial examples using white-box attacks on the training set of the above three datasets to train the diffusion model, and then randomly sample 1,000 images from the test set of these datasets for attacks.

Footnote 1: [http://www.cs.toronto.edu/](http://www.cs.toronto.edu/) kriz/cifar.html

Footnote 2: [http://www.cs.toronto.edu/](http://www.cs.toronto.edu/) kriz/cifar.html

Footnote 3: [http://cs231n.stanford.edu/tiny-imagenet-200.zip](http://cs231n.stanford.edu/tiny-imagenet-200.zip)

**Models.** We train a few widely-used deep neural networks, including VGG [30], Inception [31, 32], ResNet [33], and DenseNets [34] over the aforementioned datasets until the models achieve the best classification results. Among them, We adopt VGG-13, ResNet-18 and DeseNet-121 as the shadow models for all query- and transfer-based baselines and CDMA, while VGG-19, Inception-V3, ResNet-50 and DenseNet-169 as the victim models to be attacked for all the methods. The top-1 classification accuracy of these victim models are 90.48%, 84.51%, 94.07%, and 94.24% for CIFAR-10, 66.81%, 77.86%, 76.05% and 77.18% for CIFAR-100 and
57.62%, 65.89%, 65.41% and 56.04% for Tiny-ImageNet-200, respectively.

**Baselines.** We select nine state-of-the-art black-box attacks as the baselines, including score-based, decision-based, and query- and transfer-based methods. These include Rays [7], AdvFlow [8], Bayes_Attack [9], TA [10], NPAttack [11], ODS [19], GFCS [20], CG-Attack [21] and MCG-Attack [35]. We reproduce the attacks from the code released in the original papers with the default settings.

**Metrics.** We perform evaluations with the following metrics: Attack Success Rate (ASR) measures the attack effectiveness. Average and Median numbers of queries (Avg.Q and Med.Q) measure the attack efficiency.

### _Comparisons with Baseline Attacks_

Tables I, II and III present the untarget and targeted attack performance comparison with all baselines under the noise budget \(\epsilon=16\) on VGG-19, Inception-V3, ResNet-50, and
DenseNet-169, respectively. Specifically, in both untarget and targeted situations, we observe that our proposed CDMA enjoys much higher efficiency in terms of the average and median numbers of queries, as well as much higher attack success rate than AdvFlow, Bayes_Attack and TA for all datasets. Compared to the rest baselines, although the attack success rate of CDMA does not exceed too much, in some cases, even lower than Rays (when extending the untarget attack on VGG-19 with CIFAR-100) and GFCS (when extending the targeted attack on VGG-19 with Tiny-ImageNet-200), the Avg.Q and Med.Q are always lowest than all methods, especially in the target setting. CDMA only needs several queries to obtain a near 100% attack success rate and the Med.Q of CDMA is 1. These experimental results demonstrate the superiority of our proposed method in terms of attack effectiveness and efficiency.

Table. IV presents the performance comparison of all attack baselines on VGG-19, Inception-V3, ResNet-50 and DenseNet-169, respectively, where the noise budget is set to \(\epsilon=8\). Although the attack becomes more challenging with a small noise budget, compared with all the attack baselines, the proposed CDMA can also get the best attack performance in most situations. Especially the average and median queries of CDMA are still the lowest in all cases, which have exhibited the high effectiveness of the proposed methods.

Figure 2 shows the attack success rate versus the number of queries for all baseline methods over CIFAR-10, CIFAR-100, and Tiny-ImageNet-200 in untarget and target attack settings. Again we can see that CDMA achieves the highest attack success rate in most situations and the best query efficiency compared with other black-box attack baselines. The results show that our proposed CDMA can achieve the highest attack success rate under the same query counts. Note that CDMA can obtain a boosting attack success rate at the first few queries, especially under targeted attack settings, while other attacks only can obtain a satisfactory attack success rate after hundreds of queries.

### _Adversarial Robustness to Defense Strategies_

To further evaluate the generated adversarial examples' robustness, we adopt some defense methods to purify or pre-process the malicious examples, and then measure their effectiveness. The defense methods in our consideration involve JPEG compression (JPEG) [36], NRP [37], pixel deflection (PD) [38], GuidedDiffusionPur (GDP) [16], RP-Regularizer (RP) [39], BitDepthReduce (BDR) [40] and MedianSmoothing2D (MS) [40]. We first synthesize adversarial examples on
ResNet-50 for CIFAR-10, and then measure their attack success rate against these defense strategies. The results are shown in Table. V. Among all the black-box attack methods, our proposed method has the highest attack success rate in most cases, which implies the adversarial examples generated by CDMA are more robust to current defense methods compared with other attacks.

### _Data-independent and Model-independent Attacks_

#### Iv-D1 **Data-independent Attack**

We carry out attacks across different datasets to verify the generalization of our CDMA. The datasets include STL-10 [41], Caltech-256 [42], Places-365 [43]) and CeleBA [44]. These datasets are not used for training the diffusion model, and we only sample images from their test set to test the effectiveness of CDMA.

In detail, we train a diffusion model based on a specific dataset (CFAIR-10 and Tiny-ImageNet-200) and then apply the attack on another dataset (STL-10, Caltech-256, Places-365 and CeleBA) to verify whether it can transform clean data into its corresponding adversarial examples. The results are listed in Table VI, which illustrates that even on the dataset not involved in the diffusion model training, CDMA can also achieve a 90+% (in some cases, even 100%) attack success rate. This phenomenon strongly supports our proposition that adversarial examples can be transformed from normal exam

Fig. 2: Queries vs. ASR on CIFAR-100 and Tiny-ImageNet for untarget and targeted attack settings. The maximal query counts are limited to 1000 and the noise budget’s \(L_{\infty}\) norm is set to \(\epsilon=16\).
ples. Furthermore, the evasion attack success rate of various query counts is illustrated in Figure 3. As we can see, CDMA can achieve a good attack success rate even in relatively fewer queries. Taking Places365 as an example, it can obtain 98% \(\sim\) 99.6% attack success rate when the noise budget is set as \(\epsilon=8\) and 99.7% \(\sim\) 100% when \(\epsilon=16\).

#### V-A2 **Model-independent Attack.**

Existing black-box attack methods can only generate adversarial samples for a specific victim model. Our CDMA is not restricted by this requirement. It can synthesize adversarial examples by performing a conditional sampling manner, and we call it the model-independent attack. Specifically, in this situation, we don't know what the victim model is but just do the conditional sampling once for the specific dataset, and then verify whether these sampled examples are adversarial or not. Figure 4 shows that the average success rate of such attack on CIFAR-10 is higher than 80% over different victim models. It can also achieve a 60+% average attack success rate on CIFAR-100 and Tiny-ImageNet. This phenomenon demonstrates that even in model-independent attack scenarios, CDMA can still generate adversarial examples and achieve good attack effects on different models. Furthermore, it illustrates the high adaptability of CDMA in model-independent black-box scenarios.

### _Transfer Attack Effectiveness_

Recall that the transferability of adversarial examples is crucial to carry out transfer attacks, especially for the black-box model deployed in the real world. Therefore following the previous works [8, 45], we examine the transferability of the generated AE for each of the attack methods in Table. VII. We randomly sample 1000 images from CIFAR-10, CIFAR-100 and Tiny-ImageNet datasets, and generate AEs against on ResNet-50 model. Then we transfer these AEs to attack the VGG-19, Inception V3 and DenseNet-169. As seen, the generated AE by CDMA transfer to other models easier than other attacks. This observation precisely matches our intuition about the mechanics of CDMA. More specifically, we know that in CDMA the model is learning a transformation between a benign image and its adversarial counterpart. Comparing to other queries and optimization attacks, which calculate specific perturbations for each sample, CDMA learns to use the transformation to build AEs. Thus, CDMA tends to generate AEs with high transferability.

Fig. 4: Model-independent attack.

Fig. 3: ASR vs. Queries under data-independent settings.
### _Ablation Study_

#### Iv-F1 **Scheduling & Steps.

Although the typical training and sampling steps of DDPM are \(T=1000\), previous work [26] shows that such number of steps for the diffusion model can be inconsistent. Here, we aim to explore the effect of the number of sampling steps \(T\) on the final attack performance without other acceleration schemes [46, 47]. The victim model is ResNet-50, the noise budget is set as \(\epsilon=8\) and \(\epsilon=16\), and the maximal number of queries is set as \(Q=10\).

As shown in Figure 5, the obtained attack success rate always fluctuates regardless of using cosine or linear sampling. Compared with liner sampling, cosine sampling can achieve a higher attack success rate with fewer sampling steps. Especially when the number of sampling steps is small, the attack success rate of linear sampling is relatively lower. For example, when the number of sampling steps is \(t=10\), the attack success rate of linear sampling is around 40%-60%, while the cosine sampling is 80%-90%. Note that for each sampling schedule, the final attack success rate is roughly the same as the number of sampling steps increases. To obtain more effective and efficient attack results, we set the sampling strategies in the attack process as follows: the sampling schedule is cosine and the number of steps is \(t=50\). By doing this, the attack effectiveness is significantly promoted owning to a smaller sample step \(t\).

#### Iv-F2 **Comparisons with Generative Attacks**

Existing generative-based attacks usually use GAN to generate adversarial perturbations. We choose the most representative one, AdvGAN, among these methods to compare with our CDMA. As the experimental results are illustrated in Figure 6, we can find that although the attack success rate of our method is lower than AdvGAN in some cases, as the number of queries increases, the attack success rate of our method will increase with the number of queries, on the contrary, AdvGAN will not, which thoroughly verifies our assertion that the AEs generated by our CDMA can generate disveriform adversarial examples, even for the same clean example \(x\).

## V Conclusions

In this work, we find that adversarial examples are a particular form of benign examples, i.e., these two types of samples come from two distinct but adjacent distributions that can be transformed from each other with a perfect converter. Based on this observation, we propose a novel hard-label black-box attack, CDMA, which builds a converter to transform clean data to its corresponding adversarial counterpart. Specifically, we leverage a diffusion model to formulate the data converter and synthesize adversarial examples by conditioning on clean images to improve the query efficiency significantly. Extensive experiments demonstrate that CDMA achieves a much higher attack success rate within 1,000 queries and needs fewer queries to achieve the attack results, even in the targeted attack setting. Besides, most adversarial examples generated by CDMA can escape from mainstream defense strategies and maintain high robustness. Furthermore, CDMA can generate adversarial examples that are well transferred to different victim models or datasets.

**Acknowledgements** This work is supported in part by Yunnan Province Education Department Foundation under Grant No.2022j0008, in part by the National Natural Science Foundation of China under Grant 62162067 and 62101480, Research and Application of Object Detection based on Artificial Intelligence, in part by the Yunnan Province expert workstations under Grant 202205AF150145.
