Post

Network Protocols Deep-Dive

A deep-dive reference on the core network protocols — how they work, what ports they use, and their security implications. Built for quick lookup during CTFs, pentests, and cloud security work.

Network Protocols Deep-Dive

The OSI Model — Quick Reference

LayerNumberNameProtocol Examples
Application7ApplicationHTTP, DNS, FTP, SMTP, SSH
Presentation6PresentationTLS/SSL, JPEG, ASCII
Session5SessionNetBIOS, RPC
Transport4TransportTCP, UDP
Network3NetworkIP, ICMP, OSPF
Data Link2Data LinkEthernet, ARP, MAC
Physical1PhysicalCables, Wi-Fi, fiber

TCP/IP model (what actually matters in practice):

TCP/IP LayerMaps to OSIProtocols
Application5, 6, 7HTTP, DNS, SSH, FTP, SMTP
Transport4TCP, UDP
Internet3IP, ICMP
Network Access1, 2Ethernet, ARP

Port Reference — Most Common

PortProtocolService
20, 21TCPFTP (data, control)
22TCPSSH
23TCPTelnet
25TCPSMTP
53TCP/UDPDNS
67, 68UDPDHCP
80TCPHTTP
110TCPPOP3
119TCPNNTP
123UDPNTP
135TCPRPC / MSRPC
137–139TCP/UDPNetBIOS
143TCPIMAP
161, 162UDPSNMP
389TCPLDAP
443TCPHTTPS
445TCPSMB
465TCPSMTPS
587TCPSMTP (submission)
631TCPIPP (printing)
636TCPLDAPS
993TCPIMAPS
995TCPPOP3S
1433TCPMSSQL
1521TCPOracle DB
2049TCP/UDPNFS
3306TCPMySQL / MariaDB
3389TCPRDP
5432TCPPostgreSQL
5900TCPVNC
6379TCPRedis
8080, 8443TCPHTTP/HTTPS alt ports
8888TCPJupyter Notebook
9200TCPElasticsearch
27017TCPMongoDB

TCP — Transmission Control Protocol

How It Works

TCP is connection-oriented — a connection must be established before data flows.

Three-way handshake:

1
2
3
4
5
6
7
Client          Server
  |--- SYN ------->|   Client wants to connect
  |<-- SYN-ACK ----|   Server acknowledges, also requests
  |--- ACK ------->|   Client acknowledges — connection open
  |=== DATA ======>|
  |--- FIN ------->|   Client done sending
  |<-- FIN-ACK ----|   Server acknowledges close

TCP Flags: | Flag | Meaning | |——|———| | SYN | Synchronize — initiate connection | | ACK | Acknowledge — confirm receipt | | FIN | Finish — graceful close | | RST | Reset — abrupt close (port closed, error) | | PSH | Push — send data immediately without buffering | | URG | Urgent — prioritize this data |

Security Implications

  • SYN flood (DoS): Attacker sends mass SYN packets, server allocates state for each → exhausts memory. Mitigated by SYN cookies.
  • TCP RST injection: Attacker spoofs RST packet to tear down a connection (used in censorship and DoS).
  • Port scanning: SYN scan (nmap -sS) — sends SYN, if SYN-ACK returns → port open, then sends RST without completing handshake (stealth).
  • Session hijacking: Predict/spoof sequence numbers to inject data into an established TCP session.
1
2
3
4
5
6
7
8
# Nmap TCP connect scan (full handshake, logged)
nmap -sT target

# Nmap SYN scan (stealth, half-open)
nmap -sS target

# Grab banner via TCP
nc -nv target 80

UDP — User Datagram Protocol

Connectionless — no handshake, no guaranteed delivery, no ordering.

When to use: Speed over reliability — DNS, DHCP, NTP, video streaming, VoIP, gaming.

Security implications:

  • UDP amplification attacks: Attacker sends small spoofed request to UDP service (DNS, NTP, SSDP) → large response sent to victim. Amplification factor can be 10-500x.
  • UDP port scanning: No response = open or filtered. ICMP port unreachable = closed. Slower than TCP scanning.
1
2
3
4
5
# Nmap UDP scan (slow, requires root)
nmap -sU target

# Top UDP ports
nmap -sU --top-ports 20 target

IP — Internet Protocol

IP handles addressing and routing. Every packet carries:

  • Source IP
  • Destination IP
  • TTL (Time To Live — decremented at each hop, packet dropped at 0)
  • Protocol (6=TCP, 17=UDP, 1=ICMP)

IPv4 vs IPv6

 IPv4IPv6
Address size32 bits (4 bytes)128 bits (16 bytes)
Notation192.168.1.12001:db8::1
Header size20 bytes40 bytes
BroadcastYesNo (uses multicast)
NATCommonNot needed
IPSecOptionalBuilt-in

Private IP Ranges (RFC 1918)

1
2
3
4
5
10.0.0.0     – 10.255.255.255   (/8)
172.16.0.0   – 172.31.255.255   (/12)
192.168.0.0  – 192.168.255.255  (/16)
127.0.0.0    – 127.255.255.255  loopback
169.254.0.0  – 169.254.255.255  link-local (APIPA)

CIDR Notation

CIDRSubnet MaskHosts
/8255.0.0.016,777,214
/16255.255.0.065,534
/24255.255.255.0254
/25255.255.255.128126
/26255.255.255.19262
/27255.255.255.22430
/28255.255.255.24014
/29255.255.255.2486
/30255.255.255.2522
/32255.255.255.2551 (single host)

ICMP — Internet Control Message Protocol

ICMP carries control messages — errors, diagnostics. Not used for data transfer.

Key ICMP types:

TypeCodeMeaning
00Echo Reply (ping response)
30Destination Network Unreachable
31Destination Host Unreachable
33Destination Port Unreachable
50Redirect (routing)
80Echo Request (ping)
110TTL Exceeded (traceroute)

Security implications:

  • Ping sweep: ICMP echo requests to find live hosts (nmap -sn)
  • ICMP tunneling: Data exfiltration by embedding payload in ICMP packets (tools: icmpsh, ptunnel)
  • Ping of Death: Oversized ICMP packet causes buffer overflow (historical, patched)
  • Firewalls often block ICMP — a host not responding to ping doesn’t mean it’s down
1
2
3
4
5
6
# Ping sweep
nmap -sn 192.168.1.0/24

# Traceroute (uses TTL-exceeded ICMP messages)
traceroute target      # Linux
tracert target         # Windows

DNS — Domain Name System

DNS translates domain names to IP addresses. Uses UDP port 53 (TCP for zone transfers and large responses).

Record Types

RecordPurposeExample
AIPv4 addressexample.com → 93.184.216.34
AAAAIPv6 addressexample.com → 2606:2800::1
CNAMEAlias to another namewww → example.com
MXMail serverexample.com → mail.example.com
TXTArbitrary textSPF, DKIM, domain verification
NSName serversWho is authoritative for the domain
PTRReverse DNS (IP → name)34.216.184.93.in-addr.arpa → example.com
SOAStart of AuthorityZone metadata
SRVService location_http._tcp.example.com

DNS Resolution Flow

1
2
3
Browser → OS cache → /etc/hosts → Recursive resolver (ISP/8.8.8.8)
    → Root nameserver (.) → TLD nameserver (.com) → Authoritative NS
    → Answer returned and cached

DNS Security Implications

  • DNS enumeration: Find subdomains, mail servers, zone info
  • Zone transfer (AXFR): If misconfigured, dumps entire DNS zone — full subdomain list
  • DNS cache poisoning: Inject malicious records into resolver cache
  • DNS amplification: Small query → large response, used for DDoS
  • DNS tunneling: Encode data in DNS queries for C2 or exfiltration
  • Subdomain takeover: DNS points to a cloud resource (S3, GitHub Pages) that no longer exists — attacker claims it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Basic lookups
nslookup example.com
dig example.com A
dig example.com MX
dig example.com TXT

# Reverse lookup
dig -x 93.184.216.34

# Zone transfer attempt
dig axfr @ns1.example.com example.com

# DNS enumeration
dnsenum example.com
gobuster dns -d example.com -w /usr/share/wordlists/dns.txt

# Subdomain brute force
ffuf -w subdomains.txt -u http://FUZZ.example.com

HTTP — HyperText Transfer Protocol

Request Structure

1
2
3
4
5
6
7
8
9
GET /path?param=value HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Accept: text/html
Cookie: session=abc123
Authorization: Bearer eyJ...
Connection: keep-alive
[blank line]
[body for POST/PUT]

Response Structure

1
2
3
4
5
6
7
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 1234
Set-Cookie: session=newtoken; HttpOnly; Secure; SameSite=Strict
X-Content-Type-Options: nosniff
[blank line]
[response body]

Status Codes

CodeMeaning
200OK
201Created
204No Content
301Moved Permanently
302Found (temporary redirect)
400Bad Request
401Unauthorized (need to authenticate)
403Forbidden (authenticated but not allowed)
404Not Found
405Method Not Allowed
429Too Many Requests
500Internal Server Error
502Bad Gateway
503Service Unavailable

HTTP Methods

MethodPurposeHas Body
GETRetrieve resourceNo
POSTSubmit dataYes
PUTReplace resourceYes
PATCHPartial updateYes
DELETEDelete resourceNo
HEADGET without bodyNo
OPTIONSDiscover allowed methodsNo

Security Implications

  • HTTP vs HTTPS: HTTP is plaintext — credentials, cookies, and data visible to any network observer
  • Verb tampering: Server may handle unexpected methods (e.g., PUT, DELETE) without auth checks
  • Host header injection: Server uses Host: header to route — inject to get password reset links for another domain
  • CORS misconfiguration: Access-Control-Allow-Origin: * allows any site to read responses from your API

TLS/SSL — Transport Layer Security

TLS encrypts traffic at the transport layer. Provides: confidentiality, integrity, authentication.

TLS Handshake (TLS 1.3)

1
2
3
4
5
6
7
8
Client                          Server
  |--- ClientHello (cipher list, random) -->|
  |<-- ServerHello (chosen cipher) ---------|
  |<-- Certificate (server's cert) ---------|
  |<-- CertificateVerify --------------------|
  |<-- Finished ----------------------------|
  |--- Finished ----------------------------|
  |======= Encrypted data ================>|

Key Concepts

  • Certificate: Signed by a CA, proves the server’s identity. Contains: domain, public key, expiry, CA signature.
  • Certificate chain: Leaf cert → Intermediate CA → Root CA. Browser trusts Root CA.
  • SNI (Server Name Indication): Allows one IP to serve multiple TLS certs (virtual hosting).
  • ALPN: Protocol negotiation within TLS (HTTP/1.1 vs HTTP/2).

TLS Versions

VersionStatus
SSL 2.0Broken — disable
SSL 3.0Broken (POODLE) — disable
TLS 1.0Deprecated — disable
TLS 1.1Deprecated — disable
TLS 1.2Acceptable — widely used
TLS 1.3Current — use this

Security Implications

  • Expired/self-signed certs: Users get warnings, MITM possible if ignored
  • Weak cipher suites: RC4, DES, 3DES, NULL ciphers — allow downgrade or decryption
  • BEAST, POODLE, HEARTBLEED: Historical TLS/OpenSSL vulnerabilities
  • Certificate pinning bypass: Mobile apps can pin certs — bypass with Frida or custom CA install
  • MITM: Intercept TLS by presenting your own cert (requires victim to trust your CA)
1
2
3
4
5
6
7
8
# Check TLS version and ciphers
nmap --script ssl-enum-ciphers -p 443 target
sslscan target:443
testssl.sh target

# View certificate
openssl s_client -connect target:443 -showcerts
echo | openssl s_client -connect target:443 2>/dev/null | openssl x509 -noout -text

SSH — Secure Shell

SSH provides encrypted remote shell access, tunneling, and file transfer. Default port 22.

Authentication Methods

MethodHow it works
PasswordUsername + password over encrypted channel
Public keyClient proves possession of private key matching server’s authorized_keys
CertificateSSH CA signs user keys — scalable for large teams
GSSAPI/KerberosIntegrated with enterprise auth

Key Commands

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Connect
ssh user@host
ssh -p 2222 user@host           # non-default port
ssh -i ~/.ssh/id_rsa user@host  # specific key

# Key generation
ssh-keygen -t ed25519 -C "comment"   # modern, preferred
ssh-keygen -t rsa -b 4096            # legacy compatibility

# Copy public key to server
ssh-copy-id user@host

# SSH tunneling
ssh -L 8080:internal-server:80 user@jumphost   # local forward
ssh -R 9090:localhost:80 user@server           # remote forward
ssh -D 1080 user@server                        # SOCKS proxy

# Run command without interactive shell
ssh user@host "cat /etc/passwd"

# SCP file transfer
scp file.txt user@host:/path/
scp user@host:/path/file.txt ./

# SFTP
sftp user@host

Security Implications

  • Default port 22: Targeted by mass scanners — consider changing port or using port knocking
  • Password auth: Brute-forceable — disable it, use key auth only
  • Root login: Disable PermitRootLogin in sshd_config
  • Known hosts: SSH warns on first connection — TOFU (Trust On First Use) — if skipped, MITM possible
  • Private key theft: If ~/.ssh/id_rsa is readable, attacker gets full access to all servers
1
2
3
4
5
6
7
# Brute force (authorized testing only)
hydra -l user -P passwords.txt ssh://target
medusa -h target -u user -P passwords.txt -M ssh

# Check for weak SSH config
nmap --script ssh-auth-methods target
nmap --script ssh2-enum-algos target

SMB — Server Message Block

SMB provides file sharing, printer sharing, and named pipes on Windows networks. Port 445 (direct), 139 (NetBIOS).

SMB Versions

VersionOSNotes
SMBv1Windows XP/2003Dangerous — EternalBlue, WannaCry. Disable immediately
SMBv2Windows Vista/2008Major improvement
SMBv3Windows 8/2012+Encryption support

Security Implications

  • EternalBlue (MS17-010): Remote code execution via SMBv1 — used by WannaCry/NotPetya
  • Pass-the-Hash: Reuse captured NTLM hash without cracking it
  • SMB relay: Capture and relay auth to another SMB server
  • Null session: Anonymous access to share list and user enumeration (older systems)
  • Kerberoasting: Request service tickets for SPN accounts, crack offline
1
2
3
4
5
6
7
8
9
10
11
12
# Enumerate SMB
nmap --script smb-enum-shares,smb-enum-users -p 445 target
enum4linux -a target
smbclient -L //target -N              # null session share list
smbclient //target/share -N          # connect to share

# Check for EternalBlue
nmap --script smb-vuln-ms17-010 -p 445 target

# CrackMapExec
crackmapexec smb target -u user -p password
crackmapexec smb target -u user -H hash  # pass the hash

FTP — File Transfer Protocol

FTP transfers files. Port 21 (control), Port 20 (data in active mode).

Active vs Passive:

  • Active: Server initiates data connection back to client — blocked by most firewalls
  • Passive: Client initiates both connections — firewall-friendly, more common

Security Implications

  • Plaintext: Credentials and data sent unencrypted — visible to network sniffers
  • Anonymous login: Many FTP servers allow login with anonymous/anonymous — check for writable dirs
  • FTPS vs SFTP: FTPS = FTP + TLS (still port 21). SFTP = SSH file transfer (port 22) — different protocol entirely
  • Bounce attack: Use FTP server to scan other hosts via PORT command
1
2
3
4
5
6
7
8
9
10
11
12
13
# Connect
ftp target
ftp -n target    # no auto-login

# In FTP shell
anonymous        # try anonymous login
ls               # list files
get file.txt     # download
put file.txt     # upload (if writable)
binary           # switch to binary mode for non-text files

# Nmap FTP scripts
nmap --script ftp-anon,ftp-bounce -p 21 target

SMTP — Simple Mail Transfer Protocol

SMTP sends email. Port 25 (server-to-server), 587 (client submission), 465 (SMTPS).

Email Security Records (DNS TXT)

RecordPurpose
SPFLists servers allowed to send for the domain
DKIMCryptographic signature on outgoing mail
DMARCPolicy for what to do when SPF/DKIM fail

SPF example:

1
v=spf1 include:_spf.google.com ~all

~all = softfail (mark as spam), -all = hardfail (reject)

Security Implications

  • Open relay: SMTP server that forwards mail for anyone — used for spam and phishing
  • User enumeration: VRFY user@domain or RCPT TO: responses reveal valid users
  • Email spoofing: Without DMARC enforcement, attacker sends email pretending to be your domain
  • STARTTLS downgrade: Force plaintext by stripping STARTTLS negotiation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Manual SMTP interaction
nc -nv target 25
HELO attacker.com
MAIL FROM:<attacker@attacker.com>
RCPT TO:<victim@target.com>
DATA
Subject: Test
Test body
.
QUIT

# Enumerate users
smtp-user-enum -M VRFY -U users.txt -t target
nmap --script smtp-enum-users -p 25 target

# Check open relay
nmap --script smtp-open-relay -p 25 target

SNMP — Simple Network Management Protocol

SNMP monitors and manages network devices. UDP ports 161 (queries), 162 (traps).

Versions:

  • v1, v2c: Community string auth (plaintext password) — public and private are defaults
  • v3: Proper auth + encryption — use this

Security Implications

  • Default community strings: public (read) and private (write) — widely unchanged
  • Information disclosure: SNMP can dump routing tables, interface info, running processes, installed software, user accounts
  • v1/v2c plaintext: Community string visible on the wire
  • Write access: SNMP write with private community can change device config
1
2
3
4
5
6
7
8
9
10
# Enumerate with default community strings
snmpwalk -c public -v2c target
snmpwalk -c private -v2c target

# Specific OIDs
snmpwalk -c public -v2c target 1.3.6.1.2.1.1     # system info
snmpwalk -c public -v2c target 1.3.6.1.2.1.25.4  # running processes

# Nmap SNMP scripts
nmap --script snmp-info,snmp-sysdescr -p 161 -sU target

LDAP — Lightweight Directory Access Protocol

LDAP queries directory services (Active Directory, OpenLDAP). Port 389 (plaintext), 636 (LDAPS).

Security Implications

  • Anonymous bind: LDAP allows querying without credentials on many default configs — dump users, groups, org structure
  • LDAP injection: User input injected into LDAP filter — similar to SQLi
  • Credential exposure: LDAP often used to validate credentials — cleartext on port 389 unless LDAPS used
  • AD enumeration: BloodHound uses LDAP to map Active Directory attack paths
1
2
3
4
5
6
7
8
# Anonymous LDAP query
ldapsearch -x -H ldap://target -b "dc=domain,dc=com"

# Authenticated
ldapsearch -x -H ldap://target -D "user@domain.com" -W -b "dc=domain,dc=com"

# Enum with nmap
nmap --script ldap-search -p 389 target

ARP — Address Resolution Protocol

ARP maps IP addresses to MAC addresses on a local network. No authentication.

Security Implications

  • ARP spoofing/poisoning: Attacker broadcasts fake ARP replies claiming they have the gateway’s IP → intercepts all traffic (MITM)
  • ARP cache poisoning: Victim’s ARP cache associates attacker’s MAC with gateway IP
  • Gratuitous ARP: Unsolicited ARP — sent to update caches (legitimate use) but also used for poisoning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# ARP spoofing (MITM)
arpspoof -i eth0 -t victim_ip gateway_ip
arpspoof -i eth0 -t gateway_ip victim_ip

# With Bettercap
bettercap -iface eth0
# In bettercap console:
net.probe on
arp.spoof.targets 192.168.1.105
arp.spoof on

# View ARP cache
arp -a          # Windows/Linux
ip neigh show   # Linux

NFS — Network File System

NFS allows remote filesystem mounting. Port 2049.

Security Implications

  • No auth by default (NFSv3): Exports mounted by anyone on the network
  • root_squash bypass: If no_root_squash is set, mounting client’s root = remote root
  • Sensitive data exposure: Home dirs, config files, keys exposed via NFS shares
1
2
3
4
5
6
7
8
9
# Enumerate NFS shares
showmount -e target
nmap --script nfs-showmount -p 2049 target

# Mount an NFS share
mount -t nfs target:/exported/path /mnt/local

# Check exports config
cat /etc/exports

Key Takeaways

  • Protocol = attack surface. Every open port running a protocol is an entry point — know what each one does.
  • UDP is underscanned. Most scans focus on TCP — UDP services like SNMP, DNS, NFS are often left wide open.
  • Plaintext protocols are 2026 problems. FTP, HTTP, Telnet, SMTP (port 25), SNMP v1/v2c, LDAP (port 389) — anything on these in a modern network is a finding.
  • Default credentials are everywhere. SNMP public/private, FTP anonymous, SMB null session — always check.
  • DNS is both a recon target and an exfiltration channel. Enumerate it thoroughly, and monitor for DNS tunneling.

References


You can find me online at:

My signature image

This post is licensed under CC BY 4.0 by the author.