I’ve just tried that out, without success. Here’s my short and dirty example:
from libmproxy.script import concurrent
from libmproxy.models import decoded
from amfast import decoder
@concurrent
def request(context, flow):
with decoded(flow.request):
m=decoder.decode_packet(flow.request.content)
try:
for t in range(len(m.messages)):
me=m.messages[t]
if me.body.body['type']<>1001:
flow.live.change_upstream_proxy_server("localhost", 8888)
except:
pass
then I ran mitmdump like:
mitmdump -U http://localhost:5311 -p5310 -s changeupstream.py
assuming that I have one proxy on port 5311 and another on 8888, while setting port 5310 in my browser…
that gave me an unusual error output:
> Exception in thread ScriptThread:
> Traceback (most recent call last):
> File “/usr/lib/python2.7/threading.py”, line 801, in __bootstrap_inner
> self.run()
> File “/usr/lib/python2.7/threading.py”, line 754, in run
> self.__target(*self.__args, **self.__kwargs)
> File “/usr/local/lib/python2.7/dist-packages/libmproxy/script/concurrent.py”, line 35, in run
> fn(*args, **kwargs)
> File “differenttypesviacharles.py”, line 21, in request
> m=decoder.decode_packet(flow.request.content)
> BufferError: Attempted to read past end of buffer.
> 127.0.0.1 POST http:// xxx /GameServer03/amf
> << 200 OK 760B
> Exception in thread ScriptThread:
> Traceback (most recent call last):
> File “/usr/lib/python2.7/threading.py”, line 801, in __bootstrap_inner
> self.run()
> File “/usr/lib/python2.7/threading.py”, line 754, in run
> self.__target(*self.__args, **self.__kwargs)
> File “/usr/local/lib/python2.7/dist-packages/libmproxy/script/concurrent.py”, line 35, in run
> fn(*args, **kwargs)
> File “differenttypesviacharles.py”, line 21, in request
> m=decoder.decode_packet(flow.request.content)
> DecodeError: Unknown client type.
> 127.0.0.1:41154: clientconnect
> 127.0.0.1 POST http:// xxx /GameServer03/amf
> << 200 OK 1.32kB
each time it throws BufferError once, then DecodeError from amfast (while I am sure it works)
I am using mitmproxy 0.16
*update using mitmproxy 0.17:
still nothing, but error message is much shorter:
Script error:
Unknown client type.
(with both versions I tried proxy on port 8888 is not receiving any traffic)