-
Notifications
You must be signed in to change notification settings - Fork 65
/
MITM3.py
43 lines (36 loc) · 1.29 KB
/
MITM3.py
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
#!/usr/bin/env python3
from Crypto.Cipher import AES
import os
from utils import *
def talk_to_Alice():
global iv
name = bytes.fromhex(input("What's your name? "))
extra = bytes.fromhex(input("What else do you want to say? "))
msg = b"Thanks " + name + b" for taking my flag: " + flag + extra
plaintext = msg + hmac_crc128(MAC_key, msg)
iv = os.urandom(AES.block_size)
aes = AES.new(AES_key, AES.MODE_CBC, iv)
print("This is my encrypted message, please take it to Bob:")
print((iv + aes.encrypt(pad(plaintext))).hex())
def talk_to_Bob():
global iv
try:
ciphertext = bytes.fromhex(input("Show me your message from Alice: "))
assert iv == ciphertext[: AES.block_size]
aes = AES.new(AES_key, AES.MODE_CBC, iv)
plaintext = unpad(aes.decrypt(ciphertext[AES.block_size :]))
assert hmac_crc128(MAC_key, plaintext[:-16]) == plaintext[-16:]
print("Thanks")
except:
print("What's your problem???")
if __name__ == "__main__":
flag = open("flag3").read().encode()
AES_key = os.urandom(16)
MAC_key = os.urandom(16)
iv = None
while True:
choice = input("Whom do you want to talk to? ")
if choice == "Alice":
talk_to_Alice()
elif choice == "Bob":
talk_to_Bob()