Seccon 2017 - Man-in-the-middle on SECP384R1 (Crypto, 300)
2017-12-11
The title give us some tips : SECP384R1 -> Ellicptic Curve
Try Connect to the server, you can find there are two dev talking.
As the title, we are asked to be the middle evil to break this conversation.
Therefore, I make a public key to build the shared key between two devices.
1 2 3 4 5 6 7 8 9 10 11
import hashlib from libnum import * from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.asymmetric import ec
defget_pub(data): """ Save the key which gets from dev0 or dev1. """ # bytes-like to int x = s2n(data[24 : 24 + 48]) y = s2n(data[24 + 48 :]) prime = ec.SECP384R1() peer.append(ec.EllipticCurvePublicNumbers(x, y, prime).public_key(default_backend()))
# [KBKDF: SHA256, Encryption: AES] defderive(): """ We derive the shared key by tips : Key Derive Function is SHA256 and Encryption by AES (Guess the Mode is CBC and Default IV). """ for i inrange(2): digest = hashlib.sha256(private.exchange(ec.ECDH(), peer[i])).digest() shared_key.append(Cipher(algorithms.AES(digest), modes.CBC(b'0'*16), default_backend()))
#### Man in the middle ##### data = s.recv(256) data = decrypt(data,0) print(data) ciphertext = encrypt(data,1) s.send(ciphertext) ############################
print(s.recv(len("\n[dev1 to dev0]: OK\n"))) print(s.recv(len("[dev1 to dev0]:")))
######### Decrypt ########## data = s.recv(256) flag = decrypt(data,1) print(flag) ############################