LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Closed Thread
 
Search this Thread
Old 11-01-2004, 09:06 AM   #16
Bjorkli
Member
 
Registered: Jul 2003
Location: Norway
Posts: 65

Rep: Reputation: 15

This is a script that I found in another tread (hopefully not this one). Not sure who to credit for this script. I have not tried it on my machine yet, but it seems to be a good script.

Seems to add offending IP (hosts) to the iptables (firewall) rules.
Code:
#!/bin/sh

# Settings:
iptables="/sbin/iptables"
blockchain="blocking"
blocktarget="blacklist"

# This program will match lines:
# Illegal user (userid) from (host)
# Failed password for (userid) from (host) (...)
# and adds (host) to the iptables blacklist chain
# $blockchain.
#
#This chain is cleared regularly by a separate
# script to let entries expire after a while.

while read mm dd hms localhostname sshd word1 word2 word3 word4 host1 host2 rest; do
if [ "$word1 $word2 $word4" = "Illegal user from" ]; then
$iptables -A $blockchain -s ${host1}/32 -j $blocktarget
elif [ "$word1 $word2 $word3 $host1" = "Failed password for from" ]; then
$iptables -A $blockchain -s ${host2}/32 -j $blocktarget
fi
done
Hope it helps...
 
Old 11-01-2004, 10:48 AM   #17
BenODen
LQ Newbie
 
Registered: Oct 2004
Location: Colorado
Distribution: Fedora Core 2, Red Hat
Posts: 18

Rep: Reputation: 0
Personally, I think that script is to much of a heavy hammer. If I understand it correctly, if you fumble your own password once, the Ip
you're logging in from gets blocked.. It needs the other script (wherever it is) to back off a bit, and some counting of numbers of failures
is also in order it seems...

-Ben
 
Old 11-01-2004, 07:20 PM   #18
dmoorhouse
LQ Newbie
 
Registered: Sep 2004
Location: Whitehorse Yukon
Distribution: debian, Fedora, Ubuntu, more...
Posts: 9

Rep: Reputation: 0
I agree. That script looks promising. But counting the number of attempts would be great. I can see my deny chains becomming rather large

thanks for the script though. I'm going to look into it.
 
Old 11-11-2004, 04:32 AM   #19
Hamsjael
Member
 
Registered: Aug 2003
Location: Vejle, Denmark
Distribution: Mainly Debian, some Fedora for the bleeding edge fix
Posts: 92

Rep: Reputation: 15
Lightbulb How about this

It seems to me that these attacks try different usernames depending on what machine the attack is coming from.
I suspect that infected machines attacks with all users from the passwd file, although some user like "test" and "admin" seems constant.

Maybe this is naive, but how about this for a countermeasure:

Every time the sshd deamon get these attempts from illegal users the host should start pinging the address the attacks are coming from. This way a DoS situation will pretty soon affect the infected site, and the admins out there will be forced to take action, and clean up. ;-)

dont no if it would be illegal, and maybe it could be done in a more elegant way. but these attacks are really starting to annoy me.

An ssh server coming on the network will almost immedatly get its logs filled wwith this crap, and it has been goinig on for a LOT longer than the two weeks stated here.
 
Old 11-11-2004, 10:57 AM   #20
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Original Poster
Rep: Reputation: 57
Actually there are several versions of this malware. The first one used a limited password dictionary while newer versions have a substantially larger one like this example:

http://www.k-otik.com/exploits/08202004.brutessh2.c.php

You can see that the usernames and passwords are hard-coded, including the users test, guest, and admin. It would also be fairly trivial to add more passwords and usernames to the dictionary it's using, which likely accounts for some of the variability. Also note from the code that this is not a worm and doesn't "infect" systems by itself. If you find this on your system, it was likely uploaded manually or by an automated attack script.

Also I would highly recommend against using countermeasures like that against machines attempting these attacks. You're more likely to get into trouble with your ISP than to have an effect on the attacker. If you take preventative measures like disabling root logins, using good passwords, or switching to key-based authentication, you should be secure.

Also note that the post containing the "last two weeks" comment was posted at the beginning of August.

----
Btw, Happy Birthday.

Last edited by Capt_Caveman; 11-11-2004 at 11:00 AM.
 
Old 12-04-2004, 02:20 PM   #21
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
i haven't read this whole thread, but i'm curious about the hosts.allow.

can you specify a mac address to let through, instead of just an ip?
since i'll be using a laptop to access my server in varying locations.

thanks.
 
Old 12-05-2004, 03:52 AM   #22
adjman
LQ Newbie
 
Registered: Sep 2004
Location: Duncton, UK
Distribution: Lubuntu
Posts: 6

Rep: Reputation: 0
MAC Address

Yes, you can indeed specify MAC or Hardware addresses on the firewall for rules :

and would be done something like this

iptables -A INPUT -s any -m mac -mac-source 00:C7:8F:72:14 -j ACCEPT

You need to have compiled mac address matching into your kernel, or loaded the appropriate module.

Please correct me if I'm wrong chaps out there
 
Old 12-05-2004, 05:25 AM   #23
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Original Poster
Rep: Reputation: 57
The problem with using mac addresses is that the machine connecting has to be on the local network due to the fact that mac addresses aren't remotely transmited (in OSI terminology they're utilized on the link layer not the network layer). So if you were connecting remotely over the internet, you couldn't filter based on the remote systems mac address.
 
Old 12-15-2004, 08:33 PM   #24
jymbo
Member
 
Registered: Jan 2003
Posts: 217

Rep: Reputation: 30
Portsentry will add the offender to hosts.deny AND add a KILLROUTE. 3 caveats though:

1.) You need to run sshd on a differnet port
2.) You need to configure portsentry to monitor port 22
3.) To prevent your routing table from getting flooded, set-up a cronjob to flush it every 2 days or so
 
Old 12-20-2004, 07:36 PM   #25
whoisdevnull
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
Tried to read through all the posts here but couldn't make it ;-)

Don't know if this has already been posted, but there is some good information in a few places here.

A good summary: http://dev.gentoo.org/~krispykringle/sshnotes.txt

A blacklisting script: http://www.pettingers.org/code/SSHBlack.html

A look at what they do once they get in: http://www.security.org.sg/gtec/hone...diary=20041102

Sorry if these are dupes of other posts, we're six pages in here!
 
Old 12-27-2004, 06:55 PM   #26
whoisdevnull
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
Here is another one. Haven't looked at it too closely, the script from a few posts above is working fine.


http://linux.newald.de/new_design/login_check.html



-Mike
 
Old 12-29-2004, 12:15 AM   #27
IchBin
Member
 
Registered: Dec 2004
Distribution: Tinysofa Classic
Posts: 75

Rep: Reputation: 15
well there are a couple of IP's that I would like to give access. Is that possible?
 
Old 12-29-2004, 12:57 AM   #28
flipcode
Member
 
Registered: Dec 2004
Distribution: Red Hat 9, Fedora Core 3, KNOPPIX
Posts: 33

Rep: Reputation: 15
Yes, a sample iptables script would be:

Code:
IPT=/sbin/iptables

echo "Start of INPUT DROP"
	$IPT -N input-drop
	$IPT -t filter -A input-drop -j LOG --log-level info --log-prefix input-drop:
	$IPT -t filter -A input-drop -j DROP
echo "End of INPUT DROP"

echo "Start of INPUT ACCEPT"
	$IPT -N input-accept
	$IPT -t filter -A input-accept -j LOG --log-level info --log-prefix input-accept:
	$IPT -t filter -A input-accept -j ACCEPT
echo "End of INPUT ACCEPT"

echo "Start of INPUT Chain"
	$IPT -t filter -p tcp --dport 22 -s 203.215.112.231 -j input-accept
	$IPT -t filter -p tcp --dport 22 -s 203.215.112.232 -j input-accept
	$IPT -t filter -p tcp --dport 22 -s 203.215.112.233 -j input-accept
	$IPT -t filter -p tcp --dport 22 -j input-drop
	$IPT -t filter -p udp --dport 22 -j input-drop
echo "End of INPUT Chain"
Obviously you would modify the IPs as shown above. I also like to log connection acceptance and dropping.

Hope this helps.

Last edited by flipcode; 12-29-2004 at 05:42 AM.
 
Old 12-29-2004, 05:43 AM   #29
flipcode
Member
 
Registered: Dec 2004
Distribution: Red Hat 9, Fedora Core 3, KNOPPIX
Posts: 33

Rep: Reputation: 15
By the way, those log file entries are located in /var/log/messages just in case you wondered.
 
Old 12-30-2004, 07:26 PM   #30
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
just read a nice little article and then did some more reading on this subject.

/etc/ssh/sshd_config
AllowGroups
This keyword can be followed by a list of group name patterns, separated by spaces. If specified, login is
allowed only for users whose primary group or supplementary group list matches one of the patterns. '*'
and '?' can be used as wildcards in the patterns. Only group names are valid; a numerical group ID is not
recognized. By default, login is allowed for all groups.

AllowUsers
This keyword can be followed by a list of user name patterns, separated by spaces. If specified, login is
allowed only for user names that match one of the patterns. '*' and '?' can be used as wildcards in the
patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed
for all users. If the pattern takes the form USER@HOST then USER and HOST are separately checked,
restricting logins to particular users from particular hosts.

that should help alot of people out.
 
  


Closed Thread

Tags
ssh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH login attempts Capt_Caveman Linux - Security 225 11-07-2009 10:55 AM
SSH tricks -- any way to block failed attempts by IP address tensigh Linux - Security 10 06-06-2008 04:46 PM
ssh login attempts from localhost?! sovietpower Linux - Security 2 05-29-2005 02:19 AM
SSH login attempts - how to get rid of the automated malware? alexberk Linux - Security 1 05-24-2005 05:57 AM
/var/log/messages shows failed login attempts... plan9 Linux - Security 8 08-08-2004 01:52 PM


All times are GMT -5. The time now is 05:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration