'2019/09/02'에 해당되는 글 2건

인풋을 통해 생성된 값이랑 임의의 값을 비교한다. 이 때 두 값이 같아야 한다. 인풋을 통해 생성된 값은 인풋*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

메모 기록용 공간

,