I'm trying out SQL Injection on my localhost. I have a simple HTML form, with a username, password and a submit button. So after clicking on the submit, user is redirected from login.html
to a page called login.php
:
<form method="post" action="login.php">
Below is a snipped of my PHP code:
$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to '$dbhost'");
mysqli_select_db($connect,$dbname) or die("Could not open the database '$dbname'");
$message="";
$username = $_POST["uname"];
$pass_raw = $_POST["password"];
$password = md5($pass_raw);
$result = mysqli_query($connect,"SELECT * FROM students WHERE uname='" . $username . "' and password = '". $password."'");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
echo "Congratulations! you have logged in!";
printf("Your First Name %s and Last Name is %s", $row[3], $row[4]);
printf("Your SSN is %s ", $row[5]);
} else {
$message = "Invalid Username or Password!";
echo "invalid user ";
}
I'm able to login to the if I enter the right user and password. I'm trying to perform SQL Injection, but I'm unable to. I have tried using ' or ''='
but I'm still not able to login. I'm trying this out in Kali, which comes pre-installed with MariaDB.