Wargame & CTF/HackCTF
[HackCTF / pwnable] Random Key
cg10036
2019. 10. 8. 07:24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | int __cdecl __noreturn main(int argc, const char **argv, const char **envp) { unsigned int v3; // eax int v4; // [rsp+0h] [rbp-10h] int v5; // [rsp+4h] [rbp-Ch] unsigned __int64 v6; // [rsp+8h] [rbp-8h] v6 = __readfsqword(0x28u); setbuf(_bss_start, 0LL); v4 = 0; v3 = time(0LL); srand(v3); v5 = rand(); puts("============================"); puts(asc_400948); puts("============================"); printf("Input Key : ", 0LL, *(_QWORD *)&v4, v6); __isoc99_scanf("%d", &v4); if ( v5 == v4 ) { puts("Correct!"); system("cat /home/random/flag"); exit(0); } puts("Nah..."); exit(0); } | cs |
srand로 시드값을 현재 시간으로 설정하고 rand로 랜덤값을 뽑는다.
시드값이 동일하면 rand값도 동일하다. 내 컴퓨터에서의 seed와 서버에서의 seed가 같게하면 된다.
프로그램이 거의 동시에 실행된다면 시간값이 같을것이고(1초 단위로 바뀌므로) 그러면 나오는 rand값도 같게 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | cg10036@cg10036-virtual-machine:~/hackCTF/Random_Key$ cat key.c #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(0)); printf("%d\n", rand()); } cg10036@cg10036-virtual-machine:~/hackCTF/Random_Key$ ./key | nc ctf.j0n9hyun.xyz 3014 ============================ ======= 인증 프로그램 ====== ============================ Input Key : Correct! HackCTF{5087686686858549173307745189} | cs |
Random Key : HackCTF{5087686686858549173307745189}