random

Posted by rk700 on November 16, 2014

代码如下

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

rand()并没有真的随机化,manpage里说

If no seed value is provided, the rand() function is automatically seeded with a value of 1.

是用gdb得到这个所谓的随机值,是0x6b8b4567,所以我们输入0x6b8b4567^0xdeadbeef=3039230856就行。