DubheCTF 2024 misc方向部分题解

文章讲述了在编程挑战中,如何通过ezPythonCheckIn避免黑名单函数,利用Base64编码接收用户输入,使用Bandit工具检测潜在风险,以及通过EFS加密系统解密旗标的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出题的水平真的挺高的,好难……

目录

1.ezPythonCheckIn

2.Cipher


1.ezPythonCheckIn

第一个就是python的沙盒逃逸;

import atexit
import base64
import json
import os
import subprocess
from tempfile import NamedTemporaryFile

black_list = [
    "nosec",
    "import",
    "load",
    "''",
    '""',
    "[]",
    "{}",
    "().",
    "builtins",
    "dict",
    "dir",
    "locals",
    "base",
    "classes",
    "+",
    "mro",
    "attribute",
    "id",
]


def main():
    print("Hello!")
    print("Please send base64 encoded string!")
    data = input("> ")

    if len(data) > 1600:
        print("Too long")
        return

    decode_data = base64.b64decode(data).decode()
    print(decode_data)
    if any(item in decode_data for item in black_list):
        print("Not Safe")
        return
    with NamedTemporaryFile("wt", suffix=".py", delete=False, encoding="utf-8") as f:
        f.write(decode_data)
        temp_filename = f.name
    atexit.register(os.remove, temp_filename)
    print("step")
    check_result = json.loads(
        subprocess.run(
            ["bandit", "-r", temp_filename, "-f", "json"],
            capture_output=True,
            encoding="utf-8",
        ).stdout
    )

    if len(check_result["results"]) == 0:
        print("[+] OK")
        subprocess.run(["python3", temp_filename], timeout=60)
        print("[+] Over")
    else:
        print("[+] Not Safe")
    return
main()


这是沙盒的源码,发现黑名单过滤了很多东西,然后长度限制,还用了bandit过滤不安全的函数。然后把用户的输入都传到临时文件里。后来请教大佬方知有breakpoint()函数,作用是直接打开一个解释器首先breakpoint()绕过了黑名单,长度上ok,也通过了bandit的检测,然后传到临时文件里执行,跳出解释器,现在没什么东西可以限制我们了,直接_import_('os').system('ls')执行命令找flag然后返回flag就OK了

2.Cipher

这题多亏了一起做题的小伙伴的思路,只不过是站在他们的肩膀上拿的flag

题目给了一个vhd,挂载,发现了公用文件夹下flag,然后发现这个是加密的,无权限访问,查看属性,在压缩和加密属性那里点高级,发现了图片的权限所有者,还知道这个是EFS文件加密系

统加密的 

然后EFS的加密原理是这样的,首先用FEK文件加密密钥对文件进行对称加密,然后把用RSA对FEK密钥加密,其中公钥用来加密,私钥用来解密,私钥又收到登陆密码保护,所以我们要有登陆密码解密私钥,私钥解密FEK,FEK解密文件,默认的RSA私钥在这里:C:\Users\mark\AppData\Roaming\Microsoft\Crypto\RSA然后找到私钥后就差登陆密码,这个可以在console_history(大概是这个名字)找到,然后丢尽AEFSDR这个软件就可以自动解密了,完成!

### HGAME 2024 Misc 类别题目信息 #### 解密并转换Flag 在HGAME 2024 WEEK1 的misc类别中,有一个挑战涉及解密获得的明文,并将其全部转换为大写字母。最终的结果被包裹在`hgame{}`内作为标志(flag)[^2]。 ```python def convert_to_uppercase_flag(encrypted_text): decrypted_text = encrypted_text.upper() flag_format = f"hgame{{{decrypted_text}}}" return flag_format example_encrypted_text = "disappearintheseaofbutterfly" print(convert_to_uppercase_flag(example_encrypted_text)) ``` 此代码片段展示了如何将给定字符串转换成全大写的flag格式。 #### 字符编码变换 另一个例子来自HGAME 2024 WEEK2,在这个杂项(miscellaneous)挑战里,参与者需要通过特定偏移量来调整输入字符串中的每一个字符Unicode值的位置。当尝试不同的位移数值时,可以找到符合条件的有效输出——即以"hgame{"开头的信息[^3]。 ```python def unicode_shift(input_str, shift): shifted_string = ''.join( chr((ord(c) + shift) % 0x110000) for c in input_str) return shifted_string input_unicode_encoded = "籱籰籪籶籮粄簹籴籨粂籸籾籨籼簹籵籿籮籨籪籵簺籨籽籱簼籨籼籮籬类簼籽粆" for offset in range(-65535, 65536): result = unicode_shift(input_unicode_encoded, offset) if result.startswith("hgame"): print(f"Offset found: {offset}") print(result) break ``` 这段Python脚本实现了遍历可能的Unicode位移范围直到发现正确的标志为止的功能。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值