{"id":41455,"date":"2018-01-10T06:00:32","date_gmt":"2018-01-10T11:00:32","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=41455"},"modified":"2018-01-10T00:53:42","modified_gmt":"2018-01-10T05:53:42","slug":"broken-stuff-and-security-concerns","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=41455","title":{"rendered":"Broken Stuff and Security Concerns"},"content":{"rendered":"<p>Yes, <a href=\"https:\/\/www.shamusyoung.com\/forums\/\">the forums<\/a> are down. Yes, I realize you can&#8217;t edit your own comments. Let&#8217;s talk about that.<\/p>\n<p>On my Linux-based webserver, there is a user account linked to me. This &#8220;shamus&#8221; account owns all the files: All the PHP scripts to drive the blog, all the scripts to run the forums, and all the images and other random files that makes the site operate. Under normal circumstances, the entire file structure is designed so that only my user can upload, delete, and modify files. <\/p>\n<p>However, you need to make some exceptions. For example, I run a WordPress plugin that makes weekly database backups. This plugin needs to be able to save these backups, which means that I need to make the backup directory writable for all users, not just the &#8220;shamus&#8221; user<span class='snote' title='1'>PHP, MySQL, and other processes are owned by the root user.<\/span>. Otherwise, the backup plugin would run but it wouldn&#8217;t be allowed to save the resulting backup to disk.<\/p>\n<p>So I need to make a few spots on the machine where processes not owned by me can put files. This alone isn&#8217;t enough to compromise the security of the machine, although it&#8217;s often considered something to be avoided if you can help it.  The danger is that it may provide an attack vector for potential hackers. If there&#8217;s a vulnerability in either WordPress (the software that runs the blog) or PhpBB (the software that runs the forums) then they would be able to write files to these directories.<\/p>\n<p>Here is a ficticious example of how something like this could work: Let&#8217;s say the forum offers a feature where users can upload their own profile image. You&#8217;re supposed to upload a JPG or PNG image file. These files end up in <tt>\/forums\/profileimages\/<\/tt>. In order for this feature to work, I need to set the permissions of <tt>\/forums\/profileimages\/<\/tt> so that anyone can write to that directory. Let&#8217;s say the people who wrote the forum software didn&#8217;t do their job and the forums don&#8217;t make sure that what the user uploaded was actually an image. Like, maybe they uploaded a PHP script. This allows them to put new pages on my site, and those pages can do all sorts of nasty things. <\/p>\n<p>Now, they can&#8217;t just put those pages anywhere. Those pages can only end up in <tt>\/forums\/profileimages\/<\/tt>, and only the attacker will know about them. Once the upload is done, the attacker can then manually type in the URL like so:<\/p>\n<p><tt>shamusyoung.com\/forums\/profileimages\/badpage.php<\/tt><\/p>\n<p>This will cause the script to run and do whatever it&#8217;s supposed to do. This doesn&#8217;t give the attacker full control over the machine. (They can still only put new files in directories I&#8217;ve had to leave open.) They can&#8217;t re-write the blog or attack visitors directly, but this is still an alarming situation that allows them to see a lot of stuff they shouldn&#8217;t.<\/p>\n<p>This is a very simplified explanation. The actual method of attack is a lot more complex and to be honest most of it is beyond me. But this is the idea in broad strokes.<\/p>\n<p>A couple of months ago Peter<span class='snote' title='2'>He doesn&#8217;t comment often so you might not know him, but Peter has been providing technical and hardware support to this site for <a href=\"?p=18607\">a long time<\/a>.<\/span> and I discovered some files on the site that were not owned by the &#8220;shamus&#8221; user. Files like this:<\/p>\n<p><tt>lprvpluh.php<br \/>\npvkmnwoj.php<br \/>\nonrvyxwg.php<br \/>\nukwwtgwx.php<\/tt><\/p>\n<p>Always the same pattern: A PHP file with a gibberish eight-character name, probably generated at random. These files contained highly obfuscated PHP code and were not part of the normal file structure of either WordPress or PhpBB. More importantly, they are obviously malicious in nature.<\/p>\n<p><table class='nomargin' cellspacing='0' width='100%' cellpadding='0' align='center' border='0'><tr><td><iframe loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/www.youtube.com\/embed\/49yU1frxof4\" frameborder=\"0\" allowfullscreen class=\"embed\"><\/iframe><br\/><small><a href='http:\/\/www.youtube.com\/watch?v=49yU1frxof4'>Link (YouTube)<\/a><\/small><\/td><\/tr><\/table><\/p>\n<p>Peter and I have been battling this mess for the last month or so. We deleted all the suspect files, tightened up directory access, and then hoped we&#8217;d fixed the problem. Then a few weeks later the mystery files would show up again and we&#8217;d have to start over.<\/p>\n<p>Last week the files showed up for the third time, and so we went to maximum paranoia level. We wiped WordPress clean and started over with a fresh install. We uninstalled the forums completely. This machine is now as locked down as we can make it. There are no directories with write access. This would break several of the WordPress plugins I use, but since I haven&#8217;t installed any plugins that&#8217;s not a problem yet.<\/p>\n<p>If the problem returns, then I&#8217;ll need to contact my host and have them wipe the machine clean and start over. I&#8217;d hate to do that, since it would result in a ton of downtime. (The blog has about 1.2 gigabytes of images, and I don&#8217;t have a very fast upstream connection. That would be a long upload. Not to mention the time required to restore the databases and re-install everything.)<\/p>\n<p>I&#8217;ve deliberately left out a lot of details on the off chance that the attacker actually reads the blog<span class='snote' title='3'>This is unlikely. These kinds of attacks are often done by bots.<\/span>. So if you&#8217;re thinking of asking, &#8220;Why don&#8217;t you guys just X?&#8221;, then keep in mind we probably did X but I&#8217;m leaving it out of this explanation.<\/p>\n<p>So that&#8217;s why the forums are gone and all of our quality of life plugins are missing from the blog. It&#8217;s a known issue. We&#8217;re still investigating. If all goes well, then we&#8217;ll eventually get back comment editing and all the other little plugins we&#8217;re used to. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, the forums are down. Yes, I realize you can&#8217;t edit your own comments. Let&#8217;s talk about that. On my Linux-based webserver, there is a user account linked to me. This &#8220;shamus&#8221; account owns all the files: All the PHP scripts to drive the blog, all the scripts to run the forums, and all the [&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-41455","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\/41455","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=41455"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/41455\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}