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

# 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>" %}
