镇江市网站建设_网站建设公司_会员系统_seo优化
2026/1/18 15:49:12 网站建设 项目流程

伪随机数

在二进制分析中,会遇到很多很多伪随机数生成的问题,对于伪随机数,我们需要进行绕过,这里系统的总结一下伪随机数的绕过的思路

我们使用random直接进行随机数生成的话效果是不对的

random.seed()
rand_num = random_randint(a,b)
decrypted = (rand_num ^ enc[i])

对于这种情况,我们可以使用cyptes库进行生成

这里windows中的加载的是msvcrt.dll这个库

libc = ctypes.CDLL("msvcrt.dll")
libc.srand()
rand_num = libc.rand()
decrypted = (rand_num ^ enc[i])

伪随机有以当前的时间戳为种子,也有直接以准确的数字为种子,一般有这两种形式

python写的脚本

常规的这样写就行了

libc库的加载方式以2.23为分界线,相邻版本的种子生成的区别并不是很大

import ctypes
elf1 = ctypes.CDLL("./libc-2.27.so")
#多了一步前提的条件准备str
elf1.srand(ctypes.c_uint(int(time.time())))#ctypes.c_uint(int(time.time()))
for i in range(100):rand_num = elf1.rand()%100000 + 1#print(f"Random number: {rand_num}")sl(str(rand_num))

C写的脚本

常规的这样写就行

#include <stdio.h>
#include <time.h>int main(){
printf("%ld",time(0));
return  0;
}

或者像下面这样去写也行,多了几个库的问题

#include <stdio.h>
#include <stdlib.h>
#include <time.h>int main(){time_t v1;unsigned long long v2;unsigned long long seed = (unsigned long long)time(NULL);srand((unsigned int)seed);v2 = (unsigned long long)rand();//  printf("%#9llx\\n", v2);v2 = v2 <<12;printf("%#9llx\\n", v2);return 0;
}

题目源码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>int main(){srand((unsigned int)time(NULL));int num = rand() % 100; // Generate a random number between 0 and 99int luck;scanf("%d", &luck);if(num == luck){printf("You win!\\n");system("/bin/sh");} else {printf("You lose! The number was %d\\n", num);}
}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询