码迷,mamicode.com
首页 > 其他好文 > 详细

AWD平台搭建

时间:2021-02-09 11:45:09      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:als   网站   容器   lists   机器   python2   hosts   form   server   

第一次参加AWD的线上赛,连ssh都没连上,被打的无地自容
之前自己没有参加过AWD的比赛,完全就是一头雾水,主办方要求填写外网的IP,直接闹了个乌龙,把本机IP给报上去了,导致了网页都没访问到
自己搭建个AWD的环境,练习下,下次不要被打的找不到东南西北了

搭建环境

ubuntu18.04
GitHub项目:https://github.com/zhl2008/awd-platform
码云地址(速度快):https://gitee.com/Cl0udG0d/awd-platform

拉取项目

git clone https://gitee.com/Cl0udG0d/awd-platform   #克隆下来
cd awd-platform       #进入项目目录

AWD环境中的机器按照功能分为几种类型:

Check_Server:
服务检查服务器,用于判定选手维护的服务是否可用,如果不可用,则会扣除相应的分数,不开启任何端口,需要与flag服务器通信
简单来说这台机器的作用就是检查靶机宕机没有

Flag_Server:

选手提交flag的服务器,并存储选手的分数,开启80端口
简单来说这台机器就是获取到flag后的提交对象,用于加分

Web_Server:

选手连接的服务器,选手需要对其进行维护,并尝试攻击其他队伍的机器,通常开启80端口,22端口,并将端口映射到主机。
这个就是我们每个队伍所要操作的机器。

技术图片

搭建docker

这个就不再赘述,有时间简单写下,现在可以百度一下

pull镜像

sudo docker pull zhl2008/web_14.04

这个镜像是有点bug的,需要改下名字

sudo docker tag zhl2008/web_14.04 web_14.04 

启动比赛

按照文档

sudo python batch.py web_yunnan_simple 3    
#web开头的是本次开启的比赛环境,文件中所有web开头的都是比赛环境,后面的3表示3队伍,可以更改,使用python2开启
sudo python start.py ./ 3    
#启动docker容器

开启的是web_yunnan_simple靶机,靶机的网站端口映射规则如下

1、team1 ---- 8801
2、team2 ----8802
3、team3 ---- 8803
……

连接ssh,各靶机的密码在awd-platform/paa.txt中
ssh端口映射规则如下

1、team1 ---- 2201
2、team2 ----2202
3、team3 ---- 2203
……

现在还没有启动裁判机 check,项目中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服务

sudo docker attach check_server/
sudo python check.py

技术图片

这样就OK了

sudo python stop_clean.py      #清理环境

提交规则

(假设服务器地址是192.168.0.1)
http://192.168.0.1:8080/flag_file.php?token=teamX&flag=xxx
(其中X为自己的队伍号,flag为其他队伍的flag)

计分牌
http://192.168.0.1:8080/score.txt

攻击情况
http://192.168.0.1:8080/result.txt

出现的问题:

  • flag提交后计分牌攻击情况页面不刷新,也不自动刷新(明天再去研究)
  • 计分牌页面过于丑(明天写美化,今天太晚了)

参考资料
https://www.cnblogs.com/Cl0ud/p/13662932.html
https://www.cnblogs.com/Triangle-security/p/11332223.html#
https://www.heibai.org/post/1468.html

AWD平台搭建

标签:als   网站   容器   lists   机器   python2   hosts   form   server   

原文地址:https://www.cnblogs.com/stayelegance/p/14386870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!