/* randy (bin100) BKPctf We get x64 binary which ask for password after quick reversing, we can find that it have to be 0x1c long and its passed to function called `keygen` which determin what to print ':)' if ret == 0 or ';(' if not keygen is simply bunch (7) calls which looks like that: do_1: .text:0000000000400A2D mov rax, [r13+r12*4+0] .text:0000000000400A32 mov rdi, rax ; seed .text:0000000000400A35 call _srandom .text:0000000000400A3A call _random .text:0000000000400A3F cmp rax, 7358837Ah .text:0000000000400A45 jnz bad .text:0000000000400A4B call _random .text:0000000000400A50 cmp rax, 6E1B2658h .text:0000000000400A56 jnz bad .text:0000000000400A5C call _random .text:0000000000400A61 cmp rax, 3C00C5FFh .text:0000000000400A67 jnz bad .text:0000000000400A6D call _random .text:0000000000400A72 cmp rax, 8C0D4AAh .text:0000000000400A78 jnz bad .text:0000000000400A7E inc r12 the seed is taken from input, it split it on 7 4 byte numbers and do abowe since result of random is determistic and based od seed passed via srandom we reep of first 2 numbers to do some corretnes check and fire up brutforcer and after few minutes (or more;])we get our answer: n0t s0 r4nd0m0 4ft3r a11!!!! -- mak */ #include #include int ans[8] = {0,0,0,0,0,0,0,0}; int i=0; int foo(unsigned int *s,long int r1,long int r2,int n){ long r=0; srandom(*s); r += random() == r1; r += random() == r2; if(r==2) { printf("%d seed%d: %x %s\n", i,n, *s,(char*)s);fflush(stdout);ans[n]=*s; i++;return 1;} return 0; } void asdf(unsigned int x){ srandom(x); printf("%x\n",random()); printf("%x\n",random()); printf("%x\n",random()); printf("%x\n",random()); exit(0); } int main() { int c1,c2,c3,c4; char b[4]; for(c1=0x20;c1<0x7f;c1++){ for(c2=0x20;c2<0x7f;c2++){ for(c3=0x20;c3<0x7f;c3++){ for(c4=0x20;c4<0x7f;c4++){ b[0] = c1;b[1]=c2;b[2]=c3;b[3]=c4; if(i==7) { printf("%s\n",(char*)ans);fflush(stdout);exit(0);} if(foo((unsigned int*)b,0x7358837A,0x6E1B2658,0)) continue; if(foo((unsigned int*)b,0x34D8C3B5,0x5B56DCA1,1)) continue; if(foo((unsigned int*)b,0x1F49456C,0x27C0FA1D,2)) continue; if(foo((unsigned int*)b,0x1FEA6614,0x41CDB864,3)) continue; if(foo((unsigned int*)b,0x4E81ABC7,0x792CE075,4)) continue; if(foo((unsigned int*)b,0x683D3F5D,0x0CAAE38D,5)) continue; if(foo((unsigned int*)b,0x28c9a8fe,0x3324b23,6)) continue; } } } } puts("wrong!"); return 0; }