{"id":207,"date":"2008-09-23T20:39:00","date_gmt":"2008-09-23T20:39:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=207"},"modified":"2008-09-23T20:39:00","modified_gmt":"2008-09-23T20:39:00","slug":"improve-security-for-apc-php","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=207","title":{"rendered":"Improve security for apc.php"},"content":{"rendered":"<p>If you&#8217;re running APC with PHP, you have the option to download apc.php to view, monitor the usage\/stats. However, the default authentication is very open. Without any credential, anyone can view the running stats and also the cached filenames (a simple search on &#8220;APC INFO&#8221; will show some site running APC). The login is to view per-directory file caching. So if you want to require login credential on ALL access change this code:<\/p>\n<p><textarea name=\"code\" class=\"php\"><br \/>\n\/\/ authentication needed?<br \/>\n\/\/<br \/>\nif (!USE_AUTHENTICATION) {<br \/>\n        $AUTHENTICATED=1;<br \/>\n} else {<br \/>\n        $AUTHENTICATED=0;<br \/>\n        if (ADMIN_PASSWORD!=&#8217;password&#8217; &#038;&#038; ($MYREQUEST[&#8216;LO&#8217;] == 1 || isset($_SERVER[&#8216;PHP_AUTH_USER&#8217;]))) {<\/p>\n<p>                if (!isset($_SERVER[&#8216;PHP_AUTH_USER&#8217;]) ||<br \/>\n                        !isset($_SERVER[&#8216;PHP_AUTH_PW&#8217;]) ||<br \/>\n                        $_SERVER[&#8216;PHP_AUTH_USER&#8217;] != ADMIN_USERNAME ||<br \/>\n                        $_SERVER[&#8216;PHP_AUTH_PW&#8217;] != ADMIN_PASSWORD) {<br \/>\n                        Header(&#8220;WWW-Authenticate: Basic realm=\\&#8221;APC Login\\&#8221;&#8221;);<br \/>\n                        Header(&#8220;HTTP\/1.0 401 Unauthorized&#8221;);<\/p>\n<p>                        echo <<<eob\n                                <html><body><\/p>\n<h1>Rejected!<\/h1>\n<p>                                <big>Wrong Username or Password!<\/big><br \/>&nbsp;<br \/>&nbsp;<br \/>\n                                <big><a href='$PHP_SELF?OB={$MYREQUEST['OB']}'>Continue&#8230;<\/a><\/big><br \/>\n                                <\/body><\/html><br \/>\nEOB;<br \/>\n                        exit;<\/p>\n<p>                } else {<br \/>\n                        $AUTHENTICATED=1;<br \/>\n                }<br \/>\n        }<br \/>\n}<br \/>\n<\/textarea><\/p>\n<p>to this:<\/p>\n<p><textarea name=\"code\" class=\"php\"><br \/>\n\/\/ 9\/23\/2008: Son Nguyen changed to always require auth for ANY info, not just Per-Dir<br \/>\n$AUTHENTICATED=0;<\/p>\n<p>if (!isset($_SERVER[&#8216;PHP_AUTH_USER&#8217;]) ||<br \/>\n\t!isset($_SERVER[&#8216;PHP_AUTH_PW&#8217;]) ||<br \/>\n\t$_SERVER[&#8216;PHP_AUTH_USER&#8217;] != ADMIN_USERNAME ||<br \/>\n\t$_SERVER[&#8216;PHP_AUTH_PW&#8217;] != ADMIN_PASSWORD) {<br \/>\n\tHeader(&#8220;WWW-Authenticate: Basic realm=\\&#8221;APC Login\\&#8221;&#8221;);<br \/>\n\tHeader(&#8220;HTTP\/1.0 401 Unauthorized&#8221;);<\/p>\n<p>\techo <<<eob\n\t\t<html><body><\/p>\n<h1>Rejected!<\/h1>\n<p>\t\t<big>Wrong Username or Password!<\/big><br \/>&nbsp;<br \/>&nbsp;<br \/>\n\t\t<big><a href='$PHP_SELF?OB={$MYREQUEST['OB']}'>Continue&#8230;<\/a><\/big><br \/>\n\t\t<\/body><\/html><br \/>\nEOB;<br \/>\n\texit;<\/p>\n<p>} else {<br \/>\n\t$AUTHENTICATED=1;<br \/>\n}<br \/>\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re running APC with PHP, you have the option to download apc.php to view, monitor the usage\/stats. However, the default authentication is very open. Without any credential, anyone can view the running stats and also the cached filenames (a simple search on &#8220;APC INFO&#8221; will show some site running APC). The login is to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,18],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/207"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}