-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt_flag.py
More file actions
84 lines (66 loc) · 3.08 KB
/
Copy pathdecrypt_flag.py
File metadata and controls
84 lines (66 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
decrypt_flag.py — AES-256 Encrypted Zip Decryption
Project Helix CTF · TCM Security
Author: Dibyanshu Sekhar
Decrypts flag.zip using the RNA-decoded password.
Standard unzip can't handle AES-256 (PK compat v5.1) — pyzipper can.
Usage:
python decrypt_flag.py --zip /tmp/flag.zip [--password "|RNAPolymeraseSlip|"]
Dependencies:
pip install pyzipper
"""
import argparse
import pyzipper
# Passwords tried before arriving at the correct one.
# Documented for educational purposes — specifically the "delimiters are data" lesson.
PASSWORD_GRAVEYARD = [
b'eraseSlip||RNAPolym', # Wrong-framed single-cycle decode
b'eraseSlipRNAPolym', # Without pipes
b'RNAPolymeraseSlippage', # Full biology term
b'RNAPolymeraseSlip', # Right text, missing delimiters ← SO CLOSE
b'3817.3', # The frequency
b'helix', # Machine name
b'HELIX',
b'drowens', # Username
b'xKeyJTOPm78=', # Registry red herring
]
CORRECT_PASSWORD = b'|RNAPolymeraseSlip|'
def attempt_decrypt(zip_path: str, password: bytes, verbose: bool = False) -> str | None:
"""Attempt to decrypt and read flag.txt from the zip."""
try:
with pyzipper.AESZipFile(zip_path) as z:
z.setpassword(password)
content = z.read('flag.txt')
return content.decode('utf-8').strip()
except (RuntimeError, pyzipper.BadZipFile, KeyError) as e:
if verbose:
print(f" [-] Failed: {e}")
return None
def main():
parser = argparse.ArgumentParser(description='Decrypt flag.zip — Project Helix')
parser.add_argument('--zip', default='/tmp/flag.zip', help='Path to flag.zip')
parser.add_argument('--password', default=None, help='Password to try (default: correct one)')
parser.add_argument('--graveyard', action='store_true', help='Also try the failed passwords first')
args = parser.parse_args()
print(f"[*] Target: {args.zip}\n")
if args.graveyard:
print("[*] Trying password graveyard first (for the lols)...")
for pwd in PASSWORD_GRAVEYARD:
result = attempt_decrypt(args.zip, pwd)
status = f"✓ {result}" if result else "✗"
print(f" {pwd.decode()!r:<35} → {status}")
print()
password = args.password.encode() if args.password else CORRECT_PASSWORD
print(f"[*] Trying: {password.decode()!r}")
flag = attempt_decrypt(args.zip, password, verbose=True)
if flag:
print(f"\n[+] ══════════════════════════════════")
print(f"[+] FLAG: {flag}")
print(f"[+] ══════════════════════════════════")
leet = flag.replace('0', 'O').replace('1', 'I').replace('4', 'A').replace('7', 'T').replace('3', 'E')
print(f"[+] Leet: {leet}")
else:
print(f"[-] Decryption failed with password: {password.decode()!r}")
print(" Double-check the pipes — they're part of the key.")
if __name__ == '__main__':
main()