HackTheBox: Optimus Prime

Optimus Prime has returned to Earth, choose an historical character and overcome this threat.

Information

Challenge: Optimus prime

Category:
Crypto

Difficulty:
Easy

Environment: Remnux VM

Walkthrough

1. Server Analysis

Connecting with netcat shows a server with four menu options:

All options are useless, except option four, which returns a Public Key and Encrypted Password:

Since we are not given source code, I tried checking the traffic for the ’email’ with Wireshark, but nothing came out of it. Runing the option 4 a couple of times, I noticed that each Public Key has the same GCD, which would be the P value! Given that, we can recover the corresponding q and then decrypt the encrypted password.

2. Common Factor Attack

To recover the plaintext, we need to recover each RSA parameter:

				
					from pwn import *
import math

host = "159.65.49.103"
port =  30243

def get_values(t):
	t.recvuntil("option: ")
	t.send("4")
	out = t.recvuntil("proceed: ").decode("utf-8").split('\n')
	values = {'pk': int(out[0].replace('PUBLIC KEY: ','')), 'ep': int(out[1].replace('ENCRYPTED PASSWORD: ',''))}
	return values
	
def recovery_items(val1,val2):
	p = math.gcd(val1['pk'], val2['pk'])
	q = val2['pk'] // p 
	assert q * p == val2['pk']
	phi = (p - 1) * (q- 1)
	e = 65537
	d = pow(e, -1, phi)
	plaintext = pow(val2['ep'], d, val2['pk'])
	message = bytes.fromhex(hex(plaintext)[2:]).decode()
	return message

def solve(host,port):
	out_vals = []
	t = remote(host,port)
	out_vals.append(get_values(t))
	t.sendline("hi")
	t = remote(host,port)
	out_vals.append(get_values(t))
	message = recovery_items(out_vals[0], out_vals[1])
	t.sendline(message)
	result = t.recvline()
	print(result.decode())
	

solve(host,port)
#ACCESS GRANTED: HTB{3uc1id_w4z_th3_pr1me_h4x0r}

				
			

Flag: HTB{3uc1id_w4z_th3_pr1me_h4x0r}

Discover more from forensicskween

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%