阅读 125

CTFD批量上pwn题脚本

请配合赵师傅的插件使用:juejin.im/post/684490… pwn题文件目录格式如下图

里面命名为src/pwn即可

mkdir /home/ec2-user/CTFd/.data/CTFd/uploads/c0ace5883888b8dbe50b5fb7966a0c1b/
echo "use ctfd;">challenge.sql
for dir in `ls`; do                  #历遍ls命令显示目录
    cd $dir/src;
    if test $? == 0; then
        echo `pwd`;
        echo 'FROM glzjin/pwn_base_16
COPY pwn /pwn/pwn' > dockerfile;
        cp pwn /home/ec2-user/CTFd/.data/CTFd/uploads/c0ace5883888b8dbe50b5fb7966a0c1b/$dir                       #复制文件到目录
        docker build -t $dir .; 
       
        cd ../..;
        echo  " INSERT INTO challenges  
      ( name ,  description ,  max_attempts ,  value ,  category,  type,  state ,  requirements) 
    VALUES ('$dir','',0,200,'pwn','dynamic_docker','visible',NULL);
    set @challenge_id=1600187;
   insert into files (type,location,challenge_id) values ('challenge','c0ace5883888b8dbe50b5fb7966a0c1b/$dir',@challenge_id);
   INSERT INTO dynamic_docker_challenge(id,initial,minimum,decay,memory_limit,cpu_limit,dynamic_score,docker_image,redirect_type,redirect_port)
 VALUES (@challenge_id,200,1,100,'128m',0.5,1,'$dir','direct',10000);
   ">> challenge.sql;    
    fi                                   #直接返回主目录。
done
docker exec -i ctfd_db_1 mysql -uctfd -pctfd ctfd < challenge.sql
复制代码