Windows 遠程桌面連接 (MSTSC) 會自動記錄成功連接的 IP/域名,顯示在下拉列表中。方便複用的同時,**洩露內網拓撲、服務器地址、管理員習慣**,被駭客利用可進行針對性滲透。本文提供徹底清除與持久禁用方案。
設置後,MSTSC 無法寫入新記錄,下拉列表永遠為空,最後連接欄也不再自動填充。
# 清除註冊表 MRU
$regPath = 'HKCU:\Software\Microsoft\Terminal Server Client\Default'
if (Test-Path $regPath) {
Get-ItemProperty $regPath | ForEach-Object {
$_.PSObject.Properties | Where-Object { $_.Name -match '^MRU\d+$' } | ForEach-Object {
Remove-ItemProperty -Path $regPath -Name $_.Name -Force
}
}
}
# 刪除 Default.rdp
$rdp = Join-Path $env:USERPROFILE 'Documents\Default.rdp'
if (Test-Path $rdp) { Remove-Item $rdp -Force }
# 鎖定權限 (需管理員)
$acl = Get-Acl $regPath
$acl.SetAccessRuleProtection($true, $false)
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($env:USERNAME, 'ReadKey', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.RemoveAccessRuleAll($rule) # 先移除舊規則
$acl.AddAccessRule((New-Object System.Security.AccessControl.RegistryAccessRule('SYSTEM','FullControl','ContainerInherit,ObjectInherit','None','Allow')))
$acl.AddAccessRule((New-Object System.Security.AccessControl.RegistryAccessRule($env:USERNAME,'ReadKey','ContainerInherit,ObjectInherit','None','Allow')))
Set-Acl $regPath $acl
$rdpAcl = Get-Acl $rdp
$rdpAcl.SetAccessRuleProtection($true,$false)
$rdpAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule('SYSTEM','FullControl','ContainerInherit,ObjectInherit','None','Allow')))
$rdpAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule($env:USERNAME,'Read','ContainerInherit,ObjectInherit','None','Allow')))
Set-Acl $rdp $rdpAcl
Write-Host "RDP history cleared & write-protected. Reopen MSTSC to verify."
遠程桌面歷史看似微不足道,實則是**偵察階段的禮物**。養成「用完即清、權限鎖定、策略下發」習慣,不給駭客留線索。