{"id":440,"date":"2010-02-17T09:47:29","date_gmt":"2010-02-17T14:47:29","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=440"},"modified":"2010-02-17T09:47:29","modified_gmt":"2010-02-17T14:47:29","slug":"secure-php-upload-directory","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2010\/02\/secure-php-upload-directory\/","title":{"rendered":"Secure PHP Upload Directory"},"content":{"rendered":"<p>I was given the task to setup, configure, and manage an external facing apache web server.<\/p>\n<p>So I turned to my trusty Ubuntu Server 9.10 x86 CD, installed it and then ran the updates.  Yes, I put LAMP on there.<\/p>\n<p>After all was said and done, I grabbed my trusty internal-only php uploader script.  Unfortunately it&#8217;s not fully secure &#8211; I actually had someone attack my &#8220;honeypot&#8221; site successfully by exploiting this script and a lax apache install.  What makes this script so bad for use on the outside is it&#8217;s need for chmod 777 privileges.  Yuck.<\/p>\n<p>A good way to stop people from finding bad things to run is to hide indexing from the site (directory listing).  Another is to stop executables from running in that directory.<\/p>\n<p>Open up the sites-enabled configuration of apache<br \/>\n<code>nano \/etc\/apache2\/sites-enabled\/000-default<\/code><\/p>\n<p>Under the first virtualhost area, edit for your directory:<\/p>\n<blockquote><p>&lt;VirtualHost *:80&gt;<br \/>\nServerAdmin webmaster@localhost<\/p>\n<p>DocumentRoot \/var\/www<br \/>\n&lt;Directory \/&gt;<br \/>\nOptions FollowSymLinks<br \/>\nAllowOverride None<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;Directory \/var\/www\/&gt;<br \/>\nOptions FollowSymLinks MultiViews<br \/>\nAllowOverride None<br \/>\nOrder allow,deny<br \/>\nallow from all<br \/>\n&lt;\/Directory&gt;<\/p>\n<p>ScriptAlias \/cgi-bin\/ \/usr\/lib\/cgi-bin\/<br \/>\n&lt;Directory &#8220;\/usr\/lib\/cgi-bin&#8221;&gt;<br \/>\nAllowOverride None<br \/>\nOptions +ExecCGI -MultiViews +SymLinksIfOwnerMatch<br \/>\nOrder allow,deny<br \/>\nAllow from all<br \/>\n&lt;\/Directory&gt;<\/p>\n<p><strong>&lt;Directory \/var\/www\/upload_files\/&gt;<br \/>\nAllowOverride None<br \/>\nOptions IncludesNOEXEC<br \/>\nOptions -Indexes<br \/>\nOptions -ExecCGI<br \/>\nAddHandler cgi-script .php .php3 .php4 .phtml .pl .py .jsp .asp .htm .shtml .sh .cgi .gif .pdf .jpg .png .tif .tiff .wmv .mpg .mp3 .mp4 .avi .txt .html .exe .xml .*<br \/>\n&lt;\/Directory&gt;<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><\/p><\/blockquote>\n<p>Then restart apache<br \/>\n<code>apache2ctl restart<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was given the task to setup, configure, and manage an external facing apache web server. So I turned to my trusty Ubuntu Server 9.10 x86 CD, installed it and then ran the updates. Yes, I put LAMP on there. After all was said and done, I grabbed my trusty internal-only php uploader script. Unfortunately &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2010\/02\/secure-php-upload-directory\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Secure PHP Upload Directory<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=440"}],"version-history":[{"count":2,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":442,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/440\/revisions\/442"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}