当前位置:网站首页>[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
至此完毕,撒花结束
边栏推荐
- Sort sort
- 【zer0pts CTF 2022】 Anti-Fermat
- Redis 哈希Hash底层数据结构
- Your list is too laggy? These four optimizations can make your list silky smooth
- Latex中如何加粗字体 & 如何打出圆圈序号
- What is the prospect of low code development? Are you really optimistic about low code development?
- Control mode of CPU
- [ACTF新生赛2020]crypto-aes
- C # delegate usage -- console project, which implements events through delegation
- Realization of gobang man-machine combat
猜你喜欢

Is it really hard to understand? What level of cache is the recyclerview caching mechanism?

Realization of gobang man-machine combat

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

29. Learn the stacked column chart of highcharts using percentage

MapReduce (III)

Realize today's news website based on native JS

重新定义分析 - EventBridge 实时事件分析平台发布

【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)

NDK series (6): let's talk about the way and time to register JNI functions

Spark 离线开发框架设计与实现
随机推荐
Design and implementation of spark offline development framework
XSS Payload 学习浏览器解码
What are the methods of process synchronization?
Explain the idempotence of distributed system in detail
Lua基础语法学习
Your list is too laggy? These four optimizations can make your list silky smooth
BUUCTF-Dangerous RSA
smartRefresh嵌套多个RecycleView滑动冲突及布局显示不全
The 4-hour order exceeds 20000+, claiming to be "the most luxurious in a million". Is the domestic brand floating?
New technology leads new changes in marketing of large and medium-sized enterprises, and UFIDA BiP CRM is launched!
Which one is better to request to merge -- three skills of interface request merging, and the performance directly explodes the table
Lua basic grammar learning
Using the optical fingerprint scheme under the huiding screen, Samsung Galaxy a71 5g is listed
Current situation and future of Nb IOT industry: cross the threshold of 100million shipments and rush to 5g connection!
Zabbix4.0 uses SNMP agent to monitor vcenter6.5
xss.haozi.me练习通关
Elk log analysis system installation and deployment
Arm32 for remote debugging
TFRecord的Shuffle、划分和读取
76000 people shut down! Toshiba announced the closure of all factories in Japan