Jump to content

Recommended Posts

So here's the deal. I've created a very basic web application in order to show the effects of SQL injections.

 

I plugged ' or 1=1-- into the username field, left the password blank and got the following

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1

in SELECT * FROM USERS WHERE Username='' or 1=1--'

 

<?php 
session_name("MyLogin");
session_start();

if($_GET['action'] == "login") {
$conn = mysql_connect("localhost", "root", "");
$db = mysql_select_db("test");
$name = $_POST['uname'];
$sql = "SELECT * FROM USERS WHERE Username='$name'";
$q_user = mysql_query($sql) or die(mysql_error() . ' <br /> in ' . $sql);

if(mysql_num_rows($q_user) == 1){

$data = mysql_fetch_array($q_user);
if($_POST['pword'] == $data['Password']){
header("Location: login_success.php");	
exit;
}else{
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
}else{
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}
if(session_is_registered("name") == false) {
header("Location: login.php");
}	
?>

Link to comment
https://forums.phpfreaks.com/topic/230943-syntax-error/
Share on other sites

I need to somehow get rid of that final '

 

I know that because when I put SELECT * FROM USERS WHERE Username='' or 1=1--' into phpMyAdmin, it returns the full user table.

 

Now, I was under the impression that putting -- allowed MySQL to ignore anything after it. (ie the final ')

 

Link to comment
https://forums.phpfreaks.com/topic/230943-syntax-error/#findComment-1188819
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.