모의해킹/Wargame
[Lord of SQL Injection] dragon 20번 (feat. 개행? )
klus!
2023. 1. 12. 17:16
1. 전체 코드
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_dragon where id='guest'# and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
if($result['id'] == 'admin') solve("dragon");
highlight_file(__FILE__);
?>
2. 주요 코드 분석
$query = "select id from prob_dragon where id='guest'# and pw='{$_GET[pw]}'";
preg_match함수를 통해 필터링되는 부분은 대부분 이전 문제와 비슷하고 query문을 보면 기존과 다르다는 것을 알 수 있다.
3. Solve
이번 문제의 경우 query에서 select를 보면 id뒤에 #(주석처리)가 되어 있다는 것을 볼 수 있다.
그리고 Solve조건은? id값만 admin일 경우 풀이가 가능하다
===> hello guest에서 admin으로 변경만 해주면 된다.
#뒤에 문자을 마무리 짓고 and를 사용하여 다시 연결한다면 가능할 것 같다.
즉, 쿼리문을 select id from prob_dragon where id=iguest'# and pw='이라고 된 부분을 마무리하고 and 구문을 넣어
문장을 연결하였다. 개행(%0a)을 통해 문장을 완료