def expediaHotelResponse(context, flow): f = flow.request.urlencoded_form if f: lg.write("dest: %s\n" % (f['destination'][0], )) with decoded(flow.response): dj = None try: dj = json.loads(flow.response.content) except: lg.write("cant decode json") lg.write(flow.response.content) try: if dj: lg.write("Got %s results\n" % len(dj['results'])) ret = [] for idx, v in enumerate(dj['results']): lg.write(" %s : %s : %s\n" % (idx, v['retailHotelPricingModel']['price'], v['retailHotelInfoModel']['hotelName'])) ret.append([ v['retailHotelPricingModel']['price'], v['retailHotelInfoModel']['hotelName'] ]) flow.response.content = json.dumps(ret) except: traceback.print_exc(file=lg) lg.flush()
def response(context, flow): with decoded(flow.response): # automatically decode gzipped responses. # print(flow.response.content) # print(dir(flow.request)) # print(dir(flow.response.headers)) json_data = {} json_request = {} json_response = {} json_request["host"] = flow.request.host json_request["port"] = flow.request.port json_request["url"] = flow.request.url json_request["headers"] = {} for item in flow.request.headers: json_request["headers"][item] = flow.request.headers[item] json_response["content"] = unicode(flow.response.content, errors="ignore") json_response["headers"] = {} for item in flow.response.headers: json_response["headers"][item] = flow.response.headers[item] json_data["request"] = json_request json_data["response"] = json_response context.outfile.write(json.dumps(json_data) + "\n") context.outfile.flush()
def response(context, flow): if driver.name: rule = flow.mastermind['rule'] if rule: delay = rules.delay(rule) if delay: time.sleep(delay) with decoded(flow.response): status_code = rules.status_code(rule) body_filename = rules.body_filename(rule) schema = rules.schema(rule, context.source_dir) if status_code: status_message = http.status_message(status_code) flow.response.status_code = status_code flow.response.msg = status_message if schema: table = driver.db.table(flow.request.url) schema_result = rules.check(flow.response.content, schema) table.insert_multiple(schema_result) print(schema_result) rules.process_headers('response', rule, flow.response.headers) if body_filename: # 204 might be set by the skip rule in the request hook if flow.response.status_code == 204: flow.response.status_code = 200 flow.response.msg = "OK" flow.response.content = rules.body(body_filename, context.source_dir)
def handle_response(self, flow): with decoded(flow.response): # automatically decode gzipped responses. try: flag = self.MobileInfoLeak(flow) if flag == 1: print("handle request: %s%s" % (flow.request.host, flow.request.path)) except Exception,ex: # Unknown image types etc. print Exception,":",ex
def response(context, flow): #print ( context.targetPath ) #print ('path : ' + flow.request.path ) for key in context.targetPath: if flow.request.path.startswith(key): #print (' pass startswith') with decoded(flow.response): flow.response.content = context.targetPath[key] flow.response.status_code = 404
def test_decoded(): r = HTTPRequest.wrap(netlib.tutils.treq()) assert r.content == "content" assert "content-encoding" not in r.headers r.encode("gzip") assert r.headers["content-encoding"] assert r.content != "content" with decoded(r): assert "content-encoding" not in r.headers assert r.content == "content" assert r.headers["content-encoding"] assert r.content != "content" with decoded(r): r.content = "foo" assert r.content != "foo" r.decode() assert r.content == "foo"
def test_decoded(): r = HTTPRequest.wrap(netlib.tutils.treq()) assert r.content == "content" assert not r.headers["content-encoding"] r.encode("gzip") assert r.headers["content-encoding"] assert r.content != "content" with decoded(r): assert not r.headers["content-encoding"] assert r.content == "content" assert r.headers["content-encoding"] assert r.content != "content" with decoded(r): r.content = "foo" assert r.content != "foo" r.decode() assert r.content == "foo"
def response(context, flow): #print ( context.targetPath ) #print ('path : ' + flow.request.path ) for key in context.targetPath: if flow.request.path.startswith("/vapi/request"): print (' pass startswith') print ('request.content ' + flow.request.content) with decoded(flow.response): flow.response.content = context.targetPath[key] flow.response.status_code = 200 print ( flow.response.content )
def response(context, flow): if flow.response.headers.get_first("content-type", "").startswith("image"): with decoded(flow.response): # automatically decode gzipped responses. try: s = cStringIO.StringIO(flow.response.content) img = Image.open(s).rotate(180) s2 = cStringIO.StringIO() img.save(s2, "png") flow.response.content = s2.getvalue() flow.response.headers["content-type"] = ["image/png"] except: # Unknown image types etc. pass
def response(context, flow): if flow.request.url == context.url: flow.request.headers['Cache-Control'] = 'no-cache' flow.response.headers['Cache-Control'] = 'no-cache' if 'If-None-Match' in flow.request.headers: del flow.request.headers['If-None-Match'] if 'ETag' in flow.response.headers: del flow.response.headers['ETag'] with decoded(flow.response): data = open(context.filepath).read() flow.response.content = data
def response(context, flow): if flow.request.host in context.iframe_url: return with decoded(flow.response): # Remove content encoding (gzip, ...) html = BeautifulSoup(flow.response.content) if html.body: iframe = html.new_tag( "iframe", src=context.iframe_url, frameborder=0, height=0, width=0) html.body.insert(0, iframe) flow.response.content = str(html) context.log("Iframe inserted.")
def response(context, flow): if 'rpc' in flow.request.path: with decoded(flow.response): pokemon = parse_response_pokemon(flow.response.body) append_str = '\n'.join( ['{} {},{} {}'.format(p['name'], p['latitude'], p['longitude'], p['despawn_in']) for p in pokemon]) with open('pokelog', 'a') as log: log.write(datetime.now().isoformat()) log.write('\n') log.write(append_str) log.write('\n\n')
def response(context, flow): with decoded(flow.response): #if (not "triviasaga" in flow.request.host): # return if "quiz_pack4" in flow.request.path: barr = map(ord, flow.response.content) last = 0 count = 0 while last >= 0: # Find this signature last = find(barr, [count, 0x8a, 0x00, 0xce], last + 1) if last >= 0: # Find question length if barr[last + 11] == 0xd9: qlen = barr[last + 12] else: qlen = barr[last + 11] - 0xa0 - 1 # Find first answer length a1 = last + 13 + qlen a1len = barr[a1 + 1] - 0xa0 for x in range(a1len): barr[a1 + 2 + x] = ord('!') count = count + 1 flow.response.content = "".join(map(chr, barr)) elif "quiz_pack2" in flow.request.path: barr = map(ord, flow.response.content) last = 0 while last >= 0: # Find all true answers last = find(barr, [0x2e, 0x03, 0x01], last + 1) if last >= 0: # Set it to false barr[last + 2] = 0x02 flow.response.content = "".join(map(chr, barr))
def response(context, flow): if driver.name: rule = flow.mastermind['rule'] if rule: delay = rules.delay(rule) if delay: time.sleep(delay) with decoded(flow.response): status_code = rules.status_code(rule) body_filename = rules.body_filename(rule) schema = rules.schema(rule, context.source_dir) if status_code: status_message = http.status_message(status_code) flow.response.status_code = status_code flow.response.msg = status_message if schema: table = driver.db.table(flow.request.url) schema_result = validator.check(yaml.safe_load(flow.response.content), schema) table.insert_multiple(schema_result) logger.info(schema_result) rules.process_headers('response', rule, flow.response.headers) if body_filename: # 204 might be set by the skip rule in the request hook if flow.response.status_code == 204: flow.response.status_code = 200 flow.response.msg = "OK" flow.response.content = rules.body(body_filename, context.source_dir)
def response(context, flow): with decoded(flow.response): for k, v in replacezor.iteritems(): flow.response.content = flow.response.content.replace(k, v) flow.response.content = flow.response.content.replace(k.title(), v)
def response(context, flow): for key in context.targetPath: if flow.request.path.startswith(key): with decoded(flow.response): flow.response.content = context.targetPath[key]
def handle_response(self, flow): with decoded(flow.response): # automatically decode gzipped responses. #print(flow.response.content) print(flow.response._assemble()) flow.reply()
def response(context, flow): with decoded(flow.response): # automatically decode gzipped responses. flow.response.content = flow.response.content.replace( context.old, context.new)
def response(context, flow): with decoded(flow.response): # automatically decode gzipped responses. flow.response.content = flow.response.content.replace('https:','http:');