刷题记录:[GWCTF 2019]枯燥的抽奖
题目复现链接:https://buuoj.cn/challenges
参考链接:2018SWPUCTF-Web全详解
知识点
php伪随机性
如果mt_srand使用同一个seed,生成的随机数是可以爆破出seed的
https://www.openwall.com/php_mt_seed/
这道题的应用场景中,字符串生成方式是
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>";
根据生成算法逆向出满足php_mt_seed工具要求的参数
str1 = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
str2 = 'znXCVCNqS5'
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)
爆破出seed值后再代回原程序就可以得到完整的字符串