We ran an article on Vi løp en artikkel om How to block an IP address in iptables in Linux Slik blokkerer en IP-adresse i iptables på Linux a few days ago. for noen dager siden. 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. Her er en gratis artikkel som viser hvordan du kan registrere IP-adressene til angriperne i tilfelle aa denial of service (eller DOS) angrep.
To do this we will use free software called For å gjøre dette vil vi bruke fri programvare alarmert 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 arbeider synkronisert med iptables og overvåker iptables loggene og se etter port skanner og annen mistenkelig trafikk som vanligvis tegn på noen prøver å bryte inn i Linux-serveren.
To begin, install psad. Til å begynne, installere 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: Hvis du kjører en smak av Linux som har et fancy pakke styringssystem som Ubuntu eller Fedora du skal kunne bruke en av følgende kommandoer for å få psad på ditt system:
# sudo apt-get install psad Sudo apt-get install psad
or eller
# yum install psad # Yum installere psad
If this doesn't work for you head to the psad Hvis dette ikke fungerer for deg hodet til psad download page nedlastingssiden and download the format that works for you. og last ned et format som fungerer for deg.
As I use an Ubuntu Linux server the rest of this tutorial will be Ubuntu specific. Som jeg bruke en Ubuntu Linux server resten av denne opplæringen vil være Ubuntu bestemt. However, with some minor tweaking you should be able to make it work on other flavors of Linux. Men med noen mindre tweaking du skal kunne gjøre det fungere på andre varianter av Linux. Open the syslog.conf file with your favorite text editor: Åpne syslog.conf filen med din favoritt teksteditor:
# vim /etc/syslog.conf # Vim / etc / syslog.conf
Add the following line at the end of the of the file: Legg til følgende linje til slutten av av filen:
kern.info |/var/lib/psad/psadfifo kern.info | / var / lib / psad / psadfifo
You can use the following command to accomplish the same thing: Du kan bruke følgende kommando for å oppnå det samme:
# 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: Nå starter sysklogd og klog daemoner:
/etc/init.d/sysklogd restart / etc / init.d / sysklogd hvile
/etc/init.d/klogd restart / etc / init.d / klogd hvile
The way psad works is that it will detect and instruct iptables to block any suspicious IPs. Måten psad fungerer er at det vil oppdage og instruere iptables å hindre mistenkelig IP. Sometimes this might result in the blocking of an IP which you use. Noen ganger kan føre til blokkering av en IP som du bruker. To overcome this issue you should create a file containing a list of safe IP addresses. For å overkomme dette problemet bør du lage en fil som inneholder en liste over sikre IP-adresser. Create a file like this one: Opprett en fil som dette:
# vim /home/calvin/safeiplist.cfg # Vim / home / Calvin / safeiplist.cfg
Enter the IP addresses that you need psad to whitelist: Angi IP-adressene du trenger psad til hviteliste:
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. Ingen bruker et skript som fulgte man konfigurere iptables med de nødvendige reglene. Merk at dette skriptet vil fjerne alle tidligere innstillinger fra din iptables oppsett. Copy and paste the following script on your Linux server, and replace the variables WORKDIR and SAFEIPLIST with the correct settings from your setup. Kopier og lim inn følgende skript på Linux server og erstatte variablene WORKDIR og SAFEIPLIST med riktige innstillinger fra oppsettet ditt.
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 $]; deretter
IPS=$(grep -Ev “^#” $SAFEIPLIST) IPS = $ (grep-Ev "^ #" $ SAFEIPLIST)
for i in $IPS for i in $ IPS
do gjøre
iptables -A INPUT -s $i -j ACCEPT iptables-A INPUT-s $ i-j ACCEPT
done ferdig
fi fi
iptables -A INPUT -m state –state NEW -m recent –set iptables-A INPUT-m state-state NEW-m recent-sett
iptables -A INPUT -m state –state NEW -m recent –update –seconds $INTERVAL –hitcount $HITCOUNT -j LOG iptables-A INPUT-m state-state NEW-m recent-update-sekunder $ intervall-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. Hva scriptet gjør er at den logger en IP-adresse om det er fem eller flere forsøk på å koble seg i spennet av fem sekunder. I would suggest you use the script as is unless you know what you are doing while modifying it. Jeg foreslår at du bruker skriptet som er mindre du vet hva du gjør når du endrer den. One you are done, give it executable permissions and run it. En du er ferdig, gi den kjørbare tillatelser og kjøre den.
# chmod +x /home/calvin/ipblock.sh # Chmod + x / home / Calvin / ipblock.sh
# /home/calvin/ipblock.sh # / Home / Calvin / ipblock.sh
Now back to psad. Nå tilbake til psad. Open the psad configuration file and edit it. Åpne psad konfigurasjonsfilen og redigere den. These are the changes I suggest you make. Disse endringene jeg foreslår at du gjør. Feel free to go through the psad documentation and make other changes: Føl deg fri til å gå gjennom psad dokumentasjon og foreta andre endringer:
EMAIL_ADDRESSES you@yourdomain.com; EMAIL_ADDRESSES you@yourdomain.com;
Set machine's hostname: Still maskinen vertsnavn:
HOSTNAME yourdomain.com; HOSTNAME yourdomain.com;
If you have only one network interface on this server, set HOME_NET to: Hvis du bare har ett nettverksgrensesnitt på denne serveren, angir HOME_NET til:
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: Du kan også må justere fare nivåer for psad, og definere et sett med porter å ignorere, for eksempel spørre psad ignorere UDP port 80 og 8080, gjør følgende endring:
IGNORE_PORTS udp/80, udp/8080; IGNORE_PORTS udp/80, udp/8080;
Save and close the file. Lagre og lukk filen. Then restart psad: Start psad:
# /etc/init.d/psad restart # / Etc / init.d / psad hvile
You are now good to go. Du er nå godt å gå. To monitor psad's reports run the following command: Å overvåke psad rapporter kjøre følgende kommando:
# psad -S # Psad-S
To remove automatically clocked IPs run the following command: Slik fjerner automatisk klokket IP kjøre følgende kommando:
# psad -F # Psad-F
psad is a very versatile and powerful tool. psad er en meget allsidig og kraftig verktøy. 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. Hvis du vet hvordan du bruker det den kan gjøre underverker for deg, men hvis du ikke kan du virkelig lage til din datamaskin. So please use psad with caution. Så vennligst bruk psad med forsiktighet.























One Response One Response
Stay in touch with the conversation, subscribe to the Holde kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .
Continuing the Discussion Fortsetter Discussion