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 |
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 |
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. |
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:
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. |
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. |
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 |
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 |
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! |
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 |
well there are a couple of IP's that I would like to give access. Is that possible?
|
Yes, a sample iptables script would be:
Code:
IPT=/sbin/iptables Hope this helps. |
By the way, those log file entries are located in /var/log/messages just in case you wondered.
|
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. |
All times are GMT -5. The time now is 10:46 PM. |