-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
executable file
·51 lines (44 loc) · 1.22 KB
/
server.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
44
45
46
47
48
49
50
51
#!/usr/local/bin/python -u
import hashlib
import os
with open("flag.txt") as f:
FLAG = f.read()
QUERIED = set()
KEY = os.urandom(16)
print("Introducing Neil-MAC (NMAC), the future of hash-based message")
print("authentication codes!")
print()
print("No longer susceptible to those pesky length extension attacks!")
print()
def nmac(message):
return hashlib.md5(message + KEY).hexdigest()
def query():
print("What message would you like to query a tag for?")
print("Enter message hex-encoded:")
hex_message = input()
message = bytes.fromhex(hex_message)
QUERIED.add(message)
print("Tag:", nmac(message))
def challenge():
print("Challenge time!")
print("Enter message hex-encoded:")
hex_message = input()
tag = input("Tag: ")
message = bytes.fromhex(hex_message)
if message in QUERIED:
print("You already queried that message!")
elif nmac(message) == tag:
print("Nice job!")
print("Flag:", FLAG)
while True:
print("What do you want to do?")
print("1) Query a message")
print("2) Challenge")
match input():
case "1":
query()
case "2":
challenge()
break
case _:
print("???")