V1t 2025 - Python 0bf

  • CTF: V1t 2025
  • Challenge Name: Python 0bf
  • Category: Reverse
  • Difficulty: Unknown

Synopsis

Recover a flag that has been hidden in Python using base64 encoding and zlib compression.

Description

You don’t need to deobfuscate the Python, but that’s up to you. ;-;

Challenge

The challenge provides a single Python file with obfuscated code. The goal is to reverse the obfuscation and recover the original flag.

The main file provided is:

  • obs.py: Contains a single line with a lambda function that decompresses and decodes a string before executing it.

obs.py contains:

 _ = lambda __ : __import__('zlib').decompress(__import__('base64').b64decode(__[::-1]));exec((_)(b'==A4ZjPKD8...'))

Solution

To solve this problem, we need to:

  1. [::-1] to reverse the string
  2. base64.b64decode to decode from base64
  3. zlib.decompress to decompress the result
  4. Repeat

Step 1: Analyse the Obfuscation

The code uses:

  • [::-1] to reverse the string
  • base64.b64decode to decode from base64
  • zlib.decompress to decompress the result

We could print out that the result is from decoding and decompressing the byte string using the following Python code:

obfuscated = b'==A4ZjPKD8...'

_ = lambda __: zlib.decompress(base64.b64decode(__[::-1]))
(print((_)(obfuscated)))

Running this gives us the following output:

b"exec((_)(b'=4ez2n9H+...'))

This output looks very similar to what we had before but with a different byte string this time.

Step 2: Repeat

We can then do the same process to see what happens.

obfuscated = b'==A4ZjPKD8...'

_ = lambda __: zlib.decompress(base64.b64decode(__[::-1]))
(print((_)(obfuscated)))

obfuscated2 = b'=4ez2n9H+...'

_ = lambda __: zlib.decompress(base64.b64decode(__[::-1]))
(print((_)(obfuscated2)))

Running this gives us the following output:

b"exec((_)(b'==w5bq2N/sv///...'))

Again its another byte string to execute another obfuscated byte string.

Step 3: Automation

Since the process is repetitive and we do not know how long it will go on for, it is a good idea to automate it.

obfuscated = b'==A4ZjPKD8/33n/...'

def deobfuscate(data):
    return zlib.decompress(base64.b64decode(data[::-1]))

def extract_string(data):
    return data[11:-3]

obfuscated = deobfuscate(obfuscated)
 while True:
    obfuscated = deobfuscate(extract_string(obfuscated))
    print(obfuscated)

This will print the final code which it not obfuscated:

Summary

This reverse challenge hides a flag inside a single-line Python lambda that repeatedly reverses a string, base64-decodes it and then zlib-decompresses the result. Iteratively applying those steps eventually yields the final code and flag.

Output

b'flag = "v1t{d4ng_u_kn0w_pyth0n_d3bugg}"\n\n
inp = input("Input the flag: ")\n\n
if (inp != flag):\n    print("wrong")\nelse:\n    print("correct")'

Solution Code

import base64
import zlib

obfuscated = b'==A4ZjPKD8/33n/...'

def deobfuscate(data):
    return zlib.decompress(base64.b64decode(data[::-1]))

def extract_string(data):
    return data[11:-3]

obfuscated = deobfuscate(obfuscated)
 while True:
    obfuscated = deobfuscate(extract_string(obfuscated))
    print(obfuscated)



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Hack The Box - Weak RSA
  • TCP1P 2024 - Skibidi Format
  • TCP1P 2024 - Imperfect Guesser