Linux Administrator - Linux Network Administration II
Linux Administrator - Linux Network Administration II
Firewall
Filtering Router
DMZ/Screened Subnet
NAT/IP Masquerading
Socks Server The Internet
Proxy Server
Mail Gateway
DNS Server
Tunneling Device
Company Network
X
Company Network Company Network
NAT Web
Socks Server
Proxy
Packet
Filtering
Router
A NAT, Socks or Proxy
accepts a client connection,
Client verifies it and sets up a
second connection to the
Internet to retrieve the data
Company Network
Mail
Packet
Gateway
Filtering All e-mail to and from the
Router Internet should pass through
the Mail Gateway.
Mail All connections through the
Client
Server SMTP it are SMTP connections.
Filtering based on IP address
POP/IMAP
and port number (SMTP=25).
Company Network
POP and IMAP are only used
on the Company Network.
Company
Web
Server
Packet
Filtering An internal client can
Router
access both the Intranet
server and the Internet
server. An external client
Client
can only access the
Internet Server.
Intranet
Company Network Filtering based on IP address
Server and port number (HTTP=80)
Packet Tunneling
Filtering Device
Router Firewall
with
Client
Tunneling
Firewall
NAT Company Web
Socks Web Server
Proxy Server
Mail
Gateway Packet Tunneling
Filtering Device
Router Firewall
with
Client
Tunneling
Mail
Server Client
# vi /etc/lilo.conf # grub
boot=/dev/hda grub> md5crypt
map=/boot/map Password: secret
install=/boot/boot.b Encrypted: $1$24QV1/$ecUahVmWxCDBU3k5Mzmjy/
prompt grub> quit
timeout=50
default=linux # vi /boot/grub/menu.lst
password=secret default=0
restricted timeout=10
... password=$1$24QV1/$ecUahVmWxCDBU3k5Mzmjy/
# chmod 600 /etc/lilo.conf ...
# lilo # chmod 600 /boot/grub/menu.lst
Copyright IBM Corporation 2004
User Account Considerations
Every user account is a potential security problem!
Use as few accounts as possible
Consider deleting all default user accounts (bin, ...)
Disable/delete unused accounts as soon as possible
Two approaches
No user accounts on firewall, login as root directly
User account for each administrator, su to root
Consider changing "root" to something else
# cat /etc/issue
# cat /etc/motd
************************** NOTICE *******************************
* *
* This computer system is for authorized users only. If you *
* are not an authorized user, you may face administrative *
* disciplinary action and civil and/or criminal penalties. *
* *
* Usage of this system is monitored for security reasons. All *
* your actions are logged and can be used against you. On this *
* system, your privacy is NOT guaranteed. *
* *
* By continuing to use this system you indicate your awareness *
* of and consent to the terms above. LOG OFF IMMEDIATELY if you *
* do not agree to the conditions stated in this notice. *
* *
*****************************************************************
TCP/IP Applications
TCP UDP
ICMP
IP
Network Interface
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0 0 0 1 0 1 0| Network Identifier | Host ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TYPE | CODE | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ICMP Data (depending on type) |
| |
. .
. +-+-+-+-+-+-+-+-+-+-+-+
. | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| UDP data |
. .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
First packet:
SYN bit set, Sequence number a
(a should be random)
Second packet:
Initiator ACK bit set, Acknowledgment number a+1 Server
SYN bit set, Sequence number b
(b should be random)
Third packet:
ACK bit set, Acknowledgment number b+1
May contain data
Incoming Packets
Sanity Check
PREROUTING
y Destination n
= local?
ip_forward n
INPUT on?
y
Local Process FORWARD
OUTPUT Discard
packet
POSTROUTING
Outgoing Packets
Copyright IBM Corporation 2004
Packet Filtering in Linux
Packet Filtering done at kernel level
Usually compiled as kernel modules which are loaded
automatically
Configuration done with user space tools
Linux 2.0 kernel: ipfwadm
Linux 2.2 kernel: ipchains
Linux 2.4 kernel: iptables
Downwards compatibility ensured
Additional features:
Logging
Statistics
The Internet
ppp0: 62.186.134.70
Firewall
in-a-box
eth0: 10.0.0.1
Company Network
10.0.0.0/24
# iptables -X
# iptables -F
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A OUTPUT -o lo -j ACCEPT
# iptables -A INPUT -i eth0 -j ACCEPT
# iptables -A OUTPUT -o eth0 -j ACCEPT
# iptables -A INPUT -i ppp0 -d ! 62.186.134.70 -j DROP
# iptables -A OUTPUT -o ppp0 -s ! 62.186.134.70 -j DROP
Intranet Internet
# iptables -A input -i ppp0 -p tcp -s any/0 --sport 1024: -d 62.186.134.70 --dport 22 -j ACCEPT
# iptables -A output -o ppp0 -p tcp -s 62.186.134.70 --sport 22 -d any/0 --dport 1024: -j ACCEPT
Intranet Internet
Examples:
# socksify telnet www.instructor.com
To socksify all applications that use shared libraries:
# export LD_PRELOAD="libdsocks.so"
# telnet www.instructor.com
Intranet Internet
Packet
Filtering
Router
www.acme.com
DMZ
Sec. DNS Company
Server Web
bar.acme.com
server
62.186.134.20
foo.acme.com 62.186.134.71
DMZ Packet The Internet
Pr. DNS DMZ Filtering
Server 62.186.134.0/24 Router
62.186.134.70 62.186.134.1
ftp.acme.com 62.186.134.2
Packet
Company
Filtering
FTP server
Router
10.0.0.1
62.186.134.21
w3.acme.com widget.acme.com
Intranet Company Network 10.0.0.40
Web 10.0.0.0/24 Intranet
server DNS
10.0.0.60 Server
# cat /etc/named.conf
// Internet DNS server for acme.com
options {
directory "/var/named";
};
zone "." {
type hint;
file "named.ca";
};
zone "acme.com" {
type master;
file "named.acme.com";
allow-update { none; };
allow-transfer { 62.186.134.71; };
};
zone "134.186.62.in-addr.arpa" {
type master;
file "named.62.186.134";
allow-update { none; };
allow-transfer { 62.186.134.71; };
};
# cat /var/named/named.acme.com
$TTL 86400
@ IN SOA foo.acme.com. webmaster.acme.com. (
2001120100 ;Serial
28800 ;Refresh
14400 ;Retry
3600000 ;Expire
86400 ;Default TTL
)
@ IN NS foo.acme.com.
@ IN NS bar.acme.com.
foo IN A 62.186.134.70
bar IN A 62.186.134.71
www IN A 62.186.134.20
ftp IN A 62.186.134.21
# cat /var/named/named.62.186.134
$TTL 86400
@ IN SOA foo.acme.com. webmaster.acme.com. (
2001120100 ;Serial
28800 ;Refresh
14400 ;Retry
3600000 ;Expire
86400 ;Default TTL
)
@ IN NS foo.acme.com.
@ IN NS bar.acme.com.
70 IN PTR foo.acme.com.
71 IN PTR bar.acme.com.
20 IN PTR www.acme.com.
21 IN PTR ftp.acme.com.
# cat /etc/named.conf
// Internet DNS server for acme.com
options {
directory "/var/named";
};
zone "." {
type hint;
file "named.ca";
};
zone "acme.com" {
type slave; masters { 62.186.134.70; };
file "named.acme.com.bak";
allow-update { none; };
allow-transfer { none; };
};
zone "134.186.62.in-addr.arpa" {
type slave; masters { 62.186.134.70; };
file "named.62.186.134.bak";
allow-update { none; };
allow-transfer { none; };
};
# cat /etc/named.conf
// Intranet DNS server for acme.com
options {
directory "/var/named";
forward only;
forwarders { 62.186.134.70; 62.186.134.71; };
};
zone "acme.com" {
type master;
file "named.acme.com";
};
zone "0.0.10.in-addr.arpa" {
type master;
file "named.10.0.0";
};
# cat /var/named/named.acme.com
$TTL 86400
@ IN SOA widget.acme.com. webmaster.acme.com. (
2001120100 ;Serial
28800 ;Refresh
14400 ;Retry
3600000 ;Expire
86400 ;Default TTL
)
@ IN NS widget.acme.com.
router1-dmz IN A 62.186.134.1
router2-dmz IN A 62.186.134.2
foo IN A 62.186.134.70
bar IN A 62.186.134.71
www IN A 62.186.134.20
ftp IN A 62.186.134.21
router2-int IN A 10.0.0.1
w3 IN A 10.0.0.60
widget IN A 10.0.0.40
# cat /var/named/named.10.0.0
$TTL 86400
@ IN SOA widget.acme.com. webmaster.acme.com. (
2001120100 ;Serial
28800 ;Refresh
14400 ;Retry
3600000 ;Expire
86400 ;Default TTL
)
@ IN NS widget.acme.com.
1 IN PTR router2-int.acme.com.
40 IN PTR widget.acme.com.
60 IN PTR w3.acme.com.
On a router:
# iptables -A FORWARD -i ppp0 -p tcp -s any/0 -d 62.186.134.70 --dport 53 -j ACCEPT
# iptables -A FORWARD -i ppp1 -p tcp -s 62.186.134.70 --sport 53 -d any/0 -j ACCEPT
# iptables -A FORWARD -i ppp0 -p udp -s any/0 -d 62.186.134.70 --dport 53 -j ACCEPT
# iptables -A FORWARD -i ppp1 -p udp -s 62.186.134.70 --sport 53 -d any/0 -j ACCEPT
# iptables -A FORWARD -i ppp0 -p tcp -s any/0 -d 62.186.134.71 --dport 53 -j ACCEPT
# iptables -A FORWARD -i ppp1 -p tcp -s 62.186.134.71 --sport 53 -d any/0 -j ACCEPT
# iptables -A FORWARD -i ppp0 -p udp -s any/0 -d 62.186.134.71 --dport 53 -j ACCEPT
# iptables -A FORWARD -i ppp1 -p udp -s 62.186.134.71 --sport 53 -d any/0 -j ACCEPT
Mail
Gateway Packet
Filtering
Router
Mail
Server Client
SMTP
POP/IMAP
Company Network
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
acme.com RELAY
cracker.org REJECT
spammer.org DISCARD
good.spammer.org OK
badsmtp.org 500 Bad SMTP spoken by you
Copyright IBM Corporation 2004
SpamAssassin
Evaluates message using various criteria to determine "spam score"
If spam score is too high, message is spam and marked as such
(subject or other header fields)
Can use Bayesian filtering too
Learns what spam is from past messages classified manually as
such
Two modes:
Invoke every time (inefficient)
Run as daemon with lightweight client
Invocation:
By MTA using milter interface (Sendmail) or external filter (Postfix)
By procmail
Packet Tunneling
Filtering Device
Router Firewall
with
Client
Tunneling
H1 H2
H1 R1 R2 H2
IP packet,
IP Header AH Header IP Header IP Payload
tunneled:
IP packet, IP Header
IP Header ESP Header IP Payload (encrypted)
tunneled: (encrypted)
Session Keys
Authentication
ignore /test/
ignore /modprobe/
ignore /this too, and more/
watchfor /.*/
echo
watchfor /panic/
echo red
bell
watchfor /apm/
echo green
watchfor /startup|shutdown/
echo blue
watchfor /.*/
echo
watchfor /panic/
mail addresses=joe,pete,subject=panic
watchfor /snort/
exec "call_pager 7654321 NIDS Alert: $*"
throttle 00:05
ignore /.*/