random
{"author": ["ret2basic"]}

Source Code

1
#include <stdio.h>
2
3
int main(){
4
unsigned int random;
5
random = rand(); // random value!
6
7
unsigned int key=0;
8
scanf("%d", &key);
9
10
if( (key ^ random) == 0xdeadbeef ){
11
printf("Good!\n");
12
system("/bin/cat flag");
13
return 0;
14
}
15
16
printf("Wrong, maybe you should try 2^32 cases.\n");
17
return 0;
18
}
Copied!

Solution

Check out the rand(3) man page. It says "if no seed value is provided, the rand() function is automatically seeded with a value of 1". That means a seedless rand() is deterministic. We can run the following code to test our hypothesis:
1
#include <stdio.h>
2
3
int main()
4
{
5
int random = rand();
6
printf("%i", random);
7
8
return 0;
9
}
Copied!
The result is always 1804289383 no matter how many times we run this program. To find the key:
1
>>> 0xdeadbeef ^ 1804289383
2
3039230856
Copied!

Get Flag

Get flag
Last modified 5mo ago