Blunt
Catégorie: Crypto Difficulté: easy Flag: HTB{y0u_n3ed_a_b1gGeR_w3ap0n!!}
Challenge
Description
Valuing your life, you evade the other parties as much as you can, forsaking the piles of weaponry and the vantage points in favour of the depths of the jungle. As you jump through the trees and evade the traps lining the forest floor, a glint of metal catches your eye. Cautious, you creep around, careful not to trigger any sensors. Lying there is a knife - damaged and blunt, but a knife nonetheless. Youâre not helpless any more.
Analyse
Il sâagit dâune implĂ©mentation de lâalgorithme de Diffie-Hellman. En cherchant les diffĂ©rentes vulnĂ©rabilitĂ©s de celui-ci, on trouve un papier expliquant quâun modulo infĂ©rieur Ă 512 bits, on peut le casser avec avec un Logarithme discret.
On sait que A = pow(g, a, p)
, autrement dit 3484137181 = pow(2212633605, a, 3714892429)
Ici on utilisera le site alpertron.com pour résoudre celui-ci et trouver a
.

On trouve alors a = 2766777741
Le secret partagé se calcule avec C = pow(B, a, p)
, soit C = pow(3298958249, 2766777741, 3714892429)
C = 1739735275
ce qui donne en bytes : **67b240eb
**
Il suffit de calculer ensuite le SHA256 : **7a9aa3ea818e71ce79b4018a2e295112263be9390003abe859410b6ec238b94f
**
La clĂ© de lâAES correspond au 16 premiers octets du hash : **7a9aa3ea818e71ce79b4018a2e295112
**
Script de résolution
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
from Crypto.Util.number import long_to_bytes
import hashlib
def solve(A, b, p, ciphertext):
C = pow(A, b, p)
hash = hashlib.sha256()
hash.update(long_to_bytes(C))
key = hash.digest()[:16]
iv = b'\xc1V2\xe7\xed\xc7@8\xf9\\\xef\x80\xd7\x80L*'
cipher = AES.new(key, AES.MODE_CBC, iv)
flag = unpad(cipher.decrypt(ciphertext), 16).decode()
print(f"FLAG: {flag}")
if __name__ == '__main__':
solve(
A=0xcfabb6dd,
b=1913706799,
p=0xdd6cc28d,
ciphertext=b'\x94\x99\x01\xd1\xad\x95\xe0\x13\xb3\xacZj{\x97|z\x1a(&\xe8\x01\xe4Y\x08\xc4\xbeN\xcd\xb2*\xe6{'
)
DerniĂšre mise Ă jour
Cet article vous a-t-il été utile ?