Skip to content

Instantly share code, notes, and snippets.

@HoLyVieR
Created March 1, 2016 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoLyVieR/947bedcb763df27f3e9a to your computer and use it in GitHub Desktop.
Save HoLyVieR/947bedcb763df27f3e9a to your computer and use it in GitHub Desktop.
#!/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