WP020——CTF赛题解析-脚本

时效性

2025年8月8日

题目来源

秋名山车神 - Bugku CTF平台

题目描述

Write UP

1、直接使用脚本进行计算和提交,在两秒钟内进行数值提交即可

python 复制代码
import requests
import re
from bs4 import BeautifulSoup
import time

def calculate_expression(expression):
    """安全计算数学表达式"""
    # 清理表达式:移除非数学字符
    cleaned = re.sub(r'[^\d+\-*]', '', expression)
    # 分割数字和运算符
    parts = re.split(r'([+\-*])', cleaned)
    # 过滤空字符串
    parts = [p for p in parts if p]
    
    # 先处理所有乘法
    i = 0
    while i < len(parts):
        if parts[i] == '*':
            left = int(parts[i-1])
            right = int(parts[i+1])
            result = left * right
            parts = parts[:i-1] + [str(result)] + parts[i+2:]
            i -= 1
        else:
            i += 1
    
    # 再处理加减法
    result = int(parts[0])
    for i in range(1, len(parts), 2):
        operator = parts[i]
        num = int(parts[i+1])
        if operator == '+':
            result += num
        elif operator == '-':
            result -= num
    
    return result

def main(url):
    for attempt in range(3):  # 最多尝试3次
        try:
            session = requests.Session()
            
            # 步骤1: 获取页面
            get_response = session.get(url)
            if get_response.status_code != 200:
                print(f"获取页面失败,状态码: {get_response.status_code}")
                continue
                
            # 步骤2: 解析表达式
            soup = BeautifulSoup(get_response.text, 'html.parser')
            div_content = soup.find('div').text.strip()
            expression = div_content.split('=')[0].replace('?', '').strip()
            
            # 步骤3: 计算表达式
            start_time = time.time()
            result = calculate_expression(expression)
            calc_time = time.time() - start_time
            
            # 步骤4: 发送POST请求
            post_data = {'value': str(result)}
            post_response = session.post(url, data=post_data)
            
            # 输出结果
            print(f"尝试 #{attempt + 1}")
            print(f"表达式: {expression}")
            print(f"计算结果: {result}")
            print(f"计算耗时: {calc_time:.4f}秒")
            print("\nPOST响应内容:")
            print(post_response.text)
            print("\n" + "="*50 + "\n")
            
            # 检查是否成功
            if "flag" in post_response.text.lower() or "success" in post_response.text.lower():
                print("成功提交答案!")
                return
                
        except Exception as e:
            print(f"尝试 #{attempt + 1} 出错: {str(e)}")
            time.sleep(0.5)  # 短暂等待后重试

if __name__ == "__main__":
    target_url = "http://117.72.52.127:18350/"  # 替换为实际URL
    main(target_url)

2、按照网上的说法,可以对Cookie生命周期进行修改然后进行计算,不过我没有进行尝试

相关推荐
艾莉丝努力练剑8 小时前
【AI大模型接入SDK】解决Unicode码转化以及界面变形问题
前端·c++·人工智能·学习·安全·架构
国科安芯11 小时前
可信的电流:ASP4644S2B电源模块与星载电子供应链网络安全防护体系
网络·安全·web安全·架构·芯片·抗辐射
QXWZ_IA14 小时前
无人机巡检油气管道推荐什么型号:固定翼与多旋翼的载荷与航时权衡
人工智能·安全·无人机
kitsch0x9715 小时前
MITRE Engage 中的网络欺骗
安全·web安全·php
Joy T1 天前
Spring Security 从 Acegi 到 AI Agent——JWT、角色鉴权与异步任务安全实战
人工智能·安全·spring·spring security·json web token·securitycontext·多次鉴权
qq_谁赞成_谁反对1 天前
甲方IT的成长之路--安全远程管理工具及组件--2604
安全
QXWZ_IA1 天前
管道阴极保护数据无法实时回传怎么办:五种通信链路怎么选
人工智能·安全
如夏倾城1 天前
WAF (Web Application Firewall,Web应用防火墙)
前端·网络·安全·web安全·web app
鲁邦通物联网2 天前
DNV新造船海事网关安全通信架构与系列船验证方法
运维·安全·海事网关·船用网关·海事网络安全·智慧航运·船用路由器
小乖写代码2 天前
语音通话安全架构 · Voice Call Security Architecture
安全·安全架构·whatsapp·通信安全·语音通话