Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-17-2011, 03:52 AM
|
#1
|
|
LQ Newbie
Registered: May 2011
Posts: 28
Rep:
|
How to handle large numbers bruteforcers
My login page is being bruteforced by a large number of IPs. What do you think is the best way to prevent this from happening?
|
|
|
|
12-17-2011, 04:19 AM
|
#2
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
|
Hello,
There are several ways. You could install and configure something like Fail2Ban which should do the trick. Until you've installed and configured some protection you could use this script I've found on the internet (don't remember where) which rejects connections from the same IP if the number of connections is greater then 10 (easy to adjust). I've changed that script to do a similar thing with SSH connections and recently put it in place on some production server that got attacked.
Code:
#! /bin/bash
while [ 1 ] ;
do
for ip in `lsof -ni | grep httpd | grep -iv listen | awk '{print $8}' | cut -d : -f 2 | sort | uniq | sed s/"http->"//` ;
# the line above gets the list of all connections and connection attempts, and produces a list of uniq IPs
# and iterates through the list
do
noconns=`lsof -ni | grep $ip | wc -l`;
# This finds how many connections there are from this particular IP address
echo $ip : $noconns ;
if [ "$noconns" -gt "10" ] ;
# if there are more than 10 connections established or connecting from this IP
then
# echo More;
# echo `date` "$ip has $noconns connections. Total connections to prod spider: `lsof -ni | grep httpd | grep -iv listen | wc -l`" >>/var/log/Ddos/Ddos.log
# to keep track of the IPs uncomment the above two lines and make sure you can write to the appropriate place
iptables -I INPUT -s $ip -p tcp -j REJECT --reject-with tcp-reset
# for these connections, add an iptables statement to send resets on any packets recieved
else
# echo Less;
fi;
done
sleep 60
done
Hope it helps.
Kind regards,
Eric
|
|
|
1 members found this post helpful.
|
12-17-2011, 05:14 AM
|
#3
|
|
LQ Newbie
Registered: May 2011
Posts: 28
Original Poster
Rep:
|
Hi,
Thanks for the bash script.
I only have one question what does "--reject-with tcp-reset" does? Isnt "-j REJECT" enough?
|
|
|
|
12-17-2011, 05:20 AM
|
#4
|
|
Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 18 with Awesome WM
Posts: 6,805
|
Hello,
You're welcome. From the man page of iptables:
Quote:
--reject-with type
The type given can be icmp-net-unreachable, icmp-host-unreachable, icmp-port-unreachable, icmp-proto-unreachable, icmp-net-prohibited, icmp-host-prohibited or icmp-admin-prohibited (*) which return the appropriate ICMP error message (port-unreachable is the default). The option tcp-reset can be used on rules which only match the TCP protocol: this causes a TCP RST packet to be sent back. This is mainly useful for blocking ident (113/tcp) probes which frequently occur when sending mail to broken mail hosts (which won't accept your mail otherwise).
|
Some more information:
http://www.lowth.com/cutter/#mozTocId654024
Kind regards,
Eric
Last edited by EricTRA; 12-17-2011 at 05:24 AM.
Reason: Useful link added
|
|
|
1 members found this post helpful.
|
12-17-2011, 08:18 AM
|
#5
|
|
Moderator
Registered: May 2001
Posts: 24,969
|
The script IMHO is a kludge. Not only because use of UNIX commands ('lsof -ni4tcp:80|awk '/\(L/ {print $8}';' being short for using lsof, grep, grep and awk) but because it is forced to reap the connection table per IP and when you're dealing with large amounts of connections that can't be good no matter /proc being a VFS. Rejecting connections from the same IP if the number of connections is greater then 10 can be accomplished with a single rule:
Code:
iptables -A INPUT -i eth0 -p tcp --syn --dport 80 -m connlimit --connlimit-above 10 -j DROP
|
|
|
5 members found this post helpful.
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:27 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|