Articles

Metasploit Framework Windows Tutorial
Remote Desktop Connection
Windows Processes That May Be Dangerous
How-To use NetCat a Tutorial
Common Linux Commands
Common Ports
Netcat Commands
HTTP Response Codes
War-Google Hack Terms
Wardriving
Avoiding Social Engineering and Phishing Attacks
Intrusion Detection on Linux
Linux Intrusion Detection
Penetration Testing Guide
Penetration Testing Tools
Social Engineering Fundamentals, Part I: Hacker Tactics
Social engineering (computer security)
The Psychology of Social Engineering

The Archives

General GSO
GovernmentSecurity.org News & Suggestions
In The News
Open Topic
General Security Information
Trash Can
Exploit & Vulnerability Mailing List Archives
Trial Member Forum
Product and Program Reviews GSO Tutorials
System Security
Windows Systems
Beginners Section
Linux & Unix Systems
File Downloads
Exploit Research & Discussion Trojan & Virus Errata
Networking Security / Firewall / IDS / VPN / Routers
System Hardening
E-Mail Security
Wifi Security
Trial Member Uploads
Upload discovered Trojans & Mal ware
GSO Programming Section
C , C++ , VC++
Visual Basic.NET
Perl /CGI
Java/Javascript
PHP/XML/ASP/HTML
Assembly + Other
The Cork Board
Network Security Consultant Directory
Network Security Jobs
The Archives
Encryption Information
General Network Security
Internet Anonymity
HTTP Protocol Security
Linux Security
MS IIS Information
Exploit Articles
Programming / Tool Design
GSO Software Projects
Public Downloads
Microsoft Security Questions and Papers

PiP
Can anyone see any problems in my php login script that would allow someone to use sql injection techniques to gain access ?

or any other problems for that matter (reguarding the method i use to store/verify the hash/password)?

$luser = username passed to the php page
$lpword = password passed to the php page

CODE

   $query ="SELECT name, password, type FROM user_accounts WHERE name='$luser'";
   $result = mysql_query($query, $link);
   if (!$result) {
      die('Invalid query: ' . mysql_error());
   }
   $num_rows = mysql_num_rows($result);
   if($num_rows > 0){
list($name, $password, $type) = mysql_fetch_row($result);

$salt = substr($password, 0, 11);
$thehash = substr($password, 11, (strlen($password)));

$testp = $salt;
$testp .= $lpword;
$testhash = sha1($testp);

if($testhash == $thehash && $name == $luser && $type != "G") {
 echo("Correct Password & Username, Logging you in now");
 echo "<script>document.location='verify.php?cookie=set&nme={$name}&pwrd={$thehash}'</script>";
}else{
 echo("Wrong Password or Username, or account has not yet been verified (check email).");
}
   }else{
 echo("Wrong Password or Username, or account has not yet been verified.");
   }
JonJon
i recommend using a function like htmlspecialchars
or htmlentites or addslashed on $luser, so no special chars would be added
x303
you could add this to verify:
CODE
if(!preg_match("/\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix",$text))
{
 do_something();
}
MrK
QUOTE(PiP @ May 26 2004, 03:53 AM)
Can anyone see any problems in my php login script that would allow someone to use sql injection techniques to gain access ?

[code]
    $query ="SELECT name, password, type FROM user_accounts WHERE name='$luser'";


Hi

Just for some background ... if you're not filtering $luser before passing it to the DB then yes, there are issues. By including an apostrophe in that string, that finishes the first set of quotes. Then arbitrary SQL can be included. Finally, we have to deal with the last quote, so mysql supports three different types of comments: the '#' character, the MS-SQL style '--' delimeter, and the C-style '/* and */'. So $luser could be something as trivial as

"foo'; drop database bar; --"

which will silently drop the db if privilege allows ... however, using different techniques, it may be possible to actually circumvent the login script, by causing an update statement to be run to set password to a known value for a given user, allowing a second attempt at running the script to authenticate. It all depends on DB permissions and if your algorithm is known ... but you probably already knew that smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.