from http.server import BaseHTTPRequestHandler, HTTPServer
from base64 import b64encode, b64decode

class C2Server(BaseHTTPRequestHandler):
    def do_GET(self):
        #parse headers
        data = b64decode(self.headers["Cookie"]).decode("utf-8").rstrip()
        print(f"Recieved {data}")
        if data == "C2 data":
            response = b64encode(bytes("Recieved","utf-8"))
            self.send_response(200)
            self.end_headers()
            self.wfile.write(response)
        else:
            self.send_errpr(404)

if __name__ == "__main__":
    hostname = "localhost"
    port = 8443
    webServer = HTTPServer((hostname, port), C2Server)
    try:
        webServer.serve_forever()
    except KeyboardInterrupt:
        pass
    webServer.server_close()