[Security Lesson] Find the Vulnerability and Exploit :: 3

Learn about Security for code and servers. Learn how to secure your site and your code. Learn about hacking prevention, finding and identifying exploits, and recognising vulnerabilities. Plus, Weekly Security tips and Tutorials.
Forum rules
Post questions related to security, analyse and learn about vulnerabilities and exploits within code to protect yourself against hackers.

[Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Highway of Life » 17 Feb 2009, 23:51

As usual, please enclose your answers in the spoiler BBCode:
Code: Select all
[spoiler]your answers[/spoiler]


Find the vulnerabilities in this code and explain how they might be exploited, then explain how the coder could have protected his web application from these possible exploits.

admin/login.php
Code: Select all

$username 
SafeAddSlashes($_POST['username']);
$passcode SafeAddSlashes(md5($_POST['passcode']));
$time time();
$check SafeAddSlashes($_POST['setcookie']);

$query "SELECT user, pass FROM grestullogin WHERE user = '$username' AND pass = '$passcode'";

$result mysql_query($query$db);
if (
mysql_num_rows($result))
{
    
$_SESSION['loggedin'] = 1;
    if (
$check)
    {
        
setcookie("grestul[username]"$username$time 3600);
        
setcookie("grestul[passcode]"$passcode$time 3600);
    }


admin/index.php
Code: Select all
if (isset($_COOKIE['grestul']))
{

    include 
'inc/config.php';

    
$username $_COOKIE['grestul']['username'];
    
$passcode $_COOKIE['grestul']['passcode'];

    
$query "SELECT user, pass FROM grestullogin WHERE user = '$username' AND pass = '$passcode'";
    
$result mysql_query($query$db);
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Obsidian » 19 Feb 2009, 12:12

Can we safely assume SafeAddSlashes(); proofs against SQL inject via $_POST?
うるさいうるさいうるさい!

StopForumSpam Spam Reporting Database
Giving xrumer and friends a great big "screw you" since 2007.
User avatar
Obsidian    
Supporter
Supporter
 
Posts: 2250
Joined: 04 Mar 2008, 23:35
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Mr_Bond » 19 Feb 2009, 14:26

Was wondering the same thing, probably a wrapper of some sort for addslashes() if I had to guess... :scratch:
User avatar
Mr_Bond    
Lieutenant
Lieutenant
 
Posts: 246
Joined: 14 Feb 2008, 14:45
Location: localhost
Favorite Team: Chicago Bears
Gender: Male
phpBB Knowledge: 7

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Highway of Life » 19 Feb 2009, 22:07

Mr_Bond wrote:Was wondering the same thing, probably a wrapper of some sort for addslashes() if I had to guess... :scratch:

Yes, follow that assumption.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Obsidian » 20 Feb 2009, 10:21

Oooh, think I found the exploit/vulnerability.

Spoiler:
Code: Select all
if (isset($_COOKIE['grestul']))
{

    include 'inc/config.php';

    $username = $_COOKIE['grestul']['username'];
    $passcode = $_COOKIE['grestul']['passcode'];

    $query = "SELECT user, pass FROM grestullogin WHERE user = '$username' AND pass = '$passcode'";
    $result = mysql_query($query, $db); 


Simply by falsifying the cookie, and tossing an inject into the username field for $_COOKIE['grustul'], you could do some real damage. ;)
うるさいうるさいうるさい!

StopForumSpam Spam Reporting Database
Giving xrumer and friends a great big "screw you" since 2007.
User avatar
Obsidian    
Supporter
Supporter
 
Posts: 2250
Joined: 04 Mar 2008, 23:35
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby 3Di » 20 Feb 2009, 14:09

Spoiler:
sTraTo wrote:Simply by falsifying the cookie, and tossing an inject into the username field for $_COOKIE['grustul'], you could do some real damage. ;)

I think can be exploited using
' OR 1=1 #

instead of the username, that # tells to the MySql to ignore everything that follows being itself a comment. If that query executes that way, being 1 = 1 it returns all nicknames and PWs from the DB.. I guess. that sholud look like this..
Code: Select all
$query = "SELECT user, pass FROM grestullogin WHERE user = ' OR 1=1 # AND pass = '$passcode'";
Last edited by Handyman on 20 Feb 2009, 15:04, edited 1 time in total.
Reason: spoilerized per the rules of the topic.
Give Peace A Chance.. Pass ON It!
Image
The door that leads to the Glory is very narrow but it is mandatory to be Great to be able to cross it.
------------------------- phpBB wiki in Italiano - partecipa con il tuo contributo -----------------------
User avatar
3Di    
MOD Author
MOD Author
 
Posts: 249
Joined: 22 Apr 2008, 14:09
Location: Italy
Favorite Team: Milan
Gender: Male
phpBB Knowledge: 8

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby Highway of Life » 20 Feb 2009, 16:47

Please use a spoiler if you provide an answer (3Di). :)
sTraTo, you are on the right track, now can you provide a working example of how one might exploit it?
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby chaoskreator » 01 Mar 2009, 14:37

Spoiler:
Shouldn't the author have md5'ed the password in the database, and then the user inputted when checking?


[ Post made via Mobile Device ] Image
User avatar
chaoskreator    
Commander
Commander
 
Posts: 716
Joined: 02 Feb 2009, 22:05
Location: NC
Gender: Male
phpBB Knowledge: 7

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby eviL3 » 01 Apr 2009, 10:10

chaoskreator wrote:Shouldn't the author have md5'ed the password in the database, and then the user inputted when checking?

Assume that the value stored in the database is MD5'd (like phpBB2).
Image
User avatar
eviL3    
MOD Author
MOD Author
 
Posts: 1002
Joined: 05 Nov 2006, 08:14
Location: Cooking in the MODs kitchen
Gender: Male

Re: [Security Lesson] Find the Vulnerability and Exploit :: 3

Postby mtotheikle » 19 Apr 2009, 14:10

Not though just a plain MD5 will not protect passwords that great. The author should also at least salt the MD5.
"You have a lifetime to learn technique. But I can teach you what is more important than technique: How to see. Learn that and all you have to do afterwards is press the shutter." - Garry Winogrand

I have turned into a Military Sergeant and Highway of Life and Handyman are my newest privates under my command. Don't be scared anyone, this is all for your good!

Image
User avatar
mtotheikle    
Supporter
Supporter
 
Posts: 1054
Joined: 10 Oct 2007, 22:43
Location: Washington
Favorite Team: Seahawks
Gender: Male
phpBB Knowledge: 10

Next

Return to Security Class

Who is online

Users browsing this forum: Magpie Crawler and 1 guest

cron