summaryrefslogtreecommitdiff
path: root/script/run_experiment_test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'script/run_experiment_test.sh')
-rw-r--r--script/run_experiment_test.sh92
1 files changed, 92 insertions, 0 deletions
diff --git a/script/run_experiment_test.sh b/script/run_experiment_test.sh
new file mode 100644
index 0000000..aee3423
--- /dev/null
+++ b/script/run_experiment_test.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+#37是TCP+IP+预制的几个特征
+#1. 设置RNN隐藏状态的大小为37。
+#2. 设置AE瓶颈层的大小为40。
+#3. 设置序列长度(n-gram)为3。
+#4. RNN训练时的epoch数为50,没有使用mini-batch。
+#5. AE训练时的epoch数为1000,使用了mini-batch。
+#6. 设备名称为cpu。
+#7. RNN训练截断参数为-1。
+#8. AE训练截断参数为-1。
+#9. 设置RNN输入的大小为37。
+#10. 训练RNN模型。
+#11. 训练AE模型。
+#12. 启动并测试攻击。
+#13. 数据集文件名为mawi_ws_ds_sorted。
+#14. 上下文模式为use_gates。
+#15. 分区模式为none。
+#16. 模型类型为gru。
+#17. AE模型类型为large。
+#18. 损失加权方式为weighted。
+#19. 使用了额外特征。
+#20. 只使用出站数据包。
+#echo "Size of RNN hidden state: $1"
+#echo "Size of AE bottleneck layer: $2"
+#echo "Length of sequence (n-gram): $3"
+#echo "RNN training epochs (no mini-batch): $4"
+#echo "AE training epochs (mini-batch): $5"
+#echo "Device name (gpu/cpu): $6"
+#echo "RNN training cutoff: $7"
+#echo "AE training cutoff: $8"
+#echo "Size of RNN input: $9"
+#echo "Train RNN model: $10"
+#echo "Train AE model: $11"
+#echo "Launch and test attacks: $12"
+#echo "Dataset filename: $13"
+#echo "Context mode: $14"
+#echo "Partition mode: $15"
+#echo "Model type: $16"
+#echo "AE model type: $17"
+#echo "Loss weighting: $18"
+#echo "Additional features: $19"
+#echo "Only outbound packets: $20"
+#echo "folder:$21"
+
+#模型训练时使用一个良性流量数据集进行训练得到模型
+if [ $10 = '--train-rnn' ]
+then
+ echo "Saved RNN model filename: $13.$1.$4.$7.$16.$18"
+ python3 train.py --train-dataset ../data/processed_dataset/$13.csv.train --test-dataset ../data/processed_dataset/$13.csv.test --save-model --save-model-suffix $13.$1.$4.$7.$16.$18 --rnn-num-epochs $4 --rnn-hidden-size $1 --seed 222 --device $6 --cutoff $7 --input-size $9 --rnn-model-type $16 --loss-weighting $18 > ../log/train_rnn.$13.$1.$4.$7.$16.$18.log
+fi
+
+if [ $11 = '--train-ae' ]
+then
+ echo "Saved AE model filename: $13.$1.$2.$3.$5.$8.$14.$15.$16.$17.$18.$19.$20"
+ python3 train.py --train-dataset ../data/processed_dataset/$13.csv.train --test-dataset ../data/processed_dataset/$13.csv.test --save-model --save-model-suffix $13.$1.$2.$3.$5.$8.$14.$15.$16.$17.$18.$19.$20 --train-ae-model --vae-num-epochs $5 --n-gram $3 --ae-bottleneck-size $2 --rnn-model ../model/rnn_model.pt.$13.$1.$4.$7.$16.$18 --rnn-hidden-size $1 --seed 222 --device $6 --cutoff $8 --input-size $9 --context-mode $14 --partition-mode $15 --rnn-model-type $16 --ae-model-type $17 --extra-features $19 --conn-dir $20 > ../log/train_ae.$13.$1.$2.$3.$5.$8.$14.$15.$16.$17.$18.$19.$20.log
+ echo "Train Finish!!"
+fi
+
+if [ $10 != '--train-rnn' ]
+ #如果训练的话以下内容就不可用了
+then
+ #通过test脚本获取每个流的重构误差
+ #其中良性流量数据集是为了区分和测试流量的重构误差而保存的,可以使用训练时的数据集改名后使用,也可以继续使用该benign数据集
+
+ echo "测试阶段,对测试流量获取重构误差保存"
+ python3 test.py --attack-dataset ../data/processed_dataset/$13_$21.csv.test.attack --benign-dataset ../data/processed_dataset/$13.csv.benign --rnn-model ../model/rnn_model.pt.$13.$1.$4.$7.$16.$18 --vae-model ../model/vae_model.pt.$13.$1.$2.$3.$5.$8.$14.$15.$16.$17.$18.$19.$20 --loss-list-fpath ../data/losslist/$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20 --n-gram $3 --dataset-stats ../data/processed_dataset/$13.csv.train.stats --seed 222 --rnn-hidden-size $1 --input-size $9 --context-mode $14 --partition-mode $15 --rnn-model-type $16 --extra-features $19 --conn-dir $20 > ../log/test_loss.$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20.min
+
+ #visualize.py脚本通过之前inject_attack脚本中的固定攻击分配流中的恶意数据包的位置,记为attack.info文件。比较idx来得到实验数据和性能
+ #需要修改脚本为deeptest.py,使其可以通过重构误差来判断检测情况。
+
+
+ echo "根据良性流量和测试流量的重构误差设置阈值判断测试流量是否异常,记录流中异常的数据包索引"
+ #python3 visualize.py --loss-list-fname $13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20 --loss-list-dir ../data/losslist --fig-fpath ../data/figs/roc_wami.$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20.min --ds-title 1 > ../log/roc_score.$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20 --attack-info-fpath ../data/processed_dataset/$13_$21.csv.test.attack.info --n-gram $3
+ python3 deeptest.py --loss-list-fname $13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20 --loss-list-dir ../data/losslist > ../data/record/record.$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20
+ echo "Saved record filename: record.$13.$1.$2.$3.$4.$5.$7.$8.$21.$14.$15.$16.$17.$18.$19.$20"
+fi
+
+
+
+
+
+#cat ../log/test_loss.$13.$1.$2.$3.$4.$5.$7.$8.*.$14.$15.$16.$17.$18.$19.$20* > ../final_res/merged_test_loss.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log
+#cat ../log/roc_score.$13.$1.$2.$3.$4.$5.$7.$8.*.$14.$15.$16.$17.$18.$19.$20* > ../final_res/merged_roc_score.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log
+#rm ../log/test_loss.$13.$1.$2.$3.$4.$5.$7.$8.*.$14.$15.$16.$17.$18.$19.$20*
+#rm ../log/roc_score.$13.$1.$2.$3.$4.$5.$7.$8.*.$14.$15.$16.$17.$18.$19.$20*
+
+#echo "Adding header for producing the final resutls..."
+#echo "LABEL_OPT,ATTACK_TYPE,AUC_ROC_SCORE,[email protected],TPR@FPR009,EER_SCORE,TOP1_HIT_ACC,TOP3_HIT_ACC,TOP5_HIT_ACC" > ../final_res/header.txt
+#cat ../final_res/header.txt ../final_res/merged_roc_score.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log > ../final_res/merged_roc_score_w_header.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log
+#echo "Printing final results:"
+#cat ../final_res/merged_roc_score_w_header.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log
+#python3 paint_fig.py --fin-our ../final_res/merged_roc_score_w_header.$13.$1.$2.$3.$4.$5.$7.$8.$14.$15.$16.$17.$18.$19.$20.log --merged-res ../final_res/final_results_fig.csv