![](https://img-blog.csdnimg.cn/img_convert/46426a6b080bd1b5e55297c4fc0bda30.png)
枯燥的抽奖,有多枯燥?
点开
![](https://img-blog.csdnimg.cn/img_convert/f9783e9e09366b9399a7117527793a1a.png)
查看网页源码
![](https://img-blog.csdnimg.cn/img_convert/bb30e2bad54b2a661a3d3b032db0e6b4.png)
找到一个页面
![](https://img-blog.csdnimg.cn/img_convert/4f15a9430da02c6e64418d67887b6b21.png)
OK,这就是源码
<?php
#这不是抽奖程序的源代码!不许看!
header("Content-Type: text/html;charset=utf-8");
session_start();
if(!isset($_SESSION['seed'])){
$_SESSION['seed']=rand(0,999999999);
}
mt_srand($_SESSION['seed']);
$str_long1 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str='';
$len1=20;
for ( $i = 0; $i < $len1; $i++ ){
$str.=substr($str_long1, mt_rand(0, strlen($str_long1) - 1), 1);
}
$str_show = substr($str, 0, 10);
echo "<p id='p1'>".$str_show."</p>";
if(isset($_POST['num'])){
if($_POST['num']===$str){x
echo "<p id=flag>抽奖,就是那么枯燥且无味,给你flag{xxxxxxxxx}</p>";
}
else{
echo "<p id=flag>没抽中哦,再试试吧</p>";
}
}
show_source("check.php");
看到了mt_rand()函数,代码审计发现是PHP的伪随机数。
mt_rand()函数生成伪随机数与种子有关,需要先生成序列,将序列转换成PHP_mt_seed工具能理解的语言,进行逆向求出种子,再根据种子求出生成的伪随机数
从官方WP找到了生成序列的脚本
str1='abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
str2='hQcUKF8tdV'//这个地方换成你需要得到伪随机字符串的前十个字母
str3 = str1[::-1]
length = len(str2)
res=''
for i in range(len(str2)):
for j in range(len(str1)):
if str2[i] == str1[j]:
res+=str(j)+' '+str(j)+' '+'0'+' '+str(len(str1)-1)+' '
break
print(res)
生出数字如下
7 7 0 61 52 52 0 61 2 2 0 61 56 56 0 61 46 46 0 61 41 41 0 61 34 34 0 61 19 19 0 61 3 3 0 61 57 57 0 61
四个为一组,根据PHP_mt_seed工具使用方法可以得出种子
![](https://img-blog.csdnimg.cn/img_convert/05dcbc338ca0dbbccd659c41e9f1c6d2.png)
再用种子可以得出伪随机字符串
![](https://img-blog.csdnimg.cn/img_convert/bf72e72a915d1fc63e3c25f2ff606c4e.png)
![](https://img-blog.csdnimg.cn/img_convert/5eb9577fcaa80f0ce49e0f3448230733.png)
得到flag
![](https://img-blog.csdnimg.cn/img_convert/ac9e362d959925ebcc0278fd26e0da37.png)