Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-16-2012, 12:33 PM
|
#1
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Rep: 
|
ssh bruteforce
Hi all
how i can automatic denyy ip when some one do ssh bruteforce ....
|
|
|
06-16-2012, 12:42 PM
|
#2
|
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,551
|
Welcome to LQ!
There is a sticky post in the LQ Security forum that talks about this issue. There is a link in the last post of that thread that is extremely comprehensive. http://www.linuxquestions.org/questi...ml#post2027930
Look at Fail2Ban as it should serve your needs.
|
|
2 members found this post helpful.
|
06-22-2012, 10:04 AM
|
#3
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Original Poster
Rep: 
|
but i have script deny ssh bruteforce check it out
#!/bin/bash
#This script will monitor for failed login attempts and after a specified number of times add the ip to a deny list
#Chad
LOGFILE=”/var/log/secure”
HOSTSDENY=”/etc/hosts.deny”
BADCOUNT=”5"
# read logfile and look for invalid login attemps
grep sshd $LOGFILE |grep “Invalid user”| awk ‘{print $NF}’|sort|uniq -c|sort -n|sed “s/[[:space:]]*//” | while
read i
do
# read number of failed attempts
count=`echo $i | cut -d” ” -f1`
# read ip address from failed attempt
ip=`echo $i | cut -d” ” -f2`
#check hostdeny file to see if IP already exist
already=`grep $ip $HOSTSDENY | grep sshd`
#if IP does not exist add it to hostdeny file
if [ -z "$already" ]
then
if [ "$count" -ge "$BADCOUNT" ]
then
echo “sshd: “$ip >> $HOSTSDENY
fi
fi
done
so how about this script .....
|
|
|
06-22-2012, 10:17 AM
|
#4
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
Quote:
Originally Posted by maail
Hi all
how i can automatic denyy ip when some one do ssh bruteforce ....
|
Depending on your distro...
But on Red Hat systems (RHEL/CentOS/Fedora) you can edit the /etc/hosts.allow and the /etc/hosts.deny files
-C
|
|
|
06-22-2012, 10:24 AM
|
#5
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Original Poster
Rep: 
|
my distro fedora 12, can you try thiss script work or not in system because i do with this script not work in fedora 12.....
can you help me .....
|
|
|
06-22-2012, 11:07 AM
|
#6
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
Fedora 12 is an old distro. I would recommend upgrading to Fedora 17
Once you have that you can follow this example:
Let's say you want to deny the 192.168.2.54 address but allow all others
/etc/hosts.deny
/etc/hosts.allow
-C
|
|
|
06-22-2012, 11:46 AM
|
#7
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Original Poster
Rep: 
|
but i want to aoutomatic deny ip when someone attack my server with ssh bruteforce ....
|
|
|
06-22-2012, 12:03 PM
|
#8
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
Without writing the script for you
Something like
Code:
if ! grep ${ipaddr} /etc/hosts.deny ; then
cp /etc/hosts.deny /etc/,hosts.deny.bk
sed -e 's/sshd\: /sshd: ${ipaddr},/g' /etc/hosts.deny > /tmp/,hosts.deny
cat /tmp/,hosts.deny > /etc/hosts.deny
rm /tmp/,hosts.deny
fi
I'm sure you can fit that in with what you've already written....the white space in the sed statement is a TAB.
-C
|
|
|
06-22-2012, 12:06 PM
|
#9
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
Quote:
Originally Posted by maail
but i want to aoutomatic deny ip when someone attack my server with ssh bruteforce ....
|
Like someone else said before. Use fail2ban. That should serve your purpose. It will ban an IP after a specified number of attempts, and lock them out for a specified time.
Last edited by montel; 06-22-2012 at 12:06 PM.
Reason: spelling
|
|
|
06-22-2012, 09:57 PM
|
#10
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Original Poster
Rep: 
|
Quote:
Originally Posted by montel
Like someone else said before. Use fail2ban. That should serve your purpose. It will ban an IP after a specified number of attempts, and lock them out for a specified time.
|
are u sure fail2ban can deny ip automatic ....
can you explain step by step how to configuration fail2ban, because i not understand how to use fail2ban ....
sory my english bad, i from indonesia help me please !
|
|
|
06-24-2012, 01:29 AM
|
#11
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
Yeah, I have set fail2ban up on a few servers, it is very easy to install/administer.
I haven't used fedora much, so if im wrong with anything just let me know.
Code:
yum install fail2ban
Once it is finished installing, go into the /etc/fail2ban/jail.conf and configure with what you would like.
You can change the maxretry (the amount of times someone can try to login) and the bantime (how long the IP will be banned for).
There are lots of other settings in there too that you can tweak to fit what you want to do.
This may be helpful for you: http://www.howtoforge.com/preventing...ban-on-fedora9
Last edited by montel; 06-24-2012 at 01:30 AM.
|
|
|
06-24-2012, 01:51 AM
|
#12
|
LQ Newbie
Registered: Apr 2012
Posts: 6
Original Poster
Rep: 
|
Quote:
Originally Posted by montel
Yeah, I have set fail2ban up on a few servers, it is very easy to install/administer.
I haven't used fedora much, so if im wrong with anything just let me know.
Code:
yum install fail2ban
Once it is finished installing, go into the /etc/fail2ban/jail.conf and configure with what you would like.
You can change the maxretry (the amount of times someone can try to login) and the bantime (how long the IP will be banned for).
There are lots of other settings in there too that you can tweak to fit what you want to do.
This may be helpful for you: http://www.howtoforge.com/preventing...ban-on-fedora9
|
thank you friend ....
|
|
|
06-24-2012, 01:52 AM
|
#13
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
No problem. Good Luck 
|
|
|
All times are GMT -5. The time now is 06:50 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
|
|