We ran an article on Najazdili sme na článok How to block an IP address in iptables in Linux Ako blokovať IP adresy v iptables v Linuxe a few days ago. pred niekoľkými dňami. Here's a complimentary article that shows you how to detect the IP addresses of attackers in case of aa denial of service (or DOS) attack. Tu je lichotivý článok, ktorý vám ukáže, ako zistiť IP adresy útočníkov v prípade aa denial of service (alebo DOS) útok.
To do this we will use free software called K tomu budeme používať slobodný softvér nazvaný psad psad . psad works in sync with iptables and monitors the iptables logs and checks for port scans and other suspicious traffic which are usually signs of someone trying to break into your Linux server. . Psad pracuje synchrónne s iptables a monitory iptables protokoly a kontroluje skenovanie portov a ďalších podozrivých dopravy, ktoré sú zvyčajne príznaky sa niekto snaží preniknúť do vášho servera Linux.
To begin, install psad. Ak chcete začať, nainštalujte psad. If you are running a flavor of Linux that has a fancy package management system like Ubuntu or Fedora you should be able to use either of the following commands to get psad on your system: Ak používate systém Linux príchuť, ktorá má chuť systém správy balíkov ako je Ubuntu alebo Fedora, mali by ste byť schopní používať jeden z týchto príkazov sa dostať psad vo vašom systéme:
# sudo apt-get install psad # Sudo apt-get install psad
or alebo
# yum install psad # Yum install psad
If this doesn't work for you head to the psad Ak to nebude pracovať pre vás hlavu psad download page download page and download the format that works for you. a stiahnuť vo formáte, ktorý pracuje pre vás.
As I use an Ubuntu Linux server the rest of this tutorial will be Ubuntu specific. Ako som používať Ubuntu Linux server zvyšok tohto tutoriálu bude Ubuntu konkrétne. However, with some minor tweaking you should be able to make it work on other flavors of Linux. Avšak, s niekoľkými menšími ladením, mali by ste byť schopní, aby to fungovalo na iné varianty Linux. Open the syslog.conf file with your favorite text editor: Otvorte súbor s syslog.conf váš obľúbený textový editor:
# vim /etc/syslog.conf # Vim / etc / syslog.conf
Add the following line at the end of the of the file: Pridajte nasledujúci riadok na koniec súboru:
kern.info |/var/lib/psad/psadfifo kern.info | / var / lib / psad / psadfifo
You can use the following command to accomplish the same thing: Môžete použiť nasledujúci príkaz na vykonanie to isté:
# echo -e 'kern.info\t|/var/lib/psad/psadfifo' >> /etc/syslog.conf # Echo-e 'kern.info \ t | / var / lib / psad / psadfifo'>> / etc / syslog.conf
Now restart the sysklogd and klog daemons: Teraz reštartujte sysklogd klog a démoni:
/etc/init.d/sysklogd restart / Etc / init.d / sysklogd restart
/etc/init.d/klogd restart / Etc / init.d / klogd restart
The way psad works is that it will detect and instruct iptables to block any suspicious IPs. Psad spôsobom funguje tak, že to bude detekovať a pokyn iptables blokovať akékoľvek podozrivé IP. Sometimes this might result in the blocking of an IP which you use. Niekedy to môže mať za následok zablokovanie IP, ktorý používate. To overcome this issue you should create a file containing a list of safe IP addresses. Na prekonanie tohto problému, mali by ste vytvoriť súbor obsahujúci zoznam bezpečných IP adries. Create a file like this one: Vytvorte súbor, ako je tento:
# vim /home/calvin/safeiplist.cfg # Vim / home / calvin / safeiplist.cfg
Enter the IP addresses that you need psad to whitelist: Zadajte IP adresy, ktoré potrebujete psad na bielu listinu:
127.0.0.0/24 127.0.0.0/24
192.168.0.0/24 192.168.0.0/24
122.164.34.240 122.164.34.240
No use a script like following one to configure iptables with the necessary rules. Note that this script will remove all previous settings from your iptables setup. Nemá zmysel skriptu, ako je za jedno nastaviť iptables s potrebné pravidlá. Poznamenajme, že tento skript odstráni všetky predchádzajúce nastavenia z vášho nastavenia iptables. Copy and paste the following script on your Linux server, and replace the variables WORKDIR and SAFEIPLIST with the correct settings from your setup. Skopírujte a prilepte nasledujúci skript na serveri Linux, a nahradiť premenné WorkDir a SAFEIPLIST sa správnym nastavením z vášho nastavenia.
WORKDIR="/home/calvin/" WorkDir = "/ home / calvin /"
INTERVAL="5" INTERVAL = "5"
HITCOUNT="5" Hitcount = "5"
SAFEIPLIST="safeiplist.cfg" SAFEIPLIST = "safeiplist.cfg"
cd $WORKDIR cd $ WorkDir
iptables -F iptables-F
if [ -f $SAFEIPLIST ]; then if [-f $ SAFEIPLIST], potom
IPS=$(grep -Ev “^#” $SAFEIPLIST) IPS = $ (grep-Ev "^ #" $ SAFEIPLIST)
for i in $IPS for i in $ IPS
do robiť
iptables -A INPUT -s $i -j ACCEPT iptables-A INPUT-s $ i-j ACCEPT
done hotovo
fi fi
iptables -A INPUT -m state –state NEW -m recent –set iptables-A INPUT-m state-state NEW-m-súbor nedávnej
iptables -A INPUT -m state –state NEW -m recent –update –seconds $INTERVAL –hitcount $HITCOUNT -j LOG iptables-A INPUT-m state-state NEW-m-update-poslednej sekundy $ INTERVAL-hitcount $ hitcount-j LOG
What the script does is that it logs an IP address if it makes five or more attempts at making a connection in the span of five seconds. Čo skript robí je, že protokoly IP adresy, ak to robí päť alebo viac pokusov na to, aby pripojenie v rozpätí piatich sekúnd. I would suggest you use the script as is unless you know what you are doing while modifying it. Osobne by som odporúčal použiť skript, ako je, ak viete, čo robíte, keď sa mení. One you are done, give it executable permissions and run it. Jeden je hotovo, dať spustiteľný oprávnenia a spustite ho.
# chmod +x /home/calvin/ipblock.sh # Chmod + x / home / calvin / ipblock.sh
# /home/calvin/ipblock.sh # / Home / calvin / ipblock.sh
Now back to psad. A teraz späť k psad. Open the psad configuration file and edit it. Otvorte psad konfiguračný súbor a upraviť ho. These are the changes I suggest you make. To sú zmeny, doporučuji vám urobiť. Feel free to go through the psad documentation and make other changes: Nebojte sa prejsť psad dokumentáciu a vykonať ďalšie zmeny:
EMAIL_ADDRESSES you@yourdomain.com; EMAIL_ADDRESSES you@yourdomain.com;
Set machine's hostname: Set stroje hostname:
HOSTNAME yourdomain.com; HOSTNAME yourdomain.com;
If you have only one network interface on this server, set HOME_NET to: Ak máte iba jedno sieťové rozhranie na tomto serveri, nastavte HOME_NET na:
HOME_NET NOT_USED; HOME_NET NOT_USED;
You can also need to adjust danger levels for psad, and define a set of ports to ignore, for example to ask psad ignore udp ports 80 and 8080, make the following change: Môžete tiež musieť upraviť nebezpečenstvo limity psad, a definovať sadu portov ignorovať, napríklad požiadať psad ignorovať UDP portoch 80 a 8080, vykonajte tieto zmeny:
IGNORE_PORTS udp/80, udp/8080; IGNORE_PORTS udp/80, udp/8080;
Save and close the file. Uložte a zatvorte súbor. Then restart psad: Reštartujte psad:
# /etc/init.d/psad restart # / Etc / init.d / psad restart
You are now good to go. Teraz ste dobré ísť. To monitor psad's reports run the following command: Ak chcete sledovať psad správy zadajte nasledujúci príkaz:
# psad -S # Psad-S
To remove automatically clocked IPs run the following command: Ak chcete odstrániť automaticky taktované IP zadajte nasledujúci príkaz:
# psad -F # Psad-F
psad is a very versatile and powerful tool. psad je veľmi univerzálny a výkonný nástroj. If you know how to use it it can do wonders for you, but if you don't you can really mess up your computer. Ak viete, ako ju používať, môže pre vás urobiť zázraky, ale ak nemáte, môžete naozaj zmätok do vášho počítača. So please use psad with caution. Takže, prosím, použite psad s opatrnosťou.























One Response Jedna odpoveď
Stay in touch with the conversation, subscribe to the Zostať v kontakte s konverzácia, prihláste sa RSS feed for comments on this post RSS kanál pre komentáre k tomuto príspevku . .
Continuing the Discussion Pokračovanie Diskusia