javawindowshttpsman-in-the-middle

Installing mitmproxy on Windows Subsystem for Linux (WSL)


I've been using Fiddler to modify a HTTPS response sent by the server which has been initiated by a POST request of the client which worked fine.

Using Java on Windows I want to implement this same man-in-the-middle attack so I'm looking for code which can handle system wide HTTPS traffic. Importing a certificate into the system's truststore is also necessary but I'm struggling with starting the actual Java code. mitmproxy for instance has a Windows installer but it does not ship the mitmproxy executable so it cannot be used. Also using WSL I get the following Python exception:

$ sudo apt-get -y install mitmproxy
[sudo] password for ubuntu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
mitmproxy is already the newest version (2.0.2-3).
0 upgraded, 0 newly installed, 0 to remove and 106 not upgraded.
root@mypc:~$ mitmproxy --port 1080
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 574, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 783, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (urwid 2.0.1 (/usr/lib/python3/dist-packages), Requirement.parse('urwid<1.4,>=1.3.1'), {'mitmproxy'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/mitmproxy", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3088, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3072, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3101, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 576, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 589, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 778, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urwid<1.4,>=1.3.1' distribution was not found and is required by mitmproxy

LittleProxy-mitm's maven dependency causes a java.lang.NoClassDefFoundError: org/bouncycastle/util/Encodable.

How can I fix these problems or what else can I use to capture and modify any system-wide HTTPS traffic using Java programming? It only needs to work on Windows.


Solution

  • The pip3 installation guide worked:

    sudo apt install python3-pip && sudo pip3 install -U pip && sudo pip3 install mitmproxy
    

    Note: This command applies to Ubuntu.