firewallnotes
firewallnotes
Firewall policy
A firewall policy is a set of rules and configurations that define how a firewall
should behave and what traffic it should allow or block. These policies are crucial
for maintaining network security and ensuring that only authorized traffic is
permitted.
Firewall controls
specific mechanisms and rules that dictate how a firewall manages and regulates
the flow of traffic based on various services and protocols.
SERVICE CONTROL
• Determines which services on internal hosts are accessible from
outside
• Reject all other incoming services
• Outgoing service requests and corresponding responses may also
be controlled
• Filtering is based on the contents of IP packets and the type of
requests
• Example: Reject all HTTP requests unless directed to an official web
server
BEHAVIOUR CONTROL
• Infringing organizational policy
• Anti-social activities on a network
• Suspected attack
• Filtering action:
• May be applicable at IP or TCP level
• May require further interpretation of messages at a higher
level
• Example: Filtering of spam emails. Would require sender’s email
address in message headers. May require to scan through the
message contents.
USER cONTROL
• Discriminate between users
• Some users can access external services, others can’t
• Inhibit some users from gaining access to services
Egress Filtering
Definition: Refers to the filtering of outgoing traffic from a network.
Purpose: To prevent sensitive data from leaving the network and to
control the types of traffic that can exit.
Common Use Cases: Preventing data leaks, stopping malware from
communicating with external servers, and controlling access to the internet.
Key Differences between ingress and egress
Direction:
o Ingress: Deals with incoming traffic.
Focus:
o Ingress Filtering: Aims to block unauthorized access and protect
the network from external threats.
o Egress Filtering: Aims to prevent unauthorized data transmission
and control outbound communication.
Types of filters
1. Stateless Filtering
Definition: Stateless filtering evaluates each packet in isolation, without
considering the context of any previous packets.
How It Works:
o Each packet is analyzed based solely on predefined rules regarding
source/destination IP addresses, ports, and protocols.
o The firewall makes decisions based on this static information
without maintaining any connection state.
Advantages:
o Faster processing since there’s no need to track connections.
Disadvantages:
o Less secure, as it doesn’t recognize established connections or the
context of traffic.
o More vulnerable to spoofing and other attacks.
2. Stateful Filtering
Definition: Stateful filtering tracks active connections and makes
decisions based on the state of these connections.
How It Works:
o The firewall maintains a state table that records details about
ongoing connections (e.g., TCP handshakes).
o It allows packets that are part of established connections while
applying rules to new connection requests.
Advantages:
o More secure than stateless filtering, as it understands the context of
packets and can detect unauthorized access attempts.
o Better protection against certain types of attacks, such as session
hijacking.
Disadvantages:
o More resource-intensive, as it requires maintaining connection state
information.
o Slightly more complex to configure compared to stateless firewalls.
Netfilter is a powerful framework within the Linux kernel that provides firewall
capabilities and packet filtering.
ey Concepts of Netfilter
1. Packet Traversal Hooks:
o As packets travel through the Linux kernel's networking stack, they
pass through various layers (e.g., network, transport, application).
o The kernel defines specific points, known as hooks, along this
traversal path. These hooks allow developers to interact with
packets at various stages.
2. Callback Functions:
o Developers can create kernel modules that register callback
functions with these hooks.
o When a packet reaches a particular hook, the associated callback
function is invoked.
3. Decision Making:
o The callback functions have the power to make decisions about the
packet:
Forward: If the packet is deemed safe and meets the criteria
defined in the firewall rules, the callback function allows it to
continue through the stack to its destination.
Drop: If the packet is identified as harmful or does not
comply with the security rules, the callback function can drop
the packet, effectively preventing it from reaching its
intended destination.
How It Works in Practice
1. Hook Points:
o Netfilter defines several hook points, such as:
iptables is a powerful tool used for configuring the Linux kernel's Netfilter
framework, allowing you to set up, manage, and maintain firewall rules on Linux
systems. It operates at the network layer and can filter traffic based on various
criteria, providing essential security for servers and networks.
Key Features of iptables
1. Packet Filtering:
o Allows or blocks packets based on rules defined by the user.
2. Chains:
o Each table has built-in chains where rules are applied:
Tables
iptables utilizes different tables, each serving a specific purpose. The most
commonly used tables are:
1. filter:
o Purpose: This is the default table used for packet filtering.
3. FORWARD Chain:
o Deals with packets that are being routed through the system but are
not destined for it.
o This chain is relevant in situations where the machine acts as a
router.
4. PREROUTING Chain (in nat and mangle tables):
o Alters packets as they arrive at the interface, before any routing
decisions are made.
5. POSTROUTING Chain (in nat and mangle tables):
o Alters packets just before they leave the interface, allowing for last-
minute changes.
Rule Processing Order
Rules within each chain are processed in a top-down manner.
When a packet matches a rule, the associated action (like ACCEPT, DROP,
REJECT, or LOG) is taken, and no further rules in that chain are evaluated.
Stateful Firewall
• A stateful firewall monitors incoming and outgoing packets over a period
of time
• Records aspects about connection state (such as IP address, port numbers,
sequence numbers)
• The state enables filtering decisions to be based on context of a packet
(not just headers)
• Tracking TCP Connections
• Stateful firewalls can monitor TCP handshake protocols between two
machines to identify if there is a connection established between
the two of them.
• Example: monitoring 3-way handshake protocol or 4-way
termination protocols
• Tracking UDP Connections
• Connection less protocol
• Stateful firewalls monitor stream of packets between client and
server. If no packets are exchanged for a certain period of time, the
connection is considered to be terminated
• Tracking ICMP Connections
• Not always possible, when only one ICMP packet is sent from client
to server
• If the ICMP packet has a request and response, then tracking of
ICMP connections is possible
• Tracking Application connections
• Some firewalls may be able to track certain application protocols
such as HTTP, FTP, IRC etc.
EVADING FIREWALLS
1.SSH tunnelling to evade firewalls
SSH tunneling involves redirecting network traffic through an encrypted SSH
connection. This can be done in several ways, primarily through local and remote
port forwarding.
SSH tunneling can be effective for bypassing firewalls due to the following
reasons:
1. Encryption: Since SSH connections are encrypted, firewalls cannot
inspect the content of the packets. They only see that an SSH connection
is being established.
2. Port Whitelisting: Many firewalls allow outgoing connections on standard
ports like 22 (SSH), making it easier to establish a connection without
raising alarms.
3. Accessing Blocked Resources: By forwarding traffic through an SSH
server located outside the restrictive network, you can access services
that are normally blocked by a firewall.
Considerations and Risks
While SSH tunneling can be a useful tool, it’s important to consider the following:
Security Policies: Bypassing firewalls may violate organizational security
policies and could lead to disciplinary actions.
Monitoring: Some organizations monitor for unusual SSH usage, and
frequent or suspicious tunneling might raise flags.
Potential for Misuse: Tunneling can also be used maliciously to exfiltrate
sensitive data, which is a risk that organizations need to mitigate.
2.dynamic port forwarding
SOCKS Proxy:
When you set up dynamic port forwarding, you create a SOCKS proxy on
your local machine. This proxy listens on a specified local port and can
forward requests to any destination server.
SSH Tunnel:
The SSH client establishes an encrypted tunnel to the SSH server, through
which all traffic routed via the SOCKS proxy will pass. The server forwards
the requests to the desired destination.
Traffic Routing:
Applications that support SOCKS proxies can be configured to send their
traffic through the local proxy, allowing users to access external services
as if they were connecting directly from the SSH server's network.
3.using VPN
• Using VPN, one can create a tunnel between a computer inside the
network and another one outside. IP packets can be sent using this tunnel.
Since the tunnel traffic is encrypted, firewalls are not able to see what is
inside this tunnel and cannot conduct filtering. This topic will be covered in
detail in VPN
Major Firewall Drawbacks / Vulnerabilities
• Insider Attacks
• Anomalies in Firewall configurations
• Firewall policy not updated (Missed Security Patches)
• Lack of deep packet inspection
• DDoS attacks