The Firewall Management System (Distributed Firewall Rule Generator) is a robust, modular server-client-based application designed to centralize the management, generation, and enforcement of firewall rules across distributed systems.
It utilizes iptables to define and enforce network policies, ensuring secure and efficient access management.
The system includes a Policy Editor for administrators to manage firewall rules dynamically and a robust logging mechanism for auditing purposes.
- Centralized server for managing and dispatching firewall rules.
- Clients securely receive and execute policies using
iptables.
- Add, view, modify, and delete firewall rules for different user groups.
- Manage policies stored in a JSON-based configuration file (
user_policies.json).
- Policies can be updated dynamically without restarting the server.
- Clients authenticate with the server using a predefined
AUTH_TOKEN.
- Logs all dispatched policies for compliance and debugging purposes.
- Tailored firewall rules for user groups such as corporate, vpn_users, developers, guests, admins, and blocked_users.
- Remotely apply firewall policies over SSH using
ssh_policy_push.py.
- Python 3.12.7 on Kali Linux
- Socket (Python networking)
- Paramiko (SSH communication)
- YAML (configuration management)
- JSON (policy storage)
- iptables (firewall rule enforcement)
- subprocess, threading, logging
FirewallProject/
βββ client/
β βββ agent.py # Client-side script to connect to the server and execute policies
β βββ policy_executor.py # Executes firewall rules safely
βββ controller/
β βββ server.py # Server-side script to manage clients and dispatch policies
β βββ policy_dispatcher.py # Fetches policies for specific user groups
β βββ command_logger.py # Logs dispatched policies
βββ policies/
β βββ user_policies.json # JSON file storing firewall rules for user groups
βββ config/
β βββ settings.yaml # Configuration file for server settings
βββ policy_editor.py # Tool for managing firewall policies
βββ policy_logs.log # Log file for dispatched policies
- Python 3.6 or higher
iptablesinstalled on the client machine- Linux-based operating system
paramikoandpyyamlPython packages
-
Clone the repository:
git clone https://github.com/<your-username>/FirewallProject.git cd FirewallProject
-
Install required Python packages:
pip install -r requirements.txt
-
Configure the server:
- Edit
config/settings.yamlto set the server's host, port, andAUTH_TOKEN.
- Edit
-
Define firewall rules:
- Edit
policies/user_policies.jsonto define group-specific rules.
- Edit
Run the server to listen for client connections:
sudo PYTHONPATH=. python3 controller/server.pyRun the client to connect to the server and execute policies:
sudo PYTHONPATH=. python3 client/agent.pyUse the Policy Editor to manage firewall rules:
python3 policy_editor.pyThe server configuration is stored in config/settings.yaml:
server:
host: 0.0.0.0
port: 9090
auth_token: "securetoken123"Firewall rules are stored in policies/user_policies.json.
Example:
{
"corporate": [
"iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT",
"iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT"
],
"guests": [
"iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT",
"iptables -A OUTPUT -p tcp --dport 21 -j DROP"
]
}- Server: Listens for client connections, authenticates them, dispatches policies.
- Client: Authenticates to server, receives and executes firewall rules.
- Policy Editor: Tool to dynamically manage firewall rule sets.
- SSH Policy Push: Module to apply firewall policies to remote machines via SSH.
Input:
--- Policy Editor ---
1. View all policies
2. Add new group
3. Add policy to a group
4. Delete policy from a group
5. Remove group
6. Exit
Select an option: 2
Enter new group name: test_group
Output:
Group 'test_group' added.
Input (Client):
AUTH_TOKEN: securetoken123
Group name: developers
Output (Server):
[+] Connection from ('127.0.0.1', 60644)
[+] Dispatched to ('127.0.0.1', 60644): iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
-
Option-2: Add New Group Β && Β Option-3: Add Policy to New Group

-
Option-4: Delete Policy from a group Β && Β Option-5: Remove Group

- Policy Dispatch Time: ~50ms per policy
- Concurrent Client Handling: Up to 5 clients without noticeable delays
- Policy Execution Time: ~30ms per
iptablescommand
- No GUI support yet; only CLI-based.
- Limited to Linux-based systems using
iptables. - Requires manual reset of
iptablesrules after testing. - Invalid
iptablescommands inuser_policies.jsonmay cause execution errors.
- Add a GUI or web-based management dashboard.
- Extend platform support (Windows, UFW).
- Enhance SSH error handling and rule validation.
- Add validation for
iptablesrules insideuser_policies.json.







