strrev()는 문자열 뒤집는 함수<?php
include "./config.php";
login_chk();
$db = dbconnect();
$_GET['id'] = strrev(addslashes($_GET['id']));
$_GET['pw'] = strrev(addslashes($_GET['pw']));
if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~");
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_zombie_assassin 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']) solve("zombie_assassin");
highlight_file(__FILE__);
?>
소스 코드를 해석하면 get 방식으로 받은 id, pw에 addslash()를 하고 strrev()로 문자열을 뒤집는다.
이 방식에는 큰 허점이 존재하는 데 이를 이용하여 문제를 해결할 것이다.
id에 "를 입력하면 addslash() 함수를 지나며 \"이 된다. 그리고 최종적으로 strrev() 함수를 지나면서 id는 최종적으로 "\가 된다. 이때 전체 쿼리문을 적어보면 select id from prob_zombie_assassin where id='"\' and pw='' 이다. 이러면 저번 문제처럼 pw에 인젝션 공격이 가능하게 된다.