[GWCTF 2019]枯燥的抽奖

0x00 知识点

种子爆破
工具
http://www.openwall.com/php_mt_seed

0x01 解题

查看源码进入check.php

zOHF0Cxp49
<?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_scrand(),mt_rand()这俩函数; 并且session是用的随机数设置的;
先用脚本将伪随机数转换成php_mt_seed可以识别的数据

str1='abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
str2='zOHF0Cxp49'
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

得到

将这一串拿到工具里去使用
爆破出伪随机数和php版本

./php_mt_seed 25 25 0 61 50 50 0 61 43 43 0 61 41 41 0 61 26 26 0 61 38 38 0 61 23 23 0 61 15 15 0 61 30 30 0 61 35 35 0 61 

将send设置为:819101489,如下

改写源码,生成完整字符串(如爆破到的seed是830701381)

<?php
mt_srand(819101489);

$str_long1 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str='';
$len1=20;
for ( $i = 0; $i < $len1; $i++ ){
    $str.=substr($str_long1, mt_rand(0, strlen($str_long1) - 1), 1);       
}
echo $str;

?>

拿着得到得字符转提交

posted @ 2020-02-09 20:52  王叹之  阅读(1839)  评论(0编辑  收藏  举报