LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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

Reply
 
LinkBack Search this Thread
Old 12-29-2004, 12:57 AM   #91
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, 01:05 AM   #92
IchBin
Member
 
Registered: Dec 2004
Distribution: Tinysofa Classic
Posts: 75

Rep: Reputation: 15
Awesome!

Cheers!
 
Old 12-29-2004, 05:43 AM   #93
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-29-2004, 05:32 PM   #94
whoisdevnull
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
Ooops, sorry, this was a reply to an earlier post....

Of course. You could do something like this (with three bogus hosts here as an example):

Code:
iptables -A INPUT -s 192.168.2.2 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 192.168.3.3 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 192.168.200.200 -p tcp --dport 22 -j ACCEPT
Assuming you had already done something like an:

Code:
iptables -P INPUT DROP
which sets the "policy" for your input chain to "DROP". That way anything that doesn't get caught by an explicit ACCEPT rule will get dropped.

I find this doesn't work for me because I use too many dynamic hosts to access my machine -- dial-ups, mooched wi-fi, DSL, etc. I would have to go in and fiddle my iptables a couple of times a day.

Although it is a bit more risky, if you know your ISP has a block at, say, 192.168.0.0 - 192.168.255.255 you can of couse use standard notation in iptables:

Code:
iptables -A INPUT -s 192.168.0.0/16 -p tcp --dport 22 -j ACCEPT

This opens it up to more addresses but still blocks off a huge portion of the Internet.

One comment on flipcode's post, I don't know if that will work without the -A or -I command. The -t filter is optional, but I don't think the actual "append" or "insert" command is.... not sure.


Last edited by whoisdevnull; 12-29-2004 at 05:48 PM.
 
Old 12-30-2004, 04:12 PM   #95
ryedunn
Member
 
Registered: Jul 2003
Location: Chicago
Distribution: Fedora, ubuntu
Posts: 458

Rep: Reputation: 30
Quick question I edited my sshd_config file but my logs apper different than others who have posted and are blocking them...

This is what I have:
Dec 30 14:00:53 www sshd[12565]: Invalid user blue from ::ffff:201.128.98.208
Dec 30 14:00:53 www sshd[12565]: error: Could not get shadow information for NOUSER
Dec 30 14:00:53 www sshd[12565]: Failed password for invalid user blue from ::ffff:201.128.98.208 port 46485 ssh2
Dec 30 14:00:53 www sshd[12567]: rexec line 96: Deprecated option RhostsAuthentication
Dec 30 14:00:55 www sshd[12567]: Invalid user red from ::ffff:201.128.98.208
Dec 30 14:00:55 www sshd[12567]: error: Could not get shadow information for NOUSER
Dec 30 14:00:55 www sshd[12567]: Failed password for invalid user red from ::ffff:201.128.98.208 port 46527 ssh2
Dec 30 14:00:56 www sshd[12569]: rexec line 96: Deprecated option RhostsAuthentication
Dec 30 14:00:58 www sshd[12569]: Invalid user yellow from ::ffff:201.128.98.208
Dec 30 14:00:58 www sshd[12569]: error: Could not get shadow information for NOUSER

where I would feel more confortable if my logs appard like this:
Oct 4 11:33:34 atr2 sshd[3251]: User root not allowed because listed in DenyUsers
Oct 4 11:33:34 atr2 sshd[3251]: Failed password for invalid user root from 4.28.181.157 port 50314 ssh2

Also, how can I get a summary such as this:
61.184.104.236 -j DROP # illegal ssh login attempt 22.9.2004
218.232.104.41 -j DROP # illegal ssh login attempt 22.9.2004
201.10.45.4 -j DROP # illegal ssh login attempt 23.9.2004
218.188.9.51 -j DROP # illegal ssh login attempt 23.9.2004
148.215.14.181 -j DROP # illegal ssh login attempt 24.9.2004
70.240.3.138 -j DROP # illegal ssh login attempt 24.9.2004

Thanks
R
 
Old 12-30-2004, 07:26 PM   #96
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.
 
Old 12-30-2004, 08:38 PM   #97
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 14,972

Rep: Reputation: 528Reputation: 528Reputation: 528Reputation: 528Reputation: 528Reputation: 528
One person asked whether or not the entire IP block should be blocked in the firewall or just the individual offender.

I think a sensible policy would be to report the offending IP address to the ISP. If the ISP doesn't address the problem, then don't trust any address from that IP block.
 
Old 12-30-2004, 09:14 PM   #98
whoisdevnull
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
Quote:
Originally posted by jschiwal

I think a sensible policy would be to report the offending IP address to the ISP. If the ISP doesn't address the problem, then don't trust any address from that IP block.

This would be fine except about 80% of my attackers don't have a reverse DNS entry so one is left to guess who they belong to. It is true that most of these machines are trojaned and it would be a good idea to let the owner know.
I have reported a few that belong to universities around the world and got replies from a few of them. Basically if the address doesn't reverse or it shows up in China or Asia, I just block it and forget about it. If the owner doesn't care enough to set up their DNS entries correctly, I can't help them with their trojan problems.

I don't think there is any use in blacklisting entire netblocks. This is a per-machine problem, not organized groups of hackers. Spammers are where you want to blacklist the entire netblock.

Just my $0.02....
 
Old 12-30-2004, 10:29 PM   #99
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 14,972

Rep: Reputation: 528Reputation: 528Reputation: 528Reputation: 528Reputation: 528Reputation: 528
The rational behind my suggestion is that if the organization owning the block is indifferent to abuse by its members, then the entire organization shouldn't be trusted and could be rightly considered a hacker's haven. Admittedly this situation is most likely a rare case, but maybe not for certain geographic locations.
 
Old 01-09-2005, 01:07 PM   #100
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
this seems to be a nice little script for those that are really paranoid about there ssh port.

http://www.undersea.net/seanm/softwa...-access.tar.gz

take a look at the README in it. it tells you how to set the whole thing up.

you might have to wget it.
 
Old 01-25-2005, 01:47 AM   #101
carboncopy
Senior Member
 
Registered: Jan 2003
Location: Malaysia
Distribution: Fedora Core, Slackware, Mac OS X, Debian, OpenSUSE
Posts: 1,210
Blog Entries: 4

Rep: Reputation: 45
My machine has also been attempted on.

I know debate on counter measure is on going. Basically I see 2 category of counter measure.

1. Hardening the system. Including using non-standard port but not limited to that.
2. Block access. At firewall OR host.deny/host.allow.

Now, I am interested with the source of attack. It has been debated whether to block the whole net block or just the attacker IP. It would be good if we can consolidate the IPs which attacker is coming from. At least we can try to analysis the source satistically. It would also form a database for those who wants to use Blocking measure. Admins here can also analyze the treats pose by the Net Block (IP range owner).

I don't think it is too difficult, just write a script to gather all attacker's IPs and filter out duplicates. I am willing to host the list on a webhosting account I have.
 
Old 01-26-2005, 10:03 PM   #102
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
the whole thing about building a db for this, is that basically all of these are coming from dynamic ip's, or from compromised machines.

i've had attempts from all over the world, u.s., japan, china, poland, cz republic, so they're from all over. one of the best things that you can do is to set up a mailing script, which i'm going to work on now, to email the isp of the address telling them what is going on.

from a couple of replies that i've received back from the isp's, is to put the log output into the text of the file and not as an attachment. i had one that wouldn't receive it as an attachment.

cheers.
 
Old 01-29-2005, 11:26 AM   #103
junkken
LQ Newbie
 
Registered: Jul 2004
Posts: 7

Rep: Reputation: 0
RE: one of the best things that you can do is to set up a mailing script, which i'm going to work on now, to email the isp of the address telling them what is going on"

I really can't believe what I am reading here. Are we proposing sending automated emails to ISP's to inform them of automated ssh scripts? At what point would this include reporting someone wget'ing something off your web server or nmap'ing your server? Where do search bots come into the picture?

I am of the opinion that the best approach is to learn how to properly secure the system so these trivial scripts and their results become un-interesting to their authors. I do not want some "ISP authority" telling me I cant do something on the internet "cause someone reported me".

Remember, since there is quite a long wait in response to an incorrect login these scripts place virtually no load on the system.

Cheers
 
Old 01-29-2005, 03:51 PM   #104
emetib
Member
 
Registered: Feb 2003
Posts: 482

Rep: Reputation: 33
Jan 23 08:21:40 prometheus sshd[32496]: Illegal user robert from ::ffff:66.79.171.190
Jan 23 08:21:41 prometheus sshd[32502]: Illegal user coolboy from ::ffff:66.79.171.190
Jan 23 08:21:42 prometheus sshd[32504]: Illegal user derek from ::ffff:66.79.171.190
Jan 23 08:21:43 prometheus sshd[32506]: Illegal user james from ::ffff:66.79.171.190
Jan 23 08:21:45 prometheus sshd[32508]: Illegal user james from ::ffff:66.79.171.190
Jan 23 08:21:46 prometheus sshd[32510]: Illegal user james from ::ffff:66.79.171.190
Jan 23 08:21:48 prometheus sshd[32512]: Illegal user lisa from ::ffff:66.79.171.190
Jan 23 08:21:49 prometheus sshd[32514]: Illegal user mario from ::ffff:66.79.171.190
Jan 23 08:21:51 prometheus sshd[32516]: Illegal user martin from ::ffff:66.79.171.190
Jan 23 08:21:53 prometheus sshd[32518]: Illegal user sonya from ::ffff:66.79.171.190
Jan 23 08:21:55 prometheus sshd[32520]: Illegal user tony from ::ffff:66.79.171.190
Jan 23 08:21:57 prometheus sshd[32522]: Illegal user just from ::ffff:66.79.171.190
Jan 23 08:22:00 prometheus sshd[32524]: Illegal user justice from ::ffff:66.79.171.190
Jan 23 08:22:02 prometheus sshd[32530]: Illegal user bank from ::ffff:66.79.171.190
Jan 23 08:22:03 prometheus sshd[32532]: Illegal user vip from ::ffff:66.79.171.190

so if i'm looking into my logs for this kind of thing, which wget doesn't make, then you're trying to tell me that i shouldn't be sending an alert to the isp?
 
Old 02-03-2005, 09:25 AM   #105
johnnydangerous
Member
 
Registered: Jan 2005
Location: Sofia, Bulgaria
Distribution: Fedora Core 4 Rawhide
Posts: 431

Rep: Reputation: 30
Red face

what is that +i for?
 
  


Reply

Tags
hostsdeny, keys, 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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh...log files that store the login attempts Bgrad Linux - Networking 4 03-29-2010 10:40 AM
Failed SSH login attempts Capt_Caveman Linux - Security 38 01-03-2006 04:22 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
How do I block IP's to prevent unauthorized SSH login attempts? leofoxx Linux - Security 6 05-23-2005 10:36 PM


All times are GMT -5. The time now is 07:47 AM.

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
Open Source Consulting | Domain Registration