# Unquoted Service Path

Windows 시스템에서 서비스를 실행할 때 절대 경로에 공백이 포함되었지만 따옴표로 감싸져있지 않을 경우,  시스템이 해석하는 방식에 결함이 있어 서비스 바이너리를 가로채어 실행할 수 있습니다.

## Abuse

{% embed url="<https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1>" %}

<pre class="language-powershell"><code class="lang-powershell"><strong># 따옴표가 없는 공백이 포함된 서비스 경로 열거
</strong>Get-WmiObject Win32_Service | Where-Object { $_.PathName -notlike 'C:\Windows\*' -and $_.PathName -notmatch '^\s*\".*\".*$' } | Select-Object Name, DisplayName, PathName, StartMode

<strong># PowerUp을 사용해 열거
</strong>Get-UnquotedService

<strong># 디렉토리 권한 확인
</strong>icacls .
</code></pre>

## Root Cause

`C:\Users\Mick3y\Desktop\My Service\Daily Update\update.exe` 와 같이 공백이 포함된 따옴표로 감싸지지 않은 서비스의 바이너리 절대 경로가 있다고 가정할 때, Windows는 공백을 발견하면 그것이 바이너리의 구분점이라 생각하여 다음과 같은 실행 파일을 찾습니다.

* `C:\Users\Mick3y\Desktop\My.exe`&#x20;
* `C:\Users\Mick3y\Desktop\My Service\Daily.exe`
* &#x20;`C:\Users\Mick3y\Desktop\My Service\Daily Update\update.exe`

공백의 디렉토리 경로를 실행 파일로 해석하는 과정에서 공격자가 상위 디렉토리인 Desktop, My Service 등에 쓰기 권한이 있다면 My.exe, Daily.exe 등의 실행 파일을 올려 서비스 바이너리 하이재킹이 가능합니다.

{% hint style="info" %}
기본적으로 표준 사용자는 서비스를 중지하거나 시작할 수 없으므로 일반적으로 컴퓨터를 재부팅해야 합니다.
{% endhint %}

## References

{% embed url="<https://0xmh.tistory.com/31>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pentestwiki.com/privilege-escalation/windows/unquoted-service-path.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
