happypete Posted September 3, 2012 Share Posted September 3, 2012 Hi Experts, I'm designing the back-end of a CMS and not being a great programmer would like someone to test the script for vulnerabilities, in particular: image uploads + photo gallery in general availability calendar (the calendar isn't showing on the index.php page but can be viewed/updated by clicking the 'Edit Availbility Calendar' link WYSIWYG inputs Google Map URL: http://bit.ly/QfI6od Verification: http://bit.ly/SdI4Rr If you find any vulnerabilities then hinds on getting them sorted would be very much appreciated Thanks a lot, Pete Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/ Share on other sites More sharing options...
darkfreaks Posted September 4, 2012 Share Posted September 4, 2012 just so you know XSS me passed all of it's test on every page i scanned. however that means that tool did not find any known exploits (XSS) but i will continue to test and let you know. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1374990 Share on other sites More sharing options...
happypete Posted September 4, 2012 Author Share Posted September 4, 2012 thanks very much, I really appreciate you taking the time Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1375018 Share on other sites More sharing options...
darkfreaks Posted September 5, 2012 Share Posted September 5, 2012 CRLF injection/HTTP response splitting Vulnerability description This script is possibly vulnerable to CRLF injection attacks. HTTP headers have the structure "Key: Value", where each line is separated by the CRLF combination. If the user input is injected into the value section without properly escaping/removing CRLF characters it is possible to alter the HTTP headers structure. HTTP Response Splitting is a new application attack technique which enables various new attacks such as web cache poisoning, cross user defacement, hijacking pages with sensitive user information and cross-site scripting (XSS). The attacker sends a single HTTP request that forces the web server to form an output stream, which is then interpreted by the target as two HTTP responses instead of one response. Affected items /accounts/adminupdate.php /accounts/calendarupdate.php The impact of this vulnerability Is it possible for a remote attacker to inject custom HTTP headers. For example, an attacker can inject session cookies or HTML code. This may conduct to vulnerabilities like XSS (cross-site scripting) or session fixation. How to fix this vulnerability You need to restrict CR(0x13) and LF(0x10) from the user input or properly encode the output in order to prevent the injection of custom HTTP headers. [/color Links: Find & Fix CSRF what is CSRF? CSRF attacks & fixes HTTP Verb Tampering Vulnerability description By manipulating the HTTP verb it was possible to bypass the authorization on this directory. The scanner sent a request with POST HTTP verb and managed to bypass the authorization. An application is vulnerable to HTTP Verb tampering if the following conditions hold: it uses a security control that lists HTTP verbs the security control fails to block verbs that are not listed it has GET functionality that is not idempotent or will execute with an arbitrary HTTP verb For example, Apache with .htaccess is vulnerable if HTTP verbs are specified using the LIMIT keyword: <Limit GET> require valid-user </Limit> Affected items /accounts/ckeditor/ /accounts/ckeditor/skins/ /accounts/ckeditor/skins/kama/ /accounts/ckeditor/skins/kama/images/ /accounts/contact/ /accounts/contact/datepicker/ /accounts/contact/datepicker/calendar/ /accounts/contact/datepicker/calendar/ui/ /accounts/css/ /accounts/fancybox/ /accounts/js/ /accounts/media/ /css/ /images/ /media/ The impact of this vulnerability An attacker can bypass web authentication and authorization. How to fix this vulnerability In the case of Apache + .htaccess, don't use HTTP verb restrictions or use LimitExcept. Check references for more information on how to fix this problem on other platforms. Links: BYpassing VBAAC with HTTP verb Tampering Cross Site Scripting Vulnerability description This script is possibly vulnerable to Cross Site Scripting (XSS) attacks. Cross site scripting (also referred to as XSS) is a vulnerability that allows an attacker to send malicious code (usually in the form of Javascript) to another user. Because a browser cannot know if the script should be trusted or not, it will execute the script in the user context allowing the attacker to access any cookies or session tokens retained by the browser. Affected items /accounts/adminupdate.php The impact of this vulnerability Malicious users may inject JavaScript, VBScript, ActiveX, HTML or Flash into a vulnerable application to fool a user in order to gather data from them. An attacker can steal the session cookie and take over the account, impersonating the user. It is also possible to modify the content of the page presented to the user. How to fix this vulnerability Your script should filter metacharacters from user input with htmlspecialchars example: <?php $var = htmlspecialchars($var,ENT_QUOTES,'utf-8'); ?> or even better you could use the HTMLPURIFIER library to filter input. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1375391 Share on other sites More sharing options...
happypete Posted September 6, 2012 Author Share Posted September 6, 2012 thanks again, I appreciate the time you have taken to do this...now I have lots of homework! Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1375845 Share on other sites More sharing options...
darkfreaks Posted September 6, 2012 Share Posted September 6, 2012 tell me when you have applied a solution for these and i will retest it. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1375870 Share on other sites More sharing options...
happypete Posted September 7, 2012 Author Share Posted September 7, 2012 Hi darkfreaks, I have made some changes to my script and if you have time would really appreciate if you would check it for me again, Thanks, Pete Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376126 Share on other sites More sharing options...
Maq Posted September 7, 2012 Share Posted September 7, 2012 Just so you know, a lot of these tools are browser plugins. I know FF has XSS ME, SQL Inject me, Exploit me, and a few others for common vulnerabilities and security holes. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376146 Share on other sites More sharing options...
happypete Posted September 7, 2012 Author Share Posted September 7, 2012 Just so you know, a lot of these tools are browser plugins. I know FF has XSS ME, SQL Inject me, Exploit me, and a few others for common vulnerabilities and security holes. thanks, I've tired some of those, but didn't come up with the stuff darkfreaks pointed out Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376148 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 that is because it isn't a "browser" tool it is a paid for program. but yes there is XSS and SQL inject me. which both work for Mozilla firefox. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376170 Share on other sites More sharing options...
darkfreaks Posted September 8, 2012 Share Posted September 8, 2012 just so i am following the rules more thoroughly i am using Acunetix. it is a more detailed security analyzer program that analyzes both server and code exploits and gives you advice on how to best go about fixing them. much progress has been made here the XSS and CLRF exploits have been cleaned up and most of the CKeditor HTTPverb tampering but i still found exploits in one CKeditor /source folder. and much of the jquery /calendar/datepicker/ui folders. Still Vunerable to HTTP tampering: /accounts/assets/ /accounts/assets/images/ /accounts/ckeditor/_source/ /accounts/contact/datepicker/ /accounts/contact/datepicker/calendar/ /accounts/contact/datepicker/calendar/ui/ /accounts/inc/ /accounts/js/ /cgi-bin/ /inc/ Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376236 Share on other sites More sharing options...
happypete Posted September 8, 2012 Author Share Posted September 8, 2012 Thanks very much darkfreaks, I will sort those last folders and am really happy that my project is a little bit more secure Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376290 Share on other sites More sharing options...
Coreye Posted September 9, 2012 Share Posted September 9, 2012 Looks like someone found a vulnerability with the "amenities page". Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376376 Share on other sites More sharing options...
darkfreaks Posted September 9, 2012 Share Posted September 9, 2012 i would like to add the code i have for htmlspecialchars does not escape all types of Injection. also i would validate for data using ctype_alnum @ OP. example: if(ctype_alnum($var)) { //insert code here } this will make it so nothing other than letters and numbers goes into that text area. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376381 Share on other sites More sharing options...
darkfreaks Posted September 10, 2012 Share Posted September 10, 2012 http://lmgtfy.com/?q=htmlpurifier+validation+php might want to check into it Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1376836 Share on other sites More sharing options...
happypete Posted September 13, 2012 Author Share Posted September 13, 2012 if I use htmlpurifier should I use it on all text inputs or just the ones where a WYIWYG edit is used. If I use it on all inputs doesn't it use up a lot or server resources and slow things down? Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377524 Share on other sites More sharing options...
darkfreaks Posted September 13, 2012 Share Posted September 13, 2012 can you post the code inputs? so i can better help you come up with a solution Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377532 Share on other sites More sharing options...
happypete Posted September 13, 2012 Author Share Posted September 13, 2012 I'm using htmlpurifier on the WYSIWYG textarea and htmlspecialchars(stripslashes($_POST[$page1]), ENT_QUOTES, "UTF-8"), on the other text inputs. admin.php <?php // check user logged in include("assets/member.inc.php"); $member->LoggedIn(); $page = $_GET['page']; if ($page == 'home') { $page = 'home'; } elseif ($page == 'gallery') { $page = 'gallery'; } elseif ($page == 'features') { $page = 'features'; } elseif ($page == 'location') { $page = 'location'; } elseif ($page == 'rates') { $page = 'rates'; } elseif ($page == 'availability') { $page = 'availability'; } elseif ($page == 'contact') { $page = 'contact'; } elseif ($page == 'testimonials') { $page = 'testimonials'; } else { header('Location: index.php'); exit; } $page1 = $page.'title'; $page2 = $page.'text'; // Extract details from database $sql = "SELECT * FROM content WHERE siteid=".(int) $siteid.""; $stmt = $db->prepare($sql); $stmt->execute(); $e = $stmt->fetch(); ?> <!DOCTYPE html> <html lang="en"> <head> <?php include('inc/head.php'); ?> </head> <body> <div id="content"> <div class="editcontent"> <h1><?php echo ucfirst($page); ?> Page</h1> <form method="post" action="adminupdate.php?page=<?php echo $page ;?>" enctype="multipart/form-data"> <label><?php echo ucfirst($page); ?> Page Title <span>(max 90 characters)</span> <input type="text" name="<?php echo $page1; ?>" maxlength="90" value="<?php echo stripslashes($e[$page1]) ?>" class="large" /> </label> <label><?php echo ucfirst($page); ?> Page Content</label> <textarea name="<?php echo $page2; ?>" id="ckeditor"><?php echo htmlspecialchars(stripslashes($e[$page2])) ?></textarea> <p> </p> <div class="clear"></div> <input id="button" class="button" type="submit" name="submit" value="Save Changes" /> <input id="button" class="buttoncancel" type="submit" name="submit" value="Cancel / Return to site" /> <div id="spinner" class="spinner"><img id="img-spinner" src="../media/spinner.gif" alt="Loading"/></div> </form> </div><!--content--> </div><!--content--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script> <script type="text/javascript"> $(document).ready(function(){$('#button').click(function(){$('#spinner').show()})}); </script> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> <script type="text/javascript"> CKEDITOR.replace( 'ckeditor', { toolbar : [ ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker'], ['Undo','Redo'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink'], ['HorizontalRule','SpecialChar'], ['Format'],['Source'], ] }); </script> </body> </html> adminupdate.php <?php // check user logged in include("assets/member.inc.php"); $member->LoggedIn(); require ('htmlpure/HTMLPurifier.standalone.php'); // Get page name that need updating $page = $_GET['page']; if ($page == 'home') { $page = 'home'; } elseif ($page == 'gallery') { $page = 'gallery'; } elseif ($page == 'features') { $page = 'features'; } elseif ($page == 'location') { $page = 'location'; } elseif ($page == 'rates') { $page = 'rates'; } elseif ($page == 'availability') { $page = 'availability'; } elseif ($page == 'contact') { $page = 'contact'; } elseif ($page == 'testimonials') { $page = 'testimonials'; } else { header('Location: index.php'); exit; } $page1 = $page.'title'; $page2 = $page.'text'; // Check if coming from a POST command and Save Changes // Save header and text and email if($_SERVER['REQUEST_METHOD']=='POST' && $_POST['submit']=='Cancel / Return to site') { // cancel & return to admin page header('Location: index.php?success=5&page='.$page.'&#'.$page.''); exit; } // Check if coming from a POST command and Save Changes // Save header and text and email if($_SERVER['REQUEST_METHOD']=='POST' && $_POST['submit']=='Save Changes') { $config = HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', 'UTF-8'); $config->set('HTML.AllowedElements', 'p,b,strong,i,em,u,a,ol,ul,li,hr,blockquote,img,table,tr,td,th,span,object,param,embed'); $config->set('HTML.AllowedAttributes', 'a.href'); $purifier = new HTMLPurifier($config); $clean_html2 = $purifier->purify(stripslashes($_POST[$page2])); $sql = "UPDATE content SET $page1=?, $page2=? WHERE siteid=".(int) $siteid." LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute( array( htmlspecialchars(stripslashes($_POST[$page1]), ENT_QUOTES, "UTF-8"), $clean_html2, ) ); $stmt->closeCursor(); // once updated return to admin page header('Location: index.php?success=1&page='.$page.'&#'.$page.''); exit; } else { // If nothing happend send back to admin page header('Location: index.php?success=error&#=[$page]'); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377553 Share on other sites More sharing options...
darkfreaks Posted September 13, 2012 Share Posted September 13, 2012 you should purify all inputs. also delete coreye databse injection attempts i'll redo it the way he did. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377581 Share on other sites More sharing options...
happypete Posted September 13, 2012 Author Share Posted September 13, 2012 thanks. just getting some help on how to apply it to my photo gallery (http://forums.phpfreaks.com/index.php?topic=365133.0) them will upload it to the test site Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377598 Share on other sites More sharing options...
happypete Posted September 14, 2012 Author Share Posted September 14, 2012 I've updated the script and it available for some more testing if you are willing: URL: http://bit.ly/QfI6od Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377787 Share on other sites More sharing options...
darkfreaks Posted September 14, 2012 Share Posted September 14, 2012 tried manually inputting string it just stripped my attempts. i'll do some scanning overnight and get back to you. Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377791 Share on other sites More sharing options...
darkfreaks Posted September 14, 2012 Share Posted September 14, 2012 HTTP Verb Tampering: /accounts/contact/datepicker/ /accounts/contact/datepicker/calendar/ /accounts/contact/datepicker/calendar/ui /cgi-bin/ /images/ /inc/ /media/ http://lmgtfy.com/?q=prevent+HTTP+Tampering Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377804 Share on other sites More sharing options...
happypete Posted September 14, 2012 Author Share Posted September 14, 2012 Thanks again for testing. I've read about HTTP verb tampering but still not sure how to stop it. Originally I had this in the .htaccess file: # disable directory browsing Options All -Indexes but took it out as it didn't seem to do anything security wise FIX 1. Limit HTTP Verbs There are two ways how you can limit which HTTP Verbs should be handled by your server. Limit directive ? By using the limit Apache directive, you specify which HTTP verbs (methods) you want to allow. I need to allow GET, POST & DELETE (I have file uploads and deletes) so how do I restrict that without restricting legitimate users from using the software? 2. Always ask for Authentication The second method is to completely remove any type of HTTP method restrictions (Limit or LimitExcept) from access control and authorization rules, and adjust your .htaccess configuration to ALWAYS ask for authentication. Example of a .htaccess file follows: AuthUserFile C:\xampp\htdocs\Acuart\.htpasswd AuthName "Authorization Required" AuthType Basic require valid-user How to I relate this to a login script? Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377872 Share on other sites More sharing options...
darkfreaks Posted September 14, 2012 Share Posted September 14, 2012 Deny everything but GET POST DELETE: < LimitExcept GET POST DELETE > require valid-user < /LimitExcept > Link to comment https://forums.phpfreaks.com/topic/267947-cms-backend-test-for-vulnerabilities-and-security-problems/#findComment-1377910 Share on other sites More sharing options...
Recommended Posts