We ran an article on Mēs ilga rakstu par How to block an IP address in iptables in Linux Kā nobloķēt IP adresi iptables Linux a few days ago. pirms dažām dienām. 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. Lūk cildinošs raksts, kas parāda, kā noteikt IP adreses, uzbrucēji gadījumā aa atteikums pakalpojumu (vai DOS) uzbrukumiem.
To do this we will use free software called Lai to paveiktu, mēs izmantosim bezmaksas programmatūras sauc 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 strādā sinhronizācija ar iptables un uzrauga iptables žurnālus un pārbaudes ostu skenē un citiem aizdomīgiem satiksmi, kas parasti ir pazīmes, kāds mēģina ielauzties jūsu Linux serveri.
To begin, install psad. Lai sāktu, instalējiet 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: Ja jūs izmantojat aromāts Linux, kas ir fancy paketes vadības sistēmu, piemēram, Ubuntu vai Fedora jūs varat izmantot kādu no šādām komandām iegūt psad jūsu sistēma:
# sudo apt-get install psad # Sudo apt-get install psad
or vai
# yum install psad # Yum install psad
If this doesn't work for you head to the psad Ja tas nepalīdz jums galvu psad download page Download Page and download the format that works for you. un lejupielādējiet formātu, kas strādā priekš jums.
As I use an Ubuntu Linux server the rest of this tutorial will be Ubuntu specific. Kā es varu izmantot Ubuntu Linux servera pārējo šī apmācība būs Ubuntu specifiski. However, with some minor tweaking you should be able to make it work on other flavors of Linux. Tomēr ar nelieliem tweaking jums jābūt iespējai, lai tā darbotos uz citām flavors of Linux. Open the syslog.conf file with your favorite text editor: Open syslog.conf failu ar savu iecienītāko teksta redaktoru:
# vim /etc/syslog.conf # Spars / etc / syslog.conf
Add the following line at the end of the of the file: Pievienot šādu rindu beigās par failu:
kern.info |/var/lib/psad/psadfifo kern.info | / var / lib / psad / psadfifo
You can use the following command to accomplish the same thing: Jūs varat izmantot šādu komandu, lai veiktu to pašu:
# 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: Tagad restart sysklogd un klog daemons:
/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. Veids psad darbiem ir, ka tas būs noteikt un pilnvarot iptables bloķēt jebkuru aizdomīgu IP. Sometimes this might result in the blocking of an IP which you use. Dažkārt tas var izraisīt bloķēt IP kuru lietojat. To overcome this issue you should create a file containing a list of safe IP addresses. Lai pārvarētu šo problēmu jums vajadzētu izveidot failu, kas satur sarakstu par drošām IP adresēm. Create a file like this one: Izveidojiet failu like this one:
# vim /home/calvin/safeiplist.cfg # Spars / home / Calvin / safeiplist.cfg
Enter the IP addresses that you need psad to whitelist: Ievadiet IP adreses, kas jums ir nepieciešams psad to whitelist:
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. Netiek izmantota skriptu, piemēram, pēc viena konfigurēt iptables ar vajadzīgos noteikumus. Ņemiet vērā, ka šis skripts darbosies noņemt visus iepriekšējos iestatījumus no iptables setup. Copy and paste the following script on your Linux server, and replace the variables WORKDIR and SAFEIPLIST with the correct settings from your setup. Nokopējiet un ielīmējiet šādu skriptu jūsu Linux serveri, un aizvietot mainīgos WORKDIR un SAFEIPLIST ar Pareizos uzstādījumus no jūsu setup.
WORKDIR="/home/calvin/" WORKDIR = "/ home / Calvin /"
INTERVAL="5" Intervāls = "5"
HITCOUNT="5" HITCOUNT = "5"
SAFEIPLIST="safeiplist.cfg" SAFEIPLIST = "safeiplist.cfg"
cd $WORKDIR cd $ WORKDIR
iptables -F iptables-F
if [ -f $SAFEIPLIST ]; then ja [-f $ SAFEIPLIST], pēc tam
IPS=$(grep -Ev “^#” $SAFEIPLIST) IPS = $ (grep-Ev "^ #" $ SAFEIPLIST)
for i in $IPS par i $ IPS
do darīt
iptables -A INPUT -s $i -j ACCEPT iptables-A INPUT-s $ i-j ACCEPT
done izdarīts
fi fi
iptables -A INPUT -m state –state NEW -m recent –set iptables-A INPUT-m state-valsts NEW-m nesen izvirzītiem
iptables -A INPUT -m state –state NEW -m recent –update –seconds $INTERVAL –hitcount $HITCOUNT -j LOG iptables-A INPUT-m state-valsts NEW-m nesen-update sekundes $ Intervāls-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. Kāds skripts tas ir, ka tas logs IP adresi, ja tajā ir pieci vai vairāk mēģinājumiem veikt savienojumu ilgst piecas sekundes. I would suggest you use the script as is unless you know what you are doing while modifying it. Es gribētu ieteikt jums lietot skriptu, kā tas ir, ja vien jūs zināt, ko jūs darāt, bet mainīt to. One you are done, give it executable permissions and run it. Vienam tas ir paveikts, kā arī tā izpildāmā atļaujas un palaist to.
# chmod +x /home/calvin/ipblock.sh # Chmod + x / home / Calvin / ipblock.sh
# /home/calvin/ipblock.sh # / Home / Calvin / ipblock.sh
Now back to psad. Tagad atpakaļ uz psad. Open the psad configuration file and edit it. Open psad konfigurācijas failu un rediģēt to. These are the changes I suggest you make. Tās ir izmaiņas, iesaku jums darīt. Feel free to go through the psad documentation and make other changes: Jūtieties brīvi iet cauri psad dokumentāciju un veikt citas izmaiņas:
EMAIL_ADDRESSES you@yourdomain.com; EMAIL_ADDRESSES you@yourdomain.com;
Set machine's hostname: Set mašīnas resursdatora:
HOSTNAME yourdomain.com; Resursdatora yourdomain.com;
If you have only one network interface on this server, set HOME_NET to: Ja jums ir tikai viena tīkla saskarne uz šī servera, kas HOME_NET uz:
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: Jūs varat arī nepieciešamību pielāgot briesmu līmeni psad, un definēt kopumu ostas ignorēt, piemēram, prasīt psad ignorēt UDP porti 80 un 8080, lai šādas izmaiņas:
IGNORE_PORTS udp/80, udp/8080; IGNORE_PORTS udp/80, udp/8080;
Save and close the file. Saglabājiet un aizveriet failu. Then restart psad: Tad restart psad:
# /etc/init.d/psad restart # / Etc / init.d / psad restart
You are now good to go. Jūs tagad labi iet. To monitor psad's reports run the following command: Uzraudzīt psad ziņojumi palaist šādu komandu:
# psad -S # Psad-S
To remove automatically clocked IPs run the following command: Lai noņemtu automātiski clocked IP palaist šādu komandu:
# psad -F # Psad-F
psad is a very versatile and powerful tool. psad ir ļoti daudzpusīga un spēcīgs instruments. 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. Ja jūs zināt, kā to izmantot tā var darīt brīnumus jums, bet, ja jums nav jūs tiešām var izjaukt datoru. So please use psad with caution. Tātad, lūdzu, izmantojiet psad piesardzīgi.























One Response One Response
Stay in touch with the conversation, subscribe to the Uzturēt kontaktus ar sarunu, abonēt RSS feed for comments on this post RSS barību komentārus par šo ziņu . .
Continuing the Discussion Turpinot iztirzājumu