📣 攻击实验

Last updated on 2023-10-13 20:22

我想做哪些攻击呢?

白块、随机矩阵、高斯噪声、椒盐噪声、语义后门、模型替换后门

引入高频信号可能会改变图像的视觉外观

1.单次攻击(√)

1.白块攻击(√)

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Baikuai
# 通信轮次,在不同轮次注入后门则选择的总轮次不同,50轮设置150轮,100轮设置200轮,因为我主要是想看注入后门之后100轮的后门持久情况
epochs: 150
# 本地训练轮次
fl_local_epochs: 2
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 10
# 单次攻击轮次
fl_single_epoch_attack: 50
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_oneBaikuai_50_10:表示数据集-模型-单次pattern攻击-攻击轮次-攻击者数量

单次攻击的变量:1.攻击者数量(10);2.不同的攻击轮次(50)。我这里先跑一下不同的攻击轮次,然后攻击之后100轮的情况,如下所示:

画图1:pattern攻击在不同的攻击轮次的后门持久性,包括(50—√ ,100,150,200)

2.pattern(随机矩阵)后门攻击(√)

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Pattern
# 通信轮次
epochs: 150
# 本地训练轮次
fl_local_epochs: 2
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 10
# 单次攻击轮次
fl_single_epoch_attack: 50
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_onePattern_50_10:表示数据集-模型-单次pattern攻击-攻击轮次-攻击者数量

单次攻击的变量:1.攻击者数量;2.不同的攻击轮次。我这里先跑一下不同的攻击轮次,然后攻击之后100轮的情况,如下所示:

画图1:pattern攻击在不同的攻击轮次的后门持久性,包括(50—√,100,150,200)

3.高斯噪声(√)

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Noice
# 通信轮次
epochs: 150
# 本地训练轮次
fl_local_epochs: 2
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 10
# 单次攻击轮次
fl_single_epoch_attack: 50
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_oneNoise_50_10:表示数据集-模型-单次pattern攻击-攻击轮次-攻击者数量

单次攻击的变量:1.攻击者数量;2.不同的攻击轮次。我这里先跑一下不同的攻击轮次,然后攻击之后100轮的情况,如下所示:

画图1:pattern攻击在不同的攻击轮次的后门持久性,包括(50—√,100,150,200)

4.语义后门攻击

1.cifar10数据集

选择的特征图片:

暂缓,因为要打标记,挺累的,可以换别的后门攻击来操作。

5.模型替换后门(√)

服务器收到客户端的更新根据下面公式聚合得到一个全局模型:$$G^{t+1}=G^{t}+\frac{\eta}{n} \sum_{i=1}^{m}\Delta \boldsymbol{w}_{i}^{r+1}$$,其中n=100, m=10

模型替换:$$X=G^{t}+\frac{\eta}{n} \sum_{i=1}^{m}\Delta \boldsymbol{w}_{i}^{r+1}$$

随着训练轮次增多,$$\Delta \boldsymbol{w}{i}^{r+1}→0$$,所以最后提交的恶意更新(假设第k个客户端为恶意客户端)为:$$\Delta \boldsymbol{w}{k}^{r+1}=\frac{n}{\eta} (X-G^{t})-\sum_{i=1,i≠k}^{m}\Delta \boldsymbol{w}_{i}^{r+1} \approx \frac{n}{\eta}\left(X-G^{t}\right)$$

**这种攻击将后门模型 X 的权重缩放为$$\gamma =\frac{n}{\eta}=100/10=10$$**,以确保后门在平均聚合算法中存活,全局模型能够被 X 替换

不知道 n 和 η 的攻击者可以通过每轮迭代地增加比例因子 γ 并测量模型在后门任务上的准确性来近似比例因子 γ。

这个攻击的实现很简单,就是提高恶意更新的权重。(已实现)

这里使用pattern来实现单次的模型替换后门。

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Pattern
# 通信轮次,在不同轮次注入后门则选择的总轮次不同,50轮设置150轮,100轮设置200轮,因为我主要是想看注入后门之后100轮的后门持久情况
epochs: 150
# 本地训练轮次
fl_local_epochs: 2
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 10
# 攻击者数量
fl_number_of_adversaries: 2
# 单次攻击轮次
fl_single_epoch_attack: 50
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_onePatModel_50_2:表示数据集-模型-单次pattern攻击-攻击轮次-攻击者数量

python training.py –name cifar10_onePatModel_50_2 –params configs/cifar_fed.yaml,这里的客户端权重设置的是10.

python training.py –name cifar10_onePatModel_50_2_weight50 –params configs/cifar_fed.yaml,增加权重为50

由于单次攻击且不加模型后门的后门攻击效果太差,因此这里就不在继续做单次攻击了。

换白块进行模型替换攻击:cifar10_onePatModel_Baikuai_50_2_weight10,权重为10,50轮2个攻击者

2.多次攻击

1.白块攻击(√)

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Baikuai
# 通信轮次,在不同轮次注入后门则选择的总轮次不同,50轮设置150轮,100轮设置200轮,因为我主要是想看注入后门之后100轮的后门持久情况
epochs: 300
# 本地训练轮次
fl_local_epochs: 2
# 单次攻击
fl_single_epoch_attack: False
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 20
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_Baikuai_20:表示数据集-模型-白块攻击-攻击者数量,分别为cifar10_resnet18_Baikuai_20,cifar10_resnet18_Baikuai_25,cifar10_resnet18_Baikuai_30,cifar10_resnet18_Baikuai_35,cifar10_resnet18_Baikuai_40,cifar10_resnet18_Baikuai_45

单次攻击的变量:攻击者数量(20-√,25-√,30-√,35-√,40-√,45-√,50-√)。

画图1:白块攻击攻击在不同的攻击者数量下的后门精度,包括(20,25,30,35.40)

python training.py –name cifar10_resnet18_Baikuai_20 –params configs/cifar_fed.yaml

tensorboard –logdir=runs/cifar10_resnet18_Baikuai_20

2.随机矩阵攻击

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Pattern
# 通信轮次,在不同轮次注入后门则选择的总轮次不同,50轮设置150轮,100轮设置200轮,因为我主要是想看注入后门之后100轮的后门持久情况
epochs: 300
# 本地训练轮次
fl_local_epochs: 2
# 单次攻击
fl_single_epoch_attack: False
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 20
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_Pattern_20:表示数据集-模型-后门攻击-攻击者数量,分别为cifar10_resnet18_Pattern_20,cifar10_resnet18_Pattern_25,cifar10_resnet18_Pattern_30,cifar10_resnet18_Pattern_35,cifar10_resnet18_Pattern_40,cifar10_resnet18_Pattern_45

单次攻击的变量:攻击者数量(20-√,25-√,30-,35-,40-)。

画图1:白块攻击攻击在不同的攻击者数量下的后门精度,包括(20,25,30,35,40)

python training.py –name cifar10_resnet18_Pattern_20 –params configs/cifar_fed.yaml

tensorboard –logdir=runs/cifar10_resnet18_Pattern_20

2.噪声

修改参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 后门攻击的方式
synthesizer: Noise
# 通信轮次,在不同轮次注入后门则选择的总轮次不同,50轮设置150轮,100轮设置200轮,因为我主要是想看注入后门之后100轮的后门持久情况
epochs: 300
# 本地训练轮次
fl_local_epochs: 2
# 单次攻击
fl_single_epoch_attack: False
# 这是模型替换后门增加权重的,这里默认100,我改为1
fl_weight_scale: 1
# 攻击者数量
fl_number_of_adversaries: 20
# 恶意参与方的样本比例
poisoning_proportion: 0.5

取名:cifar10_resnet18_Noise_20:表示数据集-模型-后门攻击-攻击者数量,分别为cifar10_resnet18_Noise_20,cifar10_resnet18_Noise_25,cifar10_resnet18_Noise_30,cifar10_resnet18_Noise_35,cifar10_resnet18_Noise_40,cifar10_resnet18_Noise_45

单次攻击的变量:攻击者数量(20-√,25-√,30-√,35-√,40-√)。

画图1:白块攻击攻击在不同的攻击者数量下的后门精度,包括(20,25,30,35,40)

python training.py –name cifar10_resnet18_Noise_25 –params configs/cifar_fed.yaml

tensorboard –logdir=runs/cifar10_resnet18_Noise_20

1
pip --trusted-host pypi.python.org --trusted-host pypi.tuna.tsinghua.edu.cn install albumentations -i https://pypi.tuna.tsinghua.edu.cn/simple/

遇到的问题:

🎗 1.联邦学习的更新范数差别太大了,以至于损失值为Nan,在fl_task的get_update_norm函数中打印的范数。

🎗 2.在用Tensorboard –logdir进行打印时,噪声50轮单次攻击打印不出来,显示没有该文件

解决:输入命令tensorboard --logdir="F:\papercode\backdoors101\runs\cifar10_oneNoise_50_10"

采用绝对路径就可以打印了。

🎗 3.ModuleNotFoundError: No module named ‘albumentations’

解决:采用这个命令pip install albumentations会出现以下问题:

1
2
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/albumentations/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/albumentations/。。。。

于是输入命令:conda config --append channels conda-forge来添加channel,然后使用conda install albumentations安装成功

🎗 4. File “F:\mxj\代码版本2\backdoors101\synthesizers\noise_synthesizer.py”, line 67, in addnoise
img = img.numpy()
TypeError: can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.


📣 攻击实验
https://luoynothing.github.io/2023/09/04/📣-攻击实验/
Author
John Doe
Posted on
2023-09-04 17:50
Updated on
2023-10-13 20:22
Licensed under