<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Checkmate &#187; Research</title>
	<atom:link href="http://niiconsulting.com/checkmate/category/research/feed/" rel="self" type="application/rss+xml" />
	<link>http://niiconsulting.com/checkmate</link>
	<description>An Information Security Blog by NII Consulting</description>
	<lastBuildDate>Fri, 02 Dec 2011 08:26:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Format Preserving Encryption &#8211; In the guise yet retrievable as it is</title>
		<link>http://niiconsulting.com/checkmate/2010/02/09/format-preserving-encryption-in-the-guise-yet-retreivsble-as-it-is/</link>
		<comments>http://niiconsulting.com/checkmate/2010/02/09/format-preserving-encryption-in-the-guise-yet-retreivsble-as-it-is/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 11:11:02 +0000</pubDate>
		<dc:creator>Khushbu Jithra</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Encrypt with format intact]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Format Preserving Encryption]]></category>
		<category><![CDATA[German Data Privacy Law]]></category>
		<category><![CDATA[PCI DSS]]></category>
		<category><![CDATA[UK Data Privacy Act]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=239</guid>
		<description><![CDATA[A recent dive into challenges faced from privacy compliance requirements unearthed an interesting patent. The unearthing of this new patent on the block came from the need of anonymizing data for several reasons including compliance (PCI DSS, German Data Privacy Law [BDSG], UK Data Privacy Act).]]></description>
			<content:encoded><![CDATA[<p>A recent dive into challenges faced from privacy compliance requirements unearthed an interesting patent. The unearthing of this new patent on the block came from the need of anonymizing data for several reasons including compliance (PCI DSS, German Data Privacy Law [BDSG], UK Data Privacy Act).<span id="more-239"></span></p>
<p>With inputs from experts in the domain here is an overview of this unique encryption technology.</p>
<p><strong>The challenge:</strong><br />
Simply randomizing the data won&#8217;t help if the data drives a process like indexing in a database &#8211; the introduction of database indexing problems, or destruction of the integrity of the data in the de-identification process may render it useless as far as a business application or statistical analysis is concerned even if the process should not access specific identifiable fields. So, if you need to de-identify or depersonalize yet still use the data, there needs to be a more thought put into it to ensure the process cannot be reversed and to ensure that the use of the de-identified data can be preserved.</p>
<p>For example, if we have two databases, both indexed on a national ID number containing e.g. health records but we need to de-identify the personal data, yet retain the referential integrity across internal database tables in addition to preserving record relationships across two independent databases, and replace the personal data with data that is still meaningful for analysis but truly de-identified, then we need to preserve referential integrity across all the de-identified databases.</p>
<p>What if we need this process to be selectively reversible for e.g. a e-discovery request or specific analysis where real data is needed? Traditionally, data owners would have to keep some kind of mapping table &#8211; an ugly solution as it simple moves the problem of de-identification to another place.</p>
<p><strong>The solution:</strong><br />
There are some new techniques that permit de-identification of data &#8211; in a secure fashion. Specifically Format Preserving Encryption (FFX/FFSEM mode AES) which can:</p>
<p>* Encrypt/De-identify data without changing length, structure, type, format, referential integrity of data (again optional if this is essential or if de-association of record relationships is actually required) on the fly</p>
<p>* Provide the dual purpose &#8211; de-identification or data protection in place (no database schema changes) or protection of data in live systems with a single technique</p>
<p>* reversible or non reversible by policy</p>
<p>* Supports native mainframe, open systems and legacy out of production systems.</p>
<p>In <a href="http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffsem/ffsem-spec.pdf">this</a> paper on Fiestal Finite Set Encryption (FFSEM), the author elaborates on the Pseudo-Random Permutation used in this mode and the security of the construction. The author is quoted, &#8220;In many applications, such as encryption of credit card numbers, it is desirable to encrypt items from an arbitrarily sized set onto that same set. Unfortunately, conventional cipher modes such as ECB, CBC, or CTR are unsuitable for this purpose. Feistel Finite Set Encryption Mode (FFSEM) allows encryption of a value ranging from 0..n with resultant ciphertext in that same range. This mode can be used to encrypt fields where the expansion associated with a block cipher is undesirable or the format of the data must be preserved.&#8221;</p>
<p>An <a href="http://eprint.iacr.org/2009/251">academic paper</a> on the subject summarizes &#8211; &#8220;Format-preserving encryption (FPE) encrypts a plaintext of some specified format into a ciphertext of identical format—for example, encrypting a valid credit-card number into a valid creditcard number. The problem has been known for some time, but it has lacked a fully general and rigorous treatment.We provide one, starting off by formally defining FPE and security goals for it.We investigate the natural approach for achieving FPE on complex domains, the “rank-then-encipher” approach, and explore what it can and cannot do. We describe two flavors of unbalanced Feistel networks that can be used for achieving FPE, and we prove new security results for each. We revisit the cycle-walking approach for enciphering on a non-sparse subset of an encipherable domain, showing that the timing information that may be divulged by cycle walking is not a damaging thing to leak.&#8221;</p>
<p>Now the interesting bit&#8230;.is it implemented and is it commercial?<br />
Yes. <a href="http://www.voltage.com/technology/format-preserving-encryption.htm">http://www.voltage.com/technology/format-preserving-encryption.htm</a></p>
<p>Full patent description is available here<br />
<a href="http://www.freshpatents.com/Format-preserving-cryptographic-systems-dt20080717ptan20080170693.php?type=description">http://www.freshpatents.com/Format-preserving-cryptographic-systems-dt20080717ptan20080170693.php?type=description</a></p>
<p>And of course, at the first look, Wikipedia also did not help understanding it much unless I read the background and the two papers</p>
<p><a href="http://en.wikipedia.org/wiki/Format-Preserving_Encryption">http://en.wikipedia.org/wiki/Format-Preserving_Encryption</a></p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2010/02/09/format-preserving-encryption-in-the-guise-yet-retreivsble-as-it-is/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Phishy Story</title>
		<link>http://niiconsulting.com/checkmate/2009/11/05/a-phishy-story/</link>
		<comments>http://niiconsulting.com/checkmate/2009/11/05/a-phishy-story/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 12:17:40 +0000</pubDate>
		<dc:creator>TAS</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Incident Response]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=80</guid>
		<description><![CDATA[Phishing sounds similar to fishing. Fishes are to the volume of internet users today much like fishermen are to phishers. Zillions of fishes falling prey the nets is nothing less compared to internet users being phished through their own in boxes and messengers. Phishers tend to have some personal favorites &#8211; personal information, credit cards [...]]]></description>
			<content:encoded><![CDATA[<p>Phishing sounds similar to fishing. Fishes are to the volume of internet users today much like fishermen are to phishers. Zillions of fishes falling prey the nets is nothing less compared to internet users being phished through their own in boxes and messengers.  Phishers tend to have some personal favorites &#8211; personal information, credit cards numbers, debit cards numbers with ATM pins, etc. Though phishing has been around for a long time, it became more prominent back in 2003. You can read more here on the big scams <a href="http://www.washingtonpost.com/wp-dyn/articles/A59350-2004Nov18.html">here</a>.</p>
<p>How does it all work?</p>
<p><span id="more-80"></span></p>
<p>
A typical modus operandi:</p>
<p>1)	The Phisher would either go out and buy a phishing kit from the underground channels or create a look alike page himself.</p>
<p>2)	 He would then need hacked websites or a server where the pages can be hosted. This can also be easily made available. He would pay or trade for a list of hacked websites on IRC channels, underground forums etc. These are some very common sources for such deals. He could also target systems that are vulnerable to a particular vulnerability or weakness in the website &#8211; vulnerability in the hosting providers control panel software, exploit for popular CMS like Joomla, 0day vulnerability in web server, etc. A zero-day (or zero-hour) attack or threat is a computer threat that tries to exploit computer application vulnerabilities that are unknown to others, undisclosed to the software vendor, or for which no security fix is available. (ref : <a href="http://en.wikipedia.org/wiki/Zero_day_vulnerability">http://en.wikipedia.org/wiki/Zero_day_vulnerability</a>)</p>
<p>3)	Once the hacked infrastructure is ready it’s time to spam. They would ideally send out emails in large volumes. These emails are crafted to perfection. They would have the company logo, an appealing message in the email; use the CSS as the company that is phished, etc. All this together make it look perfect. It’s like decorating the devils face with cosmetics to make it look innocent. But not to forget the devil under a thin layer of cosmetics. They will have a crafted link and the hyperlink actually pointing to some website where the pages are hosted.</p>
<p>However, the entire process is a gamble. Some may fall prey to their phish nets while others may not. Over the years, phishing scams have grown from simply stealing accounts into much more dangerous criminal intention. Assuming the user is a prey of the phish net, let us understand the ways in which a phisher can harvest the data of the victim. There are various ways in which this can be done.</p>
<p>1)	The attacker here uses services of websites that let you send HTML forms embedded in your email. On submit of this HTML form the phished page will redirect you to the legitimate website. This often tricks the user. They don’t realize what just happened. The details entered on the form are then emailed to the phisher’s inbox that is supposed to collect the details. The most common examples where you can see them are when advertising on the internet.</p>
<p>2)	Second, the email is scripted in a way that a user is tempted or forced to visit the copied website. The attacker can also use the tactic mentioned above and use services like www.emailmeform.com. Attacker creates an account here and links his entire phished page to use their service to capture the details and then email it to them. This is the most common method used by phishers. Also the pages are scripted in server side programming languages like PHP, .NET, JSP etc. Doing so it does not expose the modus operandi or the attacker’s identity in any way or other details in any way.</p>
<p>3)	The third type is where the phishers use nothing like above and instead writes all the output to a predefined file. In this way he needs no email address or anything mentioned above to capture the user details. This is what I am exactly going to write about.</p>
<p>Since I had some time off before I could start with the next takedown, I decided to dig further. Before we begin let me give you a brief about our service and the client. We offer take down services to a large public sector bank. We have a strict timeline defined of 24 hrs for every takedown. Every time a customer or their monitoring reports a phished page we have to takedown the site to protect the loss of financial and other details. While doing takedowns I also get a chance to research on understanding the modus operandi behind the operation. It is very interesting.</p>
<p>I have just started my day checking my email over a cup of coffee. I receive a new email on Tue 11/3/2009 10:22 AM about a phished link being up with the URL and we need to immediately start the takedown. He also sends me a sample email. We did the usual process and the link was down by noon. Have a look at a sample phishing email. </p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/fraudlent-email-sample1.jpg" alt="" /></p>
<p><br/><br/></p>
<p>The email looks so real. It has the logo of the customer and perfect login URL. On hover I found it was actually pointing to some server in Russia. The page &#8216;retails.html&#8217; simply redirects to the next URL where the phished page is hosted. Have a look at the closing lines of the email below. The phisher uses pressure tactic that will force the user to browse the URL.</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/2009-11-04_151209.jpg" alt="" /></p>
<p>Ok I now click and I am now redirected to the URL http://200.119.X.X/retail/login.php. The page looks like this</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/login-page.jpg" alt="" /></p>
<p>I then enter some fake details on this page and press the Enter key. I am now redirected to another page called &#8216;accounts.php&#8217; on the same domain. I quickly check the html source code (view source) of the page to check for the</p>
<form> tag. This is where I would see where the page is going on hitting &#8216;submit&#8217;. I am now redirected to another page hosted on a hacked domain called hxxp://stirileprotv.fnhost.org/bi/ib.php</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/2009-11-04_151925.jpg" alt="" /></p>
<p>I go a level up in the URL hxxp://200.119.X.X/retail/login.php and now I see the directory listing. I see 2 files under the retail folder namely &#8216;login.php&#8217; and &#8216;accounts.php&#8217;. Directory Listing has been common in all my takedowns. They don’t really care for the directory listings. What I also observed, at the bottom of the &#8216;account.php&#8217; page is more interesting. The page is has an IFRAME with src pointing to <a href="http://statanalyze.cn/lib/index.php">http://statanalyze.cn/lib/index.php</a>. This is some malware getting downloaded on victim system. </p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/2009-11-04_124018_malware.jpg" alt="" /></p>
<p>My anti virus immediately pops up an alert that a malware is getting downloaded. And it immediately blocks it. Coming back to &#8216;accounts.php&#8217; it asks for my Name, email address, credit card number, ATM pin and expiration date. On entering some fake details I am now redirected to a third domain hxxp://stirileprotv.fnhost.org/bi/ib.php. And from &#8216;ib.php&#8217; it redirects me to the legitimate page of my client website. I have changed that to hxxp://www.google.com in the code snippet. Aren’t these guys sick of so many re directions? Not really they have a smart modus operandi. They don’t use one domain to complete their operation.</p>
<p>I again go a level up on the <a href="http://stirileprotv.fnhost.org/bi/ib.php">http://stirileprotv.fnhost.org/bi/ib.php</a>. What I happen to find is something even more interesting. It had a page &#8216;ib.php&#8217; under the ib folder and a .txt file. When I tried accessing the file what I find is the actual account details of the people who have fallen prey to the trick with their usernames, credit card numbers, internet banking IDs and passwords. Check file snippet below</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/2009-11-05_113230.jpg" alt="" /> </p>
<p>I then contact the client to freeze the accounts and get in touch with the hosting providers. I make sure I ask the hosting providers to provide me with the pages as they aid to my research in understanding various modus operandi out on pr0wl. Most of the time they don’t give the pages but this time I was lucky. The tech support guys actually emailed me the contents of the ib folder. Have a look at the php code</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/the-actual-code.jpg" alt="" /></p>
<p>Let me explain the code in brief. It opens a stream to a file called x-account-all.txt and then captures the post variables from the URL http://200.119.X.X/retail/accounts.php. The following table explains what each variable means</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/11/table.jpg" alt="" /></p>
<p>I thought that was it. I was done with my research. I relaxed a bit and stretched my arms. But hold on readers I recollect that the website was also vulnerable to IFRAME injection. No more research on this malware guys I have colleagues who enjoys this. I will send this to him. Till he comes up with his analysis there are some who have already done it. Check the link below</p>
<p><a href="http://wepawet.iseclab.org/view.php?hash=363c95666cf1e80072656c7b562c4dbb&amp;type=js">http://wepawet.iseclab.org/view.php?hash=363c95666cf1e80072656c7b562c4dbb&amp;type=js</a> </p>
<p><a href="http://anubis.iseclab.org/?action=result&amp;task_id=1c109b3e2cc07d1f49168943cc884e1d2">http://anubis.iseclab.org/?action=result&amp;task_id=1c109b3e2cc07d1f49168943cc884e1d2</a></p>
<p><a href="http://www.virustotal.com/analisis/837508d65acc78ec684c0d7a907bea7f49ce223052a18a076240018fc61a0d7f-1257141946">http://www.virustotal.com/analisis/837508d65acc78ec684c0d7a907bea7f49ce223052a18a076240018fc61a0d7f-1257141946</a></p>
<p>I was still way too itchy to pull down a full stop. I picked some arbitrary entries from the file and picked the &#8216;ea&#8217; and &#8216;bb&#8217; field. Why only them? (I got this particular combination after trying out a few) I was able to login to the Yahoo accounts of the victim since the password used was the same for both the accounts. I then checked the spam box and found the email that the victim had received. There were similar emails and to my surprise I found another URL hosting the phished page. Ok guys that’s it, I need to get back to my next takedown immediately  Oh! By the way, this time it is some Windows 2003 server behind some ADSL router running the phished page on a XAMP server. I did RDP to the box, 3389 was found open. I will come back if I find something more interesting.</p>
<p>All the details in this post have being changed or rename to protect real identity of our client. </p>
<p>Adios!<br />
Taufiq Ali</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2009/11/05/a-phishy-story/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deobfuscating Javascript Malware</title>
		<link>http://niiconsulting.com/checkmate/2009/10/01/deobfuscating-javascript-malware/</link>
		<comments>http://niiconsulting.com/checkmate/2009/10/01/deobfuscating-javascript-malware/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 11:20:32 +0000</pubDate>
		<dc:creator>Wasim Halani</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Malware Analysis]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[javascript deobfuscation]]></category>
		<category><![CDATA[javascript malware]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=62</guid>
		<description><![CDATA[Some days back I was greeted by a Google Safe browsing warning when I tried visiting a &#8216;known&#8217; site. As I was sure it was supposed to be clean and harmless site, I thought it would be good to dig further into this problem. The trail led to interesting amounts of codes, concepts and techniques. [...]]]></description>
			<content:encoded><![CDATA[<p>Some days back I was greeted by a Google Safe browsing warning when I tried visiting a &#8216;known&#8217; site. As I was sure it was supposed to be clean and harmless site, I thought it would be good to dig further into this problem. The trail led to interesting amounts of codes, concepts and techniques.</p>
<p>Malware writers are very smart nowadays (haven&#8217;t they always been ?). They know that once their code is understood it most likely to be detected by anti-malware applications. To delay detection by such applications, they resort to a wide range of techniques. In this blog post I&#8217;ll be discussing the most potent and easily created malware.</p>
<p>Javascript has become the boon and bane of the Internet. It provides greater interactivity with the user but can also be used by malware writers to infect innocent users. Javascript is a client-side scripting technology which means the processing of the script is handled by the user&#8217;s browser.</p>
<blockquote><p><strong><em>Obfuscation is the concealment of intended meaning in communication, making communication confusing, intentionally ambiguous, and more difficult to interpret.</em></strong></p></blockquote>
<p><span id="more-62"></span></p>
<p>JavaScript is sometimes obfuscated to prevent users from easily understanding their functionality. ( Legitimate uses are to prevent stealing of code)</p>
<p>There may be many ways to obfuscate a code and similarly there may be multiple ways to de-obfuscate a code. What I&#8217;ve presented below is very raw and cannot be used to analyze many malicious JS. But since this is the beginning for me, I thought it may help others too.</p>
<p><strong>Disclaimer: Links presented below are live at the time of writing this blog post. Please do not visit them if you do not know what you are getting into.<br />
</strong></p>
<p>First thing first, we need to get the HTML source the malicious page. We can either use wget/curl or <a href="http://malzilla.sourceforge.net/">Malzilla</a>, which is what I used. It was observed that this page is dependent on the HTTP referrer. So if the domain receives a request for the page without a &#8216;valid&#8217; HTTP referrer page, the page is not returned.<br />
We get the &#8216;bad&#8217; HTML at http://mybetorwager.cn:8080/index.php with a valid HTTP referrer.</p>
<p>The complete HTML source can be viewed <a href="http://docs.google.com/View?id=dctvmpj6_28f9pwcrhd"><strong>here</strong></a> </p>
<p>The code starts off with the following in the SCRIPT tag.</p>
<blockquote><p><strong>Vhotzdq(function(p,a,c,k,e,d)</strong></p></blockquote>
<p>This section of the code shows that the javascript has been packed by the popular <a href="http://dean.edwards.name/packer/">Dean Edword JS Packer</a>. This packer is available online as well as in <a href="http://dean.edwards.name/download/#packer">download-able formats</a>. We use a GreaseMonkey script &#8220;<a href="http://userscripts.org/scripts/show/25935">Decode It!</a>&#8221; to enable the online &#8216; <em>Decoder</em>&#8216; on the webpage.<br />
</br><br />
We paste the code from Vhotzdq(function(p,a,c,k,e,d) onwards till the end and <strong>rename the function name Vhotzdq to eval</strong>. This will help us decode and evaluate the result. The output of which can be found <a href="http://docs.google.com/View?id=dctvmpj6_29hgzk3tdr"><strong>here</strong></a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Update</strong><em><br />
Seems like Dean Edwards had coded an UNPACKER as well. It can be accessed at <a href="http://dean.edwards.name/unpacker/">http://dean.edwards.name/unpacker/</a>. If using this tool, simply <strong>replace the Vhotzdq to eval</strong> and run the script. No additional GreaseMonkey scripts are necessary <img src='http://niiconsulting.com/checkmate/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
</em></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<div id="attachment_82" class="wp-caption alignnone" style="width: 610px"><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/10/js_unpack_1.jpg" alt="Fig: Unpacked Javascript using Dean Edwards Packer" title="Unpacked Javascript using Dean Edwards Packer" width="600" height="178" class="size-full wp-image-82" /><p class="wp-caption-text">Fig: Unpacked Javascript using Dean Edwards Packer</p></div>
<p>As can be seen above, we need to unescape the code to get the decoded output. This can be done in multiple ways:</p>
<ul>
<li>Replace <em>Vhotzdq </em>as <em>eval</em>, and execute the script</li>
<li>Use the Malzilla decoder feature &#8220;Decode UCS2 (%u)&#8221;</li>
<li>Use an online encoder/decoder like <a href="http://www.yehg.net/encoding/">PHP Charset Encoder/PHP String Encrypter</a></li>
</ul>
<p></br><br />
<div id="attachment_83" class="wp-caption aligncenter" style="width: 610px"><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/10/js_decoded-php-charset-1.jpg?w=600" alt="Fig: Using the &#39;unescape&#39; feature provided by PHP Charset Encoder" title="Using the &#39;unescape&#39; feature provided by PHP Charset Encoder" width="600" height="315" class="size-full wp-image-83" /><p class="wp-caption-text">Fig: Using the 'unescape' feature provided by PHP Charset Encoder</p></div></p>
<p>The decoded output of the above step can be found <a href="http://docs.google.com/View?id=dctvmpj6_30dd9nvgdk"><strong>here</strong></a></p>
<p>Now the code is in a more human readable format. To further complicate analysis, the malware authors have implemented small amounts of string manipulations on the code. Also, the variables used have been obfuscated or mangled. This will not pose a problem to us as the variables can be given any names.</p>
<blockquote><p><em>Note that there exists a certain amount of code-block which is still encoded. Another <a href="http://wepawet.iseclab.org/view.php?hash=835f950f74bbdaebab4e91a28c73d1d8&amp;t=1250389682&amp;type=js">malware analysis</a> shows this section as the Shellcode. I will update this as I get more information on how to decode it.</em></p></blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><strong>Update</strong><em><br />
OK, it turns out that the segment was indeed the shellcode. Using the Malzilla tool we concatenate the variable &#8220;<strong>var unf57UBnT</strong>&#8221;<br />
This presents us with an encoding which seems to be UCS2. Next, we can either use Malzilla to convert UCS2 to Hex (which does not provide reliable results) or use a shellcode to EXE converter available at <a href="http://sandsprite.com/shellcode_2_exe.php">http://sandsprite.com/shellcode_2_exe.php</a>.</em><br />
</br><div id="attachment_96" class="wp-caption aligncenter" style="width: 463px"><a href="http://sandsprite.com/shellcode_2_exe.php"><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/10/shellcode-2-exe_2.jpg" alt="Fig: ShellCode 2 EXE" title="ShellCode 2 EXE" width="453" height="518" class="size-full wp-image-96" /></a><p class="wp-caption-text">Fig: ShellCode 2 EXE</p></div><br />
</br><br />
<em>Once we obtain the EXE from the shellcode, we can analyze this executable in a tool called <a href="http://www.webwasher.de/download/fileinsight/"><strong>FileInsight </strong>developed by Mcafee Labs</a>. Below is a snapshot of FileInsight analysis output which shows the malicious URL.</em><br />
</br><br />
<div id="attachment_97" class="wp-caption aligncenter" style="width: 610px"><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/10/fileinsight-2.jpg" alt="Fig: FileInsight - Shellcode.exe analysis" title="FileInsight - Shellcode.exe analysis" width="600" height="420" class="size-full wp-image-97" /><p class="wp-caption-text">Fig: FileInsight - Shellcode.exe analysis</p></div> </br></p>
<p><em>URLMON.DLL is a system DLL generally used by malwares to download files from online locations</em></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
The next step is to execute the &#8216;replace&#8217; functions which involve Regular Expressions to clean out the manipulated code.<br />
As an example below is the line of code that we currently have in our decoded output.</p>
<blockquote><p>rqeqG6Spq.setAttribute(&#8216;i#)@d!&#8217;.replace(/\(|\!|&amp;|\$|@|\^|\)|#/ig, &#8221;),rqeqG6Spq);</p></blockquote>
<p>Let&#8217;s take this code in detail:</p>
<table>
<tr>
<td><strong>rqeqG6Spq</strong></td>
<td>&#8211;&gt;</td>
<td>declared variable</td>
</tr>
<tr>
<td><strong>setAttribute</strong></td>
<td>&#8211;&gt;</td>
<td>the property of the variable rqeqG6Spq</td>
</tr>
<tr>
<td><strong>/\(|\!|&amp;|\$|@|\^|\)|#/ig</strong></td>
<td>&#8211;&gt;</td>
<td>Regular Expression</td>
<tr>
<td colspan="3">
(In JavaScript, to define a regex pattern, we define it between <strong>/&#8230;../</strong> .<br />
&#8216;<strong>g</strong>&#8216; indicates <em>Global Match</em> and &#8216;<strong>i</strong>&#8216; is for <em>Case-Insensitive</em> search)
</td>
<tr>
<td><strong>.replace()</strong></td>
<td>&#8211;&gt;</td>
<td>is a JavaScript string manipulation function, which runs the regex on the &#8216;object&#8217; <strong>i#)@d!</strong></td>
</tr>
</table>
<p>After executing the replace() function, the output would look like this </p>
<blockquote><p><em>rqeqG6Spq.setAttribute(&#8216;id&#8217;,rqeqG6Spq);</em></p></blockquote>
<p>Similar replace operations are performed at all other places, till we get the final output as shown <a href="http://docs.google.com/View?id=dctvmpj6_32fhwmwdfz">here</a></p>
<p><strong>NOTE: Your Anti-Malware may issue an alert when you try to visit the above link. I have modified the malicious URL a bit so the script won&#8217;t move ahead.</strong></p>
<p>We are now at a stage where we can make a few observations on what the JavaScript does and how it works.<br />
The original malicious domain is found to be <strong>http://3c8.ru:8080/welcome.php</strong> .This domain serves the malware payload.<br />
The script tries to exploit a vulnerability in ActiveX which allows it to download and execute a malicious binary.<br />
I haven&#8217;t had the chance to go deeper into the execution of the malware But once I get the time, I&#8217;ll look into analyzing the binary as well.</p>
<p>Before I end this long post, just a quick note that to automate this entire process, we can use an online tool called <strong><em><a href="http://wepawet.iseclab.org/index.php">wepawet</a></em></strong>, which is a service for detecting and analyzing web-based malware. It currently handles Flash and JavaScript files.<br />
You can find the result of the analysis of our malicious page at <a href="http://wepawet.iseclab.org/view.php?hash=07fc283602731721a97f196c3ab19092&amp;type=js">http://wepawet.iseclab.org/view.php?hash=07fc283602731721a97f196c3ab19092&amp;type=js</a><br />
It provides for a comprehensive analysis. </p>
<p>Also, do check out the VirusTotal scan results for the obfuscated and deobfuscated Javascript<br />
<a href="http://www.virustotal.com/analisis/2cd3069c412cac7b1159d20070503ee91238f1e4682a5b90b003b29a569c9291-1251527312">Obfuscated Detection rate is 2/41</a><br />
<a href="http://www.virustotal.com/analisis/218209456d7c0dc654596eab91b8cf0127dbbe1642eef9f56a3366021835d504-1251527404">De-obfuscated Detection rate is 14/41</a></p>
<p>I  guess that&#8217;s it. Hope you liked this basic tutorial. Do leave your feedback in the comments section below</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2009/10/01/deobfuscating-javascript-malware/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

