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";}
?>
d1과 d2는 반드시 필요한데, 강제로 int로 형변환을 하고 있다.
전혀 감 잡히는 바가 없기때문에 int 취약점에 대해서 검색해봤는데, 첨에 생각한건 32bit 라면 int가 2147483647 이상 올라가지 않아서 오버플로우 될것이라고 생각했다. 그래서 자릿수를 높여서 적어봤는데 되진 않았다.
이 경로에 p7.c가 있다니 접근해보니 소스를 얻을 수 있었다
#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);
}
컴파일해보았다. 그 이후 오버플로우가 발생하도록 int의 최대자리를 넣어보았다.
gcc p7.c ./a.out 2147483647
그러자 띠용.. 생각도 못한 값이 나왔다. 야매로 하다간 밤샐뻔했다. 나오는 숫자를 보내주면 키가 반환된다.