Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Forum Archive > Main Support Categories > Networking & Wireless
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Hello, Unregistered You are browsing a READ only archive of the main support categories pre 4/21/2008. You will not be able to post or reply any threads in this section.

Networking & Wireless
Having problems getting connected to the internet or getting your wireless card to work? Ask here.

 
Thread Tools Display Modes
Old April 30th, 2007   #1
Hopkins
5 Cups of Ubuntu
 
Join Date: Jan 2007
Beans: 19
Banning an IP Address?

Hi,

I've been running my own personal Ubuntu server for six months or so now, and I love it! However, it seems to attract script kiddies all the time The current one has been going for days, a different password every two seconds or so. The hard disk is blipping every time as it makes the log entry. Whilst it is very satisfying to know that Ubuntu (and my passwords!) can take this abuse, it is rather annoying. The guy's specifically trying to get into my vsftpd based ftp site, but is there a way to put in place some general remote access policy regardless of what someone is trying to log into? Something along the lines of 10 false attempts from a single IP address will result in a ban and all future requests will be ignored would be ideal.

I've spent a while trying to locate this information for myself, but I cannot find any forum posts asking a similar question! Does no-one else suffer from this problem?

Cheers.
Hopkins is offline   Reply With Quote
Old April 30th, 2007   #2
Lord Illidan
Ubuntu addict and loving it
 
Lord Illidan's Avatar
 
Join Date: Jun 2005
Location: Malta
Beans: 5,097
Ubuntu 7.10 Gutsy Gibbon
Send a message via MSN to Lord Illidan
Re: Banning an IP Address?

Are you using the command line to administrate the server? Why not learn more about iptables, the linux firewall here : http://www.netfilter.org/documentati...umentation-faq

Otherwise, if you are using a GUI, try using firestarter..
Lord Illidan is offline   Reply With Quote
Old April 30th, 2007   #3
Hopkins
5 Cups of Ubuntu
 
Join Date: Jan 2007
Beans: 19
Re: Banning an IP Address?

Thanks for the suggestion - I will do that! This server is command line only. I'd heard netfilter mentioned in relation to the Ubuntu Desktop that I'm trying on my laptop, but it had only been in passing and I hadn't followed it up.
Hopkins is offline   Reply With Quote
Old April 30th, 2007   #4
Hopkins
5 Cups of Ubuntu
 
Join Date: Jan 2007
Beans: 19
Re: Banning an IP Address?

Wow, that seems to be a pretty powerful system. It's going to take a bit more reading though I was trying to work out if I can achieve my aim using the "-m state" option, but it seems my brain is demanding I sleep now. Damn brain.
Hopkins is offline   Reply With Quote
Old May 2nd, 2007   #5
Hopkins
5 Cups of Ubuntu
 
Join Date: Jan 2007
Beans: 19
Re: Banning an IP Address?

I seem to be able to do all sorts of fancy stuff with iptables, such as "limit the number of new incoming connections in a given time period", but I can't figure out how to say "limit the number of new incoming connections in a given time period per IP address". Maybe I would have to do something like create a chain that will write an IP address to a log file if it connects too frequently and then have another chain forbid any IP addresses in the log file... If so it seems like quite a long-winded way to perform what must surely be a common function.

Am I missing something?

Thanks!
Hopkins is offline   Reply With Quote
Old May 2nd, 2007   #6
octoberdan
Gee! These Aren't Roasted!
 
octoberdan's Avatar
 
Join Date: Mar 2007
Location: Massachusetts
Beans: 197
Xubuntu 7.04 Feisty Fawn
Send a message via AIM to octoberdan Send a message via MSN to octoberdan Send a message via Yahoo to octoberdan
Re: Banning an IP Address?

Quote:
Originally Posted by Hopkins View Post
Hi,

I've been running my own personal Ubuntu server for six months or so now, and I love it! However, it seems to attract script kiddies all the time The current one has been going for days, a different password every two seconds or so. The hard disk is blipping every time as it makes the log entry. Whilst it is very satisfying to know that Ubuntu (and my passwords!) can take this abuse, it is rather annoying. The guy's specifically trying to get into my vsftpd based ftp site, but is there a way to put in place some general remote access policy regardless of what someone is trying to log into? Something along the lines of 10 false attempts from a single IP address will result in a ban and all future requests will be ignored would be ideal.

I've spent a while trying to locate this information for myself, but I cannot find any forum posts asking a similar question! Does no-one else suffer from this problem?

Cheers.
Quick fix:
http://www.linuxforums.org/forum/ubu...ip-vsftpd.html
__________________
Behold, how good and how pleasant it is for brethren to dwell together in unity!
octoberdan is offline   Reply With Quote
Old May 7th, 2007   #7
TauRush
First Cup of Ubuntu
 
Join Date: May 2007
Beans: 1
Re: Banning an IP Address?

I was looking for a script to stop those ftp attacks some time ago and found a possible solution at a Gentoo forum.
Although I am not using Gentoo (but Fedora) I gave the script a try.
After fixing some small issues and adding a permanent banlist, I have it working at home and at the office for some time now.
I am running the script every 2 minutes through a cronjob, to keep the amount of attacks small and also my logfiles don't overflow.

Thanks to destuxor for the initial setup of the script.

Here is my adjusted script for all to use.


Code:
#!/usr/bin/perl -w
# destuxor (wjholden@gmail.com) - 4/26/2006
# TauRush (snakesandarrows@gmail.com) - 3/17/2007
# A simple script to go through a VSFTPD log and block people who have
# unsuccessfully attempted to log in.

#configuration options:
$logfilename = '/var/log/vsftpd/vsftpd.log'; # location of your logfile.
$allow_exceptions = 1; # if you wish to specify a file to put exceptions into,
                       # say 1 here, otherwise put 0.
$exception_file = '/var/log/vsftpd/banned.log';  # if you said 1 above, put your filename here.
$max_failures = 5;    # maximum number of failures someone can have before
                       # getting blocked.
#end of configuration options

$command = 'grep \'FAIL LOGIN\' '.$logfilename.' | sed -r \'s/^.{0,}Client .//\' | sed -r \'s/\"//\' | uniq -c';

@connected_ips = `$command`;


undef %noblock;
if ($allow_exceptions == 1) {
    open (FH, $exception_file) or die "$!\n";
    @exceptions = <FH>;
    close (FH);
}

foreach $ip (@exceptions) {
# Added by TauRush to chop LF character
    chop ($ip);
    $noblock{"$ip"} = 1;
}

foreach $host (@connected_ips)
{
    @info = split(/\s+/, $host);
    if (($info[1] > $max_failures) and !$noblock{$info[2]}) {
        system("/sbin/iptables -I INPUT 1 -s $info[2] -j DROP");
# 3 lines added by TauRush to create banned.log file
        open FILE,">>$exception_file" or die "Unable to open file!\n";
        print FILE "$info[2]\n";
   close FILE;
    }
}
TauRush is offline   Reply With Quote
Old January 10th, 2008   #8
outz
First Cup of Ubuntu
 
Join Date: Jan 2008
Beans: 1
Re: Banning an IP Address?

TauRush, thanks for the script... it has been extremely helpful in blocking the brute force attacks on my vsftpd server.

I have modified the script to log the ip's being blocked to a file as well as time stamp them. I'm new to perl, but the changes I made seem to work.

Code:
#!/usr/bin/perl -w
# destuxor (wjholden@gmail.com) - 4/26/2006
# TauRush (snakesandarrows@gmail.com) - 3/17/2007
# outz (ubuntu@outz.com)- 1/09/2008
# A simple script to go through a VSFTPD log and block people who have
# unsuccessfully attempted to log in.

#configuration options:
$logfilename = '/var/log/vsftpd.log'; # location of your logfile.


# 1 line added by outz to create a file to store ip's being blocked

$blocked = '/var/log/blocked-ips.log'; # location to log ip's that were blocked

# 5 lines added by outz to create a timestamp for the blocked-ips.log

@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";

$allow_exceptions = 1; # if you wish to specify a file to put exceptions into,
                       # say 1 here, otherwise put 0.
$exception_file = '/var/log/banned.log';  # if you said 1 above, put your filename here.
$max_failures = 5;    # maximum number of failures someone can have before
                       # getting blocked.
#end of configuration options

$command = 'grep \'FAIL LOGIN\' '.$logfilename.' | sed -r \'s/^.{0,}Client .//\' | sed -r \'s/\"//\' | uniq -c';

@connected_ips = `$command`;


undef %noblock;
if ($allow_exceptions == 1) {
    open (FH, $exception_file) or die "$!\n";
    @exceptions = <FH>;
    close (FH);
}

foreach $ip (@exceptions) {
# Added by TauRush to chop LF character
    chop ($ip);
    $noblock{"$ip"} = 1;
}

foreach $host (@connected_ips)
{
    @info = split(/\s+/, $host);
    if (($info[1] > $max_failures) and !$noblock{$info[2]}) {
        system("/sbin/iptables -I INPUT 1 -s $info[2] -j DROP");

# 3 lines added by outz to write the blocked ip along with a timestamp to blocked-ips.log
        open FILE,">>$blocked" or die "Unable to open file!\n";
        print FILE "$theTime $info[2]\n";
   close FILE;

# 3 lines added by TauRush to create banned.log file
        open FILE,">>$exception_file" or die "Unable to open file!\n";
        print FILE "$info[2]\n";
   close FILE;
    }
}

Last edited by outz; May 13th, 2008 at 10:05 AM..
outz is offline   Reply With Quote
Old January 24th, 2008   #9
Mithrilhall
Ubuntu Extra Shot
 
Mithrilhall's Avatar
 
Join Date: Sep 2005
Location: The American Empire
Beans: 349
Re: Banning an IP Address?

You might also want to setup fail2ban.

http://www.fail2ban.org/wiki/index.php/Main_Page
__________________
Registered Linux User # 437006
http://sidux.com/ - K Desktop Environment (Debian Sid)
MasterShaper - Network traffic under control

Currently listening to
Mithrilhall is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:30 AM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry