1. 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__);
?>
2. Condition
- GET ํ๋ผ๋ฏธํฐ id, pw๊ฐ์ด addslashesํจ์์ strrevํจ์๋ฅผ ๊ฑฐ์น๋ค.
3. Solution
๋ฌธ์ ์งํ์ ์ํด php ํจ์์ธ addslashes์ strrev์ ๋ํด ๊ฐ๋ตํ ์ค๋ช ํ๊ฒ ๋ค.
addslashes
๋ฏธ๋ฆฌ ์ ์๋ ๋ฌธ์(' " \ NULL) ์์ backslash๋ฅผ ๋ถ์ฌ, escaping ์ํค๋ ํจ์์ด๋ค.
์์๋ ์๋ ํ์ ๊ฐ๋ค.
input | output |
Hello world | Hello world |
'apple' | \'apple\' |
hihi%00 | hihi%5c%00 |
"utopia' | \"utopia\' |
strrev
์ ๋ ฅ๋ ๋ฌธ์์ด์ ๋ค์ง์ด์ฃผ๋ ํจ์์ด๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก ์์๋ ์๋ ํ์ ๊ฐ๋ค.
input | output |
Hello | olleH |
๋ค์ ์ ๋ฌธ์ ๋ก ๋์์์, ์ฐ๋ฆฌ๊ฐ ์ ๋ ฅํ ํ๋ผ๋ฏธํฐ๊ฐ addslashes → strrev ์์ผ๋ก ๊ฑฐ์น๊ฒ ๋๋ค.
๊ทธ๋ ๋ค๋ฉด, ๋๋ถ๋ถ์ backslash๊ฐ ์ค๊ฒ ํจ ์ผ๋ก์จ, ๊ธฐ์กด ์ฟผ๋ฆฌ ์ single quote๋ฅผ escaping ์ํฌ ์ ์๋ค.
select id from prob_zombie_assassin where id='{$_GET[id]}' and pw='{$_GET[pw]}'
select id from prob_zombie_assassin where id='\' and pw='{$_GET[pw]}'
4. Injection
์์ ๊ฐ์ ์ํฉ์ ๋ง๋๋ ค๋ฉด, id๊ฐ์ NULLํน์ "๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ์ฝ๊ฒ ํด๊ฒฐ๋๋ค.
addslashes ํจ์์ ๊ฑธ๋ฆฌ๋ ํน์ํ ๋ฌธ์์์ ๋ถ์ backslash๊ฐ strrevํจ์๋ฅผ ๊ฑฐ์ณ, ๊ฐ์ฅ ๋ค๋ก ๊ฐ๋ ๊ฒ์ด๋ค.
$_GET[id] | addslashes | strrev |
" | \" | "\ |
%00 | %5c%00 | %00%5c |
๋ค์์ผ๋ก pw๊ฐ์ or 1=1๊ณผ ๊ฐ์ ์ฟผ๋ฆฌ๊ฐ์ ๋ค์ง์ด ๋ฃ์ด์ฃผ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋ค.
๋ณ์๋ช | ๊ฐ |
id | " |
pw | %231=1 ro |
![](https://blog.kakaocdn.net/dn/dQCKPO/btspVNazamX/bIPVf3EVlneBJuVrOIoeIK/img.png)
'wargame ๐ดโโ ๏ธ write-up > Lord of SQLInjection' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
xavis (0) | 2023.08.03 |
---|---|
nightmare (0) | 2023.08.03 |
succubus (0) | 2023.08.01 |
assasin (0) | 2023.08.01 |