ISELAB SOC by Scenario
Technical 20 phút đọc 22/01/2025

🔐 Windows Authentication Event Codes & Logon Types

Hướng dẫn chi tiết về các Event Code và Logon Type trong Windows Authentication logs, cách phân tích và ứng dụng trong SOC operations.

W

Windows Security Expert

Authentication Specialist

📋 Mục lục

Phần 1: Cơ bản

  • • Event Code 4624 - Successful Logon
  • • Event Code 4625 - Failed Logon
  • • Event Code 4634 - Logoff
  • • Event Code 4648 - Logon with Explicit Credentials

Phần 2: Logon Types

  • • LogonType 2 - Interactive
  • • LogonType 3 - Network
  • • LogonType 10 - Remote Interactive (RDP)
  • • LogonType 11 - Cached Interactive
  • • Ví dụ thực tế

🔍 Phần 1: Windows Authentication Event Codes

Event Code 4624 - Successful Logon

Event này được ghi lại khi có một logon thành công vào hệ thống Windows. Đây là event quan trọng nhất để theo dõi hoạt động đăng nhập hợp lệ.

Thông tin quan trọng trong Event 4624:

  • SubjectUserName - Tên user thực hiện logon
  • TargetUserName - Tên user được logon
  • TargetDomainName - Domain của target user
  • LogonType - Loại logon (2, 3, 10, 11...)
  • WorkstationName - Tên máy workstation
  • IpAddress - IP address nguồn
  • ProcessName - Process thực hiện logon
# Query Elasticsearch để tìm successful logons:
winlog.event_id: 4624
# Tìm logons từ IP cụ thể:
winlog.event_id: 4624 AND winlog.event_data.IpAddress: "192.168.1.100"
# Tìm RDP logons:
winlog.event_id: 4624 AND winlog.event_data.LogonType: "10"

Event Code 4625 - Failed Logon

Event này được ghi lại khi có một logon thất bại. Đây là event quan trọng để phát hiện brute force attacks và các hoạt động đăng nhập bất thường.

Thông tin quan trọng trong Event 4625:

  • SubjectUserName - Tên user thực hiện logon
  • TargetUserName - Tên user bị logon thất bại
  • FailureReason - Lý do thất bại
  • Status - Status code (0xC000006D, 0xC000006A...)
  • SubStatus - Sub status code
  • IpAddress - IP address nguồn
  • LogonType - Loại logon thất bại
# Query để tìm failed logons:
winlog.event_id: 4625
# Tìm failed logons từ IP cụ thể:
winlog.event_id: 4625 AND winlog.event_data.IpAddress: "212.132.125.106"
# Tìm failed RDP attempts:
winlog.event_id: 4625 AND winlog.event_data.LogonType: "10"

Event Code 4634 - Logoff

Event này được ghi lại khi user logoff khỏi hệ thống. Hữu ích để theo dõi session lifecycle.

Event Code 4648 - Logon with Explicit Credentials

Event này được ghi lại khi có logon sử dụng explicit credentials (như RunAs). Quan trọng để phát hiện privilege escalation.

🎯 Phần 2: Logon Types và ý nghĩa

Type 2

Interactive Logon

User đăng nhập trực tiếp tại console của máy tính (keyboard + mouse).

# Ví dụ:
User: admin
Workstation: DESKTOP-ABC123
Process: winlogon.exe
# Khi nào xảy ra: Đăng nhập tại máy local
Type 3

Network Logon

User đăng nhập qua network (SMB, file sharing, network resources). Lưu ý: RDP cũng có thể tạo LogonType 3 trong một số trường hợp.

# Ví dụ thông thường:
User: domain\user1
Workstation: CLIENT-PC
Process: lsass.exe
# Khi nào xảy ra: Truy cập shared folder, SMB

# ⚠️ Trường hợp đặc biệt - RDP với LogonType 3:
User: administrator
Workstation: REMOTE-CLIENT
Process: winlogon.exe
LogonType: 3 (thay vì 10)
# Khi nào xảy ra: RDP qua terminal server, RDP gateway

🔍 Tại sao RDP lại có LogonType 3?

  • Terminal Server: Khi RDP qua terminal server, authentication được xử lý như network logon
  • RDP Gateway: Khi sử dụng RDP Gateway, logon type có thể là 3
  • Load Balancer: Khi RDP đi qua load balancer hoặc proxy
  • Nested RDP: RDP trong RDP session có thể tạo LogonType 3
Type 10

Remote Interactive (RDP)

User đăng nhập qua Remote Desktop Protocol (RDP). Quan trọng để phát hiện brute force.

# Ví dụ:
User: administrator
Workstation: REMOTE-CLIENT
Process: winlogon.exe
# Khi nào xảy ra: RDP, Terminal Services
Type 11

Cached Interactive

User đăng nhập sử dụng cached credentials khi domain controller không available.

# Ví dụ:
User: domain\user1
Workstation: LAPTOP-OFFLINE
Process: winlogon.exe
# Khi nào xảy ra: Offline logon, cached credentials

🌍 Ví dụ thực tế trong SOC

Scenario 1: Brute Force Attack

Hacker thực hiện brute force attack trên RDP server từ IP 212.132.125.106

# Logs sẽ xuất hiện:
Event ID: 4625 (Failed Logon)
LogonType: 10 (RDP)
IpAddress: 212.132.125.106
TargetUserName: admin, administrator, user1...
FailureReason: Unknown user name or bad password

# Nếu thành công:
Event ID: 4624 (Successful Logon)
LogonType: 10 (RDP)
TargetUserName: admin

Scenario 2: Lateral Movement

Attacker đã compromise một máy và đang thực hiện lateral movement

# Logs sẽ xuất hiện:
Event ID: 4624 (Successful Logon)
LogonType: 3 (Network)
WorkstationName: COMPROMISED-PC
TargetUserName: domain\service_account
ProcessName: \\server\share\malware.exe

# Sau đó có thể thấy:
Event ID: 4648 (Explicit Credentials)
SubjectUserName: COMPROMISED-PC$

Scenario 3: Insider Threat

Employee sử dụng credentials của người khác để truy cập tài nguyên

# Logs sẽ xuất hiện:
Event ID: 4648 (Explicit Credentials)
SubjectUserName: employee1
TargetUserName: manager1
ProcessName: runas.exe
WorkstationName: EMPLOYEE-PC

# Sau đó:
Event ID: 4624 (Successful Logon)
LogonType: 2 (Interactive)
TargetUserName: manager1

🔍 SOC Analysis Queries

Phát hiện Brute Force Attack

# Tìm failed logons từ cùng IP:
winlog.event_id: 4625
| stats count() by winlog.event_data.IpAddress, winlog.event_data.TargetUserName
| where count > 5
| sort by count desc

Phát hiện RDP Brute Force

# Tìm failed RDP attempts (LogonType 10):
winlog.event_id: 4625 AND winlog.event_data.LogonType: "10"
# Tìm failed RDP attempts (LogonType 3 - RDP qua gateway):
winlog.event_id: 4625 AND winlog.event_data.LogonType: "3"
# Kết hợp cả hai trường hợp:
winlog.event_id: 4625 AND (winlog.event_data.LogonType: "10" OR winlog.event_data.LogonType: "3")
# Trong 1 giờ qua:
AND @timestamp >= "now-1h"
# Từ IP external:
AND NOT winlog.event_data.IpAddress: "192.168.*"

Phát hiện Lateral Movement

# Tìm network logons bất thường:
winlog.event_id: 4624 AND winlog.event_data.LogonType: "3"
# Từ máy không phải domain controller:
AND NOT winlog.event_data.WorkstationName: "*DC*"
# Vào giờ làm việc bất thường:
AND NOT date_hour: [9, 10, 11, 12, 13, 14, 15, 16, 17]

Phát hiện Privilege Escalation

# Tìm explicit credentials usage:
winlog.event_id: 4648
# Không phải từ domain controller:
AND NOT winlog.event_data.WorkstationName: "*DC*"
# Với process đáng ngờ:
AND winlog.event_data.ProcessName: ["cmd.exe", "powershell.exe", "runas.exe"]

⭐ Best Practices cho SOC Analyst

1

Monitor Failed Logons

Luôn theo dõi Event ID 4625 để phát hiện brute force attacks sớm

2

Correlate Logon Types

Kết hợp LogonType với IP addresses và thời gian để phát hiện patterns bất thường

3

Track Lateral Movement

Theo dõi LogonType 3 và 4648 để phát hiện lateral movement

4

Baseline Normal Activity

Thiết lập baseline cho hoạt động bình thường để phát hiện anomalies

5

Automate Detection

Tạo alerts tự động cho các patterns đáng ngờ

🎯 Kết luận

Hiểu rõ về Windows Authentication Event Codes và Logon Types là kỹ năng cơ bản nhưng cực kỳ quan trọng cho SOC Analyst. Việc nắm vững các event codes này giúp:

💡 Tip cho SOC Analyst

Luôn kết hợp nhiều event codes và logon types để có cái nhìn toàn diện về hoạt động authentication. Một attack thường tạo ra nhiều loại events khác nhau, việc correlate chúng sẽ giúp phát hiện threats hiệu quả hơn.

W

Windows Security Expert

Authentication Specialist

Đăng ngày: 22/01/2025
← Quay lại Blog