@@ -28,10 +27,8 @@ So we have a website that is written in php. We have a login functionality, wher
$password=$_POST['password'];
$query="SELECT * FROM users WHERE username = '$username' AND password='$password'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
}
?>
```
So the user input is not filtered or sanitized in any way. Which means that what the users puts in in the login-form will be executed my mysql. So just like in xss-injections we just try to escape the input field to be able to execute sql-commands. So if we input the following into the user-field and password-field in the login:
@@ -42,6 +39,7 @@ whatever' or '1'='1
```
The query will look like this:
```
$query = "SELECT * FROM users WHERE username = 'whatever' OR '1'='1' AND password='whatever' OR '1'='1'";
```
@@ -58,11 +56,11 @@ $query = "SELECT * FROM users WHERE username = 'admin' AND password='whatever' O
So first we should try to break the sql-syntaxt by adding a **'**.
We should first ad a **'** or a **"**.
So first we should try to break the sql-syntaxt by adding a `'`.
We should first ad a `'` or a `"`.
```
http://example.com/photoalbum.php?id=1'
@@ -289,14 +283,13 @@ Two things are needed for it to work:
- If the username column in the database has a character-limit the rest of the characters are truncated, that is removed. So if the database has a column-limit of 20 characters and we input a string with 21 characters the last 1 character will be removed.
With this information we can create a new admin-user and have our own password set to it. So if the max-length is 20 characters we can inser teh following string
With this information we can create a new admin-user and have our own password set to it. So if the max-length is 20 characters we can insert the following string
```
admin removed
```
This means that the "removed" part will be removed/truncated/deleted. And the trailing spaces will be removed upon insert in the database. So it will effectivly be inserted as "admin".
This means that the "removed" part will be removed/truncated/deleted. And the trailing spaces will be removed upon insert in the database. So it will effectively be inserted as "admin".