Python based Packet Filtering Firewall
Packet filtering firewall is a network security technique that is used to control data flow to and from a network. It is a security mechanism that allows the movement of packets across the network and controls their flow on the basis of a set of rules, protocols, IP addresses, and ports.
In this simple firewall, I added 4 interfaces and these interfaces are running on threads for receive the traffic simultaneously. All the traffic forward into one funtion and It checks the packets against the set of rules defines in text file. If there no rule matches, the traffic allowed and forwarded to its destination.
- Four interfaces for filtering
- Port level and IP level blocking
====By default all the traffic allowed!====
Empty the file for allow all the traffic
DENY <SRC_IP> <SRC_PORT> <DST_IP> <DST_PORT>
Eg:-
192.168.1.10 20 192.168.1.20 50
Block any packet with Source 192.168.1.10:20 to Dest 192.168.1.20:50
DENY ANY ANY 192.168.1.10 80
Block packet from any source that destinationed to ip 192.168.1.20 and port 80
- Four Interfaces with Static IP configured
- All the interfaces should be active
- Python 3.8.2 (tested)
- Ubuntu 20.04 box (tested)
- Bit of knowledge in Python Virtual Environment
-
Enter into python virtual environment
source env1/bin/activate
-
Execute
python3 firewall.py