Linux - SecurityThis 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.
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.
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
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...
Distribution: Mainly Debian, some Fedora for the bleeding edge fix
Posts: 92
Rep:
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.
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:
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 10:00 AM.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.