Init
This commit is contained in:
commit
4e450a270d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.deb
|
6
DEBIAN/control
Normal file
6
DEBIAN/control
Normal file
@ -0,0 +1,6 @@
|
||||
Package: sshutter
|
||||
Version: 0.1
|
||||
Maintainer: Martin "maride" Dessauer
|
||||
Architecture: all
|
||||
Description: ping-conditional SSH firewall
|
||||
Depends: iputils-ping, nftables
|
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2024 Martin "maride" Dessauer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# sshutter
|
||||
|
||||
Apply firewall rules depending on ping results
|
||||
|
||||
## Motivation
|
||||
|
||||
SSH is, by nature, a very powerful and mighty tool which can be found on almost any UNIX system - and some Windows hosts, too. However, incidents like [the XZ backdoor](https://en.wikipedia.org/wiki/XZ_Utils_backdoor) have shown that SSH is not invulnerable, and a critical vulnerability would be as desastrous as [EternalBlue](https://en.wikipedia.org/wiki/EternalBlue) on Windows hosts.
|
||||
|
||||
This situation asks for dynamic solutions. And **sshutter** is such a dynamic solution. It activates or deactivates firewall rules for dropping requests to SSH as long as a certain IP address or network is reachable.
|
||||
|
||||
## Building/Packing
|
||||
|
||||
To create the Debian/Ubuntu package for sshutter, run `dpkg-deb --root-owner-group --build . sshutter-v0.1.deb`
|
3
etc/sshutter.conf
Normal file
3
etc/sshutter.conf
Normal file
@ -0,0 +1,3 @@
|
||||
TARGET=10.0.0.1
|
||||
WHITELIST=10.0.0.0/16
|
||||
PORT=22
|
8
etc/systemd/system/sshutterd.service
Normal file
8
etc/systemd/system/sshutterd.service
Normal file
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=sshutter - ping-conditional SSH firewall
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/sshutterd
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
32
usr/sbin/sshutterd
Executable file
32
usr/sbin/sshutterd
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -f "/etc/sshutter.conf" ]; then
|
||||
. /etc/sshutter.conf
|
||||
fi
|
||||
|
||||
function log {
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') $@"
|
||||
}
|
||||
|
||||
if [ "$UID" -ne 0 ]; then
|
||||
echo "Error: must be root." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while [ true ]; do
|
||||
ping -c 3 "$TARGET" 1>/dev/null
|
||||
if [ "$?" -eq 0 ]; then
|
||||
# Ping successful, apply shutter
|
||||
log "[sshutter] Blocking port 22 for IPs outside $WHITELIST"
|
||||
nft add table inet filter
|
||||
nft add chain inet filter sshutterv4 \{ type filter hook input priority filter \; policy accept \; \}
|
||||
nft add rule inet filter sshutterv4 tcp dport "$PORT" ip saddr "$WHITELIST" accept
|
||||
nft add rule inet filter sshutterv4 tcp dport "$PORT" drop
|
||||
else
|
||||
# Ping failed, lift shutter
|
||||
log "[sshutter] Releasing port block"
|
||||
nft destroy chain inet filter sshutterv4
|
||||
fi
|
||||
|
||||
sleep 60
|
||||
done
|
Loading…
Reference in New Issue
Block a user