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

Khóa bảo mật mạng trong Windows Registry

Khóa bảo mật mạng KHÔNG lưu trực tiếp trong Registry

Windows KHÔNG lưu mật khẩu Wi-Fi dạng plaintext (text rõ) trong Registry. Thay vào đó, Windows lưu trữ:

  • Profile XML chứa cấu hình mạng (SSID, auth type, cipher, v.v.)
  • Hash/Encrypted key được bảo vệ bởi DPAPI (Data Protection API) — chỉ hệ thống/user sở hữu mới giải mã được

Vị trí lưu trữ thực tế

  1. File hệ thống (Profile XML):
    C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces\{Interface_GUID}\{Profile_Name}.xml
    Chứa: <sharedKey>ENCRYPTED_DATA</sharedKey> — đã mã hóa DPAPI.
  2. Registry (Chỉ metadata, KHÔNG có mật khẩu):
    HKLM\SOFTWARE\Microsoft\WlanSvc\Profiles\{Interface_GUID}\{Profile_Name}
    Chứa: SSID, Connection mode, Auto connect, Cost settings... — KHÔNG có key.
  3. Credential Manager (Windows Vault): Control Panel → Credential Manager → Windows Credentials → Generic Credentials → Wi-Fi network entries (nếu được lưu bởi ứng dụng).

Cách xem mật khẩu (Chỉ cách chính thức, an toàn)

KHÔNG cố gắng đọc Registry/file XML thủ công — dữ liệu đã mã hóa DPAPI, cần API Windows để giải mã.

Cách 1: Settings (Win 10/11)

Settings → Network & Internet → Wi-Fi → Manage known networks → Click mạng → Properties → Network security key

Cách 2: Control Panel

Network and Sharing Center → Change adapter settings → Right-click Wi-Fi → Status → Wireless Properties → Security → Show characters

Cách 3: PowerShell (Admin)

# Liệt kê profile
netsh wlan show profiles

# Xem mật khẩu profile cụ thể (Key Content = mật khẩu)
netsh wlan show profile name="TEN_WIFI" key=clear

Cách 4: PowerShell Script (Get all passwords)

(netsh wlan show profiles) | Select-String "\:(.+)$" | ForEach-Object {
    $name = $_.Matches[0].Groups[1].Value.Trim()
    $profile = netsh wlan show profile name="$name" key=clear
    $pass = ($profile | Select-String "Key Content\s+:\s(.+)$").Matches[0].Groups[1].Value.Trim()
    if ($pass) { [PSCustomObject]@{SSID=$name; Password=$pass} }
} | Format-Table -AutoSize

Tại sao không nên đọc Registry/file trực tiếp?

  • Dữ liệu được mã hóa bằng DPAPI (Data Protection API) — khóa mã hóa gắn liền với user account/SID và máy tính
  • Copy file/registry sang máy khác → KHÔNG giải mã được
  • Chỉnh sửa thủ công → Hỏng profile, không kết nối được Wi-Fi
  • Vi phạm nguyên tắc bảo mật Windows

Backup/Restore Wi-Fi Profiles (Cách đúng)

# Export tất cả profile (có mật khẩu đã mã hóa)
netsh wlan export profile folder="C:\WiFiBackup" key=clear

# Import trên máy khác / sau khi cài lại Windows
netsh wlan add profile filename="C:\WiFiBackup\Wi-Fi_TenMang.xml" user=all

key=clear cho phép xuất mật khẩu dạng text trong file XML — Chỉ dùng khi backup an toàn, xóa file sau khi dùng.