刷題記錄:[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值后再代回原程序就可以得到完整的字符串