schilly Posted February 5, 2008 Share Posted February 5, 2008 Hi Everyone, Hoping you can help. I've been using session authentication for a while on a few small sites without any problems up until now. I have recently been getting some html injections into a form that only members can view thought session authentication. I set up a log on the login page and compromised form to see if they were gaining access through the login form then injecting into the other form but the entries didn't match up so I assume they are bypassing my authentication script for that form. Here is my authentication script which is called at the start of every member only page: function memberAuth(){ session_start(); if($_SESSION['MEMBER'] !== "YES"){ session_destroy(); header("Location: memberLogin.php"); } } Is there any easy way to bypass this? I've used this for a while and never ran into any problems before. If you need any additional info, please let me know. Thx. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/ Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 change this: if($_SESSION['MEMBER'] !== "YES") to this: if($_SESSION['MEMBER'] != "YES") And see if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458391 Share on other sites More sharing options...
Aureole Posted February 5, 2008 Share Posted February 5, 2008 In case you don't understand the difference between != and !== <?php // In PHP, both of these mean true... $a = true; $b = 1; // Both $a and $b are true, but !== also checks to see if they are of the same type, $a is a boolean and $b is an integer. if( $a !== $b ) echo( 'false' ); // Will return false. ?> Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458395 Share on other sites More sharing options...
gizmola Posted February 5, 2008 Share Posted February 5, 2008 Did you consider session fixation? What's important is what you're doing in memberLogin.php. This topic is discussed in many places, including an article that they've linked to on the php.net page for sessions, and there's also this article that's php specific by Chris Shifflet. http://shiflett.org/articles/session-fixation Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458415 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 Thanks for the feedback. I recently changed to '!=='. Before I was using strcmp. Reading up on session fixation now. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458426 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 Interesting article. I will start using session_regenerate_id(); when I set my session variables and see if that makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458429 Share on other sites More sharing options...
PFMaBiSmAd Posted February 5, 2008 Share Posted February 5, 2008 What does your code do after it calls that function? The header() redirect is performed by the browser. If your code just continues execution and the browser (or a script that could care less about headers your code sends out) does not redirect, then they will access the protected content on the page. You must execute an exit; statement at some point after the header() statement to stop the code on the rest of the page from executing. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458532 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 There is no code after the redirect, it just loads up the form page. So if they aren't using a browser or have some modded browser that doesn't recognize the header cmd then it will just send them my form and they can post to it? Will exit; stop the html afterwards from loading? Thx. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-458725 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 Sry bump. Anyone know about this? Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459067 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 Put an exit after your header call <?php function memberAuth(){ session_start(); if($_SESSION['MEMBER'] !== "YES"){ session_destroy(); header("Location: memberLogin.php"); exit; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459075 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 Ok so essentially custom requests to web servers can essentially bypass the header cmd and view any code after that? Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459083 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 i *think* so Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459089 Share on other sites More sharing options...
schilly Posted February 5, 2008 Author Share Posted February 5, 2008 Awesome thanks. I didn't really think about being able to bypass the header cmd. I'm guessing this is the problem. I will update tonight and see how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459099 Share on other sites More sharing options...
rhodesa Posted February 5, 2008 Share Posted February 5, 2008 My rule of thumb: Always have an exit after a header('Location: file.php'); command Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-459102 Share on other sites More sharing options...
schilly Posted February 7, 2008 Author Share Posted February 7, 2008 Looks like it fixed the problem. No spam in over a day now. Thanks everyone. Quote Link to comment https://forums.phpfreaks.com/topic/89494-solved-form-injection-problems/#findComment-460930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.