|
|
| (14 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) |
| Zeile 1: |
Zeile 1: |
| =Vorüberlegung=
| | *[[Was ist eine SQL Injection]] |
| ==Verhaltensweise einer SQL Abfrage==
| | *[[SQL Injection Datenabfrage]] |
| ;Normale Abfrage
| | *[[SQL-Injection-Exploits]] |
| *MariaDB [sql_injections]> select * from users where username = 'rudi.burkart'; | | *[[SQL Injection - Übersicht]] |
| +------+--------------+----------+
| | *[[SQL Blind Injection]] |
| | id | username | password |
| | *[[Sql-Injection-Proof-of-Concept]] |
| +------+--------------+----------+
| |
| | 2 | rudi.burkart | secret |
| |
| +------+--------------+----------+
| |
| 1 row in set (0.000 sec)
| |
| ;Oder Verknüpfung
| |
| *MariaDB [sql_injections]> select * from users where username = 'rudi.burkart' or username = 'hans.will'; | |
| +------+--------------+----------+
| |
| | id | username | password |
| |
| +------+--------------+----------+
| |
| | 2 | rudi.burkart | secret |
| |
| | 1 | hans.will | geheim |
| |
| +------+--------------+----------+
| |
| 2 rows in set (0.000 sec)
| |
| =PHP Code=
| |
| ==Unsicher==
| |
| <pre>
| |
| $search = $_POST['search'];
| |
| $sql = "SELECT * FROM users WHERE username='$search'";
| |
| $result = mysqli_query($link, $sql);
| |
| </pre>
| |
| [[Datei:Sql-injection-2.png]] | |
| | |
| ==Sicher==
| |
| <pre>
| |
| $search = mysqli_real_escape_string($link, $_POST['search']);
| |
| $sql = "SELECT * FROM users WHERE username='$search'";
| |
| $result = mysqli_query($link, $sql);
| |
| </pre>
| |
| | |
| | |
| | |
| [[Datei:Sql-injection-1.png]] | |