当前位置:网站首页>[GWCTF 2019]枯燥的抽奖
[GWCTF 2019]枯燥的抽奖
2022-07-27 21:13:00 【茶经新读.】
[GWCTF 2019]枯燥的抽奖
f12查看源码发现了check.php

查看check.php发现了抽奖源码:
MkmGxMm3Ky
<?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");审计代码可得当满足($_POST['num']===$str)的时候就会给flag,去看str满足的条件:
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是通过mt_rand函数通过生成20个随机数得到的,并且这里不知道seed。这里存在伪随机数漏洞,伪随机数漏洞存在可预测性,这意味着:如果知道了种子,或者已经产生的随机数,都可能获得接下来随机数序列的信息。我们需要知道种子,然后把密文生成出来,这时我们需要先把随机数生成出来,str1在代码最上面已经给出,脚本小子火速出击:
str1 ='MkmGxMm3Ky'
str2 = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
result =''
length = str(len(str2)-1)
for i in range(0,len(str1)):
for j in range(0,len(str2)):
if str1[i] == str2[j]:
result += str(j) + ' ' +str(j) + ' ' + '0' + ' ' + length + ' '
break
print(result)(python脚本)运行即可得到随机数序列:48 48 0 61 10 10 0 61 12 12 0 61 42 42 0 61 23 23 0 61 48 48 0 61 12 12 0 61 29 29 0 61 46 46 0 61 24 24 0 61
这里我们利用php_mt_seed,它可以破解mt_rand函数seed:
php_mt_seed - PHP mt_rand() seed cracker
下载php_mt_seed 4.0
然后把压缩包放入kali,使用命令:tar -zxvf php_mt_seed-4.0.tar.gz,压缩得到文件夹
打开文件夹可能会出现:无法打开目录,权限不够的情况

这时需要再次执行命令:chomd 777 php_mt_seed-4.0(文件夹的名字)

执行完就发现,文件夹可以进去了,进去之后在当前页面打开终端先执行命令:make,生成php_mt_seed

这里因为我已经make过一次了,所以它显示我的php_mt_seed已经是最新,然后需要执行命令:./php_mt_seed 48 48 0 61 10 10 0 61 12 12 0 61 42 42 0 61 23 23 0 61 48 48 0 61 12 12 0 61 29 29 0 61 46 46 0 61 24 24 0 61(自己得到的随机数),得到种子:626348345

然后就是代码中给的脚本,修改一下即可:
<?php
mt_srand(626348345);
$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;
?>运行即得str
将str提交到一开始的页面即得flag
至此完毕,撒花结束
边栏推荐
- Latex中如何加粗字体 & 如何打出圆圈序号
- Binary conversion method
- Bank Marketing预测一个客户购买理财产品的成功率
- What is the difference between concurrency and parallelism?
- 【zer0pts CTF 2022】 Anti-Fermat
- BUUCTF-Dangerous RSA
- Use a grayscale filter
- In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
- Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
- [NPUCTF2020]EzRSA
猜你喜欢

MapReduce (III)

【C语言】通讯录(动态版本)

2022年土木,建筑与环境工程国际会议(ICCAEE 2022)
![[RoarCTF2019]babyRSA威尔逊定理](/img/c1/52e79b6e40390374d48783725311ba.gif)
[RoarCTF2019]babyRSA威尔逊定理

2022 International Conference on civil, building and Environmental Engineering (iccaee 2022)

Bank marketing predicts the success rate of a customer's purchase of financial products

(十二)51单片机----用DS18B20浅测一下工(江)西的室外温度

Master data management theory and Practice

Introduction to several common usage scenarios of message queue

Lua基础语法学习
随机推荐
QT with OpenGL (shadow mapping)
Zabbix4.0 uses SNMP agent to monitor vcenter6.5
CPU的控制方式
This is the most concise guide to tcpdump in history. It's enough to read this one
数据中台的那些“经验与陷阱”
NDK series (6): let's talk about the way and time to register JNI functions
J9数字科普:Sui网络的双共识是如何工作的?
【飞控开发基础教程6】疯壳·开源编队无人机-SPI(六轴传感器数据获取)
What are the methods of process synchronization?
Redefine analysis - release of eventbridge real-time event analysis platform
尚硅谷尚品项目汇笔记(一)
Is it really hard to understand? What level of cache is the recyclerview caching mechanism?
[C language] address book (dynamic version)
In 2019, the world's top ten semiconductor manufacturers: Intel returned to the first place, and apple rose sharply against the trend
主数据管理理论与实践
Latex中如何加粗字体 & 如何打出圆圈序号
Notes on Shangpin project in shangsilicon Valley (I)
Latex common summary (2): input matrix (input matrix, diagonal matrix, equations, etc.)
[NPUCTF2020]EzRSA
2022年土木,建筑与环境工程国际会议(ICCAEE 2022)