Uncategorized

How to block ads in Reddit iOS app via self-hosted mitmproxy

Block Ads on Reddit iOS App: A Step-by-Step Guide to Using Mitmproxy

As a Reddit user, I’m sure you’ve encountered ads on the platform at some point. While they can be annoying, there’s a way to block them on your iOS device using a self-hosted mitmproxy. In this post, I’ll walk you through the process of setting it up and using it to filter out ads from the Reddit API.

What is Mitmproxy?

Mitmproxy is an HTTPS proxy that can decrypt and modify traffic. It’s a powerful tool that can be used for a variety of purposes, including blocking ads. By using a small Python script, you can configure mitmproxy to filter out ads from the Reddit API.

Disclaimer

Before we dive into the instructions, I want to note that this method is still relatively new and may not work for everyone. Some users may experience issues or have different API response shapes, which can affect the functionality of the addon. However, with a little patience and tweaking, you should be able to get it working.

Instructions

To get started, you’ll need to install mitmproxy. You can find the official documentation on the mitmproxy website, which includes instructions for installing the software on your device. One option is to use the mitmproxy/mitmproxy Docker container, which makes it easy to set up and run mitmproxy on your device.

Once you have mitmproxy installed, you’ll need to configure it to work with the Reddit API. You can do this by downloading a small Python script that will act as an addon for mitmproxy. The script is available on GitHub, and you can follow the instructions provided to download and install it.

To run mitmproxy with the addon, you’ll need to use the following command:

mitmproxy -s /path/to/addon.py --listen-host 0.0.0.0 --listen-port 8080 --allow-hosts '^gql-fed\.reddit\.com(?::\d+)?$'

This will start mitmproxy and configure it to listen on port 8080. You can adjust the port number to suit your needs.

Next, you’ll need to enable mitmproxy on your iPhone. To do this, go to the Settings app and select the Wi-Fi network you’re connected to. Scroll down to the HTTP Proxy section and select “Manual”. Enter the IP address or hostname of your device running mitmproxy, and set the port to the one you specified earlier (in this case, 8080).

Finally, you’ll need to install the mitmproxy CA on your iPhone. You can do this by going to the mitm.it website and following the instructions provided. This will allow mitmproxy to decrypt and modify traffic on your device.

Tailscale Tip

If you want to use mitmproxy on your iPhone even when you’re not connected to your home Wi-Fi network, you can set up Tailscale. This will allow you to use the Tailscale machine name as the proxy server, which will block ads on your phone even when you’re out and about.

For example, if you’re running mitmproxy on a laptop, you can use the laptop’s machine name as the proxy server. If you’re running mitmproxy in a Docker container on a machine, you can install Tailscale on that machine and expose a port in Docker. Then, you can use the Tailscale hostname of the underlying machine as the proxy server.

Extending the Addon

The addon used in this example was built using the mitmweb program, which is a web app that lists requests and responses for you to examine. You can use this program to tweak the addon code and re-test it, which can help you customize the addon to suit your needs.

I hope this guide has been helpful in showing you how to block ads on the Reddit iOS app using mitmproxy. While it may take some time and effort to set up, the end result is well worth it – a ad-free Reddit experience on your iPhone.

Blokowanie Reklam na Aplikacji Reddit iOS: Krok po Kroku za Pomocą Mitmproxy

Jako użytkownik Reddit, na pewno spotkałeś się z reklamami na tej platformie. Chociaż mogą być one irytujące, istnieje sposób, aby je zablokować na urządzeniu z systemem iOS za pomocą samodzielnie hostowanego mitmproxy. W tym poście, przeprowadzę Cię przez proces konfigurowania i używania go do filtrowania reklam z API Reddit.

Co to jest Mitmproxy?

Mitmproxy to serwer proxy HTTPS, który może odszyfrowywać i modyfikować ruch. To potężne narzędzie, które może być używane do różnych celów, w tym blokowania reklam. Za pomocą małego skryptu Python, możesz skonfigurować mitmproxy do filtrowania reklam z API Reddit.

Uwaga

Przed przejściem do instrukcji, chcę zauważyć, że ta metoda jest jeszcze dość nowa i może nie działać dla wszystkich. Niektórzy użytkownicy mogą doświadczyć problemów lub mieć różne kształty odpowiedzi API, co może wpłynąć na funkcjonalność dodatku. Jednak z trochę cierpliwością i dostosowaniem, powinieneś być w stanie go uruchomić.

Instrukcje

Aby rozpocząć, musisz zainstalować mitmproxy. Możesz znaleźć oficjalną dokumentację na stronie mitmproxy, która zawiera instrukcje dotyczące instalacji oprogramowania na Twoim urządzeniu. Jedną z opcji jest użycie kontenera Docker mitmproxy/mitmproxy, który ułatwia konfigurację i uruchomienie mitmproxy na Twoim urządzeniu.

Gdy już zainstalujesz mitmproxy, musisz go skonfigurować do współpracy z API Reddit. Możesz to zrobić, pobierając mały skrypt Python, który będzie działał jako dodatek do mitmproxy. Skrypt jest dostępny na GitHub, a możesz postępować zgodnie z instrukcjami, aby go pobrać i zainstalować.

Aby uruchomić mitmproxy z dodatkiem, musisz użyć następującej komendy:

mitmproxy -s /path/to/addon.py --listen-host 0.0.0.0 --listen-port 8080 --allow-hosts '^gql-fed\.reddit\.com(?::\d+)?$'

To spowoduje uruchomienie mitmproxy i jego konfigurację do nasłuchiwania na porcie 8080. Możesz dostosować numer portu do swoich potrzeb.

Następnie musisz włączyć mitmproxy na swoim iPhone. Aby to zrobić, przejdź do aplikacji Ustawienia i wybierz sieć Wi-Fi, z którą jesteś połączony. Przewiń w dół do sekcji Proxy HTTP i wybierz “Ręczne”. Wpisz adres IP lub nazwę hosta urządzenia, na którym działa mitmproxy, i ustaw port na ten, który określisz wcześniej (w tym przypadku 8080).

Na koniec musisz zainstalować certyfikat mitmproxy na swoim iPhone. Możesz to zrobić, przejdź do strony mitm.it i postępując zgodnie z instrukcjami. To pozwoli mitmproxy odszyfrowywać i modyfikować ruch na Twoim urządzeniu.

Wskazówka dotycząca Tailscale

Jeśli chcesz używać mitmproxy na swoim iPhone, nawet gdy nie jesteś połączony z siecią Wi-Fi domu, możesz skonfigurować Tailscale. To pozwoli Ci używać nazwy maszyny Tailscale jako serwera proxy, co zablokuje reklamy na Twoim telefonie, nawet gdy jesteś poza domem.

Na przykład, jeśli uruchamiasz mitmproxy na laptopie, możesz użyć nazwy maszyny laptopa jako serwera proxy. Jeśli uruchamiasz mitmproxy w kontenerze Docker na maszynie, możesz zainstalować Tailscale na tej maszynie i udostępnić port w Docker. Następnie możesz użyć nazwy hosta Tailscale maszyny podstawowej jako serwera proxy.

Rozszerzanie dodatku

Dodatek użyty w tym przykładzie został zbudowany za pomocą programu mitmweb, który jest aplikacją webową, wyświetlającą żądania i odpowiedzi do Twojej inspekcji. Możesz użyć tego programu do dostosowania kodu dodatku i ponownego przetestowania, co pomoże Ci dostosować dodatek do Twoich potrzeb.

Mam nadzieję, że ten przewodnik był pomocny w pokazaniu, jak zablokować reklamy na aplikacji Reddit iOS za pomocą mitmproxy. Chociaż może to zająć trochę czasu i wysiłku, efekt końcowy jest wart tego – doświadczenie Reddit bez reklam na Twoim iPhone.

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux