SlideShare ist ein Scribd-Unternehmen logo
1 von 128
Firewall
Author: Przemysław Piotrowski
Email: przemyslav.piotrowski@gmail.com
Firewall
What is it?
Firewall
Firewall is a hardware or software that prevents
unauthorized access to or from a network
What is it?
Firewall
Firewall is a hardware or software that prevents
unauthorized access to or from a network
What is it?
----- Too vague and unclear
Firewall
Firewall is a hardware or software that prevents
unauthorized access to or from a network
What is it?
----- Too vague and unclear
Firewall provides a whole variety of tools necessary for
safe and successful exchange of information between
hosts in networks
Firewall - history
Note: The term firewall originally referred to a wall intended
to confine a fire or potential fire within a building
Firewall - history
Note: The term firewall originally referred to a wall intended
to confine a fire or potential fire within a building
The need for firewall emerged in the late 1980s
- Morris Worm in 1988
Firewall – first generation
● First firewall version in 1988 – packet filter
Firewall – first generation
● First firewall version in 1988 – packet filter
● Filters packets based on the contents of packet headers
(IP addresses, MAC addresses, protocols (TCP, UDP,
ICMP, etc.) and TCP/UDP ports)
Firewall – first generation
● First firewall version in 1988 – packet filter
● Filters packets based on the contents of packet headers
(IP addresses, MAC addresses, protocols (TCP, UDP,
ICMP, etc.) and TCP/UDP ports)
● Ebtables, arptables
Firewall – first generation
● First firewall version in 1988 – packet filter
● Filters packets based on the contents of packet headers
(IP addresses, MAC addresses, protocols (TCP, UDP,
ICMP, etc.) and TCP/UDP ports)
● Ebtables, arptables
Firewall – second generation
● Stateful packet filters
Firewall – second generation
● Stateful packet filters
● Packets can be filtered based on their connection state
Firewall – second generation
● Stateful packet filters
● Packets can be filtered based on their connection state
● iptables
Firewall – third generation
● Application layer firewall
Firewall – third generation
● Application layer firewall
Firewall – third generation
●
Application layer firewall
Firewall – third generation
● Application layer firewall
● Able to control network traffic regarding a specific application or
sevice
● AppArmor, Kerio Control
Firewall - concepts
● Firewall consists of 3 main concepts:
Firewall - concepts
● Firewall consists of 3 main concepts:
1 Filtering of frames and ARP messages (in OSI layer 2)
and packets (in OSI layer 3)
Firewall - concepts
● Firewall consists of 3 main concepts:
1 Filtering of frames and ARP messages (in OSI layer 2)
and packets (in OSI layer 3)
2 Modification of headers (IP addresses, MAC addresses,
ports)
Firewall - concepts
● Firewall consists of 3 main concepts:
1 Filtering of frames and ARP messages (in OSI layer 2)
and packets (in OSI layer 3)
2 Modification of headers (IP addresses, MAC addresses,
ports)
3 Modification of payload
Firewall – filtering
● The most common use of firewall
Firewall – filtering
● The most common use of firewall
● Example usage: filtering packets based on their
destination ports
Web server Internet
Firewall
HTTP request on port 80
SSH port 22
Telnet port 23
Firewall - filtering
● Filtering can be done based on:
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
– Ports (OSI layer 4)
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
– Ports (OSI layer 4)
– Protocol (OSI layers 2-4)
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
– Ports (OSI layer 4)
– Protocol (OSI layers 2-4)
– Interface
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
– Ports (OSI layer 4)
– Protocol (OSI layers 2-4)
– Interface
– Fragmentation (OSI layer 3)
Firewall - filtering
● Filtering can be done based on:
– MAC address (OSI layer 2)
– IP address (OSI layer 3)
– Ports (OSI layer 4)
– Protocol (OSI layers 2-4)
– Interface
– Fragmentation (OSI layer 3)
– Payload
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
3) Reject it without any notification
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
3) Reject it without any notification
● Packet filter contains a table with specified set of rules
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
3) Reject it without any notification
● Packet filter contains a table with specified set of rules
● If incoming packet or frame matches the first rule then the
action specified in this rule is performed
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
3) Reject it without any notification
● Packet filter contains a table with specified set of rules
● If incoming packet or frame matches the first rule then the
action specified in this rule is performed
● If it doesn't match, then the next rule is checked (if it
exists)
Firewall - filtering
● Packet filter can do 3 things with an incoming packet:
1) Accept it
2) Reject it and notify the sender about rejection
3) Reject it without any notification
● Packet filter contains a table with specified set of rules
● If incoming packet or frame matches the first rule then the
action specified in this rule is performed
● If it doesn't match, then the next rule is checked (if it exists)
● If packet or frame doesn't match any of the rules, then is it
rejected without any notification
Firewall – header modification
● Firewall can modify information located in headers of packets and frames
Firewall – header modification
● Firewall can modify information located in headers of packets and frames
● Used in IP Masquerading
IP Masquerading is a process of modifying packet's source IP address
Used in private networks, where IP Masquerading allows hosts from
inside the network that don't have a public IP address to send and
receive packets from the Internet.
Firewall – header modification
● Firewall can modify information located in headers of packets and frames
● Used in IP Masquerading
IP Masquerading is a process of modifying packet's source IP address
Used in private networks, where IP Masquerading allows hosts from
inside the network that don't have a public IP address to send and
receive packets from the Internet.
Internet
178.36.119.72192.168.1.1192.168.1.2
Host 1 Router
Packet source IP:
192.168.1.2
Packet source IP:
178.36.119.72
Firewall – header modification
● Firewall can modify information located in headers of packets and frames
● Used in IP Masquerading
IP Masquerading is a process of modifying packet's source IP address
Used in private networks, where IP Masquerading allows hosts from
inside the network that don't have a public IP address to send and
receive packets from the Internet.
Internet
178.36.119.72192.168.1.1192.168.1.2
Host 1 Router
Packet source IP:
192.168.1.2
Packet source IP:
178.36.119.72
IP Masquerading was performed inside 'Router', where source IP of a packet
sent from Host 1 was changed.
Firewall – payload modification
● Frame payload modification takes place mostly in the
top layer of OSI model
Firewall – payload modification
● Frame payload modification takes place mostly in the
top layer of OSI model
Firewall – payload modification
● Frame payload modification takes place mostly in the
top layer of OSI model
● NFQUEUE
Firewall – OSI model
ebtables, arptables
Iptables, xtables-addons
Firewall - ebtables
● The ebtables utility enables basic Ethernet frame filtering
on a Linux bridge, logging, MAC NAT and brouting
Firewall - ebtables
● The ebtables utility enables basic Ethernet frame filtering
on a Linux bridge, logging, MAC NAT and brouting
● MAC NAT - ability to change the MAC Ethernet source and
destination address
Firewall - ebtables
● The ebtables utility enables basic Ethernet frame filtering
on a Linux bridge, logging, MAC NAT and brouting
● MAC NAT - ability to change the MAC Ethernet source and
destination address
● Brouting – bridge can act as bridge and router. Using
firewall rules we can decide if frame should be routed to
higher OSI layers or should it be bridged (OSI layer 3)
Firewall – ebtables – tables
Ebtables uses rules to decide what action to perform with frames
Ebtables divides rules into 3 tables:
1. filter
In this table we place rules which filter frames
2. nat
In this table we place rules which should modify frame headers
3. broute
In this table we place rules which should route frames
Rules inside these tables are separated into chains
Firewall – ebtables – tables
Ebtables uses rules to decide what action to perform with frames
Ebtables divides rules into 3 tables:
1. filter
In this table we place rules which filter frames
Frames are directed to chain:
● INPUT - if the destination MAC address of the frame is on the
bridge itself
● FORWARD - for frames being forwared by the bridge
● OUTPUT - if the frames are generated locally or for brouted frames
2. nat
In this table we place rules which should modify frame headers
● PREROUTING – frames are modified as soon as they came in
● OUTPUT - for modifying locally generated or (b)routed frames before
they are bridged
● POSTROUTING - for altering frames as they are about to go out
3. broute
In this table we place rules which should route frames
● BROUTING
Users can also define their own chains
Firewall – ebtables – tables
Firewall – ebtables - bridge
● A network bridge connects multiple network segments
Firewall – ebtables - bridge
● A network bridge connects multiple network segments
● To create a bridge on a computer we will use brctl located
in bridge-utils package
Firewall – ebtables - bridge
● A network bridge connects multiple network segments
● To create a bridge on a computer we will use brctl located
in bridge-utils package
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
Firewall – ebtables - bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
Firewall – ebtables - bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
root@Bridge:# ifconfig eth0 0.0.0.0
root@Bridge:# ifconfig eth1 0.0.0.0
root@Bridge:# brctl addbr br0
root@Bridge:# brctl addif br0 eth0
root@Bridge:# brctl addif br0 eth1
root@Bridge:# ifconfig br0 up
Firewall – ebtables - bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
root@Bridge:# ifconfig eth0 0.0.0.0
root@Bridge:# ifconfig eth1 0.0.0.0
root@Bridge:# brctl addbr br0
root@Bridge:# brctl addif br0 eth0
root@Bridge:# brctl addif br0 eth1
root@Bridge:# ifconfig br0 up
root@Bridge:# brctl showmacs br0
port no mac addr is local? ageing timer
1 00:10:4b:b6:c6:e4 no 119.25
1 00:a0:24:d0:4c:d6 yes 0.00
1 00:a0:24:f0:22:71 no 5.81
4 08:00:09:fb:39:a1 no 27.24
4 08:00:09:fc:92:2c no 53.13
4 08:00:09:fc:d2:11 yes 0.00
Firewall – ebtables – installation & rules
Installation:
root@Bridge:# apt-get install ebtables
Firewall – ebtables – installation & rules
Installation:
root@Bridge:# apt-get install ebtables
● Ebtables holds a table of rules, which are used to filter frames
Firewall – ebtables – installation & rules
Installation:
root@Bridge:# apt-get install ebtables
● Ebtables holds a table of rules, which are used to filter frames
To list these rules we can use a command:
root@Bridge:# ebtables -L
Firewall – ebtables – installation & rules
Installation:
root@Bridge:# apt-get install ebtables
● Ebtables holds a table of rules, which are used to filter frames
To list these rules we can use a command:
root@Bridge:# ebtables -L
Firewall – ebtables – commands
To delete a rule: ebtables -D chain start_nr[:end_nr]
root@Bridge:# ebtables -D FORWARD 1
To create a user-defined chain: ebtables -N chain_name [-P policy]
root@Bridge:# ebtables -D new_chain -P ACCEPT
To specify the destination MAC address: ebtables -A chain -s mac_address -j TARGET
root@Bridge:# ebtables -A FORWARD -s b8:88:e3:79:1a:b1 -j DROP
To specify the source MAC address: ebtables -A chain -s mac_address -j TARGET
root@Bridge:# ebtables -A FORWARD -s b8:88:e3:79:1a:b1 -j DROP
Append the rule to the end of the chain: iptables -A rule_specification -j target
root@Harvey:# iptables -A INPUT --dport 80 -j DROP
List rules in chain: iptables -L [chain]
root@Harvey:# iptables -L
Flush (delete all) rules in chain: iptables -F chain
root@Harvey:# iptables -F OUTPUT
Firewall – ebtables – rule specifications (matches)
Rule specifications:
-p protocol - protocol responsible for creating the frame
-i interface - the interface the frame was originally received from
-o interface - the interface by which the frame is going to be sent
-s source - source MAC address
-d destination - destination MAC address
Firewall – ebtables – targets
TARGET specifies what happens to a frame after it matched a rule.
Firewall – ebtables – targets
TARGET specifies what happens to a frame after it matched a rule.
In Ebtables we can choose from 5 targets:
1) ACCEPT – let the frame through
2) DROP – the frame will be dropped
3) CONTINUE – next rule will be checked
4) RETURN – go back to the previous chain and check the next rule
5) Jump to user defined chain
Firewall – ebtables – basic configuration
ebtables -P FORWARD DROP
ebtables -A FORWARD -p IPv4 -j ACCEPT
ebtables -A FORWARD -p ARP -j ACCEPT
ebtables -P INPUT DROP
ebtables -A INPUT -p IPv4 -j ACCEPT
ebtables -A INPUT -p ARP -j ACCEPT
ebtables -P OUTPUT DROP
ebtables -A OUTPUT -p IPv4 -j ACCEPT
ebtables -A OUTPUT -p ARP -j ACCEPT
This is a basic filter configuration which will only let frames made by the
protocols IP version 4 and ARP through
Firewall – ebtables – MAC NAT
● Ebtables allows for changing MAC addresses in frame
headers
Firewall – ebtables – MAC NAT
root@Bridge:# ebtables -t nat -A PREROUTING -d
00:11:22:33:44:55 -i eth0 -j dnat --to-destination 54:44:33:22:11:00
● Ebtables allows for changing MAC addresses in frame
headers
Firewall – ebtables – MAC NAT
root@Bridge:# ebtables -t nat -A PREROUTING -d
00:11:22:33:44:55 -i eth0 -j dnat --to-destination 54:44:33:22:11:00
This will make all frames destined to 00:11:22:33:44:55 that
arrived on interface eth0 be transferred to 54:44:33:22:11:00
instead
● Ebtables allows for changing MAC addresses in frame
headers
Firewall – ebtables - example
● Example: we want to block ARP messages going through the bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
Firewall – ebtables - example
● Example: we want to block ARP messages going through the bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
root@192.168.1.2:# arping 192.168.2.1
ARPING 192.168.2.1 from 192.168.1.2 eth0
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms
Firewall – ebtables - example
● Example: we want to block ARP messages going through the bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
root@Bridge:# ebtables -t filter -A FORWARD -p ARP -j DROP
root@192.168.1.2:# arping 192.168.2.1
ARPING 192.168.2.1 from 192.168.1.2 eth0
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms
Firewall – ebtables - example
● Example: we want to block ARP messages going through the bridge
eth0 eth1
192.168.1.2
192.168.1.1 192.168.2.1
192.168.2.2
root@Bridge:# ebtables -t filter -A FORWARD -p ARP -j DROP
root@192.168.1.2:# arping 192.168.2.1
ARPING 192.168.2.1 from 192.168.1.2 eth0
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms
Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms
root@192.168.1.2:# arping 192.168.2.1 -c 5
ARPING 192.168.2.1 from 192.168.1.2 eth0
Sent 5 probes (5 broadcast(s))
Received 0 response(s)
Firewall - arptables
● Configuration very similar to ebtables
Firewall - arptables
● Configuration very similar to ebtables
● Not limited to bridges
● Designed to work specifically with ARP messages
Firewall - arptables
● Configuration very similar to ebtables
● Not limited to bridges
● Designed to work specifically with ARP messages
Firewall – arptables – tables
Installation:
root@Harvey:# apt-get install arptables
Firewall – arptables – tables
Installation:
root@Harvey:# apt-get install arptables
Firewall – arptables – tables
● One filter table
1) INPUT chain - for frames destined for the host
2) OUTPUT chain - for locally-generated frames
3) FORWARD chain - for frames being forwarded by the
bridge (this chain is not available in Linux kernel 2.4.X)
Installation:
root@Harvey:# apt-get install arptables
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
To add a new rule to a specific chain:
arptables -A chain rule_specification
To delete a rule from chain:
arptables -D chain rule_specification
or
arptables -D chain start_nr[:end_nr]
To set the policy for the chain: (only for built-in chains)
arptables -P chain policy (ACCEPT/DROP/RETURN)
To add a new user-defined chain:
arptables -N chain_name
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
To add a new rule to a specific chain:
arptables -A chain rule_specification
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
To add a new rule to a specific chain:
arptables -A chain rule_specification
To delete a rule from chain:
arptables -D chain rule_specification
or
arptables -D chain start_nr[:end_nr]
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
To add a new rule to a specific chain:
arptables -A chain rule_specification
To delete a rule from chain:
arptables -D chain rule_specification
or
arptables -D chain start_nr[:end_nr]
To set the policy for the chain: (only for built-in chains)
arptables -P chain policy (ACCEPT/DROP/RETURN)
Firewall – arptables – rule building & commands
Rule building:
arptables [-t table] command rule-specification [options]
● Option -t can be omitted
To add a new rule to a specific chain:
arptables -A chain rule_specification
To delete a rule from chain:
arptables -D chain rule_specification
or
arptables -D chain start_nr[:end_nr]
To set the policy for the chain: (only for built-in chains)
arptables -P chain policy (ACCEPT/DROP/RETURN)
To add a new user-defined chain:
arptables -N chain_name
Firewall – arptables – rule specifications
Rule specifications:
● '-s address[/mask]' - the Source IP specification
● '-d address[/mask]' - the Destination IP specification
● '--source-mac mac_address' - the source mac address
● '--destination-mac mac_address' - the destination mac address
● '-i name' - the interface via which a frame is received (for the INPUT
and FORWARD chains)
● '-o name' - the interface via which a frame is going to be sent (for the
OUTPUT and FORWARD chains)
'!' option before the specification inverts the test for that specification
Firewall - arptables - example
Router
Computer1
192.168.2.1
192.168.2.2
Harvey
192.168.2.3
Switch
AA:AA:AA:AA:AA:AA
BB:BB:BB:BB:BB:BB
CC:CC:CC:CC:CC:CC
Firewall - arptables - example
Router
Computer1
192.168.2.1
192.168.2.2
Harvey
192.168.2.3
Switch
● Harvey sends valuable data to Router and wants to protect himself
from Computer1 ARP Spoofing
AA:AA:AA:AA:AA:AA
BB:BB:BB:BB:BB:BB
CC:CC:CC:CC:CC:CC
Firewall - arptables - example
Router
Computer1
192.168.2.1
192.168.2.2
Harvey
192.168.2.3
Switch
● Harvey sends valuable data to Router and wants to protect himself
from Computer1 ARP Spoofing
AA:AA:AA:AA:AA:AA
BB:BB:BB:BB:BB:BB
CC:CC:CC:CC:CC:CC
root@Harvey:# arptables -A INPUT -s 192.168.2.1 --source-mac ! AA:AA:AA:AA:AA:AA -j DROP
root@Harvey:# arptables -A OUTPUT -d 192.168.2.1 --destination-mac ! AA:AA:AA:AA:AA:AA -j
DROP
Firewall - arptables - example
Router
Computer1
192.168.2.1
192.168.2.2
Harvey
192.168.2.3
Switch
● Harvey sends valuable data to Router and wants to protect himself
from Computer1 ARP Spoofing
AA:AA:AA:AA:AA:AA
BB:BB:BB:BB:BB:BB
CC:CC:CC:CC:CC:CC
root@Harvey:# arptables -A INPUT -s 192.168.2.1 --source-mac ! AA:AA:AA:AA:AA:AA -j DROP
root@Harvey:# arptables -A OUTPUT -d 192.168.2.1 --destination-mac ! AA:AA:AA:AA:AA:AA -j
DROP
root@Harvey:# arptables -L
Chain INPUT (policy ACCEPT)
-j DROP -s 192.168.2.1 ! --src-mac aa:aa:aa:aa:aa:aa
Chain OUTPUT (policy ACCEPT)
-j DROP -d 192.168.2.1 ! --dst-mac aa:aa:aa:aa:aa:aa
Chain FORWARD (policy ACCEPT)
Firewall - iptables
● Iptables is a firewall for
OSI layer 3 and 4
Firewall - iptables
● Iptables is a firewall for
OSI layer 3 and 4
● successor of ipchains and
ipfilter
Firewall - iptables - tables
● filter
– INPUT
– FORWARD
– OUTPUT
● nat
– PREROUTING
– OUTPUT
– POSTROUTING
● mangle
– PREROUTING
– INPUT
– OUTPUT
– FORWARD
– POSTROUTING
● raw
– PREROUTING
– OUTPUT
Firewall - iptables - tables
● mangle - This table is used for specialized packet
modification (e.g. change Type Of Service field in a
packet)
● raw - handled before connection tracking takes place
Firewall - iptables - rule specifications (matches)
● Other matches:
● -m or --match
● -m conntrack
Allows filter rules to match based on connection state. Permits the use
of the --ctstate option.
● --ctstate
Example: iptables -A INPUT -p tcp -m conntrack --ctstate NEW -j
ACCEPT
Firewall - iptables - rule specifications (matches)
● Other matches:
● -m or --match
● -m conntrack
Allows filter rules to match based on connection state. Permits the use
of the --ctstate option.
● --ctstate
Example: iptables -A INPUT -p tcp -m conntrack --ctstate NEW -j
ACCEPT
● -m limit - Require the rule to match only a limited number of times.
Allows the use of the --limit option. Useful for limiting logging rules.
● --limit and --limit-burst
Example: iptables -A INPUT -p icmp -m limit --limit 1/min --limit-burst 5
-j DROP
Firewall - iptables - features
● stateless packet filtering (IPv4 and IPv6)
Firewall - iptables - features
● stateless packet filtering (IPv4 and IPv6)
● stateful packet filtering (IPv4 and IPv6)
– iptables can distinguish the connection state of a packet
– this adds a new packet filtering capability based on the
connection state
Firewall - iptables - features
● stateless packet filtering (IPv4 and IPv6)
● stateful packet filtering (IPv4 and IPv6)
– iptables can distinguish the connection state of a packet
– this adds a new packet filtering capability based on the
connection state
● NAPT - network address and port translation (IPv4 and
IPv6)
– iptables can modify packet headers including IP
addresses and ports
Firewall - iptables - connection state
● Packets can be related to tracked connections in four
different so called states: NEW, ESTABLISHED, RELATED
and INVALID
Firewall - iptables - connection state
● Packets can be related to tracked connections in four
different so called states: NEW, ESTABLISHED, RELATED
and INVALID
● NEW - tells us that the packet is the first packet that we
see from a specific connection
Firewall - iptables - connection state
● Packets can be related to tracked connections in four
different so called states: NEW, ESTABLISHED, RELATED
and INVALID
● NEW - tells us that the packet is the first packet that we
see from a specific connection
● ESTABLISHED - next packets from the same connection
Firewall - iptables - connection state
● Packets can be related to tracked connections in four
different so called states: NEW, ESTABLISHED, RELATED
and INVALID
● NEW - tells us that the packet is the first packet that we
see from a specific connection
● ESTABLISHED - next packets from the same connection
● RELATED - new connection created by already
ESTABLISHED connection
Firewall - iptables - connection state
● Packets can be related to tracked connections in four
different so called states: NEW, ESTABLISHED, RELATED
and INVALID
● NEW - tells us that the packet is the first packet that we
see from a specific connection
● ESTABLISHED - next packets from the same connection
● RELATED - new connection created by already
ESTABLISHED connection
● INVALID - packet not identified
Firewall - iptables - NAT
● There are two types of NAT: Source NAT (SNAT) and Destination
NAT (DNAT)
Change the source address of a packet to 1.2.3.4
Firewall - iptables - NAT
● There are two types of NAT: Source NAT (SNAT) and Destination
NAT (DNAT)
Change the source address of a packet to 1.2.3.4
root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT
--to 1.2.3.4
Firewall - iptables - NAT
● There are two types of NAT: Source NAT (SNAT) and Destination
NAT (DNAT)
Change the source address of a packet to 1.2.3.4
root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT
--to 1.2.3.4
Change the destination address of a packet to 1.2.3.4
Firewall - iptables - NAT
● There are two types of NAT: Source NAT (SNAT) and Destination
NAT (DNAT)
Change the source address of a packet to 1.2.3.4
root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT
--to 1.2.3.4
Change the destination address of a packet to 1.2.3.4
root@Harvey:# iptables -t nat -A PREROUTING -i eth1 -j DNAT --to
1.2.3.4
Firewall - iptables - NAPT
● Forwarding ports - process of forwarding packets, which are being
received on a specific port.
Firewall - iptables - NAPT
● Forwarding ports - process of forwarding packets, which are being
received on a specific port.
We want to forward packets from interface eth0 port 80 to
192.168.1.200 to port 8080
Firewall - iptables - NAPT
● Forwarding ports - process of forwarding packets, which are being
received on a specific port.
We want to forward packets from interface eth0 port 80 to
192.168.1.200 to port 8080
iptables -t nat -A PREROUTING -i eth0 --dport 80 -j DNAT --to-
destination 192.168.1.200:8080
Firewall - iptables - more examples
●
1st
Example: IP Masquerading
Internet
178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0)
Host 1 Router
Packet source IP:
192.168.1.2
Packet source IP:
178.36.119.72
Firewall - iptables - more examples
●
1st
Example: IP Masquerading
Internet
178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0)
Host 1 Router
Packet source IP:
192.168.1.2
Packet source IP:
178.36.119.72
root@Router:# echo 1 > /proc/sys/net/ipv4/ip_forward
root@Router:# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
Firewall - iptables - more examples
●
1st
Example: IP Masquerading
Internet
178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0)
Host 1 Router
Packet source IP:
192.168.1.2
Packet source IP:
178.36.119.72
root@Router:# echo 1 > /proc/sys/net/ipv4/ip_forward
root@Router:# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
root@Host1:# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=34.5ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=34.0ms
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
● To resolve this problem we will limit incoming SYN
requests
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
● To resolve this problem we will limit incoming SYN
requests
root@Computer:# iptables -N syn_flood
root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
● To resolve this problem we will limit incoming SYN
requests
root@Computer:# iptables -N syn_flood
root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood
root@Computer:# iptables -A syn_flood --syn -m limit --limit 1/s --limit-burst 3 -j RETURN
root@Computer:# iptables -A syn_flood -j DROP
root@Computer:# iptables -L
Firewall - iptables - more examples
● 2nd Example: Blocking syn-flood attacks
● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
● To resolve this problem we will limit incoming SYN
requests
root@Computer:# iptables -N syn_flood
root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood
root@Computer:# iptables -A syn_flood --syn -m limit --limit 1/s --limit-burst 3 -j RETURN
root@Computer:# iptables -A syn_flood -j DROP
root@Computer:# iptables -L
Firewall - xtables-addons
● xtables-addons is a package containing extensions for
iptables
Firewall - xtables-addons
● xtables-addons is a package containing extensions for
iptables
● Ubuntu: apt-get install xtables-addons-common
Firewall - xtables-addons
● xtables-addons is a package containing extensions for
iptables
● Ubuntu: apt-get install xtables-addons-common
● Example extensions:
– geoip
● allows matching on countries
Firewall - xtables-addons
● xtables-addons is a package containing extensions for
iptables
● Ubuntu: apt-get install xtables-addons-common
● Example extensions:
– geoip
● allows matching on countries
– tarpit
● extends tcp matching functionality
Firewall - xtables-addons
● xtables-addons is a package containing extensions for
iptables
● Ubuntu: apt-get install xtables-addons-common
● Example extensions:
– geoip
● allows matching on countries
– tarpit
● extends tcp matching functionality
– account
● provides statistics for packets (counting packets etc)

Weitere ähnliche Inhalte

Kürzlich hochgeladen

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

Kürzlich hochgeladen (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 

Empfohlen

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Empfohlen (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Basics of firewall, ebtables, arptables and iptables

  • 1. Firewall Author: Przemysław Piotrowski Email: przemyslav.piotrowski@gmail.com
  • 3. Firewall Firewall is a hardware or software that prevents unauthorized access to or from a network What is it?
  • 4. Firewall Firewall is a hardware or software that prevents unauthorized access to or from a network What is it? ----- Too vague and unclear
  • 5. Firewall Firewall is a hardware or software that prevents unauthorized access to or from a network What is it? ----- Too vague and unclear Firewall provides a whole variety of tools necessary for safe and successful exchange of information between hosts in networks
  • 6. Firewall - history Note: The term firewall originally referred to a wall intended to confine a fire or potential fire within a building
  • 7. Firewall - history Note: The term firewall originally referred to a wall intended to confine a fire or potential fire within a building The need for firewall emerged in the late 1980s - Morris Worm in 1988
  • 8. Firewall – first generation ● First firewall version in 1988 – packet filter
  • 9. Firewall – first generation ● First firewall version in 1988 – packet filter ● Filters packets based on the contents of packet headers (IP addresses, MAC addresses, protocols (TCP, UDP, ICMP, etc.) and TCP/UDP ports)
  • 10. Firewall – first generation ● First firewall version in 1988 – packet filter ● Filters packets based on the contents of packet headers (IP addresses, MAC addresses, protocols (TCP, UDP, ICMP, etc.) and TCP/UDP ports) ● Ebtables, arptables
  • 11. Firewall – first generation ● First firewall version in 1988 – packet filter ● Filters packets based on the contents of packet headers (IP addresses, MAC addresses, protocols (TCP, UDP, ICMP, etc.) and TCP/UDP ports) ● Ebtables, arptables
  • 12. Firewall – second generation ● Stateful packet filters
  • 13. Firewall – second generation ● Stateful packet filters ● Packets can be filtered based on their connection state
  • 14. Firewall – second generation ● Stateful packet filters ● Packets can be filtered based on their connection state ● iptables
  • 15. Firewall – third generation ● Application layer firewall
  • 16. Firewall – third generation ● Application layer firewall
  • 17. Firewall – third generation ● Application layer firewall
  • 18. Firewall – third generation ● Application layer firewall ● Able to control network traffic regarding a specific application or sevice ● AppArmor, Kerio Control
  • 19. Firewall - concepts ● Firewall consists of 3 main concepts:
  • 20. Firewall - concepts ● Firewall consists of 3 main concepts: 1 Filtering of frames and ARP messages (in OSI layer 2) and packets (in OSI layer 3)
  • 21. Firewall - concepts ● Firewall consists of 3 main concepts: 1 Filtering of frames and ARP messages (in OSI layer 2) and packets (in OSI layer 3) 2 Modification of headers (IP addresses, MAC addresses, ports)
  • 22. Firewall - concepts ● Firewall consists of 3 main concepts: 1 Filtering of frames and ARP messages (in OSI layer 2) and packets (in OSI layer 3) 2 Modification of headers (IP addresses, MAC addresses, ports) 3 Modification of payload
  • 23. Firewall – filtering ● The most common use of firewall
  • 24. Firewall – filtering ● The most common use of firewall ● Example usage: filtering packets based on their destination ports Web server Internet Firewall HTTP request on port 80 SSH port 22 Telnet port 23
  • 25. Firewall - filtering ● Filtering can be done based on:
  • 26. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2)
  • 27. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3)
  • 28. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3) – Ports (OSI layer 4)
  • 29. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3) – Ports (OSI layer 4) – Protocol (OSI layers 2-4)
  • 30. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3) – Ports (OSI layer 4) – Protocol (OSI layers 2-4) – Interface
  • 31. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3) – Ports (OSI layer 4) – Protocol (OSI layers 2-4) – Interface – Fragmentation (OSI layer 3)
  • 32. Firewall - filtering ● Filtering can be done based on: – MAC address (OSI layer 2) – IP address (OSI layer 3) – Ports (OSI layer 4) – Protocol (OSI layers 2-4) – Interface – Fragmentation (OSI layer 3) – Payload
  • 33. Firewall - filtering ● Packet filter can do 3 things with an incoming packet:
  • 34. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it
  • 35. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection
  • 36. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection 3) Reject it without any notification
  • 37. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection 3) Reject it without any notification ● Packet filter contains a table with specified set of rules
  • 38. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection 3) Reject it without any notification ● Packet filter contains a table with specified set of rules ● If incoming packet or frame matches the first rule then the action specified in this rule is performed
  • 39. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection 3) Reject it without any notification ● Packet filter contains a table with specified set of rules ● If incoming packet or frame matches the first rule then the action specified in this rule is performed ● If it doesn't match, then the next rule is checked (if it exists)
  • 40. Firewall - filtering ● Packet filter can do 3 things with an incoming packet: 1) Accept it 2) Reject it and notify the sender about rejection 3) Reject it without any notification ● Packet filter contains a table with specified set of rules ● If incoming packet or frame matches the first rule then the action specified in this rule is performed ● If it doesn't match, then the next rule is checked (if it exists) ● If packet or frame doesn't match any of the rules, then is it rejected without any notification
  • 41. Firewall – header modification ● Firewall can modify information located in headers of packets and frames
  • 42. Firewall – header modification ● Firewall can modify information located in headers of packets and frames ● Used in IP Masquerading IP Masquerading is a process of modifying packet's source IP address Used in private networks, where IP Masquerading allows hosts from inside the network that don't have a public IP address to send and receive packets from the Internet.
  • 43. Firewall – header modification ● Firewall can modify information located in headers of packets and frames ● Used in IP Masquerading IP Masquerading is a process of modifying packet's source IP address Used in private networks, where IP Masquerading allows hosts from inside the network that don't have a public IP address to send and receive packets from the Internet. Internet 178.36.119.72192.168.1.1192.168.1.2 Host 1 Router Packet source IP: 192.168.1.2 Packet source IP: 178.36.119.72
  • 44. Firewall – header modification ● Firewall can modify information located in headers of packets and frames ● Used in IP Masquerading IP Masquerading is a process of modifying packet's source IP address Used in private networks, where IP Masquerading allows hosts from inside the network that don't have a public IP address to send and receive packets from the Internet. Internet 178.36.119.72192.168.1.1192.168.1.2 Host 1 Router Packet source IP: 192.168.1.2 Packet source IP: 178.36.119.72 IP Masquerading was performed inside 'Router', where source IP of a packet sent from Host 1 was changed.
  • 45. Firewall – payload modification ● Frame payload modification takes place mostly in the top layer of OSI model
  • 46. Firewall – payload modification ● Frame payload modification takes place mostly in the top layer of OSI model
  • 47. Firewall – payload modification ● Frame payload modification takes place mostly in the top layer of OSI model ● NFQUEUE
  • 48. Firewall – OSI model ebtables, arptables Iptables, xtables-addons
  • 49. Firewall - ebtables ● The ebtables utility enables basic Ethernet frame filtering on a Linux bridge, logging, MAC NAT and brouting
  • 50. Firewall - ebtables ● The ebtables utility enables basic Ethernet frame filtering on a Linux bridge, logging, MAC NAT and brouting ● MAC NAT - ability to change the MAC Ethernet source and destination address
  • 51. Firewall - ebtables ● The ebtables utility enables basic Ethernet frame filtering on a Linux bridge, logging, MAC NAT and brouting ● MAC NAT - ability to change the MAC Ethernet source and destination address ● Brouting – bridge can act as bridge and router. Using firewall rules we can decide if frame should be routed to higher OSI layers or should it be bridged (OSI layer 3)
  • 52. Firewall – ebtables – tables Ebtables uses rules to decide what action to perform with frames Ebtables divides rules into 3 tables: 1. filter In this table we place rules which filter frames 2. nat In this table we place rules which should modify frame headers 3. broute In this table we place rules which should route frames Rules inside these tables are separated into chains
  • 53. Firewall – ebtables – tables Ebtables uses rules to decide what action to perform with frames Ebtables divides rules into 3 tables: 1. filter In this table we place rules which filter frames Frames are directed to chain: ● INPUT - if the destination MAC address of the frame is on the bridge itself ● FORWARD - for frames being forwared by the bridge ● OUTPUT - if the frames are generated locally or for brouted frames 2. nat In this table we place rules which should modify frame headers ● PREROUTING – frames are modified as soon as they came in ● OUTPUT - for modifying locally generated or (b)routed frames before they are bridged ● POSTROUTING - for altering frames as they are about to go out 3. broute In this table we place rules which should route frames ● BROUTING Users can also define their own chains
  • 54. Firewall – ebtables – tables
  • 55. Firewall – ebtables - bridge ● A network bridge connects multiple network segments
  • 56. Firewall – ebtables - bridge ● A network bridge connects multiple network segments ● To create a bridge on a computer we will use brctl located in bridge-utils package
  • 57. Firewall – ebtables - bridge ● A network bridge connects multiple network segments ● To create a bridge on a computer we will use brctl located in bridge-utils package eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2
  • 58. Firewall – ebtables - bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2
  • 59. Firewall – ebtables - bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2 root@Bridge:# ifconfig eth0 0.0.0.0 root@Bridge:# ifconfig eth1 0.0.0.0 root@Bridge:# brctl addbr br0 root@Bridge:# brctl addif br0 eth0 root@Bridge:# brctl addif br0 eth1 root@Bridge:# ifconfig br0 up
  • 60. Firewall – ebtables - bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2 root@Bridge:# ifconfig eth0 0.0.0.0 root@Bridge:# ifconfig eth1 0.0.0.0 root@Bridge:# brctl addbr br0 root@Bridge:# brctl addif br0 eth0 root@Bridge:# brctl addif br0 eth1 root@Bridge:# ifconfig br0 up root@Bridge:# brctl showmacs br0 port no mac addr is local? ageing timer 1 00:10:4b:b6:c6:e4 no 119.25 1 00:a0:24:d0:4c:d6 yes 0.00 1 00:a0:24:f0:22:71 no 5.81 4 08:00:09:fb:39:a1 no 27.24 4 08:00:09:fc:92:2c no 53.13 4 08:00:09:fc:d2:11 yes 0.00
  • 61. Firewall – ebtables – installation & rules Installation: root@Bridge:# apt-get install ebtables
  • 62. Firewall – ebtables – installation & rules Installation: root@Bridge:# apt-get install ebtables ● Ebtables holds a table of rules, which are used to filter frames
  • 63. Firewall – ebtables – installation & rules Installation: root@Bridge:# apt-get install ebtables ● Ebtables holds a table of rules, which are used to filter frames To list these rules we can use a command: root@Bridge:# ebtables -L
  • 64. Firewall – ebtables – installation & rules Installation: root@Bridge:# apt-get install ebtables ● Ebtables holds a table of rules, which are used to filter frames To list these rules we can use a command: root@Bridge:# ebtables -L
  • 65. Firewall – ebtables – commands To delete a rule: ebtables -D chain start_nr[:end_nr] root@Bridge:# ebtables -D FORWARD 1 To create a user-defined chain: ebtables -N chain_name [-P policy] root@Bridge:# ebtables -D new_chain -P ACCEPT To specify the destination MAC address: ebtables -A chain -s mac_address -j TARGET root@Bridge:# ebtables -A FORWARD -s b8:88:e3:79:1a:b1 -j DROP To specify the source MAC address: ebtables -A chain -s mac_address -j TARGET root@Bridge:# ebtables -A FORWARD -s b8:88:e3:79:1a:b1 -j DROP Append the rule to the end of the chain: iptables -A rule_specification -j target root@Harvey:# iptables -A INPUT --dport 80 -j DROP List rules in chain: iptables -L [chain] root@Harvey:# iptables -L Flush (delete all) rules in chain: iptables -F chain root@Harvey:# iptables -F OUTPUT
  • 66. Firewall – ebtables – rule specifications (matches) Rule specifications: -p protocol - protocol responsible for creating the frame -i interface - the interface the frame was originally received from -o interface - the interface by which the frame is going to be sent -s source - source MAC address -d destination - destination MAC address
  • 67. Firewall – ebtables – targets TARGET specifies what happens to a frame after it matched a rule.
  • 68. Firewall – ebtables – targets TARGET specifies what happens to a frame after it matched a rule. In Ebtables we can choose from 5 targets: 1) ACCEPT – let the frame through 2) DROP – the frame will be dropped 3) CONTINUE – next rule will be checked 4) RETURN – go back to the previous chain and check the next rule 5) Jump to user defined chain
  • 69. Firewall – ebtables – basic configuration ebtables -P FORWARD DROP ebtables -A FORWARD -p IPv4 -j ACCEPT ebtables -A FORWARD -p ARP -j ACCEPT ebtables -P INPUT DROP ebtables -A INPUT -p IPv4 -j ACCEPT ebtables -A INPUT -p ARP -j ACCEPT ebtables -P OUTPUT DROP ebtables -A OUTPUT -p IPv4 -j ACCEPT ebtables -A OUTPUT -p ARP -j ACCEPT This is a basic filter configuration which will only let frames made by the protocols IP version 4 and ARP through
  • 70. Firewall – ebtables – MAC NAT ● Ebtables allows for changing MAC addresses in frame headers
  • 71. Firewall – ebtables – MAC NAT root@Bridge:# ebtables -t nat -A PREROUTING -d 00:11:22:33:44:55 -i eth0 -j dnat --to-destination 54:44:33:22:11:00 ● Ebtables allows for changing MAC addresses in frame headers
  • 72. Firewall – ebtables – MAC NAT root@Bridge:# ebtables -t nat -A PREROUTING -d 00:11:22:33:44:55 -i eth0 -j dnat --to-destination 54:44:33:22:11:00 This will make all frames destined to 00:11:22:33:44:55 that arrived on interface eth0 be transferred to 54:44:33:22:11:00 instead ● Ebtables allows for changing MAC addresses in frame headers
  • 73. Firewall – ebtables - example ● Example: we want to block ARP messages going through the bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2
  • 74. Firewall – ebtables - example ● Example: we want to block ARP messages going through the bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2 root@192.168.1.2:# arping 192.168.2.1 ARPING 192.168.2.1 from 192.168.1.2 eth0 Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms
  • 75. Firewall – ebtables - example ● Example: we want to block ARP messages going through the bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2 root@Bridge:# ebtables -t filter -A FORWARD -p ARP -j DROP root@192.168.1.2:# arping 192.168.2.1 ARPING 192.168.2.1 from 192.168.1.2 eth0 Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms
  • 76. Firewall – ebtables - example ● Example: we want to block ARP messages going through the bridge eth0 eth1 192.168.1.2 192.168.1.1 192.168.2.1 192.168.2.2 root@Bridge:# ebtables -t filter -A FORWARD -p ARP -j DROP root@192.168.1.2:# arping 192.168.2.1 ARPING 192.168.2.1 from 192.168.1.2 eth0 Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 0.950ms Unicast reply from 192.168.2.1 [B8:54:E5:34:1A:E4] 1.055ms root@192.168.1.2:# arping 192.168.2.1 -c 5 ARPING 192.168.2.1 from 192.168.1.2 eth0 Sent 5 probes (5 broadcast(s)) Received 0 response(s)
  • 77. Firewall - arptables ● Configuration very similar to ebtables
  • 78. Firewall - arptables ● Configuration very similar to ebtables ● Not limited to bridges ● Designed to work specifically with ARP messages
  • 79. Firewall - arptables ● Configuration very similar to ebtables ● Not limited to bridges ● Designed to work specifically with ARP messages
  • 80. Firewall – arptables – tables Installation: root@Harvey:# apt-get install arptables
  • 81. Firewall – arptables – tables Installation: root@Harvey:# apt-get install arptables
  • 82. Firewall – arptables – tables ● One filter table 1) INPUT chain - for frames destined for the host 2) OUTPUT chain - for locally-generated frames 3) FORWARD chain - for frames being forwarded by the bridge (this chain is not available in Linux kernel 2.4.X) Installation: root@Harvey:# apt-get install arptables
  • 83. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted To add a new rule to a specific chain: arptables -A chain rule_specification To delete a rule from chain: arptables -D chain rule_specification or arptables -D chain start_nr[:end_nr] To set the policy for the chain: (only for built-in chains) arptables -P chain policy (ACCEPT/DROP/RETURN) To add a new user-defined chain: arptables -N chain_name
  • 84. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted
  • 85. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted To add a new rule to a specific chain: arptables -A chain rule_specification
  • 86. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted To add a new rule to a specific chain: arptables -A chain rule_specification To delete a rule from chain: arptables -D chain rule_specification or arptables -D chain start_nr[:end_nr]
  • 87. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted To add a new rule to a specific chain: arptables -A chain rule_specification To delete a rule from chain: arptables -D chain rule_specification or arptables -D chain start_nr[:end_nr] To set the policy for the chain: (only for built-in chains) arptables -P chain policy (ACCEPT/DROP/RETURN)
  • 88. Firewall – arptables – rule building & commands Rule building: arptables [-t table] command rule-specification [options] ● Option -t can be omitted To add a new rule to a specific chain: arptables -A chain rule_specification To delete a rule from chain: arptables -D chain rule_specification or arptables -D chain start_nr[:end_nr] To set the policy for the chain: (only for built-in chains) arptables -P chain policy (ACCEPT/DROP/RETURN) To add a new user-defined chain: arptables -N chain_name
  • 89. Firewall – arptables – rule specifications Rule specifications: ● '-s address[/mask]' - the Source IP specification ● '-d address[/mask]' - the Destination IP specification ● '--source-mac mac_address' - the source mac address ● '--destination-mac mac_address' - the destination mac address ● '-i name' - the interface via which a frame is received (for the INPUT and FORWARD chains) ● '-o name' - the interface via which a frame is going to be sent (for the OUTPUT and FORWARD chains) '!' option before the specification inverts the test for that specification
  • 90. Firewall - arptables - example Router Computer1 192.168.2.1 192.168.2.2 Harvey 192.168.2.3 Switch AA:AA:AA:AA:AA:AA BB:BB:BB:BB:BB:BB CC:CC:CC:CC:CC:CC
  • 91. Firewall - arptables - example Router Computer1 192.168.2.1 192.168.2.2 Harvey 192.168.2.3 Switch ● Harvey sends valuable data to Router and wants to protect himself from Computer1 ARP Spoofing AA:AA:AA:AA:AA:AA BB:BB:BB:BB:BB:BB CC:CC:CC:CC:CC:CC
  • 92. Firewall - arptables - example Router Computer1 192.168.2.1 192.168.2.2 Harvey 192.168.2.3 Switch ● Harvey sends valuable data to Router and wants to protect himself from Computer1 ARP Spoofing AA:AA:AA:AA:AA:AA BB:BB:BB:BB:BB:BB CC:CC:CC:CC:CC:CC root@Harvey:# arptables -A INPUT -s 192.168.2.1 --source-mac ! AA:AA:AA:AA:AA:AA -j DROP root@Harvey:# arptables -A OUTPUT -d 192.168.2.1 --destination-mac ! AA:AA:AA:AA:AA:AA -j DROP
  • 93. Firewall - arptables - example Router Computer1 192.168.2.1 192.168.2.2 Harvey 192.168.2.3 Switch ● Harvey sends valuable data to Router and wants to protect himself from Computer1 ARP Spoofing AA:AA:AA:AA:AA:AA BB:BB:BB:BB:BB:BB CC:CC:CC:CC:CC:CC root@Harvey:# arptables -A INPUT -s 192.168.2.1 --source-mac ! AA:AA:AA:AA:AA:AA -j DROP root@Harvey:# arptables -A OUTPUT -d 192.168.2.1 --destination-mac ! AA:AA:AA:AA:AA:AA -j DROP root@Harvey:# arptables -L Chain INPUT (policy ACCEPT) -j DROP -s 192.168.2.1 ! --src-mac aa:aa:aa:aa:aa:aa Chain OUTPUT (policy ACCEPT) -j DROP -d 192.168.2.1 ! --dst-mac aa:aa:aa:aa:aa:aa Chain FORWARD (policy ACCEPT)
  • 94. Firewall - iptables ● Iptables is a firewall for OSI layer 3 and 4
  • 95. Firewall - iptables ● Iptables is a firewall for OSI layer 3 and 4 ● successor of ipchains and ipfilter
  • 96. Firewall - iptables - tables ● filter – INPUT – FORWARD – OUTPUT ● nat – PREROUTING – OUTPUT – POSTROUTING ● mangle – PREROUTING – INPUT – OUTPUT – FORWARD – POSTROUTING ● raw – PREROUTING – OUTPUT
  • 97. Firewall - iptables - tables ● mangle - This table is used for specialized packet modification (e.g. change Type Of Service field in a packet) ● raw - handled before connection tracking takes place
  • 98. Firewall - iptables - rule specifications (matches) ● Other matches: ● -m or --match ● -m conntrack Allows filter rules to match based on connection state. Permits the use of the --ctstate option. ● --ctstate Example: iptables -A INPUT -p tcp -m conntrack --ctstate NEW -j ACCEPT
  • 99. Firewall - iptables - rule specifications (matches) ● Other matches: ● -m or --match ● -m conntrack Allows filter rules to match based on connection state. Permits the use of the --ctstate option. ● --ctstate Example: iptables -A INPUT -p tcp -m conntrack --ctstate NEW -j ACCEPT ● -m limit - Require the rule to match only a limited number of times. Allows the use of the --limit option. Useful for limiting logging rules. ● --limit and --limit-burst Example: iptables -A INPUT -p icmp -m limit --limit 1/min --limit-burst 5 -j DROP
  • 100. Firewall - iptables - features ● stateless packet filtering (IPv4 and IPv6)
  • 101. Firewall - iptables - features ● stateless packet filtering (IPv4 and IPv6) ● stateful packet filtering (IPv4 and IPv6) – iptables can distinguish the connection state of a packet – this adds a new packet filtering capability based on the connection state
  • 102. Firewall - iptables - features ● stateless packet filtering (IPv4 and IPv6) ● stateful packet filtering (IPv4 and IPv6) – iptables can distinguish the connection state of a packet – this adds a new packet filtering capability based on the connection state ● NAPT - network address and port translation (IPv4 and IPv6) – iptables can modify packet headers including IP addresses and ports
  • 103. Firewall - iptables - connection state ● Packets can be related to tracked connections in four different so called states: NEW, ESTABLISHED, RELATED and INVALID
  • 104. Firewall - iptables - connection state ● Packets can be related to tracked connections in four different so called states: NEW, ESTABLISHED, RELATED and INVALID ● NEW - tells us that the packet is the first packet that we see from a specific connection
  • 105. Firewall - iptables - connection state ● Packets can be related to tracked connections in four different so called states: NEW, ESTABLISHED, RELATED and INVALID ● NEW - tells us that the packet is the first packet that we see from a specific connection ● ESTABLISHED - next packets from the same connection
  • 106. Firewall - iptables - connection state ● Packets can be related to tracked connections in four different so called states: NEW, ESTABLISHED, RELATED and INVALID ● NEW - tells us that the packet is the first packet that we see from a specific connection ● ESTABLISHED - next packets from the same connection ● RELATED - new connection created by already ESTABLISHED connection
  • 107. Firewall - iptables - connection state ● Packets can be related to tracked connections in four different so called states: NEW, ESTABLISHED, RELATED and INVALID ● NEW - tells us that the packet is the first packet that we see from a specific connection ● ESTABLISHED - next packets from the same connection ● RELATED - new connection created by already ESTABLISHED connection ● INVALID - packet not identified
  • 108. Firewall - iptables - NAT ● There are two types of NAT: Source NAT (SNAT) and Destination NAT (DNAT) Change the source address of a packet to 1.2.3.4
  • 109. Firewall - iptables - NAT ● There are two types of NAT: Source NAT (SNAT) and Destination NAT (DNAT) Change the source address of a packet to 1.2.3.4 root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4
  • 110. Firewall - iptables - NAT ● There are two types of NAT: Source NAT (SNAT) and Destination NAT (DNAT) Change the source address of a packet to 1.2.3.4 root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4 Change the destination address of a packet to 1.2.3.4
  • 111. Firewall - iptables - NAT ● There are two types of NAT: Source NAT (SNAT) and Destination NAT (DNAT) Change the source address of a packet to 1.2.3.4 root@Harvey:# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4 Change the destination address of a packet to 1.2.3.4 root@Harvey:# iptables -t nat -A PREROUTING -i eth1 -j DNAT --to 1.2.3.4
  • 112. Firewall - iptables - NAPT ● Forwarding ports - process of forwarding packets, which are being received on a specific port.
  • 113. Firewall - iptables - NAPT ● Forwarding ports - process of forwarding packets, which are being received on a specific port. We want to forward packets from interface eth0 port 80 to 192.168.1.200 to port 8080
  • 114. Firewall - iptables - NAPT ● Forwarding ports - process of forwarding packets, which are being received on a specific port. We want to forward packets from interface eth0 port 80 to 192.168.1.200 to port 8080 iptables -t nat -A PREROUTING -i eth0 --dport 80 -j DNAT --to- destination 192.168.1.200:8080
  • 115. Firewall - iptables - more examples ● 1st Example: IP Masquerading Internet 178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0) Host 1 Router Packet source IP: 192.168.1.2 Packet source IP: 178.36.119.72
  • 116. Firewall - iptables - more examples ● 1st Example: IP Masquerading Internet 178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0) Host 1 Router Packet source IP: 192.168.1.2 Packet source IP: 178.36.119.72 root@Router:# echo 1 > /proc/sys/net/ipv4/ip_forward root@Router:# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
  • 117. Firewall - iptables - more examples ● 1st Example: IP Masquerading Internet 178.36.119.72 (ppp0)192.168.1.1(eth0)192.168.1.2 (eth0) Host 1 Router Packet source IP: 192.168.1.2 Packet source IP: 178.36.119.72 root@Router:# echo 1 > /proc/sys/net/ipv4/ip_forward root@Router:# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE root@Host1:# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=34.5ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=34.0ms
  • 118. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks
  • 119. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks ● In TCP SYN attack, target's computer is being flooded with TCP SYN requests
  • 120. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks ● In TCP SYN attack, target's computer is being flooded with TCP SYN requests ● To resolve this problem we will limit incoming SYN requests
  • 121. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks ● In TCP SYN attack, target's computer is being flooded with TCP SYN requests ● To resolve this problem we will limit incoming SYN requests root@Computer:# iptables -N syn_flood root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood
  • 122. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks ● In TCP SYN attack, target's computer is being flooded with TCP SYN requests ● To resolve this problem we will limit incoming SYN requests root@Computer:# iptables -N syn_flood root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood root@Computer:# iptables -A syn_flood --syn -m limit --limit 1/s --limit-burst 3 -j RETURN root@Computer:# iptables -A syn_flood -j DROP root@Computer:# iptables -L
  • 123. Firewall - iptables - more examples ● 2nd Example: Blocking syn-flood attacks ● In TCP SYN attack, target's computer is being flooded with TCP SYN requests ● To resolve this problem we will limit incoming SYN requests root@Computer:# iptables -N syn_flood root@Computer:# iptables -I INPUT 1 -p tcp -j syn_flood root@Computer:# iptables -A syn_flood --syn -m limit --limit 1/s --limit-burst 3 -j RETURN root@Computer:# iptables -A syn_flood -j DROP root@Computer:# iptables -L
  • 124. Firewall - xtables-addons ● xtables-addons is a package containing extensions for iptables
  • 125. Firewall - xtables-addons ● xtables-addons is a package containing extensions for iptables ● Ubuntu: apt-get install xtables-addons-common
  • 126. Firewall - xtables-addons ● xtables-addons is a package containing extensions for iptables ● Ubuntu: apt-get install xtables-addons-common ● Example extensions: – geoip ● allows matching on countries
  • 127. Firewall - xtables-addons ● xtables-addons is a package containing extensions for iptables ● Ubuntu: apt-get install xtables-addons-common ● Example extensions: – geoip ● allows matching on countries – tarpit ● extends tcp matching functionality
  • 128. Firewall - xtables-addons ● xtables-addons is a package containing extensions for iptables ● Ubuntu: apt-get install xtables-addons-common ● Example extensions: – geoip ● allows matching on countries – tarpit ● extends tcp matching functionality – account ● provides statistics for packets (counting packets etc)