> 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/nsclient++-misconfiguration.md).

# NSClient++ の誤設定

許可された Windows 環境で NSClient++ の設定露出と外部スクリプト実行を検証する。

NSClient++ は管理用インターフェースを公開し、外部スクリプトを実行できます。サービスが `NT AUTHORITY\\SYSTEM`として実行されている場合、設定されたスクリプトも同じコンテキストで実行されます。

### NSClient++ を特定する

ServMon では、NSClient++ は `C:\Program Files\NSClient++`.

![NSClient++ のインストール ディレクトリ](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F7BxWRuJpkhdjgxSl6UZZ%2Fimage.png?alt=media\&token=af33c141-ded8-4b45-8df7-e27c36be6f2a)

サービスの設定とインストール済みバージョンを確認します。

```cmd
sc query nscp
sc qc nscp
nscp --version
```

![NSClient++ のバージョン出力](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FkiV1M84mNR6YXQRArlZb%2Fimage.png?alt=media\&token=7cf4fba8-3579-470c-9393-847dc70e1cfa)

NSClient++ の Web インターフェースはポート `8443`で待ち受けます。ServMon では、localhost にバインドされています。

### ローカル Web インターフェースにアクセスする

ローカルの NSClient++ インストールから、設定済みの Web インターフェースのパスワードを表示します。

```cmd
nscp web -- password --display
```

![NSClient++ Web パスワードの表示](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FEN9iqBDmnepnngEClbMR%2Fimage.png?alt=media\&token=91650362-0d14-4a65-b868-0ded2e21b031)

既存の SSH セッションを通じてローカル インターフェースを転送します:

```bash
ssh -L 8443:127.0.0.1:8443 <USER>@<TARGET>
```

![ローカルにバインドされた NSClient++ サービス](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FEf99TEkPD0kXopqr1iXh%2Fimage.png?alt=media\&token=79d00ca6-82f9-479c-b5f4-4199250a9c79)

開く `https://127.0.0.1:8443` にアクセスし、復元したパスワードで認証します。

![NSClient++ Web インターフェース](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FT66HFdAZnWr7LfJY0fTT%2Fimage.png?alt=media\&token=11655f08-6117-48c1-ba12-061bc8610bfa)

### 外部スクリプトを有効化する

で **設定 → モジュール**、次のモジュールを有効にします:

* `CheckExternalScripts`
* `Scheduler`

![有効化された NSClient++ モジュール](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FojqMY5pRFXD4O3vzu8jo%2Fimage.png?alt=media\&token=875858f2-56e4-4db0-bd32-584c698f1a45)

ターゲット上に無害なバッチ ファイルを作成します。実行時の ID を記録します。

```bat
@echo off
whoami > C:\Windows\Temp\nsclient-check.txt
```

で **設定 → 外部スクリプト → スクリプト**で、スクリプトを登録します:

```
セクション: /settings/external scripts/scripts/check
キー: command
値: C:\Path\To\nsclient-check.bat
```

![外部スクリプトの設定](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Feo5Fg9P404w5m3uCYA6I%2Fimage.png?alt=media\&token=2b8ce8d1-8389-4d17-a745-f4b853358c73)

### 実行をスケジュールして検証する

で **設定 → スケジューラ → スケジュール**で、スクリプトのスケジュールを設定します。

```
セクション: /settings/scheduler/schedules/check
キー: interval
値: 1m
```

```
セクション: /settings/scheduler/schedules/check
キー: command
値: check
```

![スケジュール済みスクリプトの間隔](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FfSaicrWxdHfiywQanquy%2Fimage.png?alt=media\&token=c14be532-14ca-4161-a2bb-f68bb3dae0a4)

![スケジュール済みスクリプトのコマンド](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FmV3EVbROLAVVm8DfP1vA%2Fimage.png?alt=media\&token=a13df7db-ab6f-44bd-b43d-512abc55a33d)

設定を保存してサービスを再起動します。

![NSClient++ サービスの再起動](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FY4uMHCNiP7fBkoVHCK6D%2Fimage.png?alt=media\&token=581d9c21-0d5f-497b-85bf-db5509300837)

スケジュールが実行された後、スクリプトに記録された ID を確認します:

```cmd
type C:\Windows\Temp\nsclient-check.txt
```

出力が `nt authority\system`であれば、設定により外部スクリプトは SYSTEM として実行されます。

![スケジュール済みスクリプトで取得した SYSTEM コンテキスト](https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCNxXBglNfZjXNA7uUQ90%2Fimage.png?alt=media\&token=d563cc8c-a1c6-4749-b253-1ca2155d1d6d)

### 対策

* NSClient++ をアップグレードし、未使用のモジュールを無効にします。
* Web インターフェースと NRPE を信頼できる管理ネットワークのみに制限します。
* スクリプトは管理者が書き込み可能なパスにのみ保存します。
* サービスは可能な限り最小権限のアカウントで実行します。


---

# 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/nsclient++-misconfiguration.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.
