Skip to content

Unable to record files properly when in upstream mode.  #5524

Closed

Description

@nicovama

Problem Description

Hi there Mitmproxy community.
Ever since I upgraded to mitmproxy 8.0.0 from 7.0.4, I'm unable to record network properly. Not only do I see the file size is much smaller that it should, but trying to open the file results in an exception.

Unaware if this issue has been resolved in the latest release of mitmproxy. I know the connections.py file has had issues since the major upgrade , but I'm unable to update to 8.1.0 because I have a dependency on python 3.8.

Steps to reproduce the behavior:

  1. Record a file in upstream mode
    Ex: mitmdump -k -v --mode upstream:proxy.net:3000 --listen-host $IP -p $PORT -w recording.bin
  2. Open the recording
    Ex: mitmdump -k -n -r

This results in the following traceback

Traceback (most recent call last):

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/addons/readfile.py", line 71, in doread
    await self.load_flows_from_path(ctx.options.rfile)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/addons/readfile.py", line 94, in load_flows_from_path
    return await super().load_flows_from_path(path)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/addons/readfile.py", line 63, in load_flows_from_path
    return await self.load_flows(f)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/addons/readfile.py", line 45, in load_flows
    for flow in freader.stream():

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/io/io.py", line 48, in stream
    yield FLOW_TYPES[mdata["type"]].from_state(mdata)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/flow.py", line 165, in from_state
    f.set_state(state)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/flow.py", line 160, in set_state
    super().set_state(state)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/stateobject.py", line 47, in set_state
    setattr(self, attr, make_object(cls, val))

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/stateobject.py", line 94, in make_object
    return _process(typeinfo, val, True)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/stateobject.py", line 56, in _process
    return typeinfo.from_state(val)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/connection.py", line 331, in from_state
    server.set_state(state)

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/connection.py", line 353, in set_state
    self.via = state["via2"]

  File "/usr/local/lib/python3.8/site-packages/mitmproxy/connection.py", line 299, in __setattr__
    raise RuntimeError(f"Cannot change server.{name} on open connection.")

RuntimeError: Cannot change server.via on open connection.

System Information

Paste the output of "mitmproxy --version" here.
mitmproxy --version

Mitmproxy: 8.0.0
Python:    3.8.11
OpenSSL:   OpenSSL 1.1.1n  15 Mar 2022
Platform:  Linux

Activity

  1. added
    kind/triage
    on Aug 11, 2022
  2. nicovama commented on Aug 16, 2022

    @nicovama
    Author

    @mhils Could you guide me? I'd like to contribute to a solution but I don't fully understand what is causing the recording to be corrupted (Which causes the -r replay to throw the RunTimeError.)

    When I record something (-w) on mitmproxy==8.0.0 Upstream mode and replay it on 7.0.4 (-n -r), The error message is "File Corrupted"

  3. Prinzhorn commented on Aug 17, 2022

    @Prinzhorn
    Member
  4. Prinzhorn commented on Aug 17, 2022

    @Prinzhorn
    Member

    When I record something (-w) on mitmproxy==8.0.0 Upstream mode and replay it on 7.0.4 (-n -r), The error message is "File Corrupted"

    This is expected behavior as the recordings are not backwards compatible (not necessarily between mitmproxy versions, but when the format changes). It should say something like "please update mitmproxy" when opening with 7.0.4, right?

  5. mhils commented on Aug 17, 2022

    @mhils
    Member

    Related to #5241, but different trigger. Let's keep it open. :)

    @nicovama: In short, the dumpfile is not corrupt, but upon reading we inadvertedly trigger this check which is supposed to catch bugs in addons modifying live flows:

    if connection_open and attr_changed:
    raise RuntimeError(f"Cannot change server.{name} on open connection.")
    . We need to "not do that", I haven't looked closer at the code to figure out how to do this best. :)

  6. reopened this on Aug 17, 2022
  7. nicovama commented on Aug 17, 2022

    @nicovama
    Author

    Thank you @mhils.
    Another unexpected change is that the dump file size changed drastically. In 7.0.4 it was around 5MB, while the same in 8.0.0 was only 1MB.

    I'm going to try to look for a solution.
    Thank you

  8. nicovama commented on Aug 17, 2022

    @nicovama
    Author

    When I record something (-w) on mitmproxy==8.0.0 Upstream mode and replay it on 7.0.4 (-n -r), The error message is "File Corrupted"

    This is expected behavior as the recordings are not backwards compatible (not necessarily between mitmproxy versions, but when the format changes). It should say something like "please update mitmproxy" when opening with 7.0.4, right?

    Thanks for the reply and I guess that makes sense. That is not the error message I see. It just says "File corrupted"

  9. added a commit that references this issue on Nov 28, 2022
    5ec4bbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions