random
Daddy, teach me how to use random value in programming!
#include <stdio.h>
int main(){
unsigned int random;
random = rand(); // random value!
unsigned int key=0;
scanf("%d", &key);
if( (key ^ random) == 0xdeadbeef ){
printf("Good!\n");
system("/bin/cat flag");
return 0;
}
printf("Wrong, maybe you should try 2^32 cases.\n");
return 0;
}As we can see the program generates a pseudo-random number (it isn't exactly random because no seed has been set).
The it takes in a key from the user.
If the XOR of the key and random results in 0xdeadbeef, cat is called which prints out the flag.
Let's open the binary in gdb.
On disassembling main, we can see that it is calling rand.
We can set a break point at the instruction at <+18>.
The result of the rand call is stored in register $rax.
Now we know that the randomly generated value was 0x6b8b4567 which in binary is 01101011100010110100010101100111.
If we XOR it with 0xdeadbeef, which is 11011110101011011011111011101111 in binary, we should get our answer.
Last updated
Was this helpful?