def response(context, flow): direction = "RESPONSE" if "all" in conf and "nocache" in conf["all"]: nocache(flow) has_resp = len([ 1 for v in conf.values() if "response" in v or "nocache" in v ])>0 if has_resp: original = flow.original original_resp = flow.response.copy() for k in conf.keys(): conf1 = conf[k] if "nocache" in conf1: nocache(flow) escape_match = False try: escape_match = original.match(re.escape(k)) except Exception as e: pass if k == "all" or escape_match or original.match(k): if "response" in conf1: if "header" in conf1["response"]: headers = conf1["response"]["header"] process_headers(flow, headers, direction) if "body" in conf1["response"]: body = conf1["response"]["body"] process_body(flow, body, direction) har_extractor.response(context,flow)
def response(flow): direction = "RESPONSE" if "all" in conf and "nocache" in conf["all"]: nocache(flow) has_resp = len([ 1 for v in conf.values() if "response" in v or "nocache" in v ])>0 if has_resp: original = flow.original original_resp = flow.response.copy() for k in conf.keys(): conf1 = conf[k] if "nocache" in conf1: nocache(flow) escape_match = False try: escape_match = re.match(re.escape(k), original.request.url) except Exception as e: pass if k == "all" or escape_match or re.match(k, original.request.url): if "response" in conf1: if "header" in conf1["response"]: headers = conf1["response"]["header"] process_headers(flow, headers, direction) if "body" in conf1["response"]: body = conf1["response"]["body"] process_body(flow, body, direction) har_extractor.response(flow)
def request(context, flow): direction = "REQUEST" q = flow.request.get_query() flow.original = flow.copy() original = flow.original changed_q = False changed_h = False changed_host = False changed_path = False for k in conf.keys(): conf1 = conf[k] escape_match = False try: escape_match = original.match(re.escape(k)) except Exception as e: pass if k == "all" or escape_match or k and original.match(k): if "request" in conf1 and "path" in conf1["request"]: path = conf1["request"]["path"] if "replace" in path: path = path["replace"] flow.request.path = realv(path, context, flow) changed_path = True if "request" in conf1 and "protocol" in conf1["request"]: protocol = conf1["request"]["protocol"] if "replace" in protocol: protocol = protocol["replace"] flow.request.scheme = realv(protocol, context, flow) if "request" in conf1 and "port" in conf1["request"]: port = conf1["request"]["port"] if "replace" in port: port = port["replace"] flow.request.port = realv(port, context, flow) if "request" in conf1 and "host" in conf1["request"]: host = conf1["request"]["host"] if "replace" in host: host = host["replace"] flow.request.host = realv(host, context, flow) changed_host = True if "request" in conf1 and "query" in conf1["request"]: query = conf1["request"]["query"] if "replace" in query: query = query["replace"] for k,v in query.items(): q[k] = [realv(v, context, flow)] changed_q = True if "request" in conf1 and "redirect" in conf1["request"]: redirect = conf1["request"]["redirect"] redirect = realv(redirect, context, flow) resp = HTTPResponse( b"HTTP/1.1", 302, b"OK", Headers(Location=redirect.encode('utf-8')), b"" ) flow.reply(resp) if "request" in conf1 and "header" in conf1["request"]: headers = conf1["request"]["header"] changed_h = changed_h or process_headers(flow, headers, direction) if "request" in conf1 and "body" in conf1["request"]: body = conf1["request"]["body"] process_body(flow, body, direction) if changed_q: flow.request.set_query(q) if changed_h: print(flow.request.headers) if changed_host: flow.request.update_host_header()
def request(flow): direction = "REQUEST" q = flow.request.query flow.original = flow.copy() original = flow.original changed_q = False changed_h = False changed_host = False changed_path = False for k in conf.keys(): conf1 = conf[k] escape_match = False try: escape_match = re.match(re.escape(k), original.request.url) except Exception as e: pass if k == "all" or escape_match or k and re.match(k, original.request.url): if "request" in conf1 and "path" in conf1["request"]: path = conf1["request"]["path"] if "replace" in path: path = path["replace"] flow.request.path = realv(path, flow) changed_path = True if "request" in conf1 and "protocol" in conf1["request"]: protocol = conf1["request"]["protocol"] if "replace" in protocol: protocol = protocol["replace"] flow.request.scheme = realv(protocol, flow) if "request" in conf1 and "port" in conf1["request"]: port = conf1["request"]["port"] if "replace" in port: port = port["replace"] flow.request.port = realv(port, flow) if "request" in conf1 and "host" in conf1["request"]: host = conf1["request"]["host"] if "replace" in host: host = host["replace"] flow.request.host = realv(host, flow) changed_host = True if "request" in conf1 and "query" in conf1["request"]: query = conf1["request"]["query"] if "replace" in query: query = query["replace"] for k,v in query.items(): q[k] = [realv(v, flow)] changed_q = True if "request" in conf1 and "redirect" in conf1["request"]: redirect = conf1["request"]["redirect"] redirect = realv(redirect, flow) resp = HTTPResponse( b"HTTP/1.1", 302, b"OK", Headers(Location=redirect.encode('utf-8')), b"" ) flow.reply(resp) if "request" in conf1 and "header" in conf1["request"]: headers = conf1["request"]["header"] changed_h = changed_h or process_headers(flow, headers, direction) if "request" in conf1 and "body" in conf1["request"]: body = conf1["request"]["body"] process_body(flow, body, direction) if changed_q: flow.request.set_query(q) if changed_h: print(flow.request.headers) if changed_host: flow.request.update_host_header()