def _request_prologue(self): self.r = self.server.pre_func(self.r) ui_lock.acquire() # before apply rules to allow auto forward if self.server._BaseServer__shutdown_request: return "d", "d", True pre_action, automated = self._apply_rules(self.r) alerts = self.server.alerter.analyse_request(self.r) if pre_action == "a": flush_input() if not alerts: e = raw_input(self._str_request(extra=" ? ", rl=True)) else: print self._str_request() for al in alerts: print " " * len(self.pt), " |", al e = raw_input(" " * len(self.pt) + " ?") else: e = pre_action if not automated or self.server.verbose: print self._str_request(extra=" " + e) for al in alerts: print " " * len(self.pt), " |", al if not automated: self.server.reqs.append(self.r) return pre_action, e, automated
def handle_one_request(self): """ Accept a request, enable the user to modify, drop or forward it. """ if self.server.persistent: self.close_connection = 0 try: self.r = self._read_request() if not self.r: return False pre_action, e, automated = self._request_prologue() while True: if self.r.method == "CONNECT" and (self.server.auto or (e == "" or e == "b")): ui_lock.release() self.r = self._bypass_ssl(self.r.hostname, self.r.port, proxy_aware=True) if not self.r: return False pre_action, e, automated = self._request_prologue() continue if self.r.method == "CONNECT" and e == "l": ui_lock.release() self._forward_ssl(self.r.hostname, self.r.port) return False if e == "v": print str(self.r) if e == "s": print self.r.repr() if e == "h": print self.r.__str__(headers_only=True) if e == "e": self.r.edit() if e == "d": ui_lock.release() return False if self.server.auto or e == "" or e == "f": break if e == "c": self.server.auto = True if self.r.method == "CONNECT": continue else: break if e == "de": if self.r.content: print self.server.decode_func(self.r.content) else: print "no content to decode" if e == "n": ui_lock.release() time.sleep(1) ui_lock.acquire() print self._str_request() flush_input() if self.r.method == "CONNECT": e = raw_input( "[b]ypass, (l)ink, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (n)ext? " ) else: e = raw_input( "[f]orward, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (de)code, (n)ext? " ) if self.server.verbose >= 2: print self.r ui_lock.release() if not self._do_connection(): return False ui_lock.acquire() self.r.response = self.server.post_func(self.r.response) if not automated or self.server.verbose: if pre_action == "a" and not self.server.auto: flush_input() e = raw_input(self.pt + " " + self.r.response.repr(rl=True) + " ? ") while True: if e == "v": print str(self.r.response) if e == "s": print self.r.repr() print self.r.response.repr() if e == "h": print self.r.response.__str__(headers_only=True) if e == "e": self.r.response.edit() if e == "d": ui_lock.release() return False if e == "" or e == "f": break if e == "c": self.server.auto = True break if e == "de": if self.r.response.content: print self.server.decode_func( self.r.response.content) else: print "no content to decode" if e == "n": ui_lock.release() time.sleep(1) ui_lock.acquire() print self.pt, self.r.response.repr() flush_input() e = raw_input( "[f]orward, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (de)code, (n)ext? " ) else: print self.pt, repr(self.r.response) for al in self.server.alerter.analyse_response(self.r): print " " * len(self.pt), " |", al if self.server.verbose >= 3: print self.r.response ui_lock.release() if not hasattr(self, "chunk_written"): self.wfile.write(self.r.response.raw()) return True except ssl.SSLError as e: self.close_connection = 1 ui_lock.acquire() if "certificate verify failed" in str(e): print self.pt, "<" + warning("SSLError") + ": Unable to verify the CA " + \ "chain. Is conf.ssl_verify set properly? >" else: print self.pt, "<" + warning("SSLError") + ": " + str(e) + ">" ui_lock.release() except NotConnected as e: self.close_connection = 1 except (UnableToConnect, socket.timeout, ProxyError) as e: self.close_connection = 1 ui_lock.acquire() print self.pt, repr(e) ui_lock.release() return False
def handle_one_request(self): """ Accept a request, enable the user to modify, drop or forward it. """ if self.server.persistent: self.close_connection = 0 try: self.r = self._read_request() if not self.r: return False pre_action, e, automated = self._request_prologue() while True: if self.r.method == "CONNECT" and (self.server.auto or (e == "" or e == "b")): ui_lock.release() self.r = self._bypass_ssl(self.r.hostname, self.r.port, proxy_aware=True) if not self.r: return False pre_action, e, automated = self._request_prologue() continue if self.r.method == "CONNECT" and e == "l": ui_lock.release() self._forward_ssl(self.r.hostname, self.r.port) return False if e == "v": print str(self.r) if e == "s": print self.r.repr() if e == "h": print self.r.__str__(headers_only=True) if e == "e": self.r.edit() if e == "d": ui_lock.release() return False if self.server.auto or e == "" or e == "f": break if e == "c": self.server.auto = True if self.r.method == "CONNECT": continue else: break if e == "de": if self.r.content: print self.server.decode_func(self.r.content) else: print "no content to decode" if e == "n": ui_lock.release() time.sleep(1) ui_lock.acquire() print self._str_request() flush_input() if self.r.method == "CONNECT": e = raw_input("[b]ypass, (l)ink, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (n)ext? ") else: e = raw_input("[f]orward, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (de)code, (n)ext? ") if self.server.verbose >= 2: print self.r ui_lock.release() if not self._do_connection(): return False ui_lock.acquire() if not automated or self.server.verbose: if pre_action == "a" and not self.server.auto: flush_input() e = raw_input(self.pt + " " + self.r.response.repr(rl=True) + " ? ") while True: if e == "v": print str(self.r.response) if e == "s": print self.r.repr() print self.r.response.repr() if e == "h": print self.r.response.__str__(headers_only=True) if e == "e": self.r.response.edit() if e == "d": ui_lock.release() return False if e == "" or e == "f": break if e == "c": self.server.auto = True break if e == "de": if self.r.response.content: print self.server.decode_func(self.r.response.content) else: print "no content to decode" if e == "n": ui_lock.release() time.sleep(1) ui_lock.acquire() print self.pt, self.r.response.repr() flush_input() e = raw_input("[f]orward, (d)rop, (c)ontinue, (v)iew, (h)eaders, (e)dit, (de)code, (n)ext? ") else: print self.pt, repr(self.r.response) for al in self.server.alerter.analyse_response(self.r): print " " * len(self.pt), " |", al if self.server.verbose >= 3: print self.r.response ui_lock.release() if not hasattr(self, "chunk_written"): self.wfile.write(self.r.response.raw()) return True except ssl.SSLError as e: self.close_connection = 1 ui_lock.acquire() if "certificate verify failed" in str(e): print self.pt, "<" + warning("SSLError") + ": Unable to verify the CA " + \ "chain. Is conf.ssl_verify set properly? >" else: print self.pt, "<" + warning("SSLError") + ": " + str(e) + ">" ui_lock.release() except NotConnected as e: self.close_connection = 1 except (UnableToConnect, socket.timeout, ProxyError) as e: self.close_connection = 1 ui_lock.acquire() print self.pt, repr(e) ui_lock.release() return False