LOS #03 goblin
Lord of SQLInjection
los.rubiya.kr
Source code
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~");
if(preg_match('/\'|\"|\`/i', $_GET[no])) exit("No Quotes ~_~");
$query = "select id from prob_goblin where id='guest' and no={$_GET[no]}";
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>";
if($result['id'] == 'admin') solve("goblin");
highlight_file(__FILE__);
?>
Query
select id from prob_goblin where id='guest' and no=
Write-up

위 사진에서 확인할 수 있는 정보는 다음과 같다.
-
파라미터는 no 1개가 사용될 수 있다.
-
no 값에 ', ", ` quotes 필터링을 하고 있다.
-
"admin" id 값을 요구하고 있다.
-
"guest" id의 no 값은 1이므로, "admin" id의 no 값은 0 또는 2일 것 같다.
', ", ` quotes 필터링을 하고 있으므로 mysql의 내장 함수인 char() 함수로 id 파라미터에 "admin"을 전달하면 된다.
* char() 함수는 ASCII Table에 따라 입력한 숫자에 매칭되는 문자로 변환해준다.
ASCII Table
ASCII Table ASCII (which stands for American Standard Code for Information Interchange) is a character encoding standard for text files in computers and other devices. ASCII is a subset of Unicode and is made up of 128 symbols in the character set. These s
www.techonthenet.com

char() 함수로 "admin" 값을 전달했지만 "Hello guest" 문구가 출력된다.
select query를 통해 "guest", "admin" id 값을 모두 가져오고 있는데, "guest" id 값에 해당하는 데이터가 "admin" 값에 해당하는 데이터보다 먼저 반환되기 때문이다.

예를 들면 위와 같다. 반환되는 값들 중 "admin" id 값만 반환하려면 limit을 사용하면 된다.

위와 같이 limit은 [start row], [return count]를 전달해서 사용할 수 있다.
Parameter
no=1 or id=char(97,100,109,105,110) limit 1,1
"limit 1,1"을 입력함으로써 두 번째 id 값인 "admin"을 가져온다. 쿼리문은 다음과 같다.
select id from prob_goblin where id='guest' and no=1 or id=char(97,100,109,105,110) limit 1,1
Success

'Wargame > LOS' 카테고리의 다른 글
| LOS #06 darkelf (0) | 2020.10.28 |
|---|---|
| LOS #05 wolfman (0) | 2020.10.28 |
| LOS #04 orc (0) | 2020.10.28 |
| LOS #02 cobolt (0) | 2020.10.28 |
| LOS #01 gremlin (0) | 2020.10.28 |