AWD平台搭建

时间:2019-08-10 18:33:53   收藏:0   阅读:288

因为之前是被AWD比赛坑过,所以想着自己搭建一下啦。这样方便可以本校和某高校,两个学校的人进行相互交流,共同进步。

搭建前提:

ubuntu16.04镜像,这个最好放到虚拟机里面进行加载。(附:Ubuntu的源可以换成阿里云的,这样的话下载速度就会比较快,这里我是给出别人的博客,我是换成阿里云的源

https://blog.csdn.net/lym152898/article/details/79100507 

 

在虚拟机里面启动好之后,然后再加载docker容器,这个容器可以存放我们比赛时候的ctf环境。启动比赛环境还是挺容易的,就是模板的问题,下面是搭建的步骤。

 

1.安装docker环境:

正常ubuntu里面是没有docker环境的,这样我们就需要下载一个docker环境。因为是linux系统,所以还是命令行下载。不过我就不演示了,直接放出别人的博客吧。如果博客失效了,大家还可以是百度下ubuntu系统安装docker环境。 

  https://www.cnblogs.com/jiyang2008/p/9014960.html 

 

2.下一步就是克隆项目

 

  sudo git clone https://github.com/zhl2008/awd-platform.git


3.进入项目


  sudo cd awd-platform/


4.下载镜像,木有镜像等于白搭


  sudo docker pull zhl2008/web_14

5.要以root权限的用户,进入到这个目录里面,如果是root权限的话会是一个 #  而不是一个 $ 。切换用户的指令是 su 用户

 

6.启动镜像

 

# python batch.py web_yunnan_simple 3//复制3个web_yunnan_simple的靶机,数值可改
# python start.py ./ 3 //启动三个docker靶机和check服务器、flag_server服务器。数值可改 

7.在当前目录下,连接裁判机

docker attach check_server
python check.py

项目的check.py是有问题的,比如无法正常启动,还有check的也是不怎么规范,所以还是修改一下,这里是宕的别人的。

#!/usr/bin/env python
# -*- coding:utf8 -*-
‘‘‘

‘‘‘
import hashlib
import base64

sleep_time  = 300
debug = True
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"}

import time
import httplib
import urllib2
import ssl 

my_time = AAAA 
__doc__ = http(method,host,port,url,data,headers)
flag_server = 172.17.0.1
key = 744def038f39652db118a68ab34895dc
hosts = open(host.lists,r).readlines()
user_id = [host.split(:)[0] for host in hosts]
hosts = [host.split(:)[1] for host in hosts]
port = 80

def http(method,host,port,url,data,headers):
    con=httplib.HTTPConnection(host,port,timeout=2)
    if method==post or method==POST:
        headers[Content-Length]=len(data)
        headers[Content-Type]=application/x-www-form-urlencoded  
        con.request("POST",url,data,headers=headers)
    else:
        headers[Content-Length] = 0    
        con.request("GET",url,headers=headers)
    res = con.getresponse()
    if res.getheader(set-cookie):
        #headers[‘Cookie‘] = res.getheader(‘set-cookie‘)
        pass
    if res.getheader(Location):
        print "Your 302 direct is: "+res.getheader(Location)
    a = res.read()
    con.close()
    return a


def https(method,host,port,url,data,headers):
    url = https:// + host + ":" + str(port) + url
    req = urllib2.Request(url,data,headers)
    response = urllib2.urlopen(req)
    return response.read()

def get_score():
    res = http(get,flag_server,8080,/score.php?key=%s%key,‘‘,headers)
    print res
    user_scores = res.split(|)
    print "******************************************************************"
    res = ‘‘

    print res
    print "******************************************************************" 
    return user_scores

def write_score(scores):
    scores = |.join(scores)
    res = http(get,flag_server,8080,/score.php?key=%s&write=1&score=%s%(key,scores),‘‘,headers)
    if res == "success":
        return True
    else:   
        print res
        raise ValueError

class check():
    
    def index_check(self):
        res = http(get,host,port,/index.php?file=%s%str(my_time),‘‘,headers)
        if perspi in res:
            return True
        if debug:
            print "[fail!] index_fail"
        return False

def server_check():
    try:
        a = check()
        if not a.index_check():
            return False
        return True
    except Exception,e:
        print e
        return False

game_round = 0
while True:
    
    scores = get_score()
    scores = []
    print "--------------------------- round %d -------------------------------"%game_round
    for host in hosts:
        print "---------------------------------------------------------------"
        host = host[:-1]
        if server_check():
            print "Host: "+host+" seems ok"
            scores.append("0")
        else:
            print "Host: "+host+" seems down"
            scores.append("-10")
    game_round += 1
    write_score(scores)
    time.sleep(sleep_time)

启动check.py之后,环境应该是这样的。至此,环境基本上就已经搭建完成了。后面还有一些东西可以看看

 

技术分享图片

 

8.事项及规则:

 

1.靶机端口规则:(假设虚拟机的ip为192.168.1.1 , 虚拟机要和真实机要在同一个C段,如果是实验室用的话,可以在vm里面设置一个桥接模式)
Team1:192.168.1.1:8801
Team2:192.168.1.1:8802
Team3:192.168.1.1:8803
……
以此类推
2.各个靶机的ssh密码可以在项目的文件夹下的pass.txt文件中,开始比赛时告知各个选手ssh密码。
SSH的端口规则为:(假设服务器ip为192.168.1.1)
Team1:192.168.1.1:2201
Team2:192.168.1.1:2202
Team3:192.168.1.1:2203
……
以此类推
3.提交flag方法:(假设服务器ip为192.168.1.1)
http://192.168.1.1:8080/flag_file.php?token=teamX&flag=xxxx
(teamX中的X为自己队伍号,flag为其他队伍的flag)
4.记分牌:查看实时分数情况,没做到实时刷新一下(假设服务器ip为192.168.1.1)
http://192.168.1.1:8080
5.攻击情况:(假设服务器ip为192.168.1.1)
http://192.168.1.1:8080/result.txt

9.这里有个异常就是可以无限提交flag,先放出别人的

 

在一次测试中,发现在一轮的五分钟有效时间内一直提交某个对手的正确flag可以无限加分,在审计一波代码后发现,关键点在这里

config.php:

<?php

$team_number = 3;
$user_list = [];
$token_list = array();
$ip_list = array();
for ($i=1; $i <= $team_number; $i++) { 
    array_push($user_list,‘team‘.$i);
    $token_list[‘team‘.$i] = $i - 1;
    $ip_list[‘172.17.0.‘.($i+1)] = $i - 1;
}

$key = ‘744def038f39652db118a68ab34895dc‘;
$time_file = ‘./time.txt‘;
$min_time_span = 120;
$record = ‘./score.txt‘;

flag_file.php:

require ‘config.php‘;
$now_time = time();
$flag_file = ‘xxxxxxxx_flag‘;

function check_time($attack_uid,$victim_uid){
    global $time_file;
    global $min_time_span;
    global $now_time;
    global $team_number;
    $old_times = explode(‘|‘ , file_get_contents($time_file));
    //print $now_time;
    $id = $attack_uid * $team_number + $victim_uid;
    //print $old_times[$id];
    if ($now_time - $old_times[$id] < $min_time_span){
    die("error: submit too quick ". ($min_time_span + $old_times[$id] - $now_time). " seconds left");
    }else{
    return True;
    }
}

这边的flag_file.php包含了config.php的配置,即变量$min_time_span和变量$time_file,通过$now_time记录当前时间戳,然后通过与$time_file记录的时间戳节点进行相减,如果符合小于预设的时间差(即一轮多长时间)这一条件则当前时间段无法再次提交flag。

然而 ,$time_file = ‘./time.txt‘; 中的time.txt是这样的

技术分享图片

  哈哈 ,为了辨别每一支队伍代表的格子,将其写为0|1|2|3|4......,然后将变量$old_times输出,经过对比后得出team对应的位置(我这里只找了三个)

技术分享图片

  此时只需要写一个脚本将五分钟为周期的时间戳更新到time.txt中即可

  脚本如下,在启动docker之前五分钟运行,或者后五分钟也可以,改一下脚本内的配置即可,这个脚本是按照某一个时间整点的00 05 10 15 进行记录时间戳的,按自己需要也可以改为其他的

#!/usr/bin/env python

#coding:UTF-8

import time

import os


print int(time.time())

Unix_time = int(time.time())

print time.ctime(Unix_time)

while True:

    time_his = []

    time_list = ["00","05","10","15","20","25","30"]

    for i in time_list:

        dt = "2019-04-28 10:"+str(i)+":00"

        time_his.append(dt)

    a = time_his[0]

    b = time_his[1]

    c = time_his[2]

    d = time_his[3]

    e = time_his[4]

    f = time_his[5]

    g = time_his[6]

    time_stamp = [a,b,c,d,e,f,g]

    for k in time_stamp:

            h = open("time.txt", ‘w+‘)

            timeArray = time.strptime(k, "%Y-%m-%d %H:%M:%S")

            timestamp = time.mktime(timeArray)

            print (int(timestamp))

            data = (int(timestamp))

            separated = ‘|‘

            zero = ‘0‘

            print >>h,(zero),(separated),(data),(separated),(zero),(separated),(data),(separated),(zero),(separated),(zero),(separated),(data),(separated),(zero),(separated),(zero),

            #           0|data|0|data|0|0|data|0|0

            h.close()

            time.sleep(300)

  目前这个问题解决了,但是需要一点技巧,就是开启这个脚本的时间要把握好。多调试几次应该就差不多了。

 

10.感觉这个页面太丑的话,可以换一个页面,这里是夜莫离大佬做的页面

 

  技术分享图片

 

计分板文件拷贝至awd-platform下的flag_server文件夹下。要注意将文件score.txt与result.txt文件权限调至777,这样才能刷新出分值。还需将scorecard.php文件中的resul变量中的ip地址更改为自己的ip地址。

 

访问ip:8080/scorecard.php来查看各队得分情况。

 

  

计分板源码打包:https://pan.baidu.com/s/18KlIeluaTtm-kT3KuXHseQ

提取码:cvdn

 

11.玩累了关闭环境的命令

 

  python stop_clean.py

 

 12.参考链接

https://www.heibai.org/post/1468.html

https://blog.csdn.net/huanghelouzi/article/details/90204325

 

https://mp.weixin.qq.com/s?__biz=MzU1MzE3Njg2Mw==&mid=2247486325&idx=1&sn=96c04f3609a04260eabdd187fc7c38b1&chksm=fbf79105cc8018131579ad228dbf22a33bbdf0c8c71d3b8c090583b42ea21d80de53fc1efa70&scene=27&key=593393174013ce6d958e86eb764289b105cb7cea44d471bd3f9fe1a2ed76f546343dacb9b40a352e642e425b55c2a4d9698146a114ecd9680ed3262c8f96f6a206f0c78d6818ce0028c9bc75830936f0&ascene=7&uin=NTQ5ODg5NzY1&devicetype=Windows+10&version=6206061c&lang=zh_CN&pass_ticket=s3n8uD0SG7m1vojw%2F%2BN7uxdrTxvWnumzuUe%2BTLY12QY9yFKjU7n%2FNruWi9PS1sJO&winzoom=1

 

现在搭建后,还是有点问题的,数据库连接不上。比较尴尬啊这个下去之后解决了,我再写出来

因为搭建的时候也是遇到很多坑,希望后来的人可以少走这些坑。所以坚持不水文

原文:https://www.cnblogs.com/Triangle-security/p/11332223.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!