03a52925d44d7751d90f9b7d6c74fa51308657b6
- New ipset.rs module wrapping ipset binary (hash:ip backend) - ban_ip() and unban_ip() use ipset.add/del instead of per-IP iptables rules - get_banned_ips() parses ipset list -json - Optional timeout via BAN_DURATION_SECS (default 3600s = 1h) - Auto-installs single iptables rule: -m set --match-set banned src -j DROP - New CLI subcommands: ban-ip, unban-ip (with --timeout) - 13 unit tests for ipset module + integration test script using netns - Update Woodpecker CI to install ipset
Martillo Maldito
Martillo Maldito is an iptables wrapper that simplifies firewall rule management in an intuitive and structured way. This CLI allows you to manage secured ports, block IPs, save rules, and more.
Features
- Retrieve all banned IPs.
- Query and manage secured ports.
- Allow or deny access by IP for specific ports.
- Rule persistence.
- Optional Docker integration.
Requirements
- Rust 1.65 or higher.
iptablesinstalled and configured on the system.- Proper permissions to manage
iptablesrules (e.g., running as root).
Installation
-
Clone the repository:
git clone https://github.com/your_user/martillo_maldito.git cd martillo_maldito -
Build the project:
cargo build --release -
Optionally, copy the executable to a directory in your PATH:
cp target/release/martillo_maldito /usr/local/bin/
Usage
General Syntax
martillo_maldito <command> [options]
Available Commands
1. Retrieve all banned IPs
martillo_maldito get-banned-ips [--docker | -d]
Options:
--docker,-d: Includes rules in Docker environments.
2. Retrieve all secured ports
martillo_maldito get-secured-ports [--docker | -d]
3. Retrieve all secured ports with allowed IPs
martillo_maldito get-secured-ports-with-allowed-ips [--docker | -d]
4. Check if a port is secured
martillo_maldito is-port-secured --port <port> [--docker | -d]
Options:
--port,-p: Specifies the port to check.--docker,-d: Includes rules in Docker environments.
5. Secure a port
martillo_maldito secure-port --port <port> [--position <position>] [--docker | -d]
Options:
--port,-p: Specifies the port to secure.--position,-P: Specifies the rule position iniptables.--docker,-d: Includes rules in Docker environments.
6. Unsecure a port
martillo_maldito unsecure-port --port <port> [--docker | -d]
Options:
--port,-p: Specifies the port to unsecure.--docker,-d: Includes rules in Docker environments.
7. Allow an IP for a port
martillo_maldito allow-ip-for-port --ip <ip> --port <port> [--position <position>] [--docker | -d]
Options:
--ip,-i: Specifies the IP to allow.--port,-p: Specifies the port to allow the IP on.--position,-P: Specifies the rule position.--docker,-d: Includes rules in Docker environments.
8. Remove an allowed IP from a port
martillo_maldito remove-allow-ip-port --ip <ip> --port <port> [--docker | -d]
Options:
--ip,-i: Specifies the IP to remove.--port,-p: Specifies the port to remove the IP from.--docker,-d: Includes rules in Docker environments.
9. Save rules
martillo_maldito save-rules
Saves all current iptables rules for future restoration.
Examples
-
Retrieve all banned IPs:
martillo_maldito get-banned-ips -
Secure port 8080 with Docker enabled:
martillo_maldito secure-port -p 8080 -d -
Allow access to IP 192.168.1.10 on port 22:
martillo_maldito allow-ip-for-port -i 192.168.1.10 -p 22 -
Save all current rules:
martillo_maldito save-rules
Disclaimer
This repository is designed solely for experimental or educational purposes. It is not intended for use in production environments or critical projects. Use at your own risk.
Description
Martillo Maldito is an iptables wrapper that simplifies firewall rule management in an intuitive and structured way.
247 KiB
Languages
Rust
89.4%
Shell
10.6%