linutil/tabs/security/firewall-baselines.sh

50 lines
1.3 KiB
Bash
Raw Normal View History

2024-07-30 20:01:13 +01:00
#!/bin/sh -e
. ../common-script.sh
2024-08-02 15:19:20 +01:00
2024-07-30 20:01:13 +01:00
installPkg() {
echo "Install UFW if not already installed..."
if ! command_exists ufw; then
case ${PACKAGER} in
pacman)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL "${PACKAGER}" -S --needed --noconfirm ufw
2024-07-30 20:01:13 +01:00
;;
*)
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL "${PACKAGER}" install -y ufw
2024-07-30 20:01:13 +01:00
;;
esac
else
echo "UFW is already installed."
fi
2024-08-02 15:19:20 +01:00
}
configureUFW() {
2024-09-12 21:14:50 +01:00
printf "%b\n" "${GREEN}Using Chris Titus Recommended Firewall Rules${RC}"
2024-08-02 15:19:20 +01:00
printf "%b\n" "${YELLOW}Disabling UFW${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw disable
2024-08-02 15:19:20 +01:00
printf "%b\n" "${YELLOW}Limiting port 22/tcp (UFW)${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw limit 22/tcp
2024-07-30 20:01:13 +01:00
printf "%b\n" "${YELLOW}Allowing port 80/tcp (UFW)${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw allow 80/tcp
2024-07-30 20:01:13 +01:00
printf "%b\n" "${YELLO}Allowing port 443/tcp (UFW)${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw allow 443/tcp
2024-07-30 20:01:13 +01:00
printf "%b\n" "${YELLOW}Denying Incoming Packets by Default(UFW)${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw default deny incoming
2024-07-30 20:01:13 +01:00
printf "%b\n" "${YELLOW}Allowing Outcoming Packets by Default(UFW)${RC}"
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw default allow outgoing
2024-07-30 20:01:13 +01:00
2024-08-23 14:12:47 +01:00
$ESCALATION_TOOL ufw enable
2024-09-12 21:14:50 +01:00
printf "%b\n" "${GREEN}Enabled Firewall with Baselines!${RC}"
2024-07-30 20:01:13 +01:00
}
checkEnv
2024-08-23 14:12:47 +01:00
checkEscalationTool
2024-07-30 20:01:13 +01:00
installPkg
2024-08-02 15:19:20 +01:00
configureUFW