문제를 풀어보자!!
[코드 분석]
main
int main(int argc, char* argv[]){
if(argc<2){
printf("usage : %s [passcode]\n", argv[0]);
return 0;
}
if(strlen(argv[1]) != 20){
printf("passcode length should be 20 bytes\n");
return 0;
}
if(hashcode == check_password( argv[1] )){
system("/bin/cat flag");
return 0;
}
else
printf("wrong passcode.\n");
return 0;
}
1. argv[1]에 입력된 값이 20byte를 넘어서는 안된다.
2. check_password에서 입력한 password를 검사하고, 검사한 password가 hashcode와 같다면 flag를 읽을 수 있다.
check_password
unsigned long check_password(const char* p){
int* ip = (int*)p;
int i;
int res=0;
for(i=0; i<5; i++){
res += ip[i];
}
return res;
}
1. p[0] ~ p[4]까지의 입력 값을 더한 후 return 한다.
즉, hashcode를 5로 나눠서 인자로 보내면, flag를 얻을 수 있다.
[EXPLIT]
1.hashcode값을 5로 나눠서 입력 값을 구하자.
hashcode = 0x21DD09EC
5로 나눴더니 나머지가 4가 나왔다.
payload = "\xc8\xce\xc5\x06" * 4 + "\xcc\xce\xc5\x06"
2.exploit
'포너블 > pwnable.kr' 카테고리의 다른 글
[Pwnable.kr] 1. fd (0) | 2024.04.21 |
---|---|
[pwnable.kr] shellshock (0) | 2020.03.09 |
[pwnable.kr] mistake (0) | 2020.03.09 |
[pwnable.kr] leg (0) | 2020.03.09 |
[pwnable.kr] input2 (0) | 2020.02.27 |