Skip to content

Instantly share code, notes, and snippets.

@sekaiwish
Last active December 17, 2023 12:09
Show Gist options
  • Save sekaiwish/7fa27d2b7d855ea35c09f87a1ce64f8c to your computer and use it in GitHub Desktop.
Save sekaiwish/7fa27d2b7d855ea35c09f87a1ce64f8c to your computer and use it in GitHub Desktop.
MHF HTTP Server
#!/usr/bin/python
import http.server
import socketserver
from urllib.parse import parse_qs
port = 80
print_headers = True
print_params = True
class CustomHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if print_headers:
print('HEADERS:\n', self.headers)
if print_params:
qp = dict()
if '?' in self.path:
path, query_string = self.path.split('?', 1)
for param in query_string.split('&'):
key, value = param.split('=', 1)
qp[key] = value
print('PARAMS:', {k: v for k, v in qp.items()})
fd = open(f".{self.path.partition('?')[0]}", 'rb').read()
self.send_response(200)
self.send_header('Content-Length', len(fd))
self.send_header('Transfer-Encoding', 'chunked')
self.end_headers()
self.wfile.write(fd)
return
Handler = CustomHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()
@sekaiwish
Copy link
Author

Process:

git clone git@github.com:ZeruLight/Servers.git
python mhf_server.py

Create file ...\Servers\v1\crypt\commonkey\rsa and enter JSON response there.

@sekaiwish
Copy link
Author

Seems to want a response with a token like so:

{
    "encrypt_key": "someBase64EncodedKey"
}

but I couldn't get the response to be valid. May need to be hashed with the client_pub_key sent.

@sekaiwish
Copy link
Author

client_pub_key is obfuscated Base64 by swapping + to - and / to _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment