def handleHeader(self, key, values): keyLower = key.lower() # some headers does not allow multiple occurrences # in case of multiple occurrences we evaluate only the first valueLower = values[0].lower() if keyLower == 'transfer-encoding' and valueLower == 'chunked': return elif keyLower == 'content-encoding' and valueLower == 'gzip': self.obj.server_response_is_gzip = True return elif keyLower == 'content-type' and re.search('text/html', valueLower): self.obj.html = True elif keyLower == 'content-length': self.receivedContentLen = valueLower return elif keyLower == 'cache-control': return if keyLower in 'location': fixed_values = [] for value in values: value = re_sub(rexp['t2w'], r'https://\2.' + config.basehost, value) fixed_values.append(value) values = fixed_values self.responseHeaders.setRawHeaders(key, values)
def handleHeader(self, key, values): keyLower = key.lower() # some headers does not allow multiple occurrences # in case of multiple occurrences we evaluate only the first valueLower = values[0].lower() if keyLower == 'transfer-encoding' and valueLower == 'chunked': return elif keyLower == 'content-encoding' and valueLower == 'gzip': self.obj.server_response_is_gzip = True return elif keyLower == 'content-type' and re.search('text/html', valueLower): self.obj.html = True elif keyLower == 'content-length': self.receivedContentLen = valueLower return elif keyLower == 'cache-control': return if keyLower in ('location'): fixed_values = [] for value in values: value = re_sub(rexp['t2w'], r'https://\2.' + config['basehost'], value) fixed_values.append(value) values = fixed_values self.responseHeaders.setRawHeaders(key, values)
def handleFixPart(self, data): if self.obj.server_response_is_gzip: data = self.unzip(data) data = self.stream + data if len(data) >= 1000: if not self.header_injected and data.find("<body") != -1: banner = yield flattenString(self, templates['banner.tpl']) data = re.sub(rexp['body'], partial(self.add_banner, banner), data) self.header_injected = True data = re_sub(rexp['t2w'], r'https://\2.' + config['basehost'], data) self.forwardData(self.handleCleartextForwardPart(data[:-500])) self.stream = data[-500:] else: self.stream = data
def handleFixEnd(self, data): if self.obj.server_response_is_gzip: data = self.unzip(data, True) data = self.stream + data data = re_sub(rexp['t2w'], r'https://\2.' + config.basehost, data) if not self.header_injected and data.find("<body") != -1: banner = yield flattenString(self, templates['banner.tpl']) data = re.sub(rexp['body'], partial(self.add_banner, banner), data) self.header_injected = True data = self.handleCleartextForwardPart(data, True) self.forwardData(data, True) self.stream = '' try: self.finish() except Exception: pass
def handleFixEnd(self, data): if self.obj.server_response_is_gzip: data = self.unzip(data, True) data = self.stream + data if not self.header_injected and data.find("<body") != -1: banner = yield flattenString(self, templates['banner.tpl']) data = re.sub(rexp['body'], partial(self.add_banner, banner), data) self.header_injected = True data = re_sub(rexp['t2w'], r'https://\2.' + config['basehost'], data) data = self.handleCleartextForwardPart(data, True) self.forwardData(data, True) self.stream = '' try: self.finish() except: pass
def process_request(self, req): """ This function: - "resolves" the address; - alters and sets the proper headers. """ t2w_log(req) self.obj.host_tor = "http://" + self.obj.onion self.obj.host_tor2web = "https://" + self.obj.onion.replace( ".onion", "") + "." + config['basehost'] self.obj.address = "http://" + self.obj.onion + self.obj.uri self.obj.headers = req.headers t2w_log("Headers before fix:") t2w_log(self.obj.headers) self.obj.headers.removeHeader(b'if-modified-since') self.obj.headers.removeHeader(b'if-none-match') self.obj.headers.setRawHeaders(b'host', [self.obj.onion]) self.obj.headers.setRawHeaders(b'connection', [b'keep-alive']) self.obj.headers.setRawHeaders(b'Accept-encoding', [b'gzip, chunked']) self.obj.headers.setRawHeaders(b'x-tor2web', [b'encrypted']) for key, values in self.obj.headers.getAllRawHeaders(): fixed_values = [] for value in values: value = re_sub(rexp['w2t'], r'http://\2.onion', value) fixed_values.append(value) self.obj.headers.setRawHeaders(key, fixed_values) t2w_log("Headers after fix:") t2w_log(self.obj.headers) return True
def process_request(self, req): """ This function: - "resolves" the address; - alters and sets the proper headers. """ rpc_log(req) self.obj.host_tor = "http://" + self.obj.onion self.obj.host_tor2web = "https://" + self.obj.onion.replace(".onion", "") + "." + config.basehost self.obj.address = "http://" + self.obj.onion + self.obj.uri self.obj.headers = req.headers rpc_log("Headers before fix:") rpc_log(self.obj.headers) self.obj.headers.removeHeader(b'if-modified-since') self.obj.headers.removeHeader(b'if-none-match') self.obj.headers.setRawHeaders(b'host', [self.obj.onion]) self.obj.headers.setRawHeaders(b'connection', [b'keep-alive']) self.obj.headers.setRawHeaders(b'Accept-encoding', [b'gzip, chunked']) self.obj.headers.setRawHeaders(b'x-tor2web', [b'encrypted']) for key, values in self.obj.headers.getAllRawHeaders(): fixed_values = [] for value in values: value = re_sub(rexp['w2t'], r'http://\2.onion', value) fixed_values.append(value) self.obj.headers.setRawHeaders(key, fixed_values) rpc_log("Headers after fix:") rpc_log(self.obj.headers) return True