Computer >> Hướng Dẫn Máy Tính >  >> Kết Nối Mạng >> An Ninh Mạng

Kerberos trong bảo mật mạng: Giao thức xác thực, cấu trúc, luồng làm việc và triển khai thực tế

Kerberos là gì?

Kerberos là giao thức xác thực mạng (authentication protocol) sử dụng mật mã học khóa đối xứng (symmetric key cryptography) và trusted third party (KDC - Key Distribution Center) để xác thực danh tính client và server lẫn nhau (mutual authentication) trên mạng không an toàn. Được phát triển bởi MIT Project Athena, hiện là chuẩn mặc định của Windows Active Directory (từ Windows 2000).

Kiến trúc 3 thành phần cốt lõi

Thành phầnVai trò
Client (Principal)User hoặc Service yêu cầu truy cập tài nguyên (ví dụ: user@DOMAIN.COM, HTTP/webserver@DOMAIN.COM)
KDC (Key Distribution Center)Trusted third party, chạy trên Domain Controller. Gồm 2 service:
• AS (Authentication Service): Xác thực client, cấp TGT
• TGS (Ticket Granting Service): Cấp Service Ticket dựa trên TGT
Application Server (Resource Server)Cung cấp dịch vụ/tài nguyên (File server, SQL, Web, Print...). Xác thực Service Ticket từ client

Luồng làm việc Kerberos (Kerberos Flow) - 3 giai đoạn

Giai đoạn 1: Authentication Service Exchange (AS Exchange) - Lấy TGT

1. Client → AS (KDC): KRB_AS_REQ
   - Client ID (User Principal Name)
   - Timestamp (encrypted with client's long-term key = hash(password))
   - Requested options (forwardable, renewable, etc.)

2. AS → Client: KRB_AS_REP
   - TGT (Ticket Granting Ticket) = {Client ID, Session Key (Client-TGS), Timestamp, Lifetime, Flags} encrypted with TGS Secret Key (chỉ KDC biết)
   - Session Key (Client-TGS) encrypted with Client's Long-term Key (hash(password))
   
   → Client giải mã Session Key bằng hash(password). Nếu pass sai → không giải mã được → auth fail.

Giai đoạn 2: Ticket Granting Service Exchange (TGS Exchange) - Lấy Service Ticket

3. Client → TGS (KDC): KRB_TGS_REQ
   - SPN (Service Principal Name) của dịch vụ mục tiêu (ví dụ: HTTP/webserver@DOMAIN.COM)
   - TGT (từ bước 2)
   - Authenticator = {Client ID, Timestamp} encrypted with Session Key (Client-TGS)

4. TGS → Client: KRB_TGS_REP
   - Service Ticket (ST) = {Client ID, Session Key (Client-Server), Timestamp, Lifetime, Flags, Authorization Data (PAC - Privilege Attribute Certificate chứa group SID)} encrypted with Service's Long-term Key (hash(service password))
   - Session Key (Client-Server) encrypted with Session Key (Client-TGS)

Giai đoạn 3: Client/Server Exchange (AP Exchange) - Truy cập dịch vụ

5. Client → Application Server: KRB_AP_REQ
   - Service Ticket (ST)
   - Authenticator = {Client ID, Timestamp, Subkey (optional)} encrypted with Session Key (Client-Server)

6. Server → Client (Mutual Auth - optional): KRB_AP_REP
   - {Timestamp + 1} encrypted with Session Key (Client-Server)
   → Client xác thực Server biết Session Key → Mutual Authentication hoàn tất

Đặc điểm bảo mật quan trọng

  • Mật khẩu không bao giờ truyền trên mạng - chỉ dùng để derive key giải mã TGT tại client
  • Timestamp + Window (mặc định 5 phút) chống replay attack - yêu cầu đồng bộ thời gian (NTP) giữa client, KDC, server
  • Mutual Authentication: Client xác thực Server, Server xác thực Client
  • Delegation: Constrained Delegation (Kerberos Constrained Delegation - KCD), Resource-based Constrained Delegation (RBCD) cho phép service A truy cập service B thay mặt user
  • PAC (Privilege Attribute Certificate): Nhúng trong TGT/ST, chứa user SID, group SID → dùng cho authorization (ACL check)

Kerberos trong Active Directory

  • KDC chạy trên mọi Domain Controller (DC)
  • Service Principal Name (SPN) đăng ký trên account service (user/computer) trong AD
  • Machine account password (computer$): Tự động rotate 30 ngày, dùng làm long-term key cho service chạy dưới SYSTEM/Network Service
  • Kerberos Armoring (FAST - Flexible Authentication Secure Tunneling): Bảo vệ pre-authentication (PKINIT, OTP) chống offline dictionary attack

Các loại khóa mã hóa (Encryption Types - enctype)

EnctypeMô tảTrạng thái
AES256-CTS-HMAC-SHA1-96 (18)AES-256, SHA-1 HMAC. Mạnh nhất hiện nayKhuyến nghị (Default Win 10/11, Server 2016+)
AES128-CTS-HMAC-SHA1-96 (17)AES-128, SHA-1 HMACChấp nhận được
RC4-HMAC-MD5 (23)RC4, MD5. Yếu, dễ bị tấn côngDisable (Disabled by default Win 10/11, Server 2016+)
DES-CBC-MD5 (3), DES-CBC-CRC (1)DES 56-bit. Rất yếuDisable (Disabled by default)

Cấu hình: Group Policy → Computer Configuration → Windows Settings → Security Settings → Local Policies → Security Options → "Network security: Configure encryption types allowed for Kerberos"

Port & Giao thức truyền tải

  • Port 88 (TCP & UDP): Kerberos traffic (AS_REQ/REP, TGS_REQ/REP, AP_REQ/REP)
  • Port 464 (TCP & UDP): Kerberos Password Change (kpasswd)
  • Port 749 (TCP): Kerberos Admin (kadmind) - ít dùng
  • Ưu tiên UDP (nhỏ gói tin), fallback TCP nếu gói lớn (> MTU) hoặc firewall chặn UDP

Tấn công phổ biến & Phòng chống

Tấn côngMô tảPhòng chống
KerberoastingRequest Service Ticket cho SPN có weak password → offline crack hash (RC4/AES)Mật khẩu service account mạnh (≥25 ký tự ngẫu nhiên), gMSA/Managed Service Account, AES only
AS-REP RoastingUser không yêu cầu pre-auth (DONT_REQ_PREAUTH) → request AS_REP → offline crackBật pre-auth cho tất cả user, kiểm tra Attribute Editor → userAccountControl
Golden TicketForge TGT với krbtgt hash → quyền Domain Admin vĩnh viễn (cho đến khi rotate krbtgt 2 lần)Bảo vệ krbtgt hash (Tier 0), monitor Event ID 4768/4769, rotate krbtgt định kỳ
Silver TicketForge Service Ticket với service account hash → truy cập service cụ thểMật khẩu service account mạnh, gMSA, monitor 4769
Pass-the-Ticket (PtT)Inject TGT/ST vào session hiện tại (mimikatz, Rubeus)Credential Guard (VBS), Restricted Admin Mode, LSASS protection (RunAsPPL)
Delegation AbuseUnconstrained Delegation / RBCD misconfig → compromiseChỉ dùng Constrained Delegation, audit delegation thường xuyên

Best Practice triển khai Kerberos an toàn

  1. Bật AES encryption only (disable RC4, DES) qua GPO
  2. Sử dụng gMSA (Group Managed Service Accounts) cho service - auto password rotation, SPN management
  3. Bật Kerberos Armoring (FAST) + PKINIT (cert-based pre-auth) hoặc OTP
  4. Đồng bộ thời gian NTP chặt chẽ (max skew 5 phút) - quan trọng!
  5. Bảo vệ krbtgt account: Tier 0 admin only, rotate password 2 lần/năm (script an toàn)
  6. Giám sát Event ID 4768 (TGT request), 4769 (ST request), 4770 (TGT renewal), 4771 (Pre-auth failed) qua SIEM
  7. Constrained Delegation thay vì Unconstrained; audit RBCD
  8. Triển khai Windows Defender Credential Guard (Virtualization-Based Security) bảo vệ LSASS

So sánh Kerberos vs NTLM

Đặc điểmKerberosNTLM
Cơ chếTicket-based, symmetric crypto, KDCChallenge-response, hash-based
Mutual AuthCóKhông (chỉ server auth client)
DelegationHỗ trợ (Constrained/RBCD)Không
PerformanceCache TGT, ít round-trip KDCMỗi request challenge-response
Offline CrackKhó hơn (cần service ticket + SPN)Dễ (NTLMv2 hash từ challenge/response)
Cross-platformTốt (Linux/Unix via MIT/Heimdal, SSO)Hạn chế (cần Samba, winbind)

Kết luận: Luôn ưu tiên Kerberos. Tắt NTLM nơi có thể (GPO: "Network security: Restrict NTLM" → "Deny all" hoặc "Deny all domain accounts").