Fix windows unquoted service path enumeration vulnerabilities with #Powershell
Here is a function to fix windows unquoted service path enumeration vulnerabilities automatically with powershell! Cheers!
function fix-servicepath {
$hosts = get-content C:\Users\*****\Documents\WindowsPowershell\Servers.txt
foreach ($box in $hosts) {
$services = $null
$services = get-wmiobject win32_service -computername $box
foreach ($service in $services){
$Displayname = $service.DisplayName
if (($service.PathName -like "* *") -and ($service.Pathname -notlike '"*"*') -and ($service.PathName -like '*.exe')) {
$box
$service.PathName
write-host "Changing Path to be quoted:"
$NewPath = $service.Pathname
$newservicepath = "`"$NewPath`""
$service.change($Displayname,$newservicepath)
write-host "Done."
;""
}
}
}
}