iblock/README.md

72 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2021-02-25 18:16:02 +00:00
# iblock
2021-02-25 19:43:58 +00:00
iblock is an inetd program adding the client IP to a Packet Filter table.
It is meant to be used to block scanner connecting on unused ports.
2021-02-28 15:58:50 +00:00
Upon connection, the IP is added to a PF table and all established connections with this IP are killed. You need to use a PF bloking rule using the table.
2021-02-28 15:58:50 +00:00
# How to use
## Add a dedicated user
```
useradd -s /sbin/nologin _iblock
```
## Configure doas
Add in `/etc/doas.conf`:
```
permit nopass _iblock cmd /sbin/pfctl
```
2021-03-10 21:37:11 +00:00
## Configure inetd
2021-02-28 15:58:50 +00:00
Start inetd service with this in `/etc/inetd.conf`:
```
2022-09-18 12:31:03 +00:00
666 stream tcp nowait _iblock /usr/local/sbin/iblock iblock
666 stream tcp6 nowait _iblock /usr/local/sbin/iblock iblock
2021-02-28 15:58:50 +00:00
```
2021-03-10 21:37:11 +00:00
You can change the PF table by adding it as a parameter like this:
2022-04-09 19:27:32 +00:00
In this example, the parameter `blocklist` will add IPs to the `blocklist` PF table.
2021-03-10 21:37:11 +00:00
```
2022-09-18 12:31:03 +00:00
666 stream tcp nowait _iblock /usr/local/sbin/iblock iblock blocklist
666 stream tcp6 nowait _iblock /usr/local/sbin/iblock iblock blocklist
2021-03-10 21:37:11 +00:00
```
2022-08-22 13:05:26 +00:00
Default is "iblocked" table.
2021-03-10 21:37:11 +00:00
## Configure packet filter
2021-02-28 15:58:50 +00:00
Use this in `/etc/pf.conf`, choose which ports will trigger the ban from the variable:
```
# services triggering a block
2021-02-28 16:01:05 +00:00
blocking_tcp="{ 21 23 53 111 135 137:139 445 1433 25565 5432 3389 3306 27019 }"
2021-02-28 15:58:50 +00:00
table <blocked> persist
2021-02-28 16:03:59 +00:00
block in quick from <blocked> label iblock
pass in quick on egress inet proto tcp to port $blocking_tcp rdr-to 127.0.0.1 port 666
pass in quick on egress inet6 proto tcp to port $blocking_tcp rdr-to ::1 port 666
2021-02-28 15:58:50 +00:00
```
2021-03-10 21:37:11 +00:00
Don't forget to reload the rules with `pfctl -f /etc/pf.conf`.
# Get some statistics
Done! You can see IP banned using `pfctl -t blocked -T show` and iBlock will send blocked addresses to syslog.
2021-02-28 15:58:50 +00:00
2021-02-28 16:03:59 +00:00
In the example I added a label to the block rule, you can use `pfctl -s labels` to view statistics from this rule, [see documentation for column meaning](https://man.openbsd.org/pfctl#s~8).
2021-02-28 15:58:50 +00:00
# TODO
- A proper man page