Hack/Pwnable

[Pwnable.kr] 문제풀이(collision)

CIDY 2022. 8. 12. 02:55

 

#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
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;
}

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;
}

이것도 인자로 적당한 값을 넣어주면 되는 문제이다.

 

인자는 20바이트여야 하며, 4바이트씩 끊어 더했을 때 해시코드의 값이 나와야 한다.

\xc8\xce\xc5\x06 를 4번,\xcc\xce\xc5\x06를 한 번 해주면 될 것이다.

 

ssh로 접속해 python버전을 확인해보니 2.27이라 아래와 같이 인자를 전달해주었다.

 

flag