https://github.com/lijiejie/GitHack首先附上git泄露利用脚本,这题我都没用御剑扫一下,看来做题目要仔细,做全工作,扫的话可以看到robots.txt中有/.git/,肯定是git源码泄露了,githack一下,dump下来了源码,并且找到有漏洞的地方。看了WP,直接找的是api.php,通过买彩票下手,一般题目做多的老手,应该就能看到paylaod点吧。感觉。可惜我小白还不是做的题目太少了。今天开始刷题,DD和国赛,太费了。加油做题。
githack dump下的源码,查看api.php
<?php
require_once(‘config.php‘);
header(‘Content-Type: application/json‘);
function response($resp){
die(json_encode($resp));
}
function response_error($msg){
$result = [‘status‘=>‘error‘];
$result[‘msg‘] = $msg;
response($result);
}
function require_keys($req, $keys){
foreach ($keys as $key) {
if(!array_key_exists($key, $req)){
response_error(‘invalid request‘);
}
}
}
function require_registered(){
if(!isset($_SESSION[‘name‘]) || !isset($_SESSION[‘money‘])){
response_error(‘register first‘);
}
}
function require_min_money($min_money){
if(!isset($_SESSION[‘money‘])){
response_error(‘register first‘);
}
$money = $_SESSION[‘money‘];
if($money < 0){
$_SESSION = array();
session_destroy();
response_error(‘invalid negative money‘);
}
if($money < $min_money){
response_error(‘you don\‘ have enough money‘);
}
}
if($_SERVER["REQUEST_METHOD"] != ‘POST‘ || !isset($_SERVER["CONTENT_TYPE"]) || $_SERVER["CONTENT_TYPE"] != ‘application/json‘){
response_error(‘please post json data‘);
}
$data = json_decode(file_get_contents(‘php://input‘), true);
if(json_last_error() != JSON_ERROR_NONE){
response_error(‘invalid json‘);
}
require_keys($data, [‘action‘]);
// my boss told me to use cryptographically secure algorithm
function random_num(){
do {
$byte = openssl_random_pseudo_bytes(10, $cstrong);
$num = ord($byte);
} while ($num >= 250);
if(!$cstrong){
response_error(‘server need be checked, tell admin‘);
}
$num /= 25;
return strval(floor($num));
}
function random_win_nums(){
$result = ‘‘;
for($i=0; $i<7; $i++){
$result .= random_num();
}
return $result;
}
function buy($req){
require_registered();
require_min_money(2);
$money = $_SESSION[‘money‘];
$numbers = $req[‘numbers‘];
$win_numbers = random_win_nums();
$same_count = 0;
for($i=0; $i<7; $i++){
if($numbers[$i] == $win_numbers[$i]){
$same_count++;
}
}
switch ($same_count) {
case 2:
$prize = 5;
break;
case 3:
$prize = 20;
break;
case 4:
$prize = 300;
break;
case 5:
$prize = 1800;
break;
case 6:
$prize = 200000;
break;
case 7:
$prize = 5000000;
break;
default:
$prize = 0;
break;
}
$money += $prize - 2;
$_SESSION[‘money‘] = $money;
response([‘status‘=>‘ok‘,‘numbers‘=>$numbers, ‘win_numbers‘=>$win_numbers, ‘money‘=>$money, ‘prize‘=>$prize]);
}
function flag($req){
global $flag;
global $flag_price;
require_registered();
$money = $_SESSION[‘money‘];
if($money < $flag_price){
response_error(‘you don\‘ have enough money‘);
} else {
$money -= $flag_price;
$_SESSION[‘money‘] = $money;
$msg = ‘Here is your flag: ‘ . $flag;
response([‘status‘=>‘ok‘,‘msg‘=>$msg, ‘money‘=>$money]);
}
}
function register($req){
$name = $req[‘name‘];
$_SESSION[‘name‘] = $name;
$_SESSION[‘money‘] = 20;
response([‘status‘=>‘ok‘]);
}
switch ($data[‘action‘]) {
case ‘buy‘:
require_keys($data, [‘numbers‘]);
buy($data);
break;
case ‘flag‘:
flag($data);
break;
case ‘register‘:
require_keys($data, [‘name‘]);
register($data);
break;
default:
response_error(‘invalid request‘);
break;
}
可以看到买彩票那个点的代码问题,通过输入的7位数字,一个一个比较,如果7位都相同的话,就中大奖了。而且是弱类型比较==,问题就是出现在这个弱类型
抓包,抓到的是json格式的request
因为json格式允许bool值,而且弱类型比较中ture和‘1‘和1是相等的
true与字符串和数字都是弱相等的。(trick get)
emmmmm,呢么直接传入number为一串数组[true,true,true,true,true,true,true]
我这里一开始还蒙了一下,一般数组不都是array定义的吗,发现可以直接赋值一个数组
字符串在py中是一个list,在php中也互通,可以通过py理解。
但是随机的数字,可能随机到0,只要么有0的话,就可以获取很多,尝试多次然后攒钱买flag,我在想这里应该可以用python脚本跑吧,反复的请求多次,并且数据改成{"action":"buy","numbers":[true,true,true,true,true,true,true]}
原文:https://www.cnblogs.com/BOHB-yunying/p/10810119.html