Firewalling (Restrict who can use services)

Can be done at the

Personal Firewall

A simple firewall (running on the host in question) which restricts the networks, hosts and domains that can access services on the host in question.

Windows firewall is an example of this.

Network Layer: By example (iptables)

Private Side: VMNET8, 192.168.0.0/255.255.255.0 Ubuntu: 192.168.0.100 Serving web and mail to the private network sudo bash for root Backtrack3/5: IP (dhcp) root/toor Windows XP Pro: 192.168.0.33 csc347/password DSL: 192.168.0.75 (To put this on the private network, you will need to switch to VMNET8) Administrators machine sudo su for root Setup networking by DSL->Setup->Net Setup->netcardconf Make the firewall the default gateway. Make sure you choose the correct side of the firewall depending on where you put this on the network. FC4 Firewall/Gateway: eth1: 192.168.0.10 eth0: 10.10.10.10 root/password see /etc/sysconfig/myFirewall.bash Public Side: VMNET1, 10.10.10.0/255.255.255.0 RH72: 10.10.10.11 hacker/password root/password DSL: 10.10.10.128 (you can switch the IP of this machine manually) DSL: 10.10.10.75 DSL: 10.10.10.33 (CEO)
(from http://www.dmccormick.pwp.blueyonder.co.uk/coursecontent/09/9_04a.htm)
Like a personal firewall, except this firewall is considerably more powerful. It typically used outside a specific system. Used to protect a network.

It can restrict, route and rewrite packets coming into the firewall, going out of the firewall and those being routed through the firewall. Decisions about packet rewriting and restricting can be made based on packet source, destination and port.

At a high level, it is used to restrict access to services, hide the network behind the firewall, act as a proxy for services running behind the firewall.

iptables: netfilter.org created iptables and the associated framework to enable packet filtering, network address [and port] translation (NA[P]T) and other packet mangling. See This long tutorial!!

iptables consists of 3 basic tables:

Each table consists of a collection of chains, filter has INPUT, FORWARD and OUTPUT. Each chain has a list of rules mentioning a target. For filter, targets include ACCEPT, DROP.
(from the iptables-tutorial) How packets are processed by the filter table... (from the packetfiltering-HOWTO) _____ Incoming / \ Outgoing -->[Routing ]--->|FORWARD|-------> [Decision] \_____/ ^ | | v ____ ___ / \ / \ |OUTPUT| |INPUT| \____/ \___/ ^ | | ----> Local Process -----

iptables example

#!/bin/sh # flush all tables /sbin/iptables -F /sbin/iptables -t nat -F /sbin/iptables -t mangle -F # default policy ACCEPT # /sbin/iptables -P INPUT ACCEPT # /sbin/iptables -P OUTPUT ACCEPT # /sbin/iptables -P FORWARD ACCEPT # default policy (if none of the other policies match, apply these) /sbin/iptables -P INPUT DROP /sbin/iptables -P OUTPUT DROP /sbin/iptables -P FORWARD DROP # so we can talk to ourselves /sbin/iptables -A INPUT -i lo -j ACCEPT /sbin/iptables -A OUTPUT -o lo -j ACCEPT # 192.168.1.39 is bad so don't allow them to ssh # /sbin/iptables -A INPUT -s 192.168.1.39 -p tcp --dport 22 -j DROP # 192.168.1.39 is bad so don't allow them to echo # /sbin/iptables -A INPUT -s 192.168.1.39 -p tcp --dport 7 -j DROP # 192.168.1.39 is bad, don't allow them to connecct /sbin/iptables -A INPUT -s 192.168.1.39 -j DROP # 192.168.1.39 is bad, don't allow us to connect to them # /sbin/iptables -A OUTPUT -d 192.168.1.39 -j DROP # so the local network can talk to us /sbin/iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT /sbin/iptables -A OUTPUT -d 192.168.1.0/24 -j ACCEPT

iptables and NAT

From the NAT HOW-TO

Network Application Layer Firewall

Firewalls that operate at this level actually understand the protocols they are attached to. They watch the traffic to ensure that communicating parties are actually using the predefined protocol to communicate.

Example: An firewall that watches port 80 (http) will ensure that communicating parties are having an http conversation.

Application Level Firewall

The application (service) itself may allow the administrator to restrict when and how the application is used. Note: Difference between this and above is that Network Application Layer Firewalls operate independently of the service they are firewalling. Network Application Layer Firewalls watch network traffic. Application Level Firewalls have features dependent on the particular creator of the service software.

Example: sendmail can restrict who uses it and how it is used. It can restrict which domains can use it as a relay (via /etc/hosts.allow and /etc/hosts.deny) to prevent it from being used by spammers.

Example: xinetd (internet super server) is used to manage a collection of services. It has configuration files which allow restriction of how frequently a service can run, which domains/networks/hosts can run the service etc. It supports logging of use of service.

# /etc/xinetd.conf # Simple configuration file for xinetd # # Some defaults, and include /etc/xinetd.d/ # Logging to SYSLOG (/var/logs/secure in RH8 VM). defaults { instances = 60 log_type = SYSLOG authpriv log_on_success = HOST PID log_on_failure = HOST cps = 25 30 } includedir /etc/xinetd.d xinetd configuration for a particular service (echo) # /etc/xinetd.d/echo # default: off # description: An xinetd internal service which echo's characters back to clients. \ # This is the tcp version. service echo { type = INTERNAL id = echo-stream socket_type = stream protocol = tcp user = root wait = no disable = no only_from = 127.0.0.1 only_from += 192.168.1.0 no_access = 192.168.1.33 } You must restart the xinetd service after you have modified a service configuration.