Captive portal python script for mitmproxy use

h4t4moto

Newbie
Joined
Oct 18, 2024
Messages
3
Reaction score
2
I wrote this captive portal python script with the help of AI, but I need one that works by targeting all url traffic passing through mitmproxy the point is to redirect to the right location which is the ipv4 and port specified
can someone help me that's all I need to do right now.

from mitmproxy import http

# List of blocked sites
BLOCKED_SITES = [
"192.168.1.1", "ebay.com", "doordash.com", "grubhub.com",
"offerup.com", "letgo.com", "uber.com", "gmail.com",
"pizzahut.com", "piratebay.org", "virustotal.com",
"nypost.com", "googleadservices.com", "myspace.com",
"dominos.com", "cityofdenton.com", "dentoncountycrimestoppers.com",
"bustednewspaper.com", "hotspotseatfresh.com"
]

def request(flow: http.HTTPFlow) -> None:
# Check if the request URL matches any in the blocked sites list
for site in BLOCKED_SITES:
if site in flow.request.pretty_host:
# Modify the request to redirect to a different IP
flow.request.scheme = "http"
flow.request.host = "192.168.1.112"
flow.request.port = 80

# Respond with an empty HTML page
flow.response = http.HTTPResponse.make(200, b"", {"Content-Type": "text/html"})
 
Back
Top