> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ja/windows-vulnerabilities/vulnerable-services-and-processes/windows-service-misconfigurations.md).

# Windowsサービスの誤設定

弱いWindowsサービス権限、書き込み可能なバイナリ、引用符なしパス、昇格した再起動条件を確認する。

サービスは、Windowsにおける権限昇格の最も一般的な経路の1つです。というのも、しばしば次のアカウントで実行されるからです `LocalSystem` 一方で、通常ユーザーが影響を与えられるファイルや権限を指しているためです。

## 確認すべきこと

何かを変更する前に、次の4点を確認してください：

* そのサービスは、次のような特権アカウントで実行されています `LocalSystem`, `LocalService`, `NetworkService`、またはローカル/ドメイン管理者です。
* サービスの設定、サービス実行ファイル、または起動時に使用される親パスを変更できます。
* サービスを再起動できる、アプリケーションを起動できる、または再起動を待てます。
* パスとアーキテクチャが、実行しようとしているペイロードまたは検証用バイナリと一致しています。

## サービスを列挙する

```cmd
sc query state= all
sc qc <service_name>
sc sdshow <service_name>
wmic service get name,displayname,startname,state,pathname
```

```powershell
Get-WmiObject Win32_Service |
  Select-Object Name,StartName,State,PathName |
  Sort-Object StartName,Name
```

## 脆弱なサービス設定

あなたのユーザーがサービスのバイナリパスを変更でき、かつサービスが昇格権限で実行されている場合は、まず許可された検証コマンドを指定してください。

```cmd
sc qc <service_name>
sc config <service_name> binPath= "cmd /c whoami > C:\Windows\Temp\svc-check.txt"
sc stop <service_name>
sc start <service_name>
type C:\Windows\Temp\svc-check.txt
```

AccessChk は、サービス権限をより分かりやすい形式で確認するのに役立ちます：

```cmd
accesschk.exe /accepteula -uwcqv <user_or_group> <service_name>
accesschk.exe /accepteula -uwcqv "Authenticated Users" *
```

注目すべき権限には次が含まれます `SERVICE_CHANGE_CONFIG`, `SERVICE_START`, `SERVICE_STOP`、および次に対する広範な書き込みアクセス `ユーザー`, `Authenticated Users`や `Everyone`.

## 書き込み可能なサービスバイナリ

サービス実行ファイルに書き込み可能であれば、元のファイルのコピーを保持し、検証の範囲内でのみ置き換え、テスト後に元に戻してください。

```cmd
sc qc <service_name>
icacls "C:\Path\To\Service.exe"
copy "C:\Path\To\Service.exe" C:\Windows\Temp\Service.exe.bak
```

```powershell
Get-Acl "C:\Path\To\Service.exe" | Format-List
```

## 引用符で囲まれていないサービスパス

引用符なしのパスは、スペースを含み、Windows が実際の実行ファイルに到達する前に書き込み可能な親ディレクトリを検索できる場合に注目されます。

```cmd
wmic service get name,displayname,pathname,startmode | findstr /i "Auto" | findstr /i /v "C:\Windows\\"
```

脆弱性のある典型例：

```
C:\Program Files\Vendor App\Service Folder\service.exe
```

各親ディレクトリの書き込み権限を確認してください：

```cmd
icacls "C:\"
icacls "C:\Program Files"
icacls "C:\Program Files\Vendor App"
```

検索される可能性のある名前には次が含まれます：

```
C:\Program.exe
C:\Program Files\Vendor.exe
C:\Program Files\Vendor App\Service.exe
```

## DLL検索順序の問題

一部のサービスは、完全パスではなく名前でDLLを読み込みます。これは、正規のDLLの場所より前に書き込み可能なディレクトリが検索されると悪用可能になります。

```cmd
procmon.exe
```

次でフィルタ：

```
Process Name is <service.exe>
結果が NAME NOT FOUND
パスが .dll で終わる
```

## 自動チェック

```powershell
Import-Module .\PowerUp.ps1
Invoke-AllChecks
```

```cmd
winPEASx64.exe servicesinfo
```

## クリーンアップ

```cmd
sc config <service_name> binPath= "<original_binary_path>"
sc start <service_name>
del C:\Windows\Temp\svc-check.txt
```

## 要点

* 書き込み可能なサービスも、より高い権限で実行される場合にのみ有用です。
* 再起動できるかどうかは重要です。できない場合は、再起動やアプリケーションの使用によってサービスが起動されるかを確認してください。
* サービスパスの発見事項には、正確なパス、権限の証拠、サービスアカウント、起動条件を含めるべきです。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ja/windows-vulnerabilities/vulnerable-services-and-processes/windows-service-misconfigurations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
