# Application Layer Protocols ### Email, Web, and Services **ผู้จัดทำ:** อรรถพล คงหวาน --- # Outline 1. บทนำ: โปรโตคอลระดับ Application 2. Email Protocols (SMTP, POP3, IMAP) 3. Web Protocols (HTTP, HTTPS) 4. Directory Services (LDAP, Kerberos) 5. Time Synchronization (NTP, SNTP) 6. Other Tools (NetCat, RDP) 7. สรุป --- # 1. โปรโตคอลระดับ Application --- ## Application Layer คืออะไร? - **Application Layer Protocols** ทำงานบนชั้นที่ 7 ของโมเดล OSI - กำหนดรูปแบบการสื่อสารระหว่างแอปพลิเคชันบนเครือข่าย - ครอบคลุม: รับส่งอีเมล, เรียกดูเว็บ, ยืนยันตัวตน, ซิงโครไนซ์เวลา **ความสำคัญด้านความปลอดภัย:** - เป็นจุดที่ผู้ใช้โต้ตอบโดยตรง → เป้าหมายหลักของการโจมตี - โปรโตคอลรุ่นเก่าถูกออกแบบโดยไม่คำนึงถึงความปลอดภัย - การโจมตีระดับ Application ยากต่อการตรวจจับด้วย Firewall แบบดั้งเดิม --- ## ภาพรวมโปรโตคอลสัปดาห์นี้ ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'primaryBorderColor': '#a89984', 'lineColor': '#fe8019', 'secondaryColor': '#3c3836', 'tertiaryColor': '#504945', 'background': '#1d2021', 'mainBkg': '#282828', 'nodeBorder': '#a89984', 'clusterBkg': '#32302f', 'titleColor': '#ebdbb2', 'edgeLabelBackground': '#3c3836' }}}%% mindmap root((Application Layer\nProtocols)) Email SMTP Port 25/587 POP3 Port 110/995 IMAP Port 143/993 Web HTTP Port 80 HTTPS Port 443 Directory LDAP Port 389/636 Kerberos Port 88 Time NTP Port 123 SNTP Tools NetCat nc RDP Port 3389 ``` --- # 2. Email Protocols --- ## องค์ประกอบระบบอีเมล - **MUA (Mail User Agent):** โปรแกรมอีเมลของผู้ใช้ เช่น Thunderbird, Outlook - **MTA (Mail Transfer Agent):** เซิร์ฟเวอร์รับส่งอีเมลระหว่างโดเมน เช่น Postfix - **MDA (Mail Delivery Agent):** ตัวแทนส่งมอบอีเมลไปยัง mailbox ของผู้รับ ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#fe8019', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% flowchart LR MUA1["📧 MUA - Outlook"] -->|SMTP 587| MTA1["📤 MTA - Postfix"] MTA1 -->|SMTP 25| MTA2["📥 MTA - Recipient"] MTA2 --> MDA["📦 MDA - Mailbox"] MDA -->|POP3/IMAP| MUA2["📧 MUA - Thunderbird"] style MUA1 fill:#458588,stroke:#83a598,color:#ebdbb2 style MTA1 fill:#d79921,stroke:#fabd2f,color:#282828 style MTA2 fill:#d79921,stroke:#fabd2f,color:#282828 style MDA fill:#98971a,stroke:#b8bb26,color:#282828 style MUA2 fill:#458588,stroke:#83a598,color:#ebdbb2 ``` --- ## SMTP – Simple Mail Transfer Protocol **RFC 5321** | โปรโตคอลมาตรฐานสำหรับ **การส่งอีเมล** | พอร์ต | การใช้งาน | การเข้ารหัส | |-------|-----------|-------------| | 25 | MTA-to-MTA | ไม่เข้ารหัส (STARTTLS ได้) | | 465 | SMTP over SSL (เลิกใช้) | SSL/TLS ทันที | | 587 | Mail Submission | STARTTLS | **คำสั่งหลัก:** `EHLO`, `MAIL FROM`, `RCPT TO`, `DATA`, `QUIT`, `STARTTLS` **Response Codes:** 220 Ready | 250 OK | 354 Start DATA | 550 Mailbox ไม่พบ --- ## SMTP – กระบวนการส่งอีเมล ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'primaryBorderColor': '#a89984', 'lineColor': '#fe8019', 'secondaryColor': '#3c3836', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% sequenceDiagram participant C as Client (MUA) participant S as SMTP Server participant R as Recipient Server C->>S: Connect TCP Port 587 S-->>C: 220 smtp.example.com Ready C->>S: EHLO mail.sender.com S-->>C: 250-OK + Capabilities C->>S: AUTH LOGIN S-->>C: 235 Authentication OK C->>S: MAIL FROM / RCPT TO S-->>C: 250 OK C->>S: DATA → Headers + Body + . S-->>C: 250 Message queued S->>R: Forward to recipient's MTA ``` --- ## SMTP – ความปลอดภัย **ปัญหา:** - ไม่มีการยืนยันตัวตน → **Email Spoofing** ได้ง่าย - ส่งข้อมูลเป็น plaintext หากไม่ใช้ TLS **มาตรการป้องกัน:** | มาตรการ | หน้าที่ | |---------|---------| | **SPF** | ระบุ IP ที่อนุญาตให้ส่งเมลแทนโดเมน | | **DKIM** | เซ็นชื่อดิจิทัลในอีเมล | | **DMARC** | นโยบายจัดการอีเมลที่ไม่ผ่าน SPF/DKIM | --- ## SMTP – Python Code ตัวอย่าง ```python import smtplib, ssl from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def send_secure_email(sender, password, recipient, subject, body): message = MIMEMultipart("alternative") message["Subject"] = subject message["From"] = sender message["To"] = recipient message.attach(MIMEText(body, "plain", "utf-8")) context = ssl.create_default_context() with smtplib.SMTP("smtp.gmail.com", 587) as server: server.ehlo() server.starttls(context=context) # อัพเกรดเป็น TLS server.login(sender, password) server.sendmail(sender, recipient, message.as_string()) return True ``` --- ## POP3 – Post Office Protocol Version 3 **RFC 1939** | โปรโตคอลสำหรับ **ดึงอีเมล** จาก Mail Server | คุณสมบัติ | รายละเอียด | |-----------|-----------| | **Download & Delete** | ดาวน์โหลดมาเก็บที่ client แล้วลบจาก server | | **Single Device** | เหมาะกับการใช้อุปกรณ์เดียว | | **No Sync** | ไม่รองรับการซิงค์หลายอุปกรณ์ | | **POP3** Port 110 | ไม่เข้ารหัส | | **POP3S** Port 995 | SSL/TLS ทันทีตั้งแต่เชื่อมต่อ | --- ## POP3 – Session Flow ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#b8bb26', 'clusterBkg': '#32302f', 'titleColor': '#b8bb26' }}}%% sequenceDiagram participant C as Client (MUA) participant S as POP3 Server (110/995) C->>S: TCP Connect Port 110 S-->>C: +OK POP3 server ready C->>S: USER username C->>S: PASS password S-->>C: +OK Mailbox ready (3 messages) C->>S: STAT S-->>C: +OK 3 120000 C->>S: RETR 1 (ดาวน์โหลดอีเมล) S-->>C: +OK message content C->>S: DELE 1 (ลบอีเมล) C->>S: QUIT S-->>C: +OK signing off ``` --- ## IMAP – Internet Message Access Protocol **RFC 3501 / RFC 9051** | โปรโตคอลจัดการอีเมลบน server โดยตรง | คุณสมบัติ | รายละเอียด | |-----------|-----------| | **Server-side Storage** | อีเมลเก็บบน server | | **Multi-device Sync** | ซิงค์ได้หลายอุปกรณ์พร้อมกัน | | **Folder Management** | จัดการโฟลเดอร์บน server | | **Partial Fetch** | ดาวน์โหลดเฉพาะ header ก่อน | | **Search** | ค้นหาบน server โดยไม่ต้องดาวน์โหลดทั้งหมด | | **พอร์ต IMAP** | 143 (ไม่เข้ารหัส) | | **พอร์ต IMAPS** | 993 (SSL/TLS) | --- ## IMAP – Flags และ Python Code **IMAP Flags:** `\Seen`, `\Answered`, `\Flagged`, `\Deleted`, `\Draft`, `\Recent` ```python import imaplib, ssl class IMAPEmailManager: def connect(self, username, password): context = ssl.create_default_context() self.imap = imaplib.IMAP4_SSL("imap.gmail.com", 993, ssl_context=context) self.imap.login(username, password) def get_recent_emails(self, folder="INBOX", days_back=7): self.imap.select(folder) status, ids = self.imap.search(None, f'(SINCE "01-Jan-2025")') for msg_id in ids[0].split()[-10:]: status, data = self.imap.fetch( msg_id, "(BODY[HEADER.FIELDS (FROM SUBJECT DATE)])") ``` --- ## เปรียบเทียบ POP3 vs IMAP | คุณสมบัติ | POP3 | IMAP | |-----------|------|------| | **RFC** | 1939 | 3501, 9051 | | **พอร์ตปกติ** | 110 | 143 | | **พอร์ต Secure** | 995 | 993 | | **เก็บอีเมล** | Client | Server | | **Multi-device** | ✗ | ✓ | | **Folder Mgmt** | ✗ | ✓ | | **Search Server** | ✗ | ✓ | | **เหมาะกับ** | อุปกรณ์เดียว / offline | หลายอุปกรณ์ / online | --- # 3. Web Protocols --- ## HTTP – HyperText Transfer Protocol **RFC 7230-7235 (HTTP/1.1), RFC 7540 (HTTP/2)** ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#fe8019', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% flowchart LR H09["HTTP/0.9 - 1991 - GET only"] --> H10["HTTP/1.0 - 1996 - Headers"] H10 --> H11["HTTP/1.1 - 1997 - Persistent Conn"] H11 --> H2["HTTP/2 - 2015 - Multiplexing"] H2 --> H3["HTTP/3 - 2022 - QUIC/UDP"] style H09 fill:#504945,stroke:#a89984,color:#ebdbb2 style H10 fill:#504945,stroke:#a89984,color:#ebdbb2 style H11 fill:#458588,stroke:#83a598,color:#ebdbb2 style H2 fill:#d79921,stroke:#fabd2f,color:#282828 style H3 fill:#98971a,stroke:#b8bb26,color:#282828 ``` --- ## HTTP Methods และ Status Codes | Method | ความหมาย | Idempotent | Safe | |--------|-----------|-----------|------| | **GET** | ดึงข้อมูล | ✓ | ✓ | | **POST** | สร้างข้อมูลใหม่ | ✗ | ✗ | | **PUT** | แทนที่ข้อมูล | ✓ | ✗ | | **DELETE** | ลบข้อมูล | ✓ | ✗ | | **PATCH** | แก้ไขบางส่วน | ✗ | ✗ | **Status Codes:** `1xx` Info | `2xx` Success | `3xx` Redirect | `4xx` Client Error | `5xx` Server Error --- ## HTTP Request / Response Structure ``` GET /api/users?page=1 HTTP/1.1 Host: api.example.com User-Agent: Mozilla/5.0 Accept: application/json Authorization: Bearer eyJhbGciOiJSUzI1NiJ9... ``` ``` HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Cache-Control: max-age=3600 Strict-Transport-Security: max-age=31536000 X-Content-Type-Options: nosniff {"users": [...], "total": 100, "page": 1} ``` --- ## HTTPS – TLS Handshake ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#83a598', 'clusterBkg': '#32302f', 'titleColor': '#83a598' }}}%% sequenceDiagram participant B as Browser (Client) participant S as Web Server Note over B,S: 1. TCP Handshake B->>S: ClientHello (TLS version, Cipher Suites, Random) S-->>B: ServerHello + Certificate Note over B: ตรวจสอบ Certificate กับ CA B->>S: ClientKeyExchange (Pre-master Secret) Note over B,S: สร้าง Session Key จาก Pre-master + Randoms B->>S: ChangeCipherSpec + Finished S-->>B: ChangeCipherSpec + Finished Note over B,S: 2. HTTP Data Transfer (Encrypted) ``` --- ## HTTPS – การคำนวณ TLS Session Key **Master Secret ใน TLS 1.2:**
master_secret
=
PRF
(
pre_master_secret
,
"master secret"
,
ClientRandom
+
ServerRandom
)
master_secret
=
HMAC-SHA256
(
0x1A2B3C4D
,
"master secret"
∥
0xAABBCC
∥
0xDDEEFF
)
=
48 bytes
จาก Master Secret → MAC key (client/server), Encryption key (client/server), IV (client/server) --- ## HTTP Security Headers | Header | วัตถุประสงค์ | |--------|-------------| | `Strict-Transport-Security` | บังคับ HTTPS | | `Content-Security-Policy` | ป้องกัน XSS | | `X-Content-Type-Options` | ป้องกัน MIME sniffing | | `X-Frame-Options` | ป้องกัน Clickjacking | | `Referrer-Policy` | ควบคุม Referrer | | `Permissions-Policy` | ควบคุมฟีเจอร์ browser | --- ## HTTPS – Security Check (Python) ```python import requests, ssl, socket SECURITY_HEADERS = [ "Strict-Transport-Security", "Content-Security-Policy", "X-Content-Type-Options", "X-Frame-Options", "Referrer-Policy", "Permissions-Policy" ] def check_https_security(url): response = requests.get(url, verify=True) score = sum(1 for h in SECURITY_HEADERS if h in response.headers) ctx = ssl.create_default_context() with socket.create_connection((urlparse(url).hostname, 443)) as s: with ctx.wrap_socket(s, server_hostname=...) as ss: tls_ver = ss.version() # TLS 1.2 / TLS 1.3 return score, tls_ver ``` --- # 4. Directory Services --- ## LDAP – Lightweight Directory Access Protocol **RFC 4511** | โปรโตคอลมาตรฐานสำหรับเข้าถึง Directory Services ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#fe8019', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% graph TD ROOT["🌐 dc=example,dc=com"] OU_USERS["ou=Users"] OU_GROUPS["ou=Groups"] OU_COMP["ou=Computers"] USER1["cn=Alice Smith\nuid=alice"] USER2["cn=Bob Jones\nuid=bob"] GROUP1["cn=Admins"] COMP1["cn=WORKSTATION-01"] ROOT --> OU_USERS --> USER1 OU_USERS --> USER2 ROOT --> OU_GROUPS --> GROUP1 ROOT --> OU_COMP --> COMP1 style ROOT fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style OU_USERS fill:#458588,stroke:#83a598,color:#ebdbb2 style OU_GROUPS fill:#458588,stroke:#83a598,color:#ebdbb2 style OU_COMP fill:#458588,stroke:#83a598,color:#ebdbb2 ``` --- ## LDAP – Distinguished Name และ Operations **DN ตัวอย่าง:** `cn=Alice Smith,ou=Users,dc=example,dc=com` | Attribute | ความหมาย | Attribute | ความหมาย | |-----------|---------|-----------|---------| | `dc` | Domain Component | `cn` | Common Name | | `ou` | Org Unit | `uid` | User ID | | `o` | Organization | `c` | Country | **Operations:** Bind, Unbind, Search, Compare, Add, Delete, Modify, ModifyDN **Search Filter ตัวอย่าง:** ``` (&(memberOf=cn=Admins,ou=Groups,dc=example,dc=com)(accountStatus=active)) ``` --- ## LDAP – ความปลอดภัย | โปรโตคอล | พอร์ต | ความปลอดภัย | |----------|-------|------------| | LDAP | 389 | ไม่เข้ารหัส | | LDAP + STARTTLS | 389 | อัพเกรดเป็น TLS | | LDAPS | 636 | เข้ารหัสตั้งแต่ต้น | **การโจมตีที่พบบ่อย:** - **LDAP Injection** — คล้าย SQL Injection แต่เป็น LDAP filter - **Anonymous Bind** — ค้นหาโดยไม่ยืนยันตัวตน - **Password Spraying** — ลองรหัสผ่านเดิมกับหลาย account --- ## Kerberos – Third-party Authentication **RFC 4120** | ใช้ **Tickets** แทนการส่งรหัสผ่านผ่านเครือข่าย **องค์ประกอบ:** - **KDC (Key Distribution Center)** — ศูนย์กลางการแจกจ่าย Key - **AS (Authentication Server)** — ออก TGT - **TGS (Ticket Granting Server)** — ออก Service Ticket - **Client** — ผู้ใช้ที่ต้องการเข้าถึงบริการ - **Service Server** — เซิร์ฟเวอร์ที่ให้บริการ **Tickets มีอายุจำกัด:** โดยทั่วไป 8–10 ชั่วโมง --- ## Kerberos – กระบวนการยืนยันตัวตน ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#8ec07c', 'clusterBkg': '#32302f', 'titleColor': '#8ec07c' }}}%% sequenceDiagram participant C as Client participant AS as AS (Auth Server) participant TGS as TGS participant SS as Service Server Note over C,AS: ขั้น 1: ขอ TGT C->>AS: AS_REQ: Username + Timestamp AS-->>C: AS_REP: TGT + Session Key Note over C,TGS: ขั้น 2: ขอ Service Ticket C->>TGS: TGS_REQ: TGT + Authenticator TGS-->>C: TGS_REP: Service Ticket Note over C,SS: ขั้น 3: เข้าถึงบริการ C->>SS: AP_REQ: Service Ticket SS-->>C: AP_REP: Confirmation ``` --- ## Kerberos – ความปลอดภัย **จุดแข็ง:** - ไม่ส่งรหัสผ่านผ่านเครือข่าย - Tickets มีอายุจำกัด - Mutual Authentication ทั้งสองฝ่าย **การโจมตีที่พบบ่อย:** | การโจมตี | วิธีการ | |---------|---------| | **Pass-the-Ticket** | ขโมย Ticket นำไปใช้แทน | | **Golden Ticket** | ปลอมแปลง TGT โดยใช้ KRBTGT hash | | **Kerberoasting** | ขโมย Service Ticket แล้ว crack offline | | **AS-REP Roasting** | โจมตีบัญชีที่ไม่ต้องการ Pre-auth | --- # 5. Time Synchronization --- ## NTP – Network Time Protocol **RFC 5905** | UDP พอร์ต 123 | ความสำคัญด้านความปลอดภัย: - **Log Correlation** — บันทึกเหตุการณ์ต้องมีเวลาตรงกัน - **Kerberos** — ต้องการเวลาตรงกันภายใน **5 นาที** - **TLS Certificates** — ตรวจสอบวันหมดอายุ - **Digital Signatures** — Timestamp ในลายเซ็นดิจิทัล --- ## NTP – Stratum Hierarchy ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#fe8019', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% graph TB GPS["🛰️ GPS / Atomic Clock - Stratum 0 ±1ns"] S1["🖥️ time.google.com - Stratum 1"] S2["🖥️ NTP Server องค์กร - Stratum 2 ~1ms"] S3["💻 Workstations / Devices - Stratum 3-15"] GPS --> S1 --> S2 --> S3 style GPS fill:#d79921,stroke:#fabd2f,color:#282828 style S1 fill:#458588,stroke:#83a598,color:#ebdbb2 style S2 fill:#98971a,stroke:#b8bb26,color:#282828 style S3 fill:#504945,stroke:#a89984,color:#ebdbb2 ``` --- ## NTP – การคำนวณ Clock Offset **Clock Offset (θ):**
θ
=
(
t
2
-
t
1
)
+
(
t
3
-
t
4
)
2
**Round-trip Delay (δ):**
δ
=
(
t
4
-
t
1
)
-
(
t
3
-
t
2
)
- `t₁` Client ส่ง Request | `t₂` Server รับ | `t₃` Server ส่ง | `t₄` Client รับ --- ## NTP – ตัวอย่างการคำนวณ สมมติ: t₁=0ms, t₂=50ms, t₃=60ms, t₄=100ms
θ
=
(
50
-
0
)
+
(
60
-
100
)
2
=
10ms
2
=
+
5ms
δ
=
(
100
-
0
)
-
(
60
-
50
)
=
90ms
**สรุป:** นาฬิกา client ช้ากว่า server **5ms** | RTT = **90ms** → NTP จะปรับนาฬิกา client ให้เพิ่มขึ้น 5ms --- ## NTP – ความปลอดภัยและ SNTP **การโจมตี NTP:** - **NTP Amplification Attack** — ใช้เป็น DDoS amplifier (~556x) - **NTP Spoofing** — ปลอมแปลงเวลาเพื่อให้ certificates หมดอายุก่อนกำหนด **การป้องกัน:** ใช้ NTPsec | NTS (Network Time Security) | Firewall จำกัด queries **NTP vs SNTP:** | คุณสมบัติ | NTP | SNTP | |-----------|-----|------| | ความแม่นยำ | < 1ms | ~1 วินาที | | ความซับซ้อน | สูง | ต่ำ | | Clock Filter | มี | ไม่มี | | เหมาะกับ | Server, PC | IoT, Embedded | --- # 6. Other Tools and Protocols --- ## NetCat – Swiss Army Knife of Network Tools **ความสามารถ:** Port Scanning, File Transfer, Banner Grabbing, Reverse Shell, Chat ```bash # Port Scanning nc -zv example.com 20-25 # Banner Grabbing nc mail.example.com 25 # SMTP nc mail.example.com 110 # POP3 nc mail.example.com 143 # IMAP # File Transfer nc -l -p 9999 > received_file.txt # ฝั่งรับ nc receiver_ip 9999 < file.txt # ฝั่งส่ง # Listener nc -l -p 8888 ``` --- ## NetCat – Python Implementation ```python import socket def nc_banner_grab(host, port, timeout=3): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(timeout) sock.connect((host, port)) banner = sock.recv(1024).decode("utf-8", errors="replace").strip() sock.close() return banner def port_scan(host, ports, timeout=0.5): results = {} for port in ports: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(timeout) result = sock.connect_ex((host, port)) results[port] = "open" if result == 0 else "closed" sock.close() return results ``` --- ## RDP – Remote Desktop Protocol **Microsoft T.128/T.124** | TCP/UDP พอร์ต 3389 ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#cc241d', 'clusterBkg': '#32302f', 'titleColor': '#fb4934' }}}%% mindmap root((RDP Security Risks)) Vulnerabilities BlueKeep CVE-2019-0708 Pre-auth RCE / Wormable DejaBlue CVE-2019-1181 Buffer Overflow Attacks Brute Force / Password Spray Man-in-the-Middle Lateral Movement Misconfigurations Port 3389 เปิดสู่ Internet NLA ปิดอยู่ No MFA ``` --- ## RDP – Best Practices | มาตรการ | รายละเอียด | |---------|-----------| | **เปิด NLA** | ยืนยันตัวตนก่อนเริ่ม session | | **ใช้ VPN** | เข้าถึง RDP ผ่าน VPN เท่านั้น | | **เปิด MFA** | Two-Factor Authentication | | **Firewall Rules** | จำกัด IP ที่เข้าถึงได้ | | **Bastion Host** | ผ่าน jump server | | **Rate Limiting** | จำกัด login ผิดพลาด | | **เปลี่ยนพอร์ต** | ไม่ใช้ 3389 ตรงๆ | --- # 7. สรุป --- ## โปรโตคอล Secure vs Insecure ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#282828', 'primaryTextColor': '#ebdbb2', 'lineColor': '#fe8019', 'clusterBkg': '#32302f', 'titleColor': '#fabd2f' }}}%% graph LR subgraph s["✅ Secure"] S1["SMTPS - 465/587+TLS"] S2["POP3S - 995"] S3["IMAPS - 993"] S4["HTTPS - 443"] S5["LDAPS - 636"] S6["NTPsec - 123"] end subgraph i["⚠️ Use Carefully"] I1["SMTP - 25"] -->|STARTTLS| S1 I2["POP3 - 110"] -->|SSL| S2 I3["IMAP - 143"] -->|SSL| S3 I4["HTTP - 80"] -->|TLS| S4 I5["LDAP - 389"] -->|SSL| S5 I6["NTP - 123"] -->|NTS| S6 end style S1 fill:#98971a,stroke:#b8bb26,color:#282828 style S2 fill:#98971a,stroke:#b8bb26,color:#282828 style S3 fill:#98971a,stroke:#b8bb26,color:#282828 style S4 fill:#98971a,stroke:#b8bb26,color:#282828 style S5 fill:#98971a,stroke:#b8bb26,color:#282828 style S6 fill:#98971a,stroke:#b8bb26,color:#282828 style I1 fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style I2 fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style I3 fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style I4 fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style I5 fill:#cc241d,stroke:#fb4934,color:#ebdbb2 style I6 fill:#d79921,stroke:#fabd2f,color:#282828 ``` --- ## Port Reference สรุป | โปรโตคอล | พอร์ตปกติ | พอร์ต Secure | Transport | |----------|-----------|-------------|-----------| | SMTP | 25, 587 | 465 (SMTPS) | TCP | | POP3 | 110 | 995 (POP3S) | TCP | | IMAP | 143 | 993 (IMAPS) | TCP | | HTTP | 80 | 443 (HTTPS) | TCP | | LDAP | 389 | 636 (LDAPS) | TCP | | Kerberos | 88 | 88 (built-in) | TCP/UDP | | NTP | 123 | 123 (NTPsec) | UDP | | RDP | 3389 | 3389 + NLA/VPN | TCP/UDP | --- ## คำสั่งปฏิบัติ Week 4 ```bash # Email Protocols openssl s_client -connect mail.example.com:587 -starttls smtp openssl s_client -connect mail.example.com:993 # HTTP/HTTPS curl -v https://example.com curl -I https://example.com # SSL Certificate openssl s_client -connect example.com:443 | openssl x509 -noout -text # LDAP ldapsearch -H ldaps://ldap.example.com:636 -x -b "dc=example,dc=com" # NTP ntpdate -d pool.ntp.org chronyc tracking # NetCat nc -zv example.com 80-443 echo "GET / HTTP/1.0" | nc example.com 80 ``` --- ## เอกสารอ้างอิง - **RFC 5321** — SMTP | **RFC 1939** — POP3 | **RFC 9051** — IMAP4rev2 - **RFC 7540** — HTTP/2 | **RFC 8446** — TLS 1.3 - **RFC 4511** — LDAP | **RFC 4120** — Kerberos V5 - **RFC 5905** — NTPv4 - OWASP TLS Cheat Sheet: https://cheatsheetseries.owasp.org - NIST SP 800-52 Rev2: https://nvlpubs.nist.gov - Microsoft RDP Docs: https://docs.microsoft.com/openspecs/windows_protocols/ms-rdpbcgr/ - NTP Project: https://www.ntp.org/documentation/ --- # คำถาม - ข้อสงสัย