문제 코드
<?php
include "./config.php";
login_chk();
$db = sqlite_open("./db/manticore.db");
$_GET['id'] = addslashes($_GET['id']);
$_GET['pw'] = addslashes($_GET['pw']);
$query = "select id from member where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = sqlite_fetch_array(sqlite_query($db,$query));
if($result['id'] == "admin") solve("manticore");
highlight_file(__FILE__);
?>
공격 백터
- id
- pw
공격 백터에 대한 검증
- id, pw : addslashes 함수
코드 분석
$db = sqlite_open("./db/manticore.db");
이젠 Mysql에서 SQLite로 넘어간 듯 싶다.
$query = "select id from member where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = sqlite_fetch_array(sqlite_query($db,$query));
if($result['id'] == "admin") solve("manticore");
이번 문제도 쿼리문이 select id from member where id='{$_GET[id]}' and pw='{$_GET[pw]}'
이다.
이제 SQLite 구문으로 addslashes 함수를 우회하여 쿼리문의 반환 값이 admin이 나오도록 하면 문제가 클리어된다.
문제 풀이
SQLite는 \'
은 \
가 문자가 되고, '
은 이스케이프가 된다. 즉, \’
을 하나의 문자열로 보기를 않는다.
그래서 Error가 발생되지 않고, 페이지가 잘 나오는 것을 알 수 있다.
Mysql은 \’
의 '
을 문자열로 보기 때문에 Error가 발생된다.
SQLite은 Hex 값을 이용하는 것은 불가능하였다.
Char 함수를 이용하여 간단하게 '
을 사용하지 않고, admin을 조회하였다.
'워게임 > Lord of SQLInjection' 카테고리의 다른 글
[Lord of SQLInjection] Poltergeist Write UP (0) | 2021.09.15 |
---|---|
[Lord of SQLInjection] banshee Write UP (0) | 2021.09.14 |
[Lord of SQLInjection] Chupacabra Write UP (0) | 2021.09.13 |
[Lord of SQLInjection] Cyclops Write UP (0) | 2021.09.12 |
[Lord of SQLInjection] Godzilla Write UP (0) | 2021.09.12 |