Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def running():
ctx.log.info("stream_modify running")
def request(f):
mitmproxy.ctx.log("XREQUEST")
record.append("request")
def share(self, flows: typing.Sequence[flow.Flow]) -> None:
u_id = "".join(random.choice(string.ascii_lowercase + string.digits)for _ in range(7))
f = io.BytesIO()
stream = mitmproxy.io.FlowWriter(f)
for x in flows:
stream.add(x)
f.seek(0)
content = f.read()
try:
res = self.post_multipart('upload.share.mitmproxy.org.s3.amazonaws.com', u_id, content)
except IOError as v:
ctx.log.warn("%s" % v)
else:
ctx.log.alert("%s" % res)
finally:
f.close()
def start_replay(self, flows: typing.Sequence[flow.Flow]) -> None:
"""
Add flows to the replay queue, skipping flows that can't be replayed.
"""
lst = []
for f in flows:
hf = typing.cast(http.HTTPFlow, f)
err = self.check(hf)
if err:
ctx.log.warn(err)
continue
lst.append(hf)
# Prepare the flow for replay
hf.backup()
hf.request.is_replay = True
hf.response = None
hf.error = None
# https://github.com/mitmproxy/mitmproxy/issues/2197
if hf.request.http_version == "HTTP/2.0":
hf.request.http_version = "HTTP/1.1"
host = hf.request.headers.pop(":authority", None)
if host is not None:
hf.request.headers.insert(0, "host", host)
self.q.put(hf)
ctx.master.addons.trigger("update", lst)
def response(self, flow: http.HTTPFlow) -> None:
try:
if "html" in flow.response.headers["Content-Type"] and len(flow.response.content):
if ctx.options.target in flow.request.host:
html = lxml.html.fromstring(flow.response.content)
the_best_words = set(html.xpath('//text()'))
ctx.log.info(print_good(f"Got {len(the_best_words)} words, the best words..."))
self.words |= the_best_words
except KeyError:
pass
if path.startswith("+"):
append = True
epath = os.path.expanduser(path[1:])
path = mitmproxy.types.Path(epath)
try:
if len(cuts) == 1 and len(flows) == 1:
with open(path, "ab" if append else "wb") as fp:
if fp.tell() > 0:
# We're appending to a file that already exists and has content
fp.write(b"\n")
v = extract(cuts[0], flows[0])
if isinstance(v, bytes):
fp.write(v)
else:
fp.write(v.encode("utf8"))
ctx.log.alert("Saved single cut.")
else:
with open(path, "a" if append else "w", newline='', encoding="utf8") as fp:
writer = csv.writer(fp)
for f in flows:
vals = [extract(c, f) for c in cuts]
writer.writerow(
[strutils.always_str(x) or "" for x in vals] # type: ignore
)
ctx.log.alert("Saved %s cuts over %d flows as CSV." % (len(cuts), len(flows)))
except IOError as e:
ctx.log.error(str(e))
def load_flows_from_path(self, path: str) -> int:
path = os.path.expanduser(path)
try:
with open(path, "rb") as f:
return self.load_flows(f)
except IOError as e:
ctx.log.error("Cannot load flows: {}".format(e))
raise exceptions.FlowReadException(str(e)) from e
def response(flow):
path = flow.request.path
if path == '/index/index_one_nine_five/make_question' or path == '/index/index_one_three_six/make_question':
ctx.log.info('Start')
data = json.loads(flow.response.text)
ctx.log.info(pformat(data))
if type(data) is list:
for m in data:
if type(m) is dict:
m['seconds'] = 20
m['symbol'] = ' 对 ' if m['is_true'] == '1' else ' 错 ' # 直接将答题区运算符号改为答案
if type(data) is dict:
for k, v in data.items():
if type(v) == dict:
v.update({'seconds': 20, 'symbol': ' 对 ' if v['is_true'] == 1 else ' 错 '})
flow.response.text = json.dumps(data)
return
def configure(options, updated):
"""
Called once on script startup before any other events, and whenever options changes.
"""
mitmproxy.ctx.log("configure")
def response(self, flow):
if not ctx.options.corrupt_handshake and "frmall.jar" in flow.request.url:
ctx.log("Serving patched frmall.jar")
patched=open("/tmp/frmall.jar","rb").read()
flow.response.content=patched
flow.response.headers["content-length"] = str(len(patched))
flow.response.status_code=200
return
if b"GDay" in flow.request.content:
self.mate=struct.unpack(">I",flow.response.content[4:8])[0]
ctx.log("Found Mate %s" % repr(flow.response.raw_content))
#Found GDay! be862007
#Found Mate! 000055f0
#RC4 Key: 205fae8605
self.key[0]=(self.gday >> 8) & 0xff
self.key[1]=(self.mate >> 4) & 0xff
self.key[2]=0xae
self.key[3]=(self.gday >> 16) & 0xff