HackTheBox Optimus Prime Writeup
Explore the basics of cybersecurity in the Optimus Prime Challenge on Hack The Box. This easy-level Challenge introduces encryption reversal and file handling concepts in a clear and accessible way, perfect for beginners.
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
#!/usr/bin/env python3
from math import gcd
from pwn import remote, sys
def get_process():
try:
host, port = sys.argv[1].split(':')
return remote(host, int(port))
except IndexError:
print(f'Usage: python {sys.argv[0]} <ip:port>')
exit(1)
def get_public_key(p) -> int:
p.sendlineafter(b'Enter the option: ', b'4')
p.recvuntil(b'PUBLIC KEY: ')
return int(p.recvline())
def get_encrypted_password(p) -> int:
p.recvuntil(b'ENCRYPTED PASSWORD: ')
return int(p.recvline())
def main():
try:
r = get_process()
n1 = get_public_key(r)
c1 = get_encrypted_password(r)
r.close()
r = get_process()
n2 = get_public_key(r)
c2 = get_encrypted_password(r)
px = gcd(n1, n2)
p2 = n2 // px
e = 65537
phi_n2 = (px - 1) * (p2 - 1)
d2 = pow(e, -1, phi_n2)
m = bytes.fromhex(hex(pow(c2, d2, n2))[2:])
r.sendlineafter(b'Please use it to proceed: ', m)
r.recvuntil(b'ACCESS GRANTED: ')
print(r.recvline().decode())
r.close()
except KeyboardInterrupt:
print("\nInterrupted by user.")
try:
r.close()
except:
pass
if __name__ == '__main__':
main()
Summary
Optimus Prime on Hack The Box teaches beginners how to reverse encryption and handle files programmatically, guiding them through decrypting a password and understanding public key factorization, all within a robust, interruption-resistant script.
This post is licensed under CC BY 4.0 by the author.