TCP และ UDP: โปรโตคอลขนส่งหลักของอินเทอร์เน็ต
TCP (Transmission Control Protocol) และ UDP (User Datagram Protocol) เป็นโปรโตคอล Layer 4 (Transport Layer) ที่ใช้ส่งข้อมูลผ่าน IP Network ผู้ดูแลความปลอดภัยเครือข่ายต้องเข้าใจทั้งคู่ เพราะ:
- เป็นพื้นฐานของ Application Layer Protocols (HTTP/HTTPS, DNS, SMTP, FTP, SSH, RDP, VPN, VoIP, Gaming, Streaming)
- การทำงานของ Firewall, IPS/IDS, Load Balancer, Proxy, DDoS Protection, Sandbox ทั้งหมดขึ้นอยู่กับการประมวลผล TCP/UDP
- ช่องโหว่และการโจมตีเฉพาะโปรโตคอล (TCP SYN Flood, UDP Amplification, TCP RST Injection, UDP Fragmentation)
- Visibility & Forensics: Packet Capture (PCAP), NetFlow, Zeek/Bro, Suricata ต้อง Parse TCP/UDP Headers
ความแตกต่างหลัก TCP vs UDP
| คุณสมบัติ | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way Handshake) | Connectionless (Datagram) |
| Reliability | Guaranteed Delivery, Sequencing, Retransmission, ACK | Best-effort, No Guarantee, No Ordering |
| Flow/Congestion Control | มี (Window Scaling, Slow Start, CUBIC/BBR) | ไม่มี (ขึ้นกับ Application) |
| Header Size | 20-60 Bytes (Options) | 8 Bytes (Fixed) |
| Overhead | สูงกว่า | ต่ำกว่า (Low Latency) |
| Use Cases | Web (HTTP/HTTPS), Email (SMTP/IMAP/POP), File Transfer (FTP/SFTP), SSH, RDP, Database, VPN (OpenVPN TCP) | DNS, DHCP, VoIP (RTP/SIP), Video Streaming (QUIC, RTP), Gaming, VPN (WireGuard, OpenVPN UDP), NTP, SNMP, TFTP |
ทำไม TCP จึงสำคัญสำหรับ Security
- Stateful Inspection: Firewall ติดตาม TCP State (SYN, SYN-ACK, ESTABLISHED, FIN, RST) เพื่อตัดสินใจ Allow/Drop
- Session Tracking: ติดตาม Session ให้ครบ (Full Session Reassembly) สำหรับ DPI, Malware Detection, Data Leak Prevention
- Attack Vectors: SYN Flood, TCP Reset Attack, Session Hijacking, TCP Sequence Prediction, Port Scanning (SYN, FIN, XMAS, NULL)
- Encryption: TLS/SSL รันบน TCP (HTTPS, FTPS, SMTPS, IMAPS) ต้องการ TCP Reliability
ทำไม UDP จึงสำคัญสำหรับ Security
- Stateless Nature: ไม่มี State ทำให้ Firewall/IDS ยากกว่า ต้องใช้ Session Timeout Heuristics
- Amplification/Reflection Attacks: DNS, NTP, Memcached, SSDP, CLDAP, CharGEN - ใช้ UDP Spoofing ทำ DDoS
- DNS Security: DNS over UDP (Port 53) เป็นเป้าหมาย Cache Poisoning, Tunneling, Exfiltration ต้องมี DNSSEC, DoH, DoT
- VPN/Encryption: WireGuard, IPsec ESP (UDP 500/4500), OpenVPN UDP, QUIC (HTTP/3) - ใช้ UDP เพื่อ Latency ต่ำ
- Real-time Traffic: VoIP, Video Conference, Live Streaming - ต้องการ Low Jitter/Loss Tolerance
Port Numbers ที่ Security Admin ต้องรู้
- Well-known Ports (0-1023): HTTP(80), HTTPS(443), SSH(22), SMTP(25), DNS(53), DHCP(67/68), FTP(20/21), RDP(3389), LDAP(389/636), Kerberos(88), SQL(1433/3306/5432)
- Registered Ports (1024-49151): OpenVPN(1194), Proxy(3128/8080), RDP Gateway(443), VNC(5900), Docker(2375/2376), Kubernetes(6443/10250)
- Ephemeral Ports (49152-65535): Client-side Source Ports
TCP/UDP เอง "ปลอดภัย" หรือไม่?
ไม่ปลอดภัยด้วยตัวเอง TCP/UDP ไม่มี Encryption, Authentication, Integrity Checking Built-in
- TCP: ใครก็ตามที่เข้าถึง Wire/Fiber ได้จะอ่าน/แก้ไข/ปลอม Packet ได้ (ต้องใช้ TLS/IPsec/MACsec)
- UDP: เหมือนกัน + ง่ายกว่าที่จะ Spoof Source IP
Security มาจาก Layer บน (TLS, DTLS, QUIC, IPsec, SSH, WireGuard) หรือ Layer ล่าง (MACsec)
สรุปสำหรับ Security Admin
- เข้าใจ TCP/UDP Header, Flags, State Machine, Handshake, Teardown
- รู้ Well-known Ports และ Application Mapping
- รู้จัก Attacks ต่อ TCP (SYN Flood, Hijack) และ UDP (Amplification, Spoofing, Flood)
- ตั้งค่า Firewall/IPS/IDS ให้เหมาะสม: Stateful TCP, UDP Timeout, Rate Limiting, Anomaly Detection
- บังคับ Encryption (TLS 1.3, DTLS 1.3, IPsec, WireGuard) สำหรับข้อมูลละเอียดอ่อน
- Monitor NetFlow/IPFIX, PCAP, Zeek Logs สำหรับ Threat Hunting