File manager - Edit - /var/www/payraty/helpdesk/public/storage/branding_media/images/ufw.tar
Back
ufw-init 0000755 00000005300 00000000000 0006173 0 ustar 00 #!/bin/sh # # ufw-init: helper script to be used by ufw itself # # Copyright 2008-2015 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # set -e # FIXME: this shouldn't be ordered rootdir= if [ "$1" = "--rootdir" ] && [ -n "$2" ]; then rootdir="$2/" # ensure trailing slash shift 2 fi datadir= if [ "$1" = "--datadir" ] && [ -n "$2" ]; then datadir="$2/" # ensure trailing slash shift 2 fi export DATA_DIR="$datadir" # Debian/Ubuntu: small boot speed improvement . "${rootdir}/etc/ufw/ufw.conf" if [ "$1" = "start" ] && [ "$2" = "quiet" ] && [ "$ENABLED" = "no" ]; then exit 0 fi if [ -s "${rootdir}/lib/ufw/ufw-init-functions" ]; then . "${rootdir}/lib/ufw/ufw-init-functions" else echo "Could not find ${rootdir}/lib/ufw/ufw-init-functions (aborting)" exit 1 fi case "$1" in start) # process multiple error strings ret=0 output=`ufw_start` || ret="$?" test -n "$output" && echo "$output" | while read line ; do if [ "$2" = "quiet" ] || [ "$QUIET" = "yes" ]; then echo "$line" | grep -q "Skip starting" && continue fi echo "$line" done exit "$ret" ;; stop) ufw_stop || exit "$?" ;; force-stop) ufw_stop --force || exit "$?" ;; restart|force-reload) ufw_reload || exit "$?" ;; status) ufw_status || exit "$?" # If before.init and after.init support 'status', just display them after # ufw_status() so it is prettier if [ -x "$RULES_PATH/before.init" ]; then "$RULES_PATH/before.init" status || exit "$?" fi if [ -x "$RULES_PATH/after.init" ]; then "$RULES_PATH/after.init" status || exit "$?" fi ;; flush-all) # Use sparingly. It flushes the built-in chains, deletes all non-builtin # chains and resets the policy to ACCEPT if [ -x "$RULES_PATH/before.init" ]; then "$RULES_PATH/before.init" flush-all || exit "$?" fi flush_builtins || exit "$?" if [ -x "$RULES_PATH/after.init" ]; then "$RULES_PATH/after.init" flush-all || exit "$?" fi ;; *) echo "Usage: /lib/ufw/ufw-init {start|stop|restart|force-reload|force-stop|flush-all|status}" exit 1 ;; esac ufw-init-functions 0000755 00000042135 00000000000 0010210 0 ustar 00 #!/bin/sh # # ufw-init-functions: functions used by ufw-init and distribution initscripts # # Copyright 2008-2015 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # set -e PATH="/sbin:/bin:/usr/sbin:/usr/bin" for s in "${DATA_DIR}/etc/default/ufw" "${DATA_DIR}/etc/ufw/ufw.conf" ; do if [ -s "$s" ]; then . "$s" else echo "Could not find $s (aborting)" exit 1 fi done RULES_PATH="${DATA_DIR}/etc/ufw" USER_PATH="${DATA_DIR}/etc/ufw" flush_builtins() { error="" execs="iptables" if ip6tables -L INPUT -n >/dev/null 2>&1; then execs="$execs ip6tables" fi for exe in $execs do $exe -F || error="yes" $exe -X || error="yes" $exe -P INPUT ACCEPT || error="yes" $exe -P OUTPUT ACCEPT || error="yes" $exe -P FORWARD ACCEPT || error="yes" # now handle the mangle table if $exe -t mangle -L -n >/dev/null 2>&1; then for i in INPUT OUTPUT FORWARD PREROUTING POSTROUTING ; do $exe -t mangle -F $i || error="yes" $exe -t mangle -P $i ACCEPT || error="yes" done fi done # now handle the nat table if iptables -t nat -L -n >/dev/null 2>&1; then for i in OUTPUT PREROUTING POSTROUTING ; do iptables -t nat -F $i || error="yes" iptables -t nat -P $i ACCEPT || error="yes" done fi if [ "$error" = "yes" ]; then return 1 fi } chains_command() { flag="$1" type="" exe="iptables" if [ "$2" = "6" ]; then type="$2" exe="ip6tables" fi for c in ufw$type-logging-deny ufw$type-logging-allow ufw$type-not-local ufw$type-user-logging-input ufw$type-user-limit-accept ufw$type-user-limit ufw$type-skip-to-policy-input ufw$type-reject-input ufw$type-after-logging-input ufw$type-after-input ufw$type-user-input ufw$type-before-input ufw$type-before-logging-input ufw$type-skip-to-policy-forward ufw$type-reject-forward ufw$type-after-logging-forward ufw$type-after-forward ufw$type-user-logging-forward ufw$type-user-forward ufw$type-before-forward ufw$type-before-logging-forward ufw$type-track-forward ufw$type-track-output ufw$type-track-input ufw$type-skip-to-policy-output ufw$type-reject-output ufw$type-after-logging-output ufw$type-after-output ufw$type-user-logging-output ufw$type-user-output ufw$type-before-output ufw$type-before-logging-output; do if [ "$UFW_INIT_DEBUG" = "yes" ]; then echo "$exe $flag $c" >&2 $exe $flag $c || true else $exe $flag $c 2>/dev/null || true fi done } delete_chains() { chains_command -F $1 chains_command -Z $1 # Delete the secondary chains to reduce clutter, but keep the primary ones # so that the primary chains don't leave the built-in chains just to come # back later in a different place. This means that some (empty) chains will # linger until the next boot after disabling ufw. for c in ufw$type-logging-deny ufw$type-logging-allow ufw$type-not-local ufw$type-user-logging-input ufw$type-user-logging-output ufw$type-user-logging-forward ufw$type-user-limit-accept ufw$type-user-limit ufw$type-user-input ufw$type-user-forward ufw$type-user-output ufw$type-skip-to-policy-input ufw$type-skip-to-policy-output ufw$type-skip-to-policy-forward ; do if [ "$UFW_INIT_DEBUG" = "yes" ]; then echo "$exe $flag $c" >&2 $exe -X $c || true else $exe -X $c 2>/dev/null || true fi done } ufw_start() { out="" if [ "$ENABLED" = "yes" ] || [ "$ENABLED" = "YES" ]; then if iptables -L ufw-user-input -n >/dev/null 2>&1 ; then echo "Firewall already started, use 'force-reload'" return 0 fi for m in $IPT_MODULES do modprobe $m || true done if [ "$MANAGE_BUILTINS" = "yes" ]; then flush_builtins fi if [ -x "$RULES_PATH/before.init" ]; then if ! "$RULES_PATH/before.init" start ; then error="yes" out="${out}\n'$RULES_PATH/before.init start' exited with error" fi fi execs="iptables" # IPv6 setup if [ "$IPV6" = "yes" ] || [ "$IPV6" = "YES" ]; then if ip6tables -L INPUT -n >/dev/null 2>&1; then execs="$execs ip6tables" else out="${out}\nProblem loading ipv6 (skipping)" fi else if ip6tables -L INPUT -n >/dev/null 2>&1; then # IPv6 support disabled but available in the kernel, so # default DROP and accept all on loopback delete_chains 6 || error="yes" printf "*filter\n"\ ":INPUT DROP [0:0]\n"\ ":FORWARD DROP [0:0]\n"\ ":OUTPUT DROP [0:0]\n"\ "-A INPUT -i lo -j ACCEPT\n"\ "-A OUTPUT -o lo -j ACCEPT\n"\ "COMMIT\n" | ip6tables-restore || error="yes" if [ "$error" = "yes" ]; then out="${out}\nProblem loading ipv6 (skipping)" fi fi fi for exe in $execs do type="" if [ "$exe" = "ip6tables" ]; then type="6" fi BEFORE_RULES="$RULES_PATH/before${type}.rules" AFTER_RULES="$RULES_PATH/after${type}.rules" USER_RULES="$USER_PATH/user${type}.rules" # flush the chains (if they exist) if $exe -L ufw${type}-before-logging-input -n >/dev/null 2>&1 ; then delete_chains $type || error="yes" else # setup all the primary chains printf "*filter\n"\ "# primary chains\n"\ ":ufw${type}-before-logging-input - [0:0]\n"\ ":ufw${type}-before-logging-output - [0:0]\n"\ ":ufw${type}-before-logging-forward - [0:0]\n"\ ":ufw${type}-before-input - [0:0]\n"\ ":ufw${type}-before-output - [0:0]\n"\ ":ufw${type}-before-forward - [0:0]\n"\ ":ufw${type}-after-input - [0:0]\n"\ ":ufw${type}-after-output - [0:0]\n"\ ":ufw${type}-after-forward - [0:0]\n"\ ":ufw${type}-after-logging-input - [0:0]\n"\ ":ufw${type}-after-logging-output - [0:0]\n"\ ":ufw${type}-after-logging-forward - [0:0]\n"\ ":ufw${type}-reject-input - [0:0]\n"\ ":ufw${type}-reject-output - [0:0]\n"\ ":ufw${type}-reject-forward - [0:0]\n"\ ":ufw${type}-track-input - [0:0]\n"\ ":ufw${type}-track-output - [0:0]\n"\ ":ufw${type}-track-forward - [0:0]\n"\ "\n"\ "-A INPUT -j ufw${type}-before-logging-input\n"\ "-A INPUT -j ufw${type}-before-input\n"\ "-A INPUT -j ufw${type}-after-input\n"\ "-A INPUT -j ufw${type}-after-logging-input\n"\ "-A INPUT -j ufw${type}-reject-input\n"\ "-A INPUT -j ufw${type}-track-input\n"\ "\n"\ "-A OUTPUT -j ufw${type}-before-logging-output\n"\ "-A OUTPUT -j ufw${type}-before-output\n"\ "-A OUTPUT -j ufw${type}-after-output\n"\ "-A OUTPUT -j ufw${type}-after-logging-output\n"\ "-A OUTPUT -j ufw${type}-reject-output\n"\ "-A OUTPUT -j ufw${type}-track-output\n"\ "\n"\ "-A FORWARD -j ufw${type}-before-logging-forward\n"\ "-A FORWARD -j ufw${type}-before-forward\n"\ "-A FORWARD -j ufw${type}-after-forward\n"\ "-A FORWARD -j ufw${type}-after-logging-forward\n"\ "-A FORWARD -j ufw${type}-reject-forward\n"\ "-A FORWARD -j ufw${type}-track-forward\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi # add reject policy if [ "$DEFAULT_INPUT_POLICY" = "REJECT" ]; then printf "*filter\n"\ "-A ufw${type}-reject-input -j REJECT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi if [ "$DEFAULT_OUTPUT_POLICY" = "REJECT" ]; then printf "*filter\n"\ "-A ufw${type}-reject-output -j REJECT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi if [ "$DEFAULT_FORWARD_POLICY" = "REJECT" ]; then printf "*filter\n"\ "-A ufw${type}-reject-forward -j REJECT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi # add tracking policy if [ "$DEFAULT_INPUT_POLICY" = "ACCEPT" ]; then printf "*filter\n"\ "-A ufw${type}-track-input -p tcp -m conntrack --ctstate NEW -j ACCEPT\n"\ "-A ufw${type}-track-input -p udp -m conntrack --ctstate NEW -j ACCEPT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi if [ "$DEFAULT_OUTPUT_POLICY" = "ACCEPT" ]; then printf "*filter\n"\ "-A ufw${type}-track-output -p tcp -m conntrack --ctstate NEW -j ACCEPT\n"\ "-A ufw${type}-track-output -p udp -m conntrack --ctstate NEW -j ACCEPT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi if [ "$DEFAULT_FORWARD_POLICY" = "ACCEPT" ]; then printf "*filter\n"\ "-A ufw${type}-track-forward -p tcp -m conntrack --ctstate NEW -j ACCEPT\n"\ "-A ufw${type}-track-forward -p udp -m conntrack --ctstate NEW -j ACCEPT\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi # now setup the secondary 'logging-deny' chains if ! $exe -L ufw${type}-logging-deny -n >/dev/null 2>&1 ; then printf "*filter\n"\ ":ufw${type}-logging-deny - [0:0]\n"\ ":ufw${type}-logging-allow - [0:0]\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi # now setup the secondary 'skip to policy' chains if ! $exe -L ufw${type}-skip-to-policy-input -n >/dev/null 2>&1 ; then printf "*filter\n"\ ":ufw${type}-skip-to-policy-input - [0:0]\n"\ ":ufw${type}-skip-to-policy-output - [0:0]\n"\ ":ufw${type}-skip-to-policy-forward - [0:0]\n"\ "-A ufw${type}-skip-to-policy-input -j %s\n"\ "-A ufw${type}-skip-to-policy-output -j %s\n"\ "-A ufw${type}-skip-to-policy-forward -j %s\n"\ "COMMIT\n" $DEFAULT_INPUT_POLICY $DEFAULT_OUTPUT_POLICY $DEFAULT_FORWARD_POLICY | $exe-restore -n || error="yes" fi # now ip[6]tables-restore before*.rules. This resets the following # chains: # ufw-before-input # ufw-before-output # ufw-before-forward # # and sets the following: # ufw-not-local if [ -s "$BEFORE_RULES" ]; then if ! $exe-restore -n < "$BEFORE_RULES" ; then out="${out}\nProblem running '$BEFORE_RULES'" error="yes" fi else out="${out}\nCouldn't find '$BEFORE_RULES'" error="yes" fi # now ip[6]tables-restore after*.rules. This resets the following # chains: # ufw-after-input # ufw-after-output # ufw-after-forward if [ -s "$AFTER_RULES" ]; then if ! $exe-restore -n < "$AFTER_RULES" ; then out="${out}\nProblem running '$AFTER_RULES'" error="yes" fi else out="${out}\nCouldn't find '$AFTER_RULES'" error="yes" fi # user chains if [ -s "$USER_RULES" ]; then # setup the secondary 'user' chains if ! $exe -L ufw${type}-user-input -n >/dev/null 2>&1 ; then printf "*filter\n"\ ":ufw${type}-user-input - [0:0]\n"\ ":ufw${type}-user-output - [0:0]\n"\ ":ufw${type}-user-forward - [0:0]\n"\ ":ufw${type}-user-logging-input - [0:0]\n"\ ":ufw${type}-user-logging-output - [0:0]\n"\ ":ufw${type}-user-logging-forward - [0:0]\n"\ ":ufw${type}-user-limit - [0:0]\n"\ ":ufw${type}-user-limit-accept - [0:0]\n"\ "COMMIT\n" | $exe-restore -n || error="yes" fi # now ip[6]tables-restore user*.rules. This resets the following # chains: # ufw-before-logging-input # ufw-before-logging-output # ufw-before-logging-forward # ufw-after-logging-input # ufw-after-logging-output # ufw-after-logging-forward # ufw-logging-deny # ufw-logging-allow # ufw-after-input # ufw-after-output # ufw-after-forward # ufw-user-limit # ufw-user-limit-accept if ! $exe-restore -n < "$USER_RULES" ; then out="${out}\nProblem running '$USER_RULES'" error="yes" fi # now hooks these into the primary chains printf "*filter\n"\ "-A ufw${type}-before-input -j ufw${type}-user-input\n"\ "-A ufw${type}-before-output -j ufw${type}-user-output\n"\ "-A ufw${type}-before-forward -j ufw${type}-user-forward\n"\ "COMMIT\n" | $exe-restore -n || error="yes" else out="${out}\nCouldn't find '$USER_RULES'" error="yes" fi # set the default policy # (do this after loading rules so not to break # network rootfs w/ INPUT DROP during ufw init.) input_pol="$DEFAULT_INPUT_POLICY" if [ "$DEFAULT_INPUT_POLICY" = "REJECT" ]; then input_pol="DROP" fi output_pol="$DEFAULT_OUTPUT_POLICY" if [ "$DEFAULT_OUTPUT_POLICY" = "REJECT" ]; then output_pol="DROP" fi forward_pol="$DEFAULT_FORWARD_POLICY" if [ "$DEFAULT_FORWARD_POLICY" = "REJECT" ]; then forward_pol="DROP" fi printf "*filter\n"\ "# builtin chains\n"\ ":INPUT %s [0:0]\n"\ ":FORWARD %s [0:0]\n"\ ":OUTPUT %s [0:0]\n"\ "COMMIT\n" $input_pol $forward_pol $output_pol | $exe-restore -n || error="yes" done if [ ! -z "$IPT_SYSCTL" ] && [ -s "$IPT_SYSCTL" ]; then sysctl -e -q -p $IPT_SYSCTL || true fi if [ -x "$RULES_PATH/after.init" ]; then if ! "$RULES_PATH/after.init" start ; then error="yes" out="${out}\n'$RULES_PATH/after.init start' exited with error" fi fi if [ "$error" = "yes" ]; then /bin/echo -e "$out" return 1 fi else out="Skip starting firewall: ufw (not enabled)" fi if [ ! -z "$out" ]; then /bin/echo -e "$out" fi } ufw_stop() { if [ "$1" != "--force" ] && [ "$ENABLED" != "yes" ] && [ "$ENABLED" != "YES" ]; then echo "Skip stopping firewall: ufw (not enabled)" return 0 fi error="" if [ -x "$RULES_PATH/before.init" ]; then if ! "$RULES_PATH/before.init" stop ; then error="yes" out="${out}\n'$RULES_PATH/before.init stop' exited with error" fi fi # If we manage the builtins, just return if [ "$MANAGE_BUILTINS" = "yes" ]; then flush_builtins || error="yes" if [ -x "$RULES_PATH/after.init" ]; then "$RULES_PATH/after.init" stop || error="yes" fi if [ "$error" = "yes" ]; then return 1 fi return 0 fi execs="iptables" if ip6tables -L INPUT -n >/dev/null 2>&1; then execs="$execs ip6tables" fi for exe in $execs do type="" if [ "$exe" = "ip6tables" ]; then type="6" fi delete_chains $type || error="yes" $exe -P INPUT ACCEPT || error="yes" $exe -P OUTPUT ACCEPT || error="yes" $exe -P FORWARD ACCEPT || error="yes" done if [ -x "$RULES_PATH/after.init" ]; then if ! "$RULES_PATH/after.init" stop ; then error="yes" fi fi if [ "$error" = "yes" ]; then return 1 fi return 0 } ufw_reload() { if [ "$ENABLED" = "yes" ] || [ "$ENABLED" = "YES" ]; then if [ -x "$RULES_PATH/before.init" ]; then "$RULES_PATH/before.init" stop || return 1 fi ufw_stop || return "$?" if [ -x "$RULES_PATH/after.init" ]; then "$RULES_PATH/after.init" stop || return 1 fi if [ -x "$RULES_PATH/before.init" ]; then "$RULES_PATH/before.init" start || return 1 fi ufw_start || return "$?" if [ -x "$RULES_PATH/after.init" ]; then "$RULES_PATH/after.init" start || return 1 fi else echo "Skipping $1 (not enabled)" fi return 0 } ufw_status() { err="" iptables -L ufw-user-input -n >/dev/null 2>&1 || { echo "Firewall is not running" return 3 } if [ "$IPV6" = "yes" ] || [ "$IPV6" = "YES" ]; then ip6tables -L ufw6-user-input -n >/dev/null 2>&1 || { # unknown state: ipv4 ok, but ipv6 isn't echo "Firewall in inconsistent state (IPv6 enabled but not running)" return 4 } fi echo "Firewall is running" return 0 } iptables/after6.rules 0000644 00000001623 00000000000 0010555 0 ustar 00 # # rules.input-after # # Rules that should be run after the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw6-after-input # ufw6-after-output # ufw6-after-forward # # Don't delete these required lines, otherwise there will be errors *filter :ufw6-after-input - [0:0] :ufw6-after-output - [0:0] :ufw6-after-forward - [0:0] # End required lines # don't log noisy services by default -A ufw6-after-input -p udp --dport 137 -j ufw6-skip-to-policy-input -A ufw6-after-input -p udp --dport 138 -j ufw6-skip-to-policy-input -A ufw6-after-input -p tcp --dport 139 -j ufw6-skip-to-policy-input -A ufw6-after-input -p tcp --dport 445 -j ufw6-skip-to-policy-input -A ufw6-after-input -p udp --dport 546 -j ufw6-skip-to-policy-input -A ufw6-after-input -p udp --dport 547 -j ufw6-skip-to-policy-input # don't delete the 'COMMIT' line or these rules won't be processed COMMIT iptables/after.rules 0000644 00000001754 00000000000 0010474 0 ustar 00 # # rules.input-after # # Rules that should be run after the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw-after-input # ufw-after-output # ufw-after-forward # # Don't delete these required lines, otherwise there will be errors *filter :ufw-after-input - [0:0] :ufw-after-output - [0:0] :ufw-after-forward - [0:0] # End required lines # don't log noisy services by default -A ufw-after-input -p udp --dport 137 -j ufw-skip-to-policy-input -A ufw-after-input -p udp --dport 138 -j ufw-skip-to-policy-input -A ufw-after-input -p tcp --dport 139 -j ufw-skip-to-policy-input -A ufw-after-input -p tcp --dport 445 -j ufw-skip-to-policy-input -A ufw-after-input -p udp --dport 67 -j ufw-skip-to-policy-input -A ufw-after-input -p udp --dport 68 -j ufw-skip-to-policy-input # don't log noisy broadcast -A ufw-after-input -m addrtype --dst-type BROADCAST -j ufw-skip-to-policy-input # don't delete the 'COMMIT' line or these rules won't be processed COMMIT check-requirements 0000755 00000016746 00000000000 0010247 0 ustar 00 #!/bin/sh # # check-requirements: verify all the required iptables functionality is # available # # Copyright 2008-2020 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # set -e chain="ufw-check-requirements" error="" error_runtime="" runcmd() { runtime="no" if [ "$1" = "runtime" ]; then runtime="yes" shift 1 fi local output ret=0 # make sure to always return success below because of set -e output=$( "$@" 2>&1 ) || ret=$? if [ $ret -eq 0 ]; then echo pass else if [ "$runtime" = "yes" ]; then echo "FAIL (no runtime support)" echo "error was: $output" error_runtime="yes" else echo FAIL echo "error was: $output" error="yes" fi fi } # check python found_python="no" echo -n "Has python: " for exe in python3 python2 python ; do if ! which $exe >/dev/null 2>&1; then continue fi v=`$exe --version 2>&1 | cut -f 2 -d ' '` if echo "$v" | grep -q "^2.[5-7]"; then echo "pass (binary: $exe, version: $v, py2)" found_python="yes" break elif echo "$v" | grep -q "^3.[1-9][0-9]*"; then echo "pass (binary: $exe, version: $v, py3)" found_python="yes" break fi done if [ "$found_python" != "yes" ]; then echo "ERROR: could not find valid python" >&2 error="yes" fi # check binaries for i in "" 6; do exe="iptables" if [ "$i" = "6" ]; then exe="ip6tables" fi echo -n "Has $exe: " if ! PATH=/sbin:/usr/sbin:/bin:/usr/bin which $exe >/dev/null 2>&1; then echo "ERROR: could not find '$exe'" >&2 error="yes" else echo "pass" fi done if [ -n "$error" ]; then exit 1 fi echo "" # check /proc for i in /proc/net/dev /proc/net/if_inet6; do echo -n "Has $i: " if [ ! -e "$i" ]; then echo "no" error="yes" else echo "pass" fi done if [ -n "$error" ]; then exit 1 fi echo "" echo "This script will now attempt to create various rules using the iptables" echo "and ip6tables commands. This may result in module autoloading (eg, for" echo "IPv6)." if [ "$1" != "-f" ]; then echo -n "Proceed with checks (Y/n)? " read ans if [ "$ans" = "n" ] || [ "$ans" = "N" ] || [ "$ans" = "no" ]; then echo "Aborting" exit 1 fi fi # check modules for i in "" 6; do exe="iptables" c="${chain}" ipv="4" if [ "$i" = "6" ]; then exe="ip6tables" c="${chain}6" ipv="6" fi if [ "$i" = "6" ]; then echo "== IPv6 ==" else echo "== IPv4 ==" fi echo -n "Creating '$c'... " $exe -N "$c" || { echo "ERROR: could not create '$c'. Aborting" >&2 error="yes" break } echo "done" # set up a RETURN rule right at the top, so we don't open anything up when # running the script. Isn't attached to INPUT, but better safe than sorry. echo -n "Inserting RETURN at top of '$c'... " $exe -I "$c" -j RETURN || { echo "ERROR: could insert RETURN rule into '$c'. Aborting" >&2 error="yes" break } echo "done" echo -n "TCP: " runcmd $exe -A $c -p tcp -j ACCEPT echo -n "UDP: " runcmd $exe -A $c -p udp -j ACCEPT echo -n "destination port: " runcmd $exe -A $c -p tcp --dport 22 -j ACCEPT echo -n "source port: " runcmd $exe -A $c -p tcp --sport 22 -j ACCEPT for j in ACCEPT DROP REJECT LOG; do echo -n "$j: " runcmd $exe -A $c -p tcp --sport 23 -j $j done echo -n "hashlimit: " runcmd $exe -A $c -m hashlimit -m tcp -p tcp --dport 22 --hashlimit 1/min --hashlimit-mode srcip --hashlimit-name ssh -m conntrack --ctstate NEW -j ACCEPT echo -n "limit: " runcmd $exe -A $c -m limit --limit 3/min --limit-burst 10 -j ACCEPT for j in NEW RELATED ESTABLISHED INVALID; do echo -n "ctstate ($j): " runcmd $exe -A $c -m conntrack --ctstate $j done echo -n "ctstate (new, recent set): " runcmd runtime $exe -A $c -m conntrack --ctstate NEW -m recent --set echo -n "ctstate (new, recent update): " runcmd runtime $exe -A $c -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 6 -j ACCEPT echo -n "ctstate (new, limit): " runcmd $exe -A $c -m conntrack --ctstate NEW -m limit --limit 3/min --limit-burst 10 -j ACCEPT echo -n "interface (input): " runcmd $exe -A $c -i eth0 -j ACCEPT echo -n "interface (output): " runcmd $exe -A $c -o eth0 -j ACCEPT echo -n "multiport: " runcmd $exe -A $c -p tcp -m multiport --dports 80,443,8080:8090 -j ACCEPT echo -n "comment: " runcmd $exe -A $c -m comment --comment 'dapp_Samba' if [ -z "$i" ]; then for j in LOCAL MULTICAST BROADCAST; do echo -n "addrtype ($j): " runcmd $exe -A $c -m addrtype --dst-type $j -j RETURN done for j in destination-unreachable source-quench time-exceeded parameter-problem echo-request; do echo -n "icmp ($j): " runcmd $exe -A $c -p icmp --icmp-type $j -j ACCEPT done else for j in destination-unreachable packet-too-big time-exceeded parameter-problem echo-request; do echo -n "icmpv6 ($j): " runcmd $exe -A $c -p icmpv6 --icmpv6-type $j -j ACCEPT done for j in neighbor-solicitation neighbor-advertisement router-solicitation router-advertisement; do echo -n "icmpv6 with hl ($j): " runcmd $exe -A $c -p icmpv6 --icmpv6-type $j -m hl --hl-eq 255 -j ACCEPT done echo -n "ipv6 rt: " runcmd $exe -A $c -m rt --rt-type 0 -j ACCEPT fi echo "" done # cleanup for i in "" 6; do exe="iptables" c="${chain}" if [ "$i" = "6" ]; then exe="ip6tables" c="${chain}6" fi $exe -F $c >/dev/null 2>&1 || { if [ -z "$error" ]; then echo "ERROR: could not flush '$c'" >&2 error="yes" fi } $exe -X $c >/dev/null 2>&1 || { if [ -z "$error" ]; then error="yes" echo "ERROR: could not remove '$c'" >&2 fi } done # check and warn if various firewall applications are installed found= for exe in apf arno-iptables-firewall ferm firehol firewalld ipkungfu iptables-persistent netfilter-persistent pyroman uruk ; do if PATH=/sbin:/usr/sbin:/bin:/usr/bin which "$exe" >/dev/null 2>&1; then found="$found $exe" fi done if [ ! -z "$found" ]; then echo "WARN: detected other firewall applications:" echo "$found" echo "(if enabled, these applications may interfere with ufw)" echo "" fi if [ -n "$error" ] || [ -n "$error_runtime" ]; then if [ -n "$error" ]; then echo "FAIL: check your kernel and that you have iptables >= 1.4.0" fi if [ -n "$error_runtime" ]; then echo "FAIL: check your kernel and iptables for additional runtime support" fi exit 1 fi echo "All tests passed" exit 0 ufw.conf 0000644 00000000470 00000000000 0006156 0 ustar 00 # /etc/ufw/ufw.conf # # Set to yes to start on boot. If setting this remotely, be sure to add a rule # to allow your remote connection before starting ufw. Eg: 'ufw allow 22/tcp' ENABLED=no # Please use the 'ufw' command to set the loglevel. Eg: 'ufw logging medium'. # See 'man ufw' for details. LOGLEVEL=low iptables/user.rules 0000644 00000000463 00000000000 0010345 0 ustar 00 *filter :ufw-user-input - [0:0] :ufw-user-output - [0:0] :ufw-user-forward - [0:0] :ufw-user-limit - [0:0] :ufw-user-limit-accept - [0:0] ### RULES ### -A ufw-user-limit -m limit --limit 3/minute -j LOG --log-prefix "[UFW LIMIT BLOCK] " -A ufw-user-limit -j REJECT -A ufw-user-limit-accept -j ACCEPT COMMIT iptables/before6.rules 0000644 00000015054 00000000000 0010721 0 ustar 00 # # rules.before # # Rules that should be run before the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw6-before-input # ufw6-before-output # ufw6-before-forward # # Don't delete these required lines, otherwise there will be errors *filter :ufw6-before-input - [0:0] :ufw6-before-output - [0:0] :ufw6-before-forward - [0:0] # End required lines # allow all on loopback -A ufw6-before-input -i lo -j ACCEPT -A ufw6-before-output -o lo -j ACCEPT # drop packets with RH0 headers -A ufw6-before-input -m rt --rt-type 0 -j DROP -A ufw6-before-forward -m rt --rt-type 0 -j DROP -A ufw6-before-output -m rt --rt-type 0 -j DROP # quickly process packets for which we already have a connection -A ufw6-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw6-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw6-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # multicast ping replies are part of the ok icmp codes for INPUT (rfc4890, # 4.4.1 and 4.4.2), but don't have an associated connection and are otherwise # be marked INVALID, so allow here instead. -A ufw6-before-input -p icmpv6 --icmpv6-type echo-reply -j ACCEPT # drop INVALID packets (logs these in loglevel medium and higher) -A ufw6-before-input -m conntrack --ctstate INVALID -j ufw6-logging-deny -A ufw6-before-input -m conntrack --ctstate INVALID -j DROP # ok icmp codes for INPUT (rfc4890, 4.4.1 and 4.4.2) -A ufw6-before-input -p icmpv6 --icmpv6-type destination-unreachable -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type packet-too-big -j ACCEPT # codes 0 and 1 -A ufw6-before-input -p icmpv6 --icmpv6-type time-exceeded -j ACCEPT # codes 0-2 (echo-reply needs to be before INVALID, see above) -A ufw6-before-input -p icmpv6 --icmpv6-type parameter-problem -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type echo-request -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type router-solicitation -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type neighbor-solicitation -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-input -p icmpv6 --icmpv6-type neighbor-advertisement -m hl --hl-eq 255 -j ACCEPT # IND solicitation -A ufw6-before-input -p icmpv6 --icmpv6-type 141 -m hl --hl-eq 255 -j ACCEPT # IND advertisement -A ufw6-before-input -p icmpv6 --icmpv6-type 142 -m hl --hl-eq 255 -j ACCEPT # MLD query -A ufw6-before-input -p icmpv6 --icmpv6-type 130 -s fe80::/10 -j ACCEPT # MLD report -A ufw6-before-input -p icmpv6 --icmpv6-type 131 -s fe80::/10 -j ACCEPT # MLD done -A ufw6-before-input -p icmpv6 --icmpv6-type 132 -s fe80::/10 -j ACCEPT # MLD report v2 -A ufw6-before-input -p icmpv6 --icmpv6-type 143 -s fe80::/10 -j ACCEPT # SEND certificate path solicitation -A ufw6-before-input -p icmpv6 --icmpv6-type 148 -m hl --hl-eq 255 -j ACCEPT # SEND certificate path advertisement -A ufw6-before-input -p icmpv6 --icmpv6-type 149 -m hl --hl-eq 255 -j ACCEPT # MR advertisement -A ufw6-before-input -p icmpv6 --icmpv6-type 151 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # MR solicitation -A ufw6-before-input -p icmpv6 --icmpv6-type 152 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # MR termination -A ufw6-before-input -p icmpv6 --icmpv6-type 153 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # ok icmp codes for OUTPUT (rfc4890, 4.4.1 and 4.4.2) -A ufw6-before-output -p icmpv6 --icmpv6-type destination-unreachable -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type packet-too-big -j ACCEPT # codes 0 and 1 -A ufw6-before-output -p icmpv6 --icmpv6-type time-exceeded -j ACCEPT # codes 0-2 -A ufw6-before-output -p icmpv6 --icmpv6-type parameter-problem -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type echo-request -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type echo-reply -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type router-solicitation -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type neighbor-advertisement -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type neighbor-solicitation -m hl --hl-eq 255 -j ACCEPT -A ufw6-before-output -p icmpv6 --icmpv6-type router-advertisement -m hl --hl-eq 255 -j ACCEPT # IND solicitation -A ufw6-before-output -p icmpv6 --icmpv6-type 141 -m hl --hl-eq 255 -j ACCEPT # IND advertisement -A ufw6-before-output -p icmpv6 --icmpv6-type 142 -m hl --hl-eq 255 -j ACCEPT # MLD query -A ufw6-before-output -p icmpv6 --icmpv6-type 130 -s fe80::/10 -j ACCEPT # MLD report -A ufw6-before-output -p icmpv6 --icmpv6-type 131 -s fe80::/10 -j ACCEPT # MLD done -A ufw6-before-output -p icmpv6 --icmpv6-type 132 -s fe80::/10 -j ACCEPT # MLD report v2 -A ufw6-before-output -p icmpv6 --icmpv6-type 143 -s fe80::/10 -j ACCEPT # SEND certificate path solicitation -A ufw6-before-output -p icmpv6 --icmpv6-type 148 -m hl --hl-eq 255 -j ACCEPT # SEND certificate path advertisement -A ufw6-before-output -p icmpv6 --icmpv6-type 149 -m hl --hl-eq 255 -j ACCEPT # MR advertisement -A ufw6-before-output -p icmpv6 --icmpv6-type 151 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # MR solicitation -A ufw6-before-output -p icmpv6 --icmpv6-type 152 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # MR termination -A ufw6-before-output -p icmpv6 --icmpv6-type 153 -s fe80::/10 -m hl --hl-eq 1 -j ACCEPT # ok icmp codes for FORWARD (rfc4890, 4.3.1) -A ufw6-before-forward -p icmpv6 --icmpv6-type destination-unreachable -j ACCEPT -A ufw6-before-forward -p icmpv6 --icmpv6-type packet-too-big -j ACCEPT # codes 0 and 1 -A ufw6-before-forward -p icmpv6 --icmpv6-type time-exceeded -j ACCEPT # codes 0-2 -A ufw6-before-forward -p icmpv6 --icmpv6-type parameter-problem -j ACCEPT -A ufw6-before-forward -p icmpv6 --icmpv6-type echo-request -j ACCEPT -A ufw6-before-forward -p icmpv6 --icmpv6-type echo-reply -j ACCEPT # ok icmp codes for FORWARD (rfc4890, 4.3.2) # Home Agent Address Discovery Reques -A ufw6-before-input -p icmpv6 --icmpv6-type 144 -j ACCEPT # Home Agent Address Discovery Reply -A ufw6-before-input -p icmpv6 --icmpv6-type 145 -j ACCEPT # Mobile Prefix Solicitation -A ufw6-before-input -p icmpv6 --icmpv6-type 146 -j ACCEPT # Mobile Prefix Advertisement -A ufw6-before-input -p icmpv6 --icmpv6-type 147 -j ACCEPT # allow dhcp client to work -A ufw6-before-input -p udp -s fe80::/10 --sport 547 -d fe80::/10 --dport 546 -j ACCEPT # allow MULTICAST mDNS for service discovery -A ufw6-before-input -p udp -d ff02::fb --dport 5353 -j ACCEPT # allow MULTICAST UPnP for service discovery -A ufw6-before-input -p udp -d ff02::f --dport 1900 -j ACCEPT # don't delete the 'COMMIT' line or these rules won't be processed COMMIT iptables/before.rules 0000644 00000004751 00000000000 0010635 0 ustar 00 # # rules.before # # Rules that should be run before the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw-before-input # ufw-before-output # ufw-before-forward # # Don't delete these required lines, otherwise there will be errors *filter :ufw-before-input - [0:0] :ufw-before-output - [0:0] :ufw-before-forward - [0:0] :ufw-not-local - [0:0] # End required lines # allow all on loopback -A ufw-before-input -i lo -j ACCEPT -A ufw-before-output -o lo -j ACCEPT # quickly process packets for which we already have a connection -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # drop INVALID packets (logs these in loglevel medium and higher) -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny -A ufw-before-input -m conntrack --ctstate INVALID -j DROP # ok icmp codes for INPUT -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT # ok icmp code for FORWARD -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT # allow dhcp client to work -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT # # ufw-not-local # -A ufw-before-input -j ufw-not-local # if LOCAL, RETURN -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN # if MULTICAST, RETURN -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN # if BROADCAST, RETURN -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN # all other non-local packets are dropped -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny -A ufw-not-local -j DROP # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above # is uncommented) -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above # is uncommented) -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT # don't delete the 'COMMIT' line or these rules won't be processed COMMIT iptables/user6.rules 0000644 00000000153 00000000000 0010427 0 ustar 00 *filter :ufw6-user-input - [0:0] :ufw6-user-output - [0:0] :ufw6-user-forward - [0:0] ### RULES ### COMMIT after.init 0000644 00000002146 00000000000 0006476 0 ustar 00 #!/bin/sh # # after.init: if executable, called by ufw-init. See 'man ufw-framework' for # details. Note that output from these scripts is not seen via the # the ufw command, but instead via ufw-init. # # Copyright 2013 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # set -e case "$1" in start) # typically required ;; stop) # typically required ;; status) # optional ;; flush-all) # optional ;; *) echo "'$1' not supported" echo "Usage: after.init {start|stop|flush-all|status}" ;; esac before.init 0000644 00000002152 00000000000 0006634 0 ustar 00 #!/bin/sh # # before.init: if executable, called by ufw-init. See 'man ufw-framework' for # details. Note that output from these scripts is not seen via the # the ufw command, but instead via ufw-init. # # Copyright 2013 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # set -e case "$1" in start) # typically required ;; stop) # typically required ;; status) # optional ;; flush-all) # optional ;; *) echo "'$1' not supported" echo "Usage: before.init {start|stop|flush-all|status}" ;; esac before.rules.md5sum 0000644 00000001056 00000000000 0010236 0 ustar 00 dd5050aa836d8a344c756367865a7c17 /usr/share/ufw/before.rules 8cfcfe296c7da50940e06fc0314f7523 /usr/share/ufw/before.rules 92023757ab10549ac2bba7c75b6000f3 /usr/share/ufw/before.rules e5f58e321f38dd7534380937b470c928 /usr/share/ufw/before.rules e30217e2a69b3da17edaf2b54374fe4f /usr/share/ufw/before.rules 8e482ff92456fcb9ea15ecbd96ea8cf5 /usr/share/ufw/before.rules 56d63ca8194e54030efb54141f42b32c /usr/share/ufw/before.rules 5fee8ec1341cebdd2d20c4946ef3cb5b /usr/share/ufw/before.rules ba34f926d08b14b2ba22aadc5d077a5b /usr/share/ufw/before.rules after.rules.md5sum 0000644 00000000461 00000000000 0010074 0 ustar 00 a7775bfb75ae1db0ffb864ffdb8d1a8c /usr/share/ufw/after.rules 64b0c46e974d8fdb84ae3694da153097 /usr/share/ufw/after.rules 3a51c36bfd12a053c50860a6b332e2d2 /usr/share/ufw/after.rules 4ccebb1697335dec480cb1326d0cb018 /usr/share/ufw/after.rules def3ea0d3a1e470665c33ab5432d1ce8 /usr/share/ufw/after.rules user6.rules.md5sum 0000644 00000000075 00000000000 0010040 0 ustar 00 17cfc3d4736a7b51ae8e9a934635cd9f /usr/share/ufw/user6.rules messages/hu.mo 0000644 00000017071 00000000000 0007273 0 ustar 00 �� ? Y p q s � { � * ) T q 9 x ) � � + � ) 7 J ^ q ! � # � � � � C % X % ~ / � � � � / E \ p '