I have set up a page and database so I can practice SQL injection. Ive tried some examples and it doesn't seem to work. It seems to add the username and password to that database, even though I input an Injection in the username field. Here is my code:
include "Connection.php";
<form method="post" action="sqltest.php">
<fieldset>
<label for="username">Username: </label>
<input type="text" name="username"/>
<label for="passwd">Password: </label>
<input type="password" name="passwd"/>
</br>
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</fieldset>
</form>
</div>
</div>
$username = $_POST["username"];
$password = $_POST["passwd"];
if (!empty($_POST)){
if (empty($username) || !isset($username)) {
echo "Please enter a valid username";
} else if (empty($password) || !isset($password)) {
echo "Please enter a valid password";
} else {
if (strlen($password) >= 6 && strlen($password) <= 8)
{
if (is_numeric($password))
{
echo "Password cannot be a number<br/>";
}
else{
$encrypted_mypassword=md5($password);
$query = "INSERT INTO sqltest (name,password) VALUES ('$username', '$password')";
$result = mysqli_query($connection,$query);
echo "You have successfully registered";
}
}
else {
echo "Password must be between 6 and 8 characters in length<br/>";
}
}
}
Can anyone tell me some examples that would drop the table, or insert a user? I just realized that its automatically escaping characters. Surely this doesn't prevent all SQL injection. Is there anything i can inject that will overcome this? Thanks!