[GWCTF 2019]枯燥的抽奖
伪随机数安全的一个题,通过php_mt_rand这个工具逆向出随机数种子,然后通过种子获取字符串
贴一下源码
<?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(min,max)函数返回该区间内的任意一个数,通过如下脚本得到逆向所需数据,通过php_mt_rand工具爆破出种子