-
-
Save HoLyVieR/947bedcb763df27f3e9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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