Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
from hashlib import md5
import SocketServer, threading, os
import time
SECRET = os.urandom(32)
FIND_ME = os.urandom(2).encode("hex")
msg = """/------------------------------------------------------------------------------\\
| Welcome Hash Service Challenge |
| |
| md5(SECRET + FIND_ME) = %s ! |
| We let you hash as many md5(SECRET + YOUR_VALUE + TIMESTAMP) |
| You have to find FIND_ME ! |
\______________________________________________________________________________/
""" % (md5(SECRET + FIND_ME).hexdigest())
class threadedserver(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
class incoming(SocketServer.BaseRequestHandler):
def handle(self):
self.request.sendall(msg + "\n")
while True:
self.request.sendall("YOUR_VALUE = ")
val = self.request.recv(1024)
timestamp = int(time.time())
h = md5(SECRET + val + str(timestamp)).hexdigest()
self.request.sendall("HASH = %s TIMESTAMP = %s \n" % (h, timestamp))
SocketServer.TCPServer.allow_reuse_address = True
server = threadedserver(("0.0.0.0", 4322), incoming)
server.timeout = 4
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = False
server_thread.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment