-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmitmproxy.sh
198 lines (189 loc) · 5.87 KB
/
mitmproxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
_patch_table() {
_patch_table_edit_options \
'--certs;*[`_choice_cert`]' \
'--mode;[`_choice_mode`]' \
'--modify-body;*[`_choice_modify_body`]' \
'--modify-headers;*[`_choice_modify_headers`]' \
'--save-stream-file;[`_choice_appendable_file`]' \
'--set;*[`_choice_option`]' \
}
_choice_option() {
_argc_util_mode_kv =
if [[ -z "$argc__kv_prefix" ]]; then
mitmproxy --options | \
yq 'to_entries | .[] | .type = (.value | type) | .key + ";" + .type' | \
sed -e 's/;!!bool//' -e 's/;!!.*$/=\x00/'
else
case "$argc__kv_key" in
confdir)
echo __argc_value=dir
;;
connection_strategy)
printf "%s\n" eager lazy
;;
console_default_contentview)
printf "%s\n" 'auto' 'raw' 'hex' 'graphql' 'json' 'xml/html' 'wbxml' 'javascript' \
'css' 'url-encoded' 'multipart form' 'image' 'query' 'protocol buffer' \
'msgpack' 'grpc/protocol buffer' 'mqtt'
;;
console_eventlog_verbosity)
printf "%s\n" 'error' 'warn' 'info' 'alert' 'debug'
;;
console_flowlist_layout)
printf "%s\n" 'default' 'list' 'table'
;;
console_layout)
printf "%s\n" 'horizontal' 'single' 'vertical'
;;
console_palette)
printf "%s\n" 'dark' 'light' 'lowdark' 'lowlight' 'solarized_dark' 'solarized_light'
;;
tls_version_client_max|tls_version_client_min|tls_version_server_max|tls_version_server_min)
printf "%s\n" 'UNBOUNDED' 'SSL3' 'TLS1' 'TLS1_1' 'TLS1_2' 'TLS1_3'
;;
view_order)
printf "%s\n" 'time' 'method', 'url', 'size'
;;
esac
fi
}
_choice_mode() {
printf "%s\n" regular transparent socks5
echo -e "reverse:\0"
echo -e "upstream:\0"
}
_choice_appendable_file() {
if [[ "$ARGC_CWORD" == '+'* ]]; then
_argc_util_comp_path prefix=+ filter="${ARGC_CWORD:1}"
else
_argc_util_comp_path
fi
}
_choice_cert() {
_argc_util_mode_kv =
if [[ -z "$argc__kv_prefix" ]]; then
_argc_util_comp_path
else
_argc_util_comp_path prefix="$argc__kv_prefix" filter="$argc__kv_filter"
fi
}
_choice_modify_body() {
_helper_three_parts_mode
if [[ -z "$argc__3p_count" ]]; then
return
fi
if [[ "$argc__3p_count" -eq 1 ]]; then
if [[ "${argc__3p_parts[0]}" == '~'* ]]; then
echo __argc_prefix="${argc__3p_prefix}~"
echo __argc_filter="${argc__3p_filter:1}"
_choice_flow_filter | _argc_util_transform nospace
fi
elif [[ "${argc__3p_filter:0:1}" == "@" ]]; then
_argc_util_comp_path prefix="${argc__3p_prefix}@" filter="${argc__3p_filter:1}"
fi
}
_choice_modify_headers() {
_helper_three_parts_mode
if [[ -z "$argc__3p_count" ]]; then
return
fi
if [[ "$argc__3p_count" -eq 1 ]]; then
if [[ "${argc__3p_parts[0]}" == '~'* ]]; then
echo __argc_prefix="${argc__3p_prefix}~"
echo __argc_filter="${argc__3p_filter:1}"
_choice_flow_filter | _argc_util_transform nospace
fi
elif [[ "$argc__3p_count" -eq 2 ]]; then
ARGC_CWORD="$argc__3p_filter" SEP="$argc__3p_sep" _module_http_header
echo __argc_prefix="${argc__3p_prefix}"
else
if [[ "${argc__3p_filter:0:1}" == "@" ]]; then
_argc_util_comp_path prefix="${argc__3p_prefix}@" filter="${argc__3p_filter:1}"
else
ARGC_CWORD="${argc__3p_parts[1]}$argc__3p_sep$argc__3p_filter" SEP="$argc__3p_sep" _module_http_header
echo __argc_prefix="${argc__3p_prefix}"
fi
fi
}
_choice_flow_filter() {
cat <<-'EOF'
a Match asset in response: CSS, JavaScript, images, fonts
all Match all flows
b Body
bq Request body
bs Response body
c HTTP response code
comment Flow comment
d Domain
dns Match DNS flows
dst Match destination address
e Match error
h Header
hq Request header
hs Response header
http Match HTTP flows
m Method
marked Match marked flows
marker Match marked flows with specified marker
meta Flow metadata
q Match request with no response
replay Match replayed flows
replayq Match replayed client request
replays Match replayed server response
s Match response
src Match source address
t Content-type header
tcp Match TCP flows
tq Request Content-Type header
ts Response Content-Type header
u URL
websocket Match WebSocket flows
EOF
}
_helper_three_parts_mode() {
local values IFS
IFS=$'\n'
if [[ -z "$ARGC_CWORD" ]]; then
return
fi
values=( $(gawk -v VALUE="$ARGC_CWORD" 'BEGIN {
if (VALUE != "") {
sep = substr(VALUE, 1, 1)
split(VALUE, arr, sep)
arrLen = length(arr)
if (arrLen > 4) {
count = 3
} else {
count = arrLen - 1
}
print count
print sep
for (i = 1; i <= count; i++) {
out = out arr[i] sep
}
print out
for (i = 2; i <= arrLen; i++) {
if (i <= count) {
print arr[i]
} else {
if (last == "") {
last = arr[i]
} else {
last = last sep arr[i]
}
}
}
if (last != "") {
print last
}
}
}') )
argc__3p_count="${values[0]}"
argc__3p_sep="${values[1]}"
argc__3p_prefix="${values[2]}"
argc__3p_parts=( ${values[@]:3} )
if [[ ${#argc__3p_parts[@]} -ne $argc__3p_count ]]; then
argc__3p_parts+=( "" )
fi
argc__3p_filter="${argc__3p_parts[-1]}"
}