今天突然在想,用time(0)当随机数种子真的安全吗?
于是有了今天的小测试
docker端程序
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 
 | #include <stdio.h>#include <stdlib.h>
 #include<time.h>
 int main()
 {
 srand(time(0));
 int guess;
 int randm=rand()%1000000;
 scanf("%d",&guess);
 if(guess==randm)
 {
 system("/bin/sh");
 }
 else
 {
 printf("rand:%d",randm);
 }
 
 }
 
 
 
 | 
我的exp(第一部分c语言)
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | #include <stdio.h>#include <stdlib.h>
 #include<time.h>
 int main()
 {
 srand(time(0)+10);//提前十秒
 int randm=rand()%1000000;
 printf("rand:%d\n",randm);
 
 }
 
 | 
第二部分(python)
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | from pwn import *context.log_level='debug'
 context(os = 'linux', arch = 'amd64')
 exp = process('./exp')
 rand=exp.recvline()[5:]
 
 for i in range(12):
 p = process('./time')
 p.send(rand)
 p.interactive()
 
 | 
最后很轻易地通了,time(0)是一秒一变,而srand(time(0))又和电脑没关系,所以可以轻易地得到几秒以后的随机数,然后爆破,等他。