Skip to content

Commit 3f4a28a

Browse files
authored
Merge pull request #12 from MobSF/bump
Migrate to mitmproxy 11.0.0
2 parents 33cc04e + 83241c7 commit 3f4a28a

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed

.github/workflows/python-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
max-parallel: 4
1515
matrix:
16-
python-version: ['3.10', '3.11']
16+
python-version: ['3.10', '3.11', '3.12']
1717

1818
steps:
1919
- uses: actions/checkout@v2

http_tools/modules/upstream.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Upstream proxy module."""
2+
3+
import http_tools.settings as settings
4+
5+
from mitmproxy import ctx
6+
from mitmproxy import http
7+
from mitmproxy.connection import Server
8+
from mitmproxy.net.server_spec import ServerSpec
9+
10+
11+
def load(loader):
12+
loader.add_option(
13+
name='proxy_ip',
14+
typespec=str,
15+
default='127.0.0.1',
16+
help='Upstream Proxy IP',
17+
)
18+
loader.add_option(
19+
name='proxy_port',
20+
typespec=int,
21+
default=8000,
22+
help='Upstream Proxy Port',
23+
)
24+
25+
26+
def request(flow: http.HTTPFlow) -> None:
27+
if (flow.request.url.endswith('/kill')
28+
and flow.request.method == 'GET'
29+
and flow.request.port == settings.PROXY_PORT):
30+
# Prevent killing the proxy server
31+
flow.kill()
32+
33+
address = (ctx.options.proxy_ip, ctx.options.proxy_port)
34+
# Check if the server connection already exists
35+
if flow.server_conn.timestamp_start:
36+
# Replace the existing server connection with a new one
37+
flow.server_conn = Server(address=flow.server_conn.address)
38+
39+
# Set the upstream proxy (via) server
40+
flow.server_conn.via = ServerSpec(('http', address))

http_tools/web/controllers/dashboard.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import glob
66
from pathlib import PurePath
7+
from urllib.parse import urlparse
78
import subprocess
89
import threading
910

@@ -67,11 +68,21 @@ def post(self, project):
6768
self.write({'error': 'No requests found for the project'})
6869
return
6970
proxy = self.get_argument('proxy', default='http://127.0.0.1:8080')
71+
parsed_url = urlparse(proxy)
7072
flow_file = os.path.join(settings.FLOWS_DIR, project + '.flow')
71-
trd = threading.Thread(target=subprocess.call, args=(
72-
['mitmdump', '-k', '-n', '-m',
73-
'upstream:{}'.format(proxy),
74-
'--client-replay', flow_file],))
73+
script_dir = os.path.join(settings.BASE_PATH, 'modules')
74+
# mitmproxy 11.0.0 has issues with client replay and upstream proxy
75+
# See: https://github.com/mitmproxy/mitmproxy/issues/7280
76+
args = ['mitmdump',
77+
'--scripts', os.path.join(script_dir, 'upstream.py'),
78+
'--set', 'connection_strategy=lazy',
79+
'--set', 'upstream_cert=false',
80+
'--set', f'proxy_ip={parsed_url.hostname}',
81+
'--set', f'proxy_port={parsed_url.port}',
82+
'--ssl-insecure',
83+
'--no-server',
84+
'--client-replay', flow_file]
85+
trd = threading.Thread(target=subprocess.call, args=(args,))
7586
trd.setDaemon(True)
7687
trd.start()
7788
self.write({'success': 'Repeating request to upstream'})

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def read(rel_path):
1717
'[mitmproxy](https://mitmproxy.org/)')
1818
setup(
1919
name='http-tools',
20-
version='4.0.0',
20+
version='5.0.0',
2121
description=description,
2222
author='Ajin Abraham',
2323
author_email='[email protected]',
@@ -42,7 +42,7 @@ def read(rel_path):
4242
long_description=read('README.md'),
4343
long_description_content_type='text/markdown',
4444
install_requires=[
45-
'mitmproxy==10.1.5',
46-
'markupsafe>=2.1.3',
45+
'mitmproxy==11.0.0',
46+
'markupsafe>=3.0.2',
4747
],
4848
)

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ skip_install = true
3333
deps =
3434
bandit
3535
commands =
36-
bandit libsast -r
36+
bandit http_tools -r -ll -iii
3737

3838
[testenv:publish]
3939
skip_install = true
@@ -91,4 +91,6 @@ ignore =
9191
# Use python sort imports
9292
SF01,
9393
# Allow Private member access
94+
W503,
95+
# Allow line break before binary operator
9496
radon_max_cc = 10

0 commit comments

Comments
 (0)