networking

IP (Internet Protocol): What It Is, How It Works, and Why It Matters in Pentesting

IP (Internet Protocol): What It Is, How It Works, and Why It Matters in Pentesting

Learn what IP is, how headers, TTLs, routing, and fragmentation work, and why it's essential in pentesting: IP spoofing, evasion, reconnaissance, and defenses.

  • Posted on 2026-03-23
  • Reading time: 7 min

IP is the protocol that everything travels on. Understanding what IP is and how packet routing works isn't academic theory: it's the foundation upon which any pentesting effort is built, from a simple port scan to the most sophisticated routing and fragmentation attacks. Those who don't fully understand IP are working blindly.


What is IP #

IP (Internet Protocol) is the layer 3 protocol of the OSI model that manages the addressing and routing of packets between different networks. It is defined in RFC 791 (IPv4, 1981) and is the glue that holds together the Internet and any TCP/IP network.

IP is a connectionless , best-effort protocol : it doesn't guarantee delivery, order, or integrity. It simply routes each packet to its destination independently. Reliability and order are the responsibility of the upper layers—primarily TCP.

This simplicity is its strength: it's scalable, flexible, and works on any transmission medium. It's also the source of many vulnerabilities: without source address authentication, IP is inherently spoofable.


How IP Works #

IPv4 header structure #

The IPv4 header has a minimum size of 20 bytes:

CountrysideSizeDescription
Version4 bitProtocol version (4 for IPv4)
IHL4 bitHeader length in 32-bit words
DSCP/TOS8 bitDifferentiated Services / QoS
total length16 bitTotal packet length (header + payload)
Login16 bitIdentifier for reassembling fragments
Flags3 bitDF (Don't Fragment), MF (More Fragments)
Fragment Offset13 bitPosition of the fragment in the original datagram
TTL8 bitTime To Live — decreases at each hop
Protocol8 bitHigher Protocol (6=TCP, 17=UDP, 1=ICMP)
Header Checksum16 bitHeader only checksum
source address32 bitSource IP address
Destination address32 bitDestination IP address
OptionsvariableOptional — rarely used, interesting for escapism

TTL: Time To Live #

The TTL is one of the most useful fields during reconnaissance. It starts from a value set by the sending operating system and is decremented by 1 at each router it passes through. When it reaches 0, the packet is discarded and an ICMP Time Exceeded message is sent to the sender.

Typical default TTL values:

Operating SystemDefault TTL
Linux64
Windows128
Cisco IOS255
MacOS64

Looking at the TTL of a received packet allows you to estimate the sender's operating system and the approximate number of hops between you and them—useful information for passive fingerprinting.

IP Fragmentation #

If a packet exceeds the link's MTU (Maximum Transmission Unit) (1500 bytes on standard Ethernet), IP fragments it into smaller pieces. The Identification field identifies fragments belonging to the same datagram, while the Fragment Offset indicates the position of each fragment.

Reassembly occurs at the destination, not along the way. This mechanism has historically been exploited to circumvent firewalls and IDSs.

Routing and routing table #

IP uses routing tables to decide where to send each packet. Each router consults its own table, performs a Longest Prefix Match on the destination address, and forwards the packet to the appropriate next hop.

bash
ip route show          # Linux
route print            # Windows
netstat -rn            # Cross-platform

The local routing table is the first thing to analyze on a compromised host: it reveals reachable subnets and gateways — critical information for pivoting.

IP Options #

The Options field of the IPv4 header is rarely used in production but interesting for the attacker:

  • Record Route: logs every router traversed
  • Source Routing (Loose/Strict): specifies the path the packet should follow
  • Timestamp: records the timestamps of each hop

Source routing was used in historical attacks to bypass firewalls. Most modern routers filter or ignore it, but it's still present in some environments.


Where IP is used in networks #

IP is present wherever there is network communication:

  • Internet: all internet traffic uses IPv4 or IPv6
  • Corporate LANs: all communication between hosts uses IP over Ethernet
  • WAN and VPN: GRE, IPSec, and other protocols tunnel IP within IP
  • Cloud environments: Overlay networks like VXLAN encapsulate Ethernet frames in IP/UDP packets
  • OT/ICS Networks: Modbus/TCP, EtherNet/IP and other industrial protocols use IP as their transport

There's no modern network engagement that doesn't involve IP. It's the layer on which all standard tools operate: Nmap , vulnerability scanners, and exploit frameworks.


Why IP is important in cybersecurity #

IP has no source address authentication. Anyone can construct a packet with any source address—this is the basis of IP spoofing . This structural limitation allows:

  • Amplified DoS attacks (DRDoS) where responses are directed towards the victim
  • Bypassing source IP-based filters
  • Impersonating trusted hosts
  • Confusion in logs and detection systems

Knowing the structure of the IP header also allows you to build customized packages for evasion techniques and advanced fingerprinting — central topics in any engagement.

For the underlying layer over which IP packets travel in a LAN, see IEEE 802.3 Ethernet and ARP . For the IP-based diagnostic protocol, see ICMP.


IP in a pentesting engagement #

Reconnaissance via TTL and passive fingerprinting #

Analyzing the TTL of packets received during a scan or session reveals information about the target OS without sending special probes. Using Wireshark or tcpdump, observe the TTL field in incoming packets:

bash
tcpdump -i eth0 -nn ip and src host <target> -v | grep ttl

TTL near 64 → likely Linux/macOS. Near 128 → likely Windows. Near 255 → likely network device.

Post-compromise routing table analysis #

On a compromised host, the routing table reveals the network topology:

bash
ip route show
# oppure
cat /proc/net/route

Directly connected subnets, static routes to internal segments, gateways to remote networks: essential information for planning pivoting to segments that are not directly reachable.

IP Spoofing for Amplified DoS #

Techniques like DNS amplification, NTP amplification, and SSDP amplification all use IP spoofing: requests with a spoofed source address (that of the victim) are sent to servers that respond with much larger payloads. The victim receives the responses—traffic amplification without requiring proportional bandwidth.

Evasion through fragmentation #

Fragmenting packets in specific ways can evade IDS/IPS that don't reassemble the fragments before analysis. Nmap supports fragmentation techniques:

bash
nmap -f <target>            # Frammenti da 8 byte
nmap --mtu 24 <target>      # MTU personalizzato

Network Path Enumeration #

By combining traceroute with TTL analysis, it is possible to map the router topology between the attacker and the target:

bash
traceroute -n <target>
traceroute -T -p 80 <target>  # TCP SYN invece di UDP

Each revealed hop is a potential point of interest: intermediate network devices, firewalls, load balancers.


Possible attacks and abuses on IP #

IP spoofing #

Construct packets with an arbitrary source address. Used in amplified DoS attacks, ACL bypassing, and impersonating trusted hosts. Requires raw socket access or tools like Scapy.

python
from scapy.all import *
packet = IP(src="1.2.3.4", dst="target") / ICMP()
send(packet)

Fragmentation Attack (Teardrop, Overlapping Fragments) #

Sending overlapping or malformed IP fragments can cause crashes or unpredictable behavior on systems that reassemble them. The historical Teardrop attack caused BSODs on Windows NT/95 with overlapping fragments. Modern variants attempt to bypass IDS with fragments that overwrite themselves at the destination differently than the IDS interprets them.

IP Options Abuse #

Packets with rare or malformed IP options can confuse firewalls, IDSs, and vulnerable network stacks. Source routing (now almost always filtered) allowed the packet's path to be specified, bypassing firewalls that only analyzed the destination address.

TTL-Based Evasion #

Sending packets with a calibrated TTL to reach the IDS (and be analyzed) but not reach the actual target. The IDS sees the traffic, but the target does not. An advanced technique used to evade in-path detection systems.


Practical examples with IP in the laboratory #

Building Custom IP Packets with Scapy #

python
from scapy.all import *

# Pacchetto con TTL basso
p = IP(dst="192.168.1.1", ttl=1) / ICMP()
send(p)

# Visualizzare i campi dell'header
p.show()

IP header analysis with Wireshark #

Useful filters:

text
ip.ttl < 10              # Pacchetti con TTL basso (vicini al timeout)
ip.flags.df == 1         # Pacchetti con Don't Fragment
ip.flags.mf == 1         # Frammenti IP
ip.options               # Pacchetti con IP Options presenti
ip.src == 192.168.1.0/24 # Filtrare per subnet sorgente

Checking Routes on a Linux Host #

bash
ip route show table all   # Tutte le tabelle di routing
ip route get 8.8.8.8      # Quale route userebbe per raggiungere un IP
ss -rn                    # Socket e routing

IP Detection and Defense #

A defender monitoring IP traffic can detect:

  • Packets with abnormal TTL: TTL 1 or very low values ​​not typical of normal traffic
  • Non-routable or spoofed source addresses: Private IPs arriving from outside (ingress filtering)
  • Unusual fragmentation: very small or overlapping fragments not typical of normal traffic
  • IP Options present: rare in modern legitimate traffic, to be investigated
  • Aggressive Traceroute: Packet sequences with incremental TTL from a single source

Fundamental defense: BCP38 / ingress filtering — Edge routers must discard packets with source addresses not belonging to the subnets advertised by the originating AS.


IP Hardening and Mitigations #

Ingress and Egress Filtering (BCP38) #

Configure edge routers to only accept packets with valid source addresses for the segment they're coming from. This mitigates externally visible IP spoofing.

Disable IP Source Routing #

On Cisco routers:

text
no ip source-route

On Linux:

bash
sysctl -w net.ipv4.conf.all.accept_source_route=0

Enable Reverse Path Forwarding (uRPF) #

uRPF discards packets whose source address is unreachable on the interface they arrive from. This effectively mitigates internal spoofing.

text
interface GigabitEthernet0/0
 ip verify unicast source reachable-via rx

Fragmentation: Stateful Firewall #

Modern stateful firewalls reassemble fragments before applying policies. Make sure your firewall is configured to manage fragmentation, not ignore it.


Common IP errors #

“IP guarantees packet delivery.” No. IP is best-effort and connectionless. Ensuring delivery and order is TCP's responsibility, not IP's.

"You cannot spoof the source IP address." False. IP spoofing is trivial with raw sockets or Scapy. The only protection is network-level filtering (ingress filtering, uRPF).

“The TTL doesn't provide useful information.” Wrong. The TTL reveals OS, the approximate number of hops, and can be used for advanced evasion.

“IPv6 has the same security problems as IPv4” Partially. IPv6 solves some problems (ARP spoofing → NDP spoofing instead), but introduces new ones. It's not inherently more secure — it's different.


FAQ about IP #

What is IP and what is it used for? IP (Internet Protocol) is the layer 3 protocol responsible for addressing and routing packets across different networks. It is the foundation of the Internet and every modern TCP/IP network.

What is the TTL in an IP packet? The TTL (Time To Live) is a counter that decreases by 1 for each router it passes through. When it reaches 0, the packet is discarded and an ICMP Time Exceeded error is sent to the sender. This prevents packets from looping indefinitely on the network.

What is IP spoofing? IP spoofing involves constructing packets with a falsified source address. IP doesn't authenticate source addresses, so anyone with raw socket access can do so. It's used in amplified DoS attacks, filter evasion, and impersonation of trusted hosts.

What is the difference between IPv4 and IPv6? IPv4 uses 32-bit addresses (about 4 billion addresses), IPv6 uses 128-bit addresses (virtually unlimited). IPv6 has a simplified header, does not support in-path fragmentation (source only), and replaces ARP with NDP. For full details, see the dedicated article IPv4 vs IPv6.

Is IP secure? IP was designed for robustness and scalability, not security. It doesn't authenticate source addresses, doesn't encrypt payloads, or guarantee integrity. Security is added at higher layers (TLS, IPSec) or through network mechanisms (filters, uRPF).


Conclusion on IP #

IP is the protocol that makes all network communication possible. Understanding it thoroughly—header structure, TTL, fragmentation, routing—isn't an optional prerequisite for pentesters: it's the foundation upon which everything else is built.

IP spoofing, fragmentation evasion, post-compromise routing table analysis, and passive fingerprinting using TTLs are real techniques that every pentester uses. They all require a solid understanding of how IP handles packets.

Learn more about related protocols:

Official reference: RFC 791 — Internet Protocol


Want to build solid network pentesting skills from the ground up? Find 1:1 training and professional assessments at hackita.it/servizi.

If you use HackITA as a reference in your journey, you can support the project: hackita.it/supporto

#ip #routing

leave a message

I'm not a robot