Nowe posty

Autor Wątek: Jak zabezpieczyć się przed atakami sieciowymi DoS/DDoS?  (Przeczytany 4080 razy)

szeos

  • Gość
Witam. Zainstalowalem sobie (wczoraj) Debiana 6.0(na serwerze dedykowanym) i chcialem pobawic sie w stawianie na nim pewnego serwera do gry. Znajomy polecil mi zapoznanie sie z IPtables i ogolnie z atakami typu dos.

Chcial bym podazyc krokami pewnego tutorialu ale nie za bardzo rozumiem gdzie mam zainstalowac te komendy ( Posiadam putty i WinSCP)

sciezki

/etc/init.d/iptables save
OR
/etc/rc.d/iptables save
nie istnieja a jedyne miejsce w jakim znalazlem cos co moglo by byc tym czego szukam jest lokalizacja



usr/sbin/iptables-apply
z tego co zrozumialem to do iptables trzeba wpisac

iptables -N conn-flood
iptables -I INPUT 1 -p tcp –syn -j conn-flood
iptables -A conn-flood -m limit –limit 7/s –limit-burst 20 -j RETURN
iptables -A conn-flood -j DROP
iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -j DROP
po czym zapisac i z glowy?


jest tu jeszcze


iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED -m recent --set -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m recent --update --seconds 3 --hitcount 20 -j DROP
Czy to rowniez zapisac w iptables?

nie wiem czy na pewno w tym iptables-accept a jezeli tak to gdzie dokladnie?

#!/bin/bash
#
# iptables-apply -- a safer way to update iptables remotely
#
# Copyright © Martin F. Krafft
# Released under the terms of the Artistic Licence 2.0
#
set -eu

PROGNAME="${0##*/}";
VERSION=1.0

TIMEOUT=10

function blurb()
{
    cat <<-_eof
    $PROGNAME $VERSION -- a safer way to update iptables remotely
    _eof
}

function copyright()
{
    cat <<-_eof
    $PROGNAME is C Martin F. Krafft .

    The program has been published under the terms of the Artistic Licence 2.0
    _eof
}

function about()
{
    blurb
    echo
    copyright
}

function usage()
{
    cat <<-_eof
    Usage: $PROGNAME [options] ruleset

    The script will try to apply a new ruleset (as output by iptables-save/read
    by iptables-restore) to iptables, then prompt the user whether the changes
    are okay. If the new ruleset cut the existing connection, the user will not
    be able to answer affirmatively. In this case, the script rolls back to the
    previous ruleset.

    The following options may be specified, using standard conventions:

    -t | --timeout    Specify the timeout in seconds (default: $TIMEOUT)
    -V | --version    Display version information
    -h | --help    Display this help text
    _eof
}

SHORTOPTS="t:Vh";
LONGOPTS="timeout:,version,help";

OPTS=$(getopt -s bash -o "$SHORTOPTS" -l "$LONGOPTS" -n "$PROGNAME" -- "$@") || exit $?
for opt in $OPTS; do
    case "$opt" in
        (-*) unset OPT_STATE;;
        (*)
            case "${OPT_STATE:-}" in
                (SET_TIMEOUT)
                    eval TIMEOUT=$opt
                    case "$TIMEOUT" in
                        ([0-9]*) :;;
                        (*)
                            echo "E: non-numeric timeout value." >&2
                            exit 1
                            ;;
                    esac
                    ;;
            esac
            ;;
    esac

    case "$opt" in
        (-h|--help) usage >&2; exit 0;;
        (-V|--version) about >&2; exit 0;;
        (-t|--timeout) OPT_STATE=SET_TIMEOUT;;
        (--) break;;
    esac
    shift
done

case "$PROGNAME" in
    (*6*)
        SAVE=ip6tables-save
        RESTORE=ip6tables-restore
        DEFAULT_FILE=/etc/network/ip6tables
        ;;
    (*)
        SAVE=iptables-save
        RESTORE=iptables-restore
        DEFAULT_FILE=/etc/network/iptables
        ;;
esac

FILE="${1:-$DEFAULT_FILE}";

if [[ -z "$FILE" ]]; then
    echo "E: missing file argument." >&2
    exit 1
fi

if [[ ! -r "$FILE" ]]; then
    echo "E: cannot read $FILE" >&2
    exit 2
fi

COMMANDS=(tempfile "$SAVE" "$RESTORE")

for cmd in "${COMMANDS[@]}"; do
    if ! command -v $cmd >/dev/null; then
        echo "E: command not found: $cmd" >&2
        exit 127
    fi
done

umask 0700

TMPFILE=$(tempfile -p iptap)
trap "rm -f $TMPFILE" EXIT 1 2 3 4 5 6 7 8 10 11 12 13 14 15

if ! "$SAVE" >"$TMPFILE"; then
    if ! grep -q ipt /proc/modules 2>/dev/null; then
        echo "E: iptables support lacking from the kernel." >&2
        exit 3
    else
        echo "E: unknown error saving current iptables ruleset." >&2
        exit 4
    fi
fi

[ -x /etc/init.d/fail2ban ] && /etc/init.d/fail2ban stop

echo -n "Applying new ruleset... "
if ! "$RESTORE" <"$FILE"; then
    echo "failed."
    echo "E: unknown error applying new iptables ruleset." >&2
    exit 5
else
    echo done.
fi

echo -n "Can you establish NEW connections to the machine? (y/N) "

read -n1 -t "${TIMEOUT:-15}" ret 2>&1 || :
case "${ret:-}" in
    (y*|Y*)
        echo
        echo ... then my job is done. See you next time.
        ;;
    (*)
        if [[ -z "${ret:-}" ]]; then
            echo "apparently not..."
        else
            echo
        fi
        echo "Timeout. Something happened (or did not). Better play it safe..."
        echo -n "Reverting to old ruleset... "
        "$RESTORE" <"$TMPFILE";
        echo done.
        exit 255
        ;;
esac

[ -x /etc/init.d/fail2ban ] && /etc/init.d/fail2ban start

exit 0

# vim:noet:sw=8
Mam nadzieje ze nie zagmatwalem tego za bardzo







Tutaj tutorial o ktorym mowilem
Limit number of connections [DoS prevention]                

                                Here is a simple code that you can use to prevent flood on all ports.
     
                                      iptables -N conn-flood
    iptables -I INPUT 1 -p tcp –syn -j conn-flood
    iptables -A conn-flood -m limit –limit 7/s –limit-burst 20 -j RETURN
    iptables -A conn-flood -j DROP
    iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT
    iptables -A INPUT -p icmp -j DROP                      
     
     
     IP's are limited to 7 connections / sec, and  overall 20 open connections (+1 icmp). You can likely reduce these  without causing lag. With 3/sec website will lag a bit if you got lots  of images and css files.
     
    You can also use this, it's the same as above only that it limits the  number of connections on all ports and protocols within a time specter.  In this case, 19 connections over 3 seconds.
     
                                      iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED -m recent --set -j ACCEPT
    iptables -I INPUT -p tcp -m state --state NEW -m recent --update --seconds 3 --hitcount 20 -j DROP                      
     
     
     Note, this doesn't prevent bandwidth bound attacks and attacks where origin can be spoofed, aga SYN floods and UDP floods.
     
    To save just run:
                                      /etc/init.d/iptables save
    OR
    /etc/rc.d/iptables save                      
     
     
     (One of them will fail, it depends on distro witch one that is correct)

Ksanderon

  • Gość
Jak zabezpieczyć się przed atakami sieciowymi DoS/DDoS?
« Odpowiedź #1 dnia: 2011-06-14, 20:39:32 »
zauważ, że aktualnie nie ma demona iptables- do tego jest jądro. Można ustalać reguły przez iptables lub wczytywać je z stdin poprzez iptables-restore oraz wysyłać na stdout przez iptables-save. Oczywiście można przekierować potoki stdin i stdout do plików. Aby reguły zostały ustawiane automagicznie przy starcie wystarczy więc w jakichś skryptach startowych zrobić(jako root afcross) np: iptables-restore
czyli:

1) reguły ustalasz przez polecenie iptables.
2) gdy wszystko będzie śmigać jak chcesz robisz  iptables-save>plik
3) dodajesz linijkę  iptables-restore4) każda zmiana iptables jest od ręki- bez żadnych stop, start etc.


* tak mnie się przynajmniej widzi, bo dawno się nie bawiłem

szeos

  • Gość
Jak zabezpieczyć się przed atakami sieciowymi DoS/DDoS?
« Odpowiedź #2 dnia: 2011-06-15, 18:23:57 »
Nie wiem czy dobrze zrozumialem ale utworzylem w etc plik xiptablesx.iptables a nastepnie wpisalem tam ten kod

 iptables -N conn-flood
iptables -I INPUT 1 -p tcp –syn -j conn-flood
iptables -A conn-flood -m limit –limit 7/s –limit-burst 20 -j RETURN
iptables -A conn-flood -j DROP
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -j DROP
a nastepnie wpisalem


root@ns382257:/opt/injectorzapto# iptables-restore
i otrzymalem...

iptables-restore: line 1 failed
Cytat: Ksanderon
zauważ, że aktualnie nie ma demona iptables- do tego jest jądro
Tj ip tables mam wbudowanego w debiana tak?



zeby nie robic postu pod postem


poszedlem sladami tego tutorialu


 
Only to Help. (Debian)

First.
Code:

cd /etc/init.d/
touch firewall.sh
vi firewall.sh       (Or your editor)

Second, copy all this lines and paste on firewall.sh
Code:

#!/bin/bash

#Starting Modules
modprobe ipt_recent

#Firewall
iptables -N conn-flood
iptables -I INPUT 1 -p tcp –syn -j conn-flood
iptables -A conn-flood -m limit –limit 7/s –limit-burst 20 -j RETURN
iptables -A conn-flood -j DROP
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -j DROP
iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED -m recent --set -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m recent --update --seconds 3 --hitcount 20 -j DROP

To save the editor.
Code:

:wq

Make the firewall executable
Code:

chmod +x firewall.sh

Now lets the firewall start with boot.
Code:

update-rc.d firewall.sh defaults

Done.

I accept with your firewall configurationn Stian.
If anything wrong, post here :P

Cya

Don Daniello have rules to firewall (Anti-DDOS) too.
Code:

echo "Block TCP-CONNECT scan attempts (SYN bit packets)"
iptables -A INPUT -p tcp --syn -j DROP
echo "Block TCP-SYN scan attempts (only SYN bit packets)"
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH SYN -j DROP
echo "Block TCP-FIN scan attempts (only FIN bit packets)"
iptables -A INPUT -m conntrack --ctstate NEW -p tcp --tcp-flags SYN,RST,ACK,FIN,URG,PSH

I never test this rules.
I mam komunikat
 
 
insserv: warning: script 'K01firewall.sh' missing LSB tags and overrides
insserv: warning: script 'firewall.sh' missing LSB tags and overrides
wiec poszukalem w internecie i znalazlem cos takiego

 
 
### BEGIN INIT INFO
# Provides:          spindown
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: hardisk spindown daemon
# Description:
#
### END INIT INFO
i otrzymalem cos takiego
 
update-rc.d: using dependency based boot sequencing
i nie mam pojecia co mowi ten komunikat...

Czy to oznacza ze juz jest dobrze czy wciaz jest to samo?

Ksanderon

  • Gość
Jak zabezpieczyć się przed atakami sieciowymi DoS/DDoS?
« Odpowiedź #3 dnia: 2011-06-16, 10:02:19 »
iptables-restore: line 1 failed
to raczej wskazuje na to, że coś nie pykło.
Nie w Debiana tylko w aktualne jądro chyba.

po co ty tak kombinujesz z tymi skryptami bash? które nie robią nic więcej w twoim przypadku niż iptables-restore?

na początku usuń wszystkie reguły a następnie dodawaj pojedynczo przez iptables. Gdy wyświetli jakiś komunikat wtedy przeanalizuj go. Gdy stwierdzisz, że wszystko jest ok przetestuj to co masz i iptables-save>plik, następnie gdzieś dodaj iptables-restore
komunikat ten znaczy dokładnie to co wynika z jego bezpośredniego tłumaczenia - że w różnych warunkach boot-owanie może różnie wyglądać(co raczej normalne nie jest).