LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 12-29-2007, 09:53 AM   #16
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40

my simple and Q&D script all of the sudden became a big and comprehensive one. ha-ha
Thank you overy much for detailed explanation and putting the script together.
I have 2 questions :
Quote:
Code:
$IPT -A OUTPUT -p TCP -o eth0 -m multiport --dports 21,80,443 \
-d ! $LAN -m state --state NEW -j ACCEPT

$IPT -A OUTPUT -p UDP -o eth0 -m multiport --dports 53,123 \
-d ! $LAN -m state --state NEW -j ACCEPT

$IPT -A OUTPUT -m owner --uid-owner dbabo \
-m state --state NEW -j ACCEPT

$IPT -A OUTPUT -m owner --uid-owner root \
-m state --state NEW -j ACCEPT
i read this : "if this is a LAN - don't allow outbound on specified ports. But allow for users dbabo or root even if it's on spec LAN and ports."
Now, should i read it:
"if this is a LAN - don't allow outbound on specified ports. But allow for all other ports/protocols if user is dbabo or root.
Or it is:
"if this is a LAN - don't allow outbound on specified ports. Allow for all other ports/protocols if user is dbabo or root"

Another question is :
say if the server has many users. Say, it's part in an company. Then what options does sys/security admin have to minimize the amount of work ( let's say we have more than 1 server that has ssh ) keeping security tight?
 
Old 12-29-2007, 10:36 AM   #17
Deleriux
Member
 
Registered: Nov 2003
Posts: 89

Rep: Reputation: 17
If you have a few servers and you want to set them up to behave the same way the best method would be to sit a firewall between all the boxes and use the forwarding chain to filter traffic. That way you would centrally administor the firewall.
 
Old 12-29-2007, 04:39 PM   #18
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by DBabo View Post
my simple and Q&D script all of the sudden became a big and comprehensive one. ha-ha
Thank you overy much for detailed explanation and putting the script together.
I have 2 questions :
Code:
$IPT -A OUTPUT -p TCP -o eth0 -m multiport --dports 21,80,443 \
-d ! $LAN -m state --state NEW -j ACCEPT

$IPT -A OUTPUT -p UDP -o eth0 -m multiport --dports 53,123 \
-d ! $LAN -m state --state NEW -j ACCEPT

$IPT -A OUTPUT -m owner --uid-owner dbabo \
-m state --state NEW -j ACCEPT

$IPT -A OUTPUT -m owner --uid-owner root \
-m state --state NEW -j ACCEPT
i read this : "if this is a LAN - don't allow outbound on specified ports. But allow for users dbabo or root even if it's on spec LAN and ports."
Now, should i read it:
"if this is a LAN - don't allow outbound on specified ports. But allow for all other ports/protocols if user is dbabo or root.
Or it is:
"if this is a LAN - don't allow outbound on specified ports. Allow for all other ports/protocols if user is dbabo or root"
Yeah, sort of. Those four rules say (in the context of the script): "Allow any outgoing FTP, HTTP, HTTPS, DNS, and NTP connections - as long as their destination is NOT the LAN. Allow absolutely any outgoing connections for users dbabo and root." The LAN limitation is there so that a user with evil intentions won't be able to attack your LAN - it also prevents a worm (Apache-based, for example) from propagating in your LAN, etc.

Quote:
Another question is :
say if the server has many users. Say, it's part in an company. Then what options does sys/security admin have to minimize the amount of work ( let's say we have more than 1 server that has ssh ) keeping security tight?
It depends. How many users? Let's say for arguments sake that you have 75 users on the server which need to have SSH access to IP 192.168.1.233 on the LAN. Instead of writing 75 iptables rules each with a different username, you could simply write one and have a substitution occur for the usernames. Like, you could have a text file with a list of the usernames and the iptables script can be told to execute the rule once for each of those usernames. Something like:
Code:
SSH_USERS=`cat /etc/ssh_users.txt`

for i in $SSH_USERS; do
  $IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
  -m owner --uid-owner $i -m state --state NEW -j ACCEPT
done
So if your /etc/ssh_users.txt file has all the SSH users listed, one per line, like:
Code:
sally
mario
susan
christian
jamie
john
tux
lisa
Etc... then the effect will be that each of them will get their own rule executed. That said, it's a balancing act. Some people would indeed be happy enough with one rule allowing SSH access to the required IPs for anybody, like:
Code:
$IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
-m state --state NEW -j ACCEPT
Any rogue users which try to connect would still need to deal with the SSH authentication, so it's not like they are getting a free pass. You could even take an inverse approach by blacklisting certain users, like:
Code:
$IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
-m owner --uid-owner apache -m state --state NEW -j REJECT

$IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
-m owner --uid-owner susan -m state --state NEW -j REJECT

$IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
-m state --state NEW -j ACCEPT
In that example, everyone would be able to SSH to 192.168.1.233 - except apache and susan.

If by "keeping security tight" you meant something more general, then the answer would still be "it depends". There's tons of aspects one needs to cover in order to keep things tight (iptables is just a small part of the picture). I don't know of a tool that will let you take care of every aspect in a super-friendly and centralized way if that's what you mean. Have you checked-out unSpawn's famous Security references thread?

EDIT: Added a blacklist example at the end. Fixed $SSH_USERS variable assignment error in the username list example. The file obviously needs to be cat-ed for the contents to be used instead of the file name/path itself - my bad.

Last edited by win32sux; 12-29-2007 at 10:22 PM.
 
Old 12-29-2007, 04:56 PM   #19
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
{QUOTE]<skip>
Etc... then the effect will be that each of them will get their own rule executed.
[/QUOTE]
ok., so every time the user's list changes i would have to re-generate the iptables. It's not bad.

Quote:
Have you checked-out unSpawn's famous Security references thread?
Thank you, i'll check it out.

Could you please recommend a good log analyzers?

Thank you very much for you help and sharing the knowledge.
 
Old 12-29-2007, 05:12 PM   #20
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by DBabo View Post
ok., so every time the user's list changes i would have to re-generate the iptables. It's not bad.
Yeah, you'd basically just need to re-execute the script. You could do this manually, or you could have cron automatically do this periodically for you.

Quote:
Could you please recommend a good log analyzers?
Logwatch is quite popular. A couple others are SWATCH and fwlogwatch. If you go into the Security category at freshmeat.net I'm sure you'll find many others. There are some that are specially made for iptables logs.

Quote:
Thank you very much for you help and sharing the knowledge.
No problem.
 
Old 12-30-2007, 03:11 AM   #21
Deleriux
Member
 
Registered: Nov 2003
Posts: 89

Rep: Reputation: 17
Alternatively, if the users will only have on role, any normal user you want to allow access to you could add the users using a primary group that are all the same (I.E "remote") then use the following firewall rule to administer them. (Sorry for plaguerizing your code win32!)

Code:
$IPT -A OUTPUT -m owner --gid-owner remote \
-m state --state NEW -j ACCEPT
Then in your sshd config you can use "AllowGroups remote".

Using this method adding a new user is simpler as you just need to do:

Code:
useradd <username> -g remote;
 
Old 12-30-2007, 03:30 AM   #22
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Deleriux View Post
Alternatively, if the users will only have on role, any normal user you want to allow access to you could add the users using a primary group that are all the same (I.E "remote") then use the following firewall rule to administer them. (Sorry for plaguerizing your code win32!)
Code:
$IPT -A OUTPUT -m owner --gid-owner remote \
-m state --state NEW -j ACCEPT
Hey, this is awesome! The thought of using a group hadn't even crossed my mind. It definitely makes things a lot simpler, and AFAICT it eliminates the need to re-execute the script (or to have it look at a file with the users listed). To give users access to the SSH daemon on the LAN you just add them to the relevant group and your done! Great stuff, thanks for posting this!

PS: I would just add that you should maintain the port/protocol/IP matches, otherwise it's carte blanche.
Code:
$IPT -A OUTPUT -p TCP -o eth0 -d 192.168.1.233 --dport 22 \
-m owner --gid-owner example -m state --state NEW -j ACCEPT

Last edited by win32sux; 12-30-2007 at 03:33 AM.
 
Old 01-21-2008, 10:10 PM   #23
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Code:
$IPT -A OUTPUT -m owner --gid-owner remote \
-m state --state NEW -j ACCEPT
Perfect. That's what i was looking for too.
Thank you.
 
Old 06-08-2009, 09:26 PM   #24
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Hello again,
I decided to change the FW rules a bit and allow the use of Inet (port 80) from this machine. So i added:
Code:
+ /sbin/iptables -A OUTPUT -p TCP -o eth0 --dport 80 -m state --state NEW -j ACCEPT
+ /sbin/iptables -A OUTPUT -p TCP -o eth0 --dport 443 -m state --state NEW -j ACCEPT
which works fine, but i want to allow only a group ("users") to browse the Inet. I changed rules above to:
Code:
+ /sbin/iptables -A OUTPUT -p TCP -o eth0 --dport 80 -m owner --gid-owner users -m state --state NEW -j ACCEPT
+ /sbin/iptables -A OUTPUT -p TCP -o eth0 --dport 443 -m owner --gid-owner users -m state --state NEW -j ACCEPT
but it's filtering it out
Please advice.

Last edited by DBabo; 06-09-2009 at 07:43 PM.
 
  


Reply



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
iptables seem to only sort of work... MrSako Linux - Security 24 08-29-2006 07:41 PM
Don't work iptables -j ScanD... NightSoul Linux - Software 2 04-28-2006 01:10 PM
iptables doesn't work with me Agent007 Linux - Networking 4 01-23-2004 07:14 AM
IPTABLES doesn't work!!! help... saruman666 Linux - Networking 11 08-16-2003 04:15 PM
IPTables doesn't seem to work X11 Linux - Software 7 07-08-2002 12:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:19 AM.

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