희디 2022. 6. 24. 05:21

진입 비번 : Lg96M10TdfaPyVBkJdjymbllQ5L6qdl1

 

문제화면이다.

 

아무 id와 pw를 입력하니까 아래와 같이 나온다. 

 

소스코드를 확인해보자. 

<?
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>

 

username과 password를 조작할 수 있는 query문이다.

username이 참이고 뒤를 모두 주석처리하면 무조건 로그인이 될 것이다. 

 

$query = "SELECT * from users where username=\"".$_REQUEST["username"]."\" and password=\"".$_REQUEST["password"]."\"";
   

 

그래서 username에  무조건 참을 만들어주는 구문 " or 1=1#을 입력해주면 비밀번호를 알려주는 창이 뜬다. 

 

AwWj0w5cvxrZiONgZ9J5stNVkmxdk39J