{"id":25353,"date":"2014-12-14T06:33:35","date_gmt":"2014-12-14T11:33:35","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=25353"},"modified":"2014-12-14T06:38:12","modified_gmt":"2014-12-14T11:38:12","slug":"the-infection","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=25353","title":{"rendered":"The Infection"},"content":{"rendered":"<p>As I mentioned last Friday, <a href=\"?p=25340\" title=\"Haq?\">this site was compromised<\/a>. A friend (thank you so much Peter!) jumped in and we tried to unravel the mess. And when I say &#8220;we&#8221; I mean, &#8220;Peter did most of the heavy lifting and my job consisted mostly of remembering things.&#8221; Since I know some of you will be curious about it, I thought I&#8217;d share the results. <\/p>\n<p>In looking at the problem, we had several goals and questions:<\/p>\n<ol>\n<li>Is the machine actually infected? If so, with what?<\/li>\n<li>Remove the infection.\n<li>Figure out how the infection occurred.\n<li>Secure the machine to prevent future infections.\n<\/ol>\n<p>Let&#8217;s look at the results:<\/p>\n<p><!--more--><\/p>\n<h3>Is the machine actually infected? If so, with what?<\/h3>\n<p>Yes, it was infected with <a href=\"https:\/\/blog.malwarebytes.org\/exploits-2\/2014\/10\/exposing-the-flash-eitest-malware-campaign\/\">Flash \u00e2\u20ac\u02dcEITest&#39;<\/a>, which seeks to spread by infecting reputable sites. (According to that website, it&#8217;s also infected sites like The Department of Statistics at Carnegie Mellon University.) <\/p>\n<p>It presents a flash file to visitors and exploits some weakness in Flash + Internet Explorer + Windows 7 to get some sort of malware onto the user&#8217;s machine. <\/p>\n<p>I must say that infections are getting more <strong>socially<\/strong> clever. Sure, a lot of them had <strong>technological<\/strong> cleverness to spare. A hacker would find and exploit any number of obscure weaknesses, and write sophisticated code to accomplish amazing wonders on the victim&#8217;s machine. But they were always so brute-force and idiotic when it came to the human element. Infections were brazen, aggressive, and obvious. You could often see right away that you were infected. Yes, a few people were oblivious enough that they didn&#8217;t realize all those porn popus from CNN.com meant their computer was hacked, but those people are not the norm. The malicious programs would attack early, attack often, and would make themselves very obvious. It&#8217;s like a guy in a ski mask walking down the street in broad daylight and attempting to mug every single person they pass, even if it&#8217;s a kid, a hobo, or a policeman. That crime spree isn&#8217;t going to last long. <\/p>\n<p>This particular devil was a little smarter. It wouldn&#8217;t present itself unless you were running Windows 7 and using Internet Explorer, since you needed both of those to be vulnerable. It kept a record of visitors, and would never attack the same person (IP address) twice. After all, after the first attack you&#8217;re either infected or immune, so why bother attacking again? <\/p>\n<p>This made the thing tough to track down. <\/p>\n<h3>Remove the infection.<\/h3>\n<p>The infection was focused on two main files. The first was templater.php, which resided in the root of the blog directory. Templater.php isn&#8217;t a normal part of WordPress, but that directory is full of PHP files. There were two clues that this file didn&#8217;t belong: 1) All proper WordPress files begin with &#8220;wp-&#8220;, so it should have been named &#8220;wp-templater.php&#8221;. 2) The file was frigging huge. The typical WordPress source file is a few hundred bytes. This thing was 38 kilobytes. The text of the file was mostly gibberish like this:<\/p>\n<pre lang=\"php\">\r\n<?php $ttbfckdqfa = '5c%x78256<pd%x5c%x7825w6Z6...\r\n(continues for a hundred pages)\r\n...\/epreg_replaceefqvzwsatb'; $nbwiiqbipb = \r\nexplode(chr((155-111)),'5322,50,8008,29,6622,67,4334,20,9933,52,3670,59,6882,...\r\n(another page of crap)\r\n...,5987,20,6371,46'); $ibhulntvxz=substr($fnfnheabvb<(\r\nsizeof($grsaktoxtd)\/2);$fnfnheabvb++) { $szifljfgnf .= \r\nsubstr($zxtzeeqjap, $grsaktoxtd[($fnfnheabvb*2)],\r\n$grsaktoxtd[($fnfnheabvb*2)+1]); } return $szifljfgnf; };} \r\n$jwwectgvwb=\"\\x20\\...\r\n(You get the idea.)\r\n<\/pre>\n<p>We figured it's probably binary data, encoded into a string, and then un-packed when needed. The sad thing is that that isn't even the most unreadable PHP file I've ever seen, and this one was obfuscated <em>on purpose<\/em>.<\/p>\n<p>The other troublesome file was \"error_log\", which looked like an error log and contained stuff you would expect to find in an error log, but is not part of WordPress proper. <\/p>\n<p>Both of these files had promiscuous file permissions set and were owned by \"nobody\" instead of being properly owned by my hosting account, as would be normal for files on my website. They were both created on August 4, which suggests that this is when the infection took place. (At the time, I was busy dealing with <a href=\"?p=24604\" title=\"Something in the Water, Part 3\">this<\/a>.) No other WordPress files (or any files) were created on or around that date. <\/p>\n<p>We checked for other files created after August 4th. Nothing had been touched outside of the WordPress folder.<\/p>\n<p>It seemed pretty easy to remove these offending files, but in the end this \"surgical strike\" approach seemed too risky. What if this thing had inserted bits of itself into other parts of WordPress? WordPress is huge. It has hundreds of files spread out over dozens of nested directories. Properly inspecting them all would be impossible.<\/p>\n<p>So we did a complete re-install of WordPress. This is why some site features vanished. Those were plugins that need to be re-installed. Over the next couple of days I'll restore comment editing and \"check here if you're not a spammer\". <\/p>\n<h3>Figure out how the infection occurred.<\/h3>\n<p>My FTP site was using a password that's as old as this blog. However, I don't think that was the attack vector. If the FTP had been used, the attacker would have been able to hide things much better. (The infected files would have been owned by me.) <\/p>\n<p>Several file permissions were far too permissive, and I think that was the opening that let the attacker in. The WordPress folder was set so that anyone on the machine could write to that directory. So if stupidcrap.com and shamusyoung.com are hosted on the same machine, and if stupidcrap.com got hacked, the hacker would also be able to put files in my WordPress directory.<\/p>\n<p>This vulnerability has probably been around for AGES. Back in the early days of this site, I was pretty careless. I didn't know the danger, I didn't quite get how permissions worked, I didn't envision this blog as something that needed to be built to last, and I didn't care what happened to it. If Linux file permissions gave me trouble, I just added permissions until it stopped. I figure I was probably working on one of the early plugins or the theme that now drives the site and wanted to do something fancy. I changed permissions while I was working, and then neglected to change them back when I was done. <\/p>\n<div class=\"dmnotes\">I've always had trouble CREATING files in PHP. If the file exists, then you can just mark the file as write-able and your code will run. But if the files doesn't exist for some reason, then you need to make the <em>directory itself<\/em> write-able, which is a much larger hole. If I want my script to be able to create one particular file (say, an error log) then I need to make it so that any other script can create ANY file. (Say, another script, or even a binary!) If there's a proper way to handle this in PHP, I've never found it.<\/div>\n<p>So it was probably my fault. The other possibility - that the machine itself was compromised - is technically possible but far less likely. I'm willing to bet this was a mistake I made ages ago. <\/p>\n<h3>Secure the machine to prevent future infections.<\/h3>\n<p>We cleansed the filesystem of all files not owned by me. (Those two were the only troublemakers.) Directory permissions were locked down again. Passwords were changed.<\/p>\n<h3>Wrapping up.<\/h3>\n<p>Remember that you're only at risk if you're on Windows 7 and using unpatched Internet Explorer 11 with Flash enabled. I imagine if you're using Internet Explorer then it's because you have to and not because you want to. Do make sure to keep it up to date. Attacks like this can come from anywhere, so sticking to \"safe\" sites isn't enough. <\/p>\n<p>Hopefully you didn't catch anything on account of me. Everything should be solid now. Thanks for your patience. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I mentioned last Friday, this site was compromised. A friend (thank you so much Peter!) jumped in and we tried to unravel the mess. And when I say &#8220;we&#8221; I mean, &#8220;Peter did most of the heavy lifting and my job consisted mostly of remembering things.&#8221; Since I know some of you will be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[],"class_list":["post-25353","post","type-post","status-publish","format-standard","hentry","category-notices"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/25353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25353"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/25353\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}