Script in python that can be used for creating a self-hosted proxy for NOT SAFE FOR WORK content filtering.
- Block images in all sites using AI for classification.
- Custom AI CLI Tool can be passed as argument to use it.
- Disable AI detection if you want.
- Blacklist with more than 28000 NSFW websites.
- All resources in blacklists websites are blocked (Video, images and gifs), no is needed analyze them.
- Buffering Video NSFW classification.
- Streaming video NSFW classification.
- Websockets NSFW classification.
- NSFW Text classification.
- Adding WhiteList in case someone doesn't wanted filter content on certain page.
- Adding compatibility with more classification NSFW tools
- Web user interface for configuration once service is started instead of only command line interface.
- User interface for start, stop and configure the service.
- Improve installation documentation.
- Adding How to configure it on a router / modem for all users in a same network. (This will work for public networks which wanted filter this content and for entire families).
- Adding How to configure it on a VPS for using out of the house. (In case someone doesn't wanted use it only locally but also when he is out).
mitmproxy is a free and open source interactive HTTPS proxy. In this project it is used for intercept, inspect, modify and replay web traffic such as HTTP/1, HTTP/2, WebSockets, or any other SSL/TLS-protected protocols. With the intention of analyze if a resource (image, gif, video, streaming) contain undesearable content, then blocking it according to your configuration.
You can download it here: https://mitmproxy.org/
This project allow you to decide which AI tool to use for classify your content. The one I personally use by its speed and low cost on memory is BONK, and it is the only one supported currently by the project. If you know one that you want to be supported on the project please leave it as an issue and I will check it.
Here are classified the supported CLI AI Classifier tools. They have a tag called Installing Difficulty what will indicate if you need or not technical knowledge to install it:
- HARD: You will need to know about git and the programming language that it is developed. Probably will be different to install it on windows, linux or mac.
- MEDIUM: To install it you will need to read a documentation and follow different steps for your operative system.
- EASY: You only download it and click continue, continue, accept, continue, finish. (Or install it in your dependency manager if you're on linux)
Name | Website | Installing difficulty | Language |
---|---|---|---|
Bonk | Here | Hard | Rust |
For cloning the project only run this command or download it as zip here.
git clone https://github.com/heliomar-pena/nsfw-proxy.git
The dependencies on the requirements.txt file are only for development, since you will run this project with mitmproxy which has its own python version installed and already have mitmproxy as a dependency, so don't worry for that file for now.
To run it, you need to open the file using mitmdump, which allow us to interact with the HTTP requests using python.
At the moment of run mitmdump, you need to make a call to this file and also declare the arguments that will decide the behaviour of the proxy. Here is a basic example:
mitmdump -s ./nsfw.py --set command="bonk <dir>" --set level=0.1
And here is are we doing splitted for explanation:
mitmdump
: Calling mitmdump command which starts an HTTP proxy server and allow us to use a python script to interact with him.-s
: Short way to say script, allow insert a script as option./nsfw.py
: The path to thensfw.py
file that you cloned from this repo--set
: Allow you insert arguments that will be used for the script.command="bonk <dir>"
: First argument for the script, which says to the script what command to use. The<dir>
is a reserved key that will be replaced on the program for the path of the image, so the CLI Tool can use this path to get the image and analyze it.--set
: Allow you to insert another argument to the script.level=0.1
: NSFW Classifiers Tools as Bonk gives you a level of NSFW that can have an image. Here you can configure what is the min level for you to considerate an image NSFW.
As you can see above, you need to run the command:
mitmdump -s ./nsfw.py
Then you can modify the behaviour of the script using --set
to insert arguments and so define which CLI tool to use for analyzing images, what level of NSFW would you like to allow, etc...
In this section you will see all the commands that you can pass to --set
and its allowed values.
Name | Optional | Default value | Value Type | Example values | Note |
---|---|---|---|---|---|
command | ✅ | "" | str | bonk <dir> |
It should include <dir> which is the slot where the script will include the image's path |
level | ✅ | 0.3 | float | 0.1 | You can use a float or an integer: 0.1, 0.2, 1, 3 |
Note
https://docs.mitmproxy.org/stable/concepts-certificates/ Mitmproxy can decrypt encrypted traffic on the fly, as long as the client trusts mitmproxy’s built-in certificate authority. Usually this means that the mitmproxy CA certificate has to be installed on the client device.
Before start navigating using our proxy we need to install the certificates. At this moment, if you try to connect to the proxy and then navigate on the web probably you'll found a message rejecting the conection and some warnings, this is because your browser or your computer doesn't trust in the proxy and needs the certificates to trust in him.
As we are using a mitmproxy proxy, we will install its certificates. To do this, you will need to follow the next steps:
- Start the project as explained above
- Go to mitm.it, then download the certificates and follow the instructions for your device or browser.
- Check if connection works with pages like https://www.github.com or https://google.com.
This will vary depending of if you wants to install it on an Operative System as Android, iOs, Linux, Windows, Mac or on a browser like Safari, Firefox, Chrome, etc...
In all cases, you will need the proxy URL, which by default is localhost:8080
, where 8080
is the port where the proxy is running on your network. If you want change the port you can use the option --listen-port
, by example mitmdump -s ./nsfw.py --listen-port 8081
.
Then, you can follow the instructions on the web for the system you have:
If your system doesn't appear here just search it is just that there is too many variety of systems and versions to include all of them here. You can search your specific case in Google and I am sure you will found the solution.