php? c? view-source code
do you know "integer type" of 32bit application?
<?php
if (isset($_GET['view-source'])) {
show_source(__FILE__);
exit();
}
require("../lib.php"); // include for auth_code function.
if(isset($_POST['d1']) && isset($_POST['d2'])){
$input1=(int)$_POST['d1'];
$input2=(int)$_POST['d2'];
if(!is_file("/tmp/p7")){exec("gcc -o /tmp/p7 ./p7.c");}
$result=exec("/tmp/p7 ".$input1);
if($result!=1 && $result==$input2){echo auth_code("php? c?");}else{echo "try again!";}
}else{echo ":p";}
?>
#include <stdio.h>
#include <stdlib.h>
void nono();
int main(int argc,char **argv){
int i;
if(argc!=2){nono();}
i=atoi(argv[1]);
if(i<0){nono();}
i=i+5;
if(i>4){nono();}
if(i<5){printf("%d",i);}
return 0;
}
void nono(){
printf("%d",1);
exit(1);
}
php쪽 코드는, d1에 입력된 값을 C의 argv[1]로 넘기는 역할을 하고 출력되는 값을 맞추면 flag를 출력한다.
C는 입력받은 값에 5를 더하여 출력하는데..
이 문제는 오버플로우, 언더플로우 개념을 알고 있으면 쉽게 풀 수 있다.
설명은 다른 사이트에도 많기 때문에, 사진 하나로 보여주겠다.
당연하게도 5를 더하여 나온 출력값을 예상할 수 있겠지요..?
'Wargame > wargame.kr' 카테고리의 다른 글
[Wargame.kr] pyc decompile 풀이 (354p) (0) | 2020.07.29 |
---|---|
[Wargame.kr] web chatting 풀이 (341p) (0) | 2020.07.29 |
[Wargame.kr] img recovery 풀이 (288p) (0) | 2020.07.29 |
[Wargame.kr] type confusion 풀이 (282p) (0) | 2020.07.29 |
[Wargame.kr] tmitter 풀이 (266p) (0) | 2020.07.29 |