본문 바로가기
공부/정보보안

[Wargame.kr] login filtering 문제

by Skogkatt의 개인 블로그 2019. 9. 16.
반응형

login filtering 문제

2019.09.16 기준 134point 문제입니다.

 

I have accounts. but, it's blocked.
can you login bypass filtering?

 

소스 코드

더보기
php 부분
<?php
if (isset($_GET['view-source'])) {
    show_source(__FILE__);
    exit();
}

/*
create table user(
 idx int auto_increment primary key,
 id char(32),
 ps char(32)
);
*/

if (isset($_POST['id']) && isset($_POST['ps'])) {
    include("../lib.php"); # include for auth_code function.

    mysql_connect("localhost", "login_filtering", "login_filtering_pz");
    mysql_select_db("login_filtering");
    mysql_query("set names utf8");
    
    $key = auth_code("login filtering");
    
    $id = mysql_real_escape_string(trim($_POST['id']));
    $ps = mysql_real_escape_string(trim($_POST['ps']));
    $row = mysql_fetch_array(mysql_query("select * from user where id='$id' and ps=md5('$ps')"));

    if (isset($row['id'])) {
        if ($id == 'guest' || $id == 'blueh4g') {
            echo "your account is blocked";
        } else {
            echo "login ok" . "<br />";
            echo "Password : " . $key;
        }
    } else {
        echo "wrong..";
    }
}
?>
html 부분
<!DOCTYPE html>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    
    body {
        background-color: #ddd;
    }

    #mdiv {
        width: 200px;
        text-align: center;
        margin: 50px auto;
    }

    input[type=text],
    input[type=[password] {
        width: 100px;
    }

    td {
        text-align: center;
    }
</style>

<body>
    <form method="post" action="./">
        <div id="mdiv">
            <table>
                <tr>
                    <td>ID</td>
                    <td><input type="text" name="id" /></td>
                </tr>
                <tr>
                    <td>PW</td>
                    <td><input type="password" name="ps" /></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="login" /></td>
                </tr>
            </table>
            <div><a href='?view-source'>get source</a></div>
    </form>
    </div>
</body>
<!--

you have blocked accounts.

guest / guest
blueh4g / blueh4g1234ps

-->

 

해결 방법

my sql은 대소문자 구분을 하지 않지만

php는 대소문자 구분을 한다는 점을 이용합니다.

 

<!--

you have blocked accounts.

guest / guest
blueh4g / blueh4g1234ps

-->

html 소스 맨 아래, 주석처리 되어있는 부분이 계정에 대한 힌트입니다.

두 계정모두 block 되어있다고 쓰여 있으며, 실제로 로그인을 시도해보면 아래 사진과 같이 나오게 됩니다.

 

 

    $id = mysql_real_escape_string(trim($_POST['id']));
    $ps = mysql_real_escape_string(trim($_POST['ps']));

    $row = mysql_fetch_array(mysql_query("select * from user where id='$id' and ps=md5('$ps')"));

my sql의 mysql_fetch_array 부분에서는 guest/blueh4g가 들어오든, GueSt/ BlUeh4g가 들어오든
대소문자를 구분하지 않기 때문에
문제없이 데이터를 꺼내올 수 있습니다.

if (isset($row['id'])) {
    if ($id == 'guest' || $id == 'blueh4g') {
        echo "your account is blocked";
    } else {
        echo "login ok" . "<br />";
        echo "Password : " . $key;
    }
} else {
    echo "wrong..";
}

하지만 아래 if문으로 넘어오면,

대소문자가 섞인 ID(Guest, BlUeh4g)는 두 번째 if문에서 거짓이 되기 때문에

해당 if문을 스킵하게 됩니다.

 

즉, 주석에 달린 아이디 그대로 로그인 시도할 경우 2번 째 if문에 걸려 "your account is blocked" 문자열이 출력되지만,

대소문자가 섞인 ID로 로그인을 시도할 경우 해당 if문을 스킵할 수 있기 때문에 정상적으로 로그인됩니다.

 

반응형

'공부 > 정보보안' 카테고리의 다른 글

[DVWA] CSP Bypass  (0) 2019.11.25
[Wargame.kr] QR CODE PUZZLE 문제  (0) 2019.09.23
[Wargame.kr] flee button 문제  (0) 2019.09.10
암호 키(Encryption Key)  (0) 2019.08.30
해시 함수(Hash Function)  (0) 2019.08.20

댓글