攻防世界-Monopoly

这道题,我做了做,我的英语不好,全都是机翻,然后就发现这好像是一个大富翁的游戏,你要到一定的钱才算赢,主程序主要是在monopoly那个文件上,可以直接在linux里边运行./monopoly,,应该是可以发现有3个难度的,但是只有最高难度才能触发种子。

玩过mc的都知道,种子通常是固定的一个地图,在这里是固定的一个步数,然后就看了别人的wp,就发现他这个是选择种子后返回再选难度和种子,你的钱和位置是不变的,而且在这个游戏里边,是有double的,也就是说,只要你只要走的合理,然后就能double。而且我是看到了别人的wp也知道地图:

[1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]

一共64个位置,然后我们在这一篇里边又看到第一次走3步RCTF-2021 部分WriteUp的种子是22,3和64是互素的,在循环地图中互素即意味着能遍历所有的格子,加上double那么就只是轮数的问题了。手动还是有点难的,我直接找ai写了个脚本。

#!/usr/bin/env python3
import subprocess
import time
import sys
import os


def correct_automation():
    """正确的自动化流程:4->3->seed22->4->3->seed22->..."""
    attempt_count = 0

    while True:
        attempt_count += 1
        print(f"=== 第 {attempt_count} 次完整循环 ===")

        try:
            # 启动游戏进程
            proc = subprocess.Popen(
                ['./monopoly'],
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True,
                bufsize=1
            )

            # 初始设置
            proc.stdin.write("haha\n")  # 名字
            proc.stdin.write("3\n")  # 选择困难模式
            proc.stdin.write("22\n")  # seed 22
            proc.stdin.flush()

            cycle_count = 0
            while cycle_count < 100:  # 最多100个循环
                cycle_count += 1
                print(f"循环内第 {cycle_count} 次")

                # 处理一个完整循环:等待->选择4->等待->选择3->输入22
                try:
                    # 等待并读取直到需要操作
                    while True:
                        line = proc.stdout.readline()
                        if not line:
                            break
                        print(f"输出: {line.strip()}")

                        # 检查是否获胜
                        if 'you win' in line or 'flag' in line or 'RCTF' in line:
                            print("🎉🎉🎉 获胜啦! 🎉🎉🎉")
                            # 读取所有剩余输出
                            remaining = proc.communicate()[0]
                            print(remaining)
                            return True

                        # 如果看到操作提示,跳出内循环
                        if 'want play' in line:
                            break

                    # 选择操作4
                    proc.stdin.write("4\n")
                    proc.stdin.flush()
                    print("选择操作: 4")
                    time.sleep(0.5)

                    # 等待下一个操作提示
                    while True:
                        line = proc.stdout.readline()
                        if not line:
                            break
                        print(f"输出: {line.strip()}")

                        if 'you win' in line:
                            print("🎉 获胜!")
                            remaining = proc.communicate()[0]
                            print(remaining)
                            return True

                        if 'want play' in line:
                            break

                    # 选择操作3(重新开始)
                    proc.stdin.write("3\n")
                    proc.stdin.flush()
                    print("选择操作: 3")
                    time.sleep(0.5)

                    # 等待seed输入提示
                    while True:
                        line = proc.stdout.readline()
                        if not line:
                            break
                        print(f"输出: {line.strip()}")

                        if 'win the game' in line:
                            break

                    # 输入seed 22
                    proc.stdin.write("22\n")
                    proc.stdin.flush()
                    print("输入seed: 22")
                    time.sleep(0.2)

                except Exception as e:
                    print(f"循环内错误: {e}")
                    break

            proc.terminate()
            time.sleep(1)

        except Exception as e:
            print(f"运行错误: {e}")
            time.sleep(0.5)


def fast_correct_automation():
    """快速版本:预先准备好所有输入"""
    attempt = 0

    while True:
        attempt += 1
        print(f"尝试 #{attempt}")

        # 构建完整的输入序列
        # 格式: 名字->3->22->4->3->22->4->3->22->...
        input_sequence = "haha\n3\n22\n"

        # 添加100个循环:4->3->22
        for i in range(100):
            input_sequence += "4\n3\n22\n"

        try:
            result = subprocess.run(
                ['./monopoly'],
                input=input_sequence,
                text=True,
                capture_output=True,
                timeout=120  # 2分钟超时
            )

            print(f"本轮输出长度: {len(result.stdout)}")

            if 'you win' in result.stdout:
                print("🎉 成功!")
                print(result.stdout)
                return True

            # 检查是否在stderr中
            if 'you win' in result.stderr:
                print("🎉 在stderr中找到!")
                print(result.stderr)
                return True

        except subprocess.TimeoutExpired:
            print("超时,继续尝试...")
        except Exception as e:
            print(f"错误: {e}")

        time.sleep(0.3)


def step_by_step_automation():
    """逐步调试版本,可以看到详细流程"""
    attempt = 0

    while True:
        attempt += 1
        print(f"\n{'=' * 50}")
        print(f"尝试 #{attempt}")
        print(f"{'=' * 50}")

        proc = subprocess.Popen(
            ['./monopoly'],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            bufsize=1
        )

        # 初始设置
        steps = [
            ("发送名字", "haha\n"),
            ("选择困难模式", "3\n"),
            ("输入seed", "22\n")
        ]

        for desc, cmd in steps:
            print(f"{desc}: {cmd.strip()}")
            proc.stdin.write(cmd)
            proc.stdin.flush()
            time.sleep(0.1)

        # 主循环
        for cycle in range(500):
            print(f"\n--- 循环 {cycle + 1} ---")

            # 步骤1: 等待并选择4
            print("等待操作提示...")
            while True:
                line = proc.stdout.readline().strip()
                if line:
                    print(f"收到: {line}")

                    if 'CTF' in line:
                        print("🎉 获胜!")
                        return True

                    if 'want play' in line:
                        break

            print("选择操作: 4")
            proc.stdin.write("4\n")
            proc.stdin.flush()
            time.sleep(0.1)

            # 步骤2: 等待并选择3
            print("等待下一个操作提示...")
            while True:
                line = proc.stdout.readline().strip()
                if line:
                    print(f"收到: {line}")

                    if 'CTF' in line:
                        print("🎉 获胜!")
                        return True

                    if 'want play' in line:
                        break

            print("选择操作: 3")
            proc.stdin.write("3\n")
            proc.stdin.flush()
            time.sleep(0.1)

            # 步骤3: 等待并输入seed 22
            print("等待seed输入提示...")
            while True:
                line = proc.stdout.readline().strip()
                if line:
                    print(f"收到: {line}")

                    if 'CTF' in line:
                        print("🎉 获胜!")
                        return True

                    if 'win the game' in line:
                        break

            print("输入seed: 2")
            proc.stdin.write("22\n")
            proc.stdin.flush()
            time.sleep(0.1)

        proc.terminate()
        time.sleep(0.5)


if __name__ == "__main__":
    print("开始正确的自动化流程: 4->3->seed22->4->3->seed22->...")
    print("按 Ctrl+C 停止")

    if not os.path.exists('./monopoly'):
        print("错误: 找不到 './monopoly' 文件")
        sys.exit(1)

    os.chmod('./monopoly', 0o755)

    try:
        # 选择一种方式运行
        # correct_automation()        # 标准版本
        # fast_correct_automation()   # 快速版本
        step_by_step_automation()  # 调试版本

    except KeyboardInterrupt:
        print("\n用户停止执行")
    except Exception as e:
        print(f"程序错误: {e}")

然后把这个py文件和你的mo文件放同一个目录中

python 1.py 

就能看到你赢了,但是没有结果。出现这个联系管理员,说明按理说应该是已经有flag了。

这里是很难受的点,因为这个题是2021年的竞赛上的题,当时是在服务器上应该是有/flag这个文件的(或者文件夹里边有flag),这里是没有的,我就直接附上flag吧。

RCTF{you_are_a_multimillionaire_now}

只能说审核没干好吧,包括那个coolcat也是一样的根本解不出来。

【最优潮流】直流最优潮流(OPF)课设(Matlab代码实现)内容概要:本文档主要围绕“直流最优潮流(OPF)课设”的Matlab代码实现展开,属于电力系统优化领域的教学与科研实践内容。文档介绍了通过Matlab进行电力系统最优潮流计算的基本原理与编程实现方法,重点聚焦于直流最优潮流模型的构建与求解过程,适用于课程设计或科研入门实践。文中提及使用YALMIP等优化工具包进行建模,并提供了相关资源下载链接,便于读者复现与学习。此外,文档还列举了大量与电力系统、智能优化算法、机器学习、路径规划等相关的Matlab仿真案例,体现出其服务于科研仿真辅导的综合性平台性质。; 适合人群:电气工程、自动化、电力系统及相关专业的本科生、研究生,以及从事电力系统优化、智能算法应用研究的科研人员。; 使用场景及目标:①掌握直流最优潮流的基本原理与Matlab实现方法;②完成课程设计或科研项目中的电力系统优化任务;③借助提供的丰富案例资源,拓展在智能优化、状态估计、微电网调度等方向的研究思路与技术手段。; 阅读建议:建议读者结合文档中提供的网盘资源,下载完整代码与工具包,边学习理论边动手实践。重点关注YALMIP工具的使用方法,并通过复现文中提到的多个案例,加深对电力系统优化问题建模与求解的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值