Other Application Protocols

Other Application Protocols

Overview

Besides HTTP, networks use various application layer protocols. This chapter covers DHCP, FTP, email protocols (SMTP, POP3, IMAP), SSH, Telnet, WebSocket, and more.

Difficulty: ⭐⭐

Learning Objectives: - Understand each protocol's role and operating principles - Familiarize with protocol-specific port numbers - Identify security considerations - Learn practical usage methods


Table of Contents

  1. DHCP
  2. FTP
  3. Email Protocols
  4. SSH
  5. Telnet
  6. WebSocket
  7. Practice Problems
  8. Next Steps
  9. References

1. DHCP

DHCP Overview

DHCP (Dynamic Host Configuration Protocol) is a protocol that automatically assigns IP addresses and network configurations to devices connected to a network.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      DHCP Basics                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports: UDP 67 (server), UDP 68 (client)                        β”‚
β”‚  RFC: 2131                                                      β”‚
β”‚                                                                 β”‚
β”‚  Assigned Information:                                          β”‚
β”‚  - IP address                                                   β”‚
β”‚  - Subnet mask                                                  β”‚
β”‚  - Default gateway                                              β”‚
β”‚  - DNS server                                                   β”‚
β”‚  - Lease time                                                   β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

DHCP DORA Process

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DHCP DORA Process                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client]                            [DHCP Server]              β”‚
β”‚   (No IP)                            (192.168.1.1)              β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(1) DHCP Discover ─────────────────▢ β”‚                 β”‚
β”‚      β”‚     Source: 0.0.0.0                   β”‚                 β”‚
β”‚      β”‚     Destination: 255.255.255.255 (broadcast)            β”‚
β”‚      β”‚     "I need an IP address"            β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀─(2) DHCP Offer ─────────────────────│                 β”‚
β”‚      β”‚     "I offer 192.168.1.100"           β”‚                 β”‚
β”‚      β”‚     Subnet: 255.255.255.0             β”‚                 β”‚
β”‚      β”‚     Gateway: 192.168.1.1              β”‚                 β”‚
β”‚      β”‚     DNS: 8.8.8.8                      β”‚                 β”‚
β”‚      β”‚     Lease time: 24 hours              β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(3) DHCP Request ──────────────────▢ β”‚                 β”‚
β”‚      β”‚     "I request 192.168.1.100"         β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀─(4) DHCP Ack ───────────────────────│                 β”‚
β”‚      β”‚     "192.168.1.100 approved"          β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚  [IP Configuration Complete]                  β”‚                 β”‚
β”‚  (192.168.1.100)                              β”‚                 β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

DORA: Discover β†’ Offer β†’ Request β†’ Acknowledge

DHCP Message Types

Message Direction Description
DISCOVER Client β†’ Server Request IP address (broadcast)
OFFER Server β†’ Client Offer IP address
REQUEST Client β†’ Server Accept offer or renew request
ACK Server β†’ Client Approve request
NAK Server β†’ Client Deny request
RELEASE Client β†’ Server Release IP
INFORM Client β†’ Server Request additional configuration

DHCP Lease Process

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    DHCP Lease Time                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Lease start                                                    β”‚
β”‚      β”‚                                                          β”‚
β”‚      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ Lease time (T)     β”‚
β”‚      β”‚                                                          β”‚
β”‚      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ T/2 (50%)                                β”‚
β”‚      β”‚                 β”‚                                        β”‚
β”‚      β”‚                 └─ Renewal attempt (Request to server)   β”‚
β”‚      β”‚                    If successful: lease time extended    β”‚
β”‚      β”‚                                                          β”‚
β”‚      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ T * 7/8 (87.5%)              β”‚
β”‚      β”‚                             β”‚                            β”‚
β”‚      β”‚                             └─ Rebinding attempt         β”‚
β”‚      β”‚                                (broadcast)               β”‚
β”‚      β”‚                                                          β”‚
β”‚      └────────────────────────────────────── T (100%)           β”‚
β”‚                                              β”‚                  β”‚
β”‚                                              └─ Lease expired   β”‚
β”‚                                                 IP released     β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
# Linux - DHCP client
# Release IP
sudo dhclient -r eth0

# Renew IP
sudo dhclient eth0

# Verbose output
sudo dhclient -v eth0

# Windows
ipconfig /release     # Release IP
ipconfig /renew       # Renew IP

# macOS
sudo ipconfig set en0 DHCP    # Reset DHCP

2. FTP

FTP Overview

FTP (File Transfer Protocol) is a protocol for transferring files between client and server.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      FTP Basic Info                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports:                                                         β”‚
β”‚  - Control connection: TCP 21                                   β”‚
β”‚  - Data connection: TCP 20 (Active) or random port (Passive)    β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Uses two channels (control + data)                           β”‚
β”‚  - Plaintext transmission (security vulnerable)                 β”‚
β”‚  - ASCII/Binary transfer modes                                  β”‚
β”‚  - Active/Passive modes                                         β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

FTP Active vs Passive Mode

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Active Mode                                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client]                              [FTP Server]             β”‚
β”‚  (Random port N)                        (Port 21, 20)           β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(1) Control connection (N β†’ 21) ───▢ β”‚                 β”‚
β”‚      β”‚      "PORT N+1"                       β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀─(2) Data connection (20 β†’ N+1) ──────│                 β”‚
β”‚      β”‚      Server connects to client        β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚  β€» Problems occur if client firewall blocks external connectionsβ”‚
β”‚                                                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Passive Mode                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client]                              [FTP Server]             β”‚
β”‚  (Random port)                         (Port 21, random port)   β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(1) Control connection (N β†’ 21) ───▢ β”‚                 β”‚
β”‚      β”‚      "PASV"                           β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀──── Response: Use port P ────────────│                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(2) Data connection (N+1 β†’ P) ───────▢ β”‚                 β”‚
β”‚      β”‚      Client connects to server        β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚  β€» Client always initiates connection β†’ fewer firewall issues   β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

FTP Main Commands

Command Description Example
USER Send username USER username
PASS Send password PASS password
LIST Directory listing LIST
CWD Change directory CWD /home/user
PWD Print working directory PWD
RETR Download file RETR file.txt
STOR Upload file STOR file.txt
DELE Delete file DELE file.txt
MKD Create directory MKD newdir
RMD Remove directory RMD olddir
PASV Passive mode PASV
PORT Active mode PORT 192,168,1,100,4,1
QUIT Close connection QUIT

FTP Response Codes

Code Range Meaning Examples
1xx Positive preliminary 150 File status OK
2xx Positive completion 200 Command OK, 226 Transfer complete
3xx Positive intermediate 331 Username OK, password needed
4xx Transient negative 421 Service unavailable
5xx Permanent negative 530 Login failed, 550 No permission

FTP Client Usage

# Basic FTP client
ftp ftp.example.com

# Commands after connection
ftp> user username
ftp> pass password
ftp> ls              # List files
ftp> cd directory    # Change directory
ftp> get file.txt    # Download
ftp> put file.txt    # Upload
ftp> binary          # Binary mode
ftp> ascii           # ASCII mode
ftp> passive         # Toggle passive mode
ftp> bye             # Close connection

SFTP and FTPS

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                FTP vs SFTP vs FTPS                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  FTP          β”‚  SFTP              β”‚  FTPS                      β”‚
β”‚  (Plaintext)  β”‚  (SSH-based)       β”‚  (TLS/SSL-based)           β”‚
β”‚               β”‚                    β”‚                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚   FTP   β”‚  β”‚  β”‚  SFTP   β”‚       β”‚  β”‚   FTP   β”‚               β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€       β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€               β”‚
β”‚  β”‚   TCP   β”‚  β”‚  β”‚   SSH   β”‚       β”‚  β”‚ TLS/SSL β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€       β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€               β”‚
β”‚               β”‚  β”‚   TCP   β”‚       β”‚  β”‚   TCP   β”‚               β”‚
β”‚  Port: 21     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚               β”‚                    β”‚                            β”‚
β”‚  Security: Noneβ”‚ Port: 22          β”‚  Port: 990 (implicit)      β”‚
β”‚               β”‚  Security: SSH     β”‚        21 (explicit)       β”‚
β”‚               β”‚  encryption        β”‚  Security: TLS encryption  β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Recommendation: Use SFTP (SSH-based, single port)

3. Email Protocols

Email Transmission Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Email Transmission Process                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Sender]     [Sending Server]   [Receiving Server] [Recipient]β”‚
β”‚  alice@a.com   mail.a.com        mail.b.com    bob@b.com       β”‚
β”‚      β”‚            β”‚                  β”‚            β”‚            β”‚
β”‚      │──(1) SMTP─▢│                  β”‚            β”‚            β”‚
β”‚      β”‚   (compose)β”‚                  β”‚            β”‚            β”‚
β”‚      β”‚            β”‚                  β”‚            β”‚            β”‚
β”‚      β”‚            │──(2) SMTP───────▢│            β”‚            β”‚
β”‚      β”‚            β”‚   (server-to-server)          β”‚            β”‚
β”‚      β”‚            β”‚                  β”‚            β”‚            β”‚
β”‚      β”‚            β”‚                  │──(3) Store─▢│            β”‚
β”‚      β”‚            β”‚                  β”‚   (mailbox)β”‚            β”‚
β”‚      β”‚            β”‚                  β”‚            β”‚            β”‚
β”‚      β”‚            β”‚                  │◀─(4) POP3/IMAP──│       β”‚
β”‚      β”‚            β”‚                  β”‚   (retrieve) β”‚          β”‚
β”‚                                                                 β”‚
β”‚  Protocols:                                                     β”‚
β”‚  - SMTP: Mail transmission (sending)                            β”‚
β”‚  - POP3: Mail retrieval (download and delete)                   β”‚
β”‚  - IMAP: Mail retrieval (keep on server)                        β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SMTP (Simple Mail Transfer Protocol)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      SMTP Information                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports: TCP 25 (default), 587 (submission), 465 (SSL)          β”‚
β”‚  RFC: 5321                                                      β”‚
β”‚  Purpose: Email transmission                                    β”‚
β”‚                                                                 β”‚
β”‚  SMTP Session Example:                                          β”‚
β”‚                                                                 β”‚
β”‚  C: Connect (TCP 25)                                            β”‚
β”‚  S: 220 mail.example.com ESMTP ready                            β”‚
β”‚  C: EHLO client.example.com                                     β”‚
β”‚  S: 250-mail.example.com Hello                                  β”‚
β”‚  S: 250-AUTH LOGIN PLAIN                                        β”‚
β”‚  S: 250 STARTTLS                                                β”‚
β”‚  C: MAIL FROM:<alice@example.com>                               β”‚
β”‚  S: 250 OK                                                      β”‚
β”‚  C: RCPT TO:<bob@example.com>                                   β”‚
β”‚  S: 250 OK                                                      β”‚
β”‚  C: DATA                                                        β”‚
β”‚  S: 354 Start mail input                                        β”‚
β”‚  C: Subject: Test                                               β”‚
β”‚  C:                                                             β”‚
β”‚  C: Hello, this is a test.                                      β”‚
β”‚  C: .                                                           β”‚
β”‚  S: 250 OK Message queued                                       β”‚
β”‚  C: QUIT                                                        β”‚
β”‚  S: 221 Bye                                                     β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SMTP Main Commands

Command Description
HELO/EHLO Client identification (EHLO is extended SMTP)
MAIL FROM Specify sender
RCPT TO Specify recipient
DATA Start mail content
QUIT Close connection
AUTH Authentication
STARTTLS Start TLS encryption
RSET Reset transaction

POP3 (Post Office Protocol v3)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      POP3 Information                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports: TCP 110 (default), 995 (SSL/TLS)                        β”‚
β”‚  RFC: 1939                                                      β”‚
β”‚  Purpose: Email retrieval (download)                            β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Downloads mail locally                                       β”‚
β”‚  - Deletes from server (by default)                             β”‚
β”‚  - Suitable for single device                                   β”‚
β”‚  - Offline reading possible                                     β”‚
β”‚                                                                 β”‚
β”‚  POP3 Session Example:                                          β”‚
β”‚                                                                 β”‚
β”‚  S: +OK POP3 server ready                                       β”‚
β”‚  C: USER alice                                                  β”‚
β”‚  S: +OK                                                         β”‚
β”‚  C: PASS password123                                            β”‚
β”‚  S: +OK Logged in                                               β”‚
β”‚  C: STAT                                                        β”‚
β”‚  S: +OK 3 1024                                                  β”‚
β”‚  C: LIST                                                        β”‚
β”‚  S: +OK 3 messages                                              β”‚
β”‚  S: 1 512                                                       β”‚
β”‚  S: 2 256                                                       β”‚
β”‚  S: 3 256                                                       β”‚
β”‚  S: .                                                           β”‚
β”‚  C: RETR 1                                                      β”‚
β”‚  S: +OK 512 octets                                              β”‚
β”‚  S: (mail content)                                              β”‚
β”‚  S: .                                                           β”‚
β”‚  C: DELE 1                                                      β”‚
β”‚  S: +OK Deleted                                                 β”‚
β”‚  C: QUIT                                                        β”‚
β”‚  S: +OK Bye                                                     β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

IMAP (Internet Message Access Protocol)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      IMAP Information                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports: TCP 143 (default), 993 (SSL/TLS)                        β”‚
β”‚  RFC: 3501 (IMAP4)                                              β”‚
β”‚  Purpose: Email retrieval (server synchronization)              β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Stores mail on server                                        β”‚
β”‚  - Synchronizes across multiple devices                         β”‚
β”‚  - Folder management available                                  β”‚
β”‚  - Supports partial download                                    β”‚
β”‚  - Requires online connection                                   β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

POP3 vs IMAP Comparison

Feature POP3 IMAP
Mail storage location Local (download) Server
Multi-device sync Difficult Supported
Offline reading Easy Limited
Server storage space Small Large needed
Folder management Limited Supported
Partial download Not possible Possible
Best use case Single device Multiple devices

Email Port Summary

Protocol Port Security
SMTP 25 Plaintext
SMTP Submission 587 STARTTLS
SMTPS 465 SSL/TLS
POP3 110 Plaintext
POP3S 995 SSL/TLS
IMAP 143 Plaintext
IMAPS 993 SSL/TLS

4. SSH

SSH Overview

SSH (Secure Shell) is a protocol that provides encrypted remote access over networks.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      SSH Information                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Port: TCP 22                                                   β”‚
β”‚  RFC: 4251-4256                                                 β”‚
β”‚  Version: SSH-2 (recommended), SSH-1 (deprecated)               β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Encrypted remote shell access                                β”‚
β”‚  - File transfer (SCP, SFTP)                                    β”‚
β”‚  - Port forwarding/tunneling                                    β”‚
β”‚  - X11 forwarding                                               β”‚
β”‚                                                                 β”‚
β”‚  Authentication methods:                                        β”‚
β”‚  - Password authentication                                      β”‚
β”‚  - Public key authentication (recommended)                      β”‚
β”‚  - Host-based authentication                                    β”‚
β”‚  - Keyboard-interactive                                         β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SSH Connection Process

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SSH Connection Process                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client]                              [Server]                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(1) TCP connection (port 22) ───────▢ β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀─(2) Protocol version exchange ───────│                 β”‚
β”‚      β”‚     SSH-2.0-OpenSSH_8.9               β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀──(3) Key exchange algorithm negotiation─▢│              β”‚
β”‚      β”‚     Encryption, MAC, compression      β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀──(4) Key exchange (DH/ECDH) ─────────▢│                 β”‚
β”‚      β”‚     Generate session key              β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀════(5) Start encrypted communication══▢│                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │──(6) User authentication ──────────▢  β”‚                 β”‚
β”‚      β”‚     (password or public key)          β”‚                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀─(7) Authentication success ──────────│                 β”‚
β”‚      β”‚                                        β”‚                 β”‚
β”‚      │◀════(8) Start shell session ═══════════▢│                 β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SSH Public Key Authentication

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                SSH Public Key Authentication                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client]                              [Server]                 β”‚
β”‚                                                                 β”‚
β”‚  Private key (id_ed25519)        Public key (authorized_keys)   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚  β”‚ Never disclose   β”‚               β”‚ Client public    β”‚        β”‚
β”‚  β”‚ Keep local only  β”‚               β”‚ key stored       β”‚        β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚           β”‚                                   β”‚                 β”‚
β”‚           β”‚                                   β”‚                 β”‚
β”‚  Authentication process:                                        β”‚
β”‚  1. Server sends random challenge                               β”‚
β”‚  2. Client signs challenge with private key                     β”‚
β”‚  3. Server verifies signature with public key                   β”‚
β”‚  4. Authentication succeeds if verification passes              β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SSH Main Commands

# Basic connection
ssh user@hostname
ssh -p 2222 user@hostname    # Specify port

# Generate keys
ssh-keygen -t ed25519 -C "email@example.com"
ssh-keygen -t rsa -b 4096

# Copy public key
ssh-copy-id user@hostname
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@hostname

# File transfer (SCP)
scp file.txt user@host:/path/
scp user@host:/path/file.txt ./
scp -r directory/ user@host:/path/

# SFTP
sftp user@hostname

SSH Tunneling

# Local port forwarding
# Local 8080 β†’ via remote server β†’ target server 80
ssh -L 8080:target.example.com:80 user@jump.example.com

# Remote port forwarding
# Remote server 8080 β†’ local machine 80
ssh -R 8080:localhost:80 user@remote.example.com

# Dynamic port forwarding (SOCKS proxy)
ssh -D 1080 user@proxy.example.com
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    SSH Local Port Forwarding                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  ssh -L 8080:db.internal:3306 user@jump.example.com             β”‚
β”‚                                                                 β”‚
β”‚  [Local PC]          [Jump Server]          [DB Server]         β”‚
β”‚  localhost:8080      jump.example.com    db.internal:3306       β”‚
β”‚      β”‚                    β”‚                   β”‚                 β”‚
β”‚      │════ SSH Tunnel ════▢│                   β”‚                 β”‚
β”‚      β”‚                    │──────────────────▢│                 β”‚
β”‚      β”‚                    β”‚                   β”‚                 β”‚
β”‚      │◀═══════════════════│◀──────────────────│                 β”‚
β”‚                                                                 β”‚
β”‚  Usage: mysql -h 127.0.0.1 -P 8080 (connect to DB locally)      β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5. Telnet

Telnet Overview

Telnet provides terminal access to remote hosts. SSH is recommended for security.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Telnet Information                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Port: TCP 23                                                   β”‚
β”‚  RFC: 854                                                       β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Plaintext transmission (no encryption)                       β”‚
β”‚  - Password exposure risk                                       β”‚
β”‚  - Vulnerable to sniffing                                       β”‚
β”‚  - Legacy systems only                                          β”‚
β”‚                                                                 β”‚
β”‚  ⚠️  Security Warning:                                          β”‚
β”‚  - Do NOT use Telnet on the Internet                            β”‚
β”‚  - Replace with SSH                                             β”‚
β”‚  - Avoid even on internal networks                              β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Telnet Usage (Testing Only)

Telnet is unsuitable for remote access due to security, but useful for port connectivity testing.

# Port connectivity test
telnet example.com 80
telnet example.com 443

# HTTP test
telnet example.com 80
GET / HTTP/1.1
Host: example.com
(blank line)

# SMTP test
telnet mail.example.com 25
EHLO test
QUIT

# Connection check only (nc recommended)
nc -zv example.com 80
nc -zv example.com 22

Telnet vs SSH

Feature Telnet SSH
Port 23 22
Encryption None (plaintext) Yes
Authentication Plaintext password Various methods
Security Very vulnerable Strong
File transfer None SCP, SFTP
Tunneling None Supported
Recommendation Testing only Always recommended

6. WebSocket

WebSocket Overview

WebSocket is a protocol that provides bidirectional real-time communication between client and server.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    WebSocket Information                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  Ports: TCP 80 (ws://), TCP 443 (wss://)                        β”‚
β”‚  RFC: 6455                                                      β”‚
β”‚                                                                 β”‚
β”‚  Features:                                                      β”‚
β”‚  - Starts with HTTP upgrade                                     β”‚
β”‚  - Full-duplex bidirectional communication                      β”‚
β”‚  - Persistent connection                                        β”‚
β”‚  - Low overhead (minimal headers)                               β”‚
β”‚  - Real-time data transmission                                  β”‚
β”‚                                                                 β”‚
β”‚  Use cases:                                                     β”‚
β”‚  - Real-time chat                                               β”‚
β”‚  - Online gaming                                                β”‚
β”‚  - Stock/cryptocurrency prices                                  β”‚
β”‚  - Live streaming                                               β”‚
β”‚  - Collaboration tools                                          β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

HTTP vs WebSocket

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  HTTP vs WebSocket                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  HTTP (Request-Response)          WebSocket (Bidirectional)     β”‚
β”‚                                                                 β”‚
β”‚  Client        Server             Client        Server          β”‚
β”‚      β”‚            β”‚                  β”‚            β”‚             β”‚
β”‚      │──Request1─▢│                  │══Connected═│             β”‚
β”‚      │◀─Response1─│                  β”‚            β”‚             β”‚
β”‚      β”‚            β”‚                  │◀─ Message ─│             β”‚
β”‚      │──Request2─▢│                  │── Message─▢│             β”‚
β”‚      │◀─Response2─│                  │◀─ Message ─│             β”‚
β”‚      β”‚            β”‚                  │── Message─▢│             β”‚
β”‚      │──Request3─▢│                  β”‚            β”‚             β”‚
β”‚      │◀─Response3─│                  │◀─ Message ─│             β”‚
β”‚                                     │══Closed════│              β”‚
β”‚                                                                 β”‚
β”‚  Create connection each time        Once connected, persistent  β”‚
β”‚  Only client can request            Both sides can send         β”‚
β”‚  Request header overhead            Minimal frame header        β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

WebSocket Handshake

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  WebSocket Handshake                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  [Client Request - HTTP Upgrade]                                β”‚
β”‚  ─────────────────────────────────                              β”‚
β”‚  GET /chat HTTP/1.1                                             β”‚
β”‚  Host: server.example.com                                       β”‚
β”‚  Upgrade: websocket                                             β”‚
β”‚  Connection: Upgrade                                            β”‚
β”‚  Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==                   β”‚
β”‚  Sec-WebSocket-Version: 13                                      β”‚
β”‚                                                                 β”‚
β”‚  [Server Response - 101 Switching Protocols]                    β”‚
β”‚  ──────────────────────────────────────                         β”‚
β”‚  HTTP/1.1 101 Switching Protocols                               β”‚
β”‚  Upgrade: websocket                                             β”‚
β”‚  Connection: Upgrade                                            β”‚
β”‚  Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=             β”‚
β”‚                                                                 β”‚
β”‚  [Then communicate via WebSocket frames]                        β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

WebSocket Client (JavaScript)

// WebSocket connection
const socket = new WebSocket('wss://example.com/chat');

// Connection opened
socket.onopen = function(event) {
    console.log('WebSocket connected');
    socket.send('Hello Server!');
};

// Receive message
socket.onmessage = function(event) {
    console.log('Message received:', event.data);
};

// Connection closed
socket.onclose = function(event) {
    console.log('Connection closed:', event.code, event.reason);
};

// Error handling
socket.onerror = function(error) {
    console.error('WebSocket error:', error);
};

// Send message
socket.send(JSON.stringify({ type: 'chat', message: 'Hello!' }));

// Close connection
socket.close();

WebSocket Server (Node.js)

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function(ws) {
    console.log('Client connected');

    // Receive message
    ws.on('message', function(message) {
        console.log('Received message:', message);

        // Echo response
        ws.send('Server response: ' + message);

        // Broadcast to all clients
        wss.clients.forEach(function(client) {
            if (client.readyState === WebSocket.OPEN) {
                client.send(message);
            }
        });
    });

    ws.on('close', function() {
        console.log('Client connection closed');
    });
});

7. Practice Problems

Basic Problems

  1. DHCP
  2. Explain each step of DORA.
  3. List all information assigned by DHCP server.

  4. FTP

  5. What's the difference between Active and Passive modes?
  6. Explain FTP's security issues and alternatives.

  7. Email

  8. Explain the roles of SMTP, POP3, and IMAP respectively.
  9. What's the difference between POP3 and IMAP?

Intermediate Problems

  1. SSH
  2. What are the advantages of SSH public key authentication?
  3. Provide an example scenario for using SSH local port forwarding.

  4. Port Numbers

  5. Write the port numbers for these protocols:

    • DHCP (client/server)
    • FTP (control/data)
    • SMTP (default/SSL)
    • SSH
    • POP3S
    • IMAPS
  6. Practical Problems

# Predict the results of these commands

# 1. Connect to remote DB via SSH tunnel
ssh -L 3306:db.internal:3306 user@bastion.example.com
mysql -h 127.0.0.1 -P 3306 -u dbuser -p

# 2. Upload file via SFTP
sftp user@server.example.com
put localfile.txt /home/user/

# 3. Test HTTP with Telnet
telnet example.com 80
GET / HTTP/1.1
Host: example.com

Advanced Problems

  1. WebSocket
  2. What's the difference between HTTP Polling and WebSocket?
  3. Why does WebSocket handshake through HTTP?

  4. Security Comparison

  5. Explain the security issues of Telnet, FTP, and SMTP.
  6. What are the secure alternatives for each?

8. Next Steps

In 15_Network_Security_Basics.md, let's learn about network security basics including firewalls, NAT, and VPNs!


9. References

RFC Documents

Port Number Summary

Protocol Plaintext Port Secure Port
FTP 21 (control), 20 (data) 990 (FTPS)
SSH/SFTP 22 -
Telnet 23 -
SMTP 25, 587 465
DNS 53 853 (DoT)
DHCP 67/68 -
HTTP 80 443 (HTTPS)
POP3 110 995
IMAP 143 993
to navigate between lessons