#!/usr/bin/env python3 from urllib.request import urlopen, build_opener, install_opener, Request, BaseHandler from http.server import BaseHTTPRequestHandler, HTTPServer from base64 import b64decode, b64encode from binascii import hexlify, unhexlify host = "localhost" port = 80 class HTTPErrorIgnore(BaseHandler): def http_response(self, request, response): return response install_opener(build_opener(HTTPErrorIgnore)) class Server(BaseHTTPRequestHandler): def do_GET(self): print(self.path) print(self.headers) self.send_response(200) self.end_headers() def do_POST(self): path = self.path if path.startswith("////////"): path = path[8:] print(path) print(self.headers) body = self.rfile.read(int(self.headers.get("Content-Length"))) if path != "/login": data = bytearray(b64decode(body)) # if data[0] == 4: # text = unhexlify("C8BFD0BFCC00C1C9C8C8BB00C1C3D0BF00D3C9CF00CFCAFF") # for i, x in enumerate(text): # data[4+i] = x # new = bytearray(unhexlify("02fad7c9ef7ffff76fa0ffff000000000000000000000000000000000000000000000000")) # new[1] = data[1] # new[2] = data[2] # new[3] = data[3] # data = new # data[4] = 0x00 # data[5] = 0x00 # data[6] = 0x00 # data[7] = 0x00 print(hexlify(data).decode()) body = b64encode(data) print(body) print("====") r = Request("https://fools2022.online" + path, data=body) for header in self.headers: r.add_header(header, self.headers.get(header)) req = urlopen(r) res = req.read() # print(req.code) print(req.headers) print(res) print() self.send_response(req.code) for header in req.headers: if header == "Transfer-Encoding": continue self.send_header(header, req.headers.get(header)) self.end_headers() self.wfile.write(res) if __name__ == "__main__": server = HTTPServer((host, port), Server) server.serve_forever()