在巨人的肩膀上(基于Attribution中各个项目的代码),本项目进行了再创造,实现了两个基于GAN的口令猜测攻击模型,两个模型共同点和区别如下:
-
共同点: 使用IWGAN,基于普通GAN,在判别器的损失函数中增加了一项约束项,具体可见相关论文。
-
不同点: 生成器和判别器使用了不同的网络结构。
-
生成器和判别器使用5层ResNets。ResNets是一种基于CNN的Residual Blocks,进行残差学习。详见reference中的
PassGAN, A Deep Learning Approach for Password Guessing.pdf
。 -
生成器和判别器使用两层GRU循环神经网络。在这种情况下生成器。CNN是捕捉样本局部特征的有利工具,非常适合CV任务。但是口令猜测任务类似NLP的文本生成任务,一般使用循环神经网络,以利用其处理序列样本的优势。详见reference中的
Recurrent GANs Password Cracker For IoT Password Security Enhancement.pdf
。
-
train.py
用于训练模型,sample.py
用于生成口令。
使用预训练好的模型,直接生成口令的方法如下(以csdn数据集为例):
# 使用CNN-GAN
python sample.py -m cnn -n 1000000 -i ./model/csdn_cnn_model -o ./guess/gen_csdn_cnn.txt -ck ./model/csdn_cnn_model/checkpoints/checkpoint_100000.ckpt
# 使用RNN-GAN
python sample.py -m rnn -n 1000000 -i ./model/csdn_rnn_model -o ./guess/gen_csdn_rnn.txt -ck ./model/csdn_rnn_model/checkpoints/checkpoint_100000.ckpt
使用csdn数据集训练模型:
# 使用CNN-GAN
python train.py -m cnn -b 64 -i ./data/csdn_train.txt -o ./model/csdn_cnn_model
# 使用RNN-GAN
python train.py -m rnn -b 64 -i ./data/csdn_train.txt -o ./model/csdn_rnn_model
可以使用自己的数据集,改变-i参数即可。
比从头开始训练多了-ck命令行参数:
# 使用CNN-GAN
python train.py -m cnn -b 64 -i ./data/csdn_train.txt -o ./model/csdn_cnn_model -ck ./model/csdn_cnn_model/checkpoints/checkpoint_100000.ckpt
# 使用RNN-GAN
python train.py -m rnn -b 64 -i ./data/csdn_train.txt -o ./model/csdn_rnn_model -c 1 -ck ./model/csdn_cnn_model/checkpoints/checkpoint_100000.ckpt
# requires CUDA 8 to be pre-installed
pip install -r requirements.txt
csdn数据集打乱后按照80%和20%比例划分为csdn_train.txt
和csdn_test.txt
,分别为训练集和测试集。yahoo数据集同理。模型训练均只使用训练集。
This code is released under an MIT License and another MIT License. You are free to use, modify, distribute, or sell it under those terms.
The majority of the credit for the code in this repository goes to @brannondorsey for his work on the PassGAN, whose code is based on improved_wgan_training written by @igul222. I've simply modified some module, added rnn-based implementation and changed some command-line interface.
The PassGAN research and paper was published by Briland Hitaj, Paolo Gasti, Giuseppe Ateniese, Fernando Perez-Cruz. The PassGAN based on RNN research and paper was published by Sungyup Nam, Seungho Jeon, Hongkyo Kim and Jongsub Moon. The default RNN-based PassGAN implemented in this project is different from above article, but you may change the neural network structure by providing specific command-line arguments.