Impacket netview.py
ドメイン内のホストを探し、SMB セッションとログオンユーザーを調べて、指定ユーザーの接続先を見つけます。
| 項目 | 内容 |
|---|---|
| 実装 | examples/netview.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 496 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/netview.py -h で確認できます。
| 引数 | 説明 |
|---|---|
identity | [domain/]username[:password] |
-user | Filter output by this user |
-users | input file with list of users to filter to output for |
-target | target system to query info from. If not specified script will run in domain mode. |
-targets | input file with targets system to query info from (one per line). If not specified script will run in domain mode. |
-noloop | Stop after the first probe |
-delay | seconds delay between starting each batch probe (default 10 seconds) |
-max-connections | Max amount of connections to keep opened (default 1000) |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-hashes | NTLM hashes, format is LMHASH:NTHASH |
-no-pass | don’t ask for password (useful for -k) |
-k | Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line |
-aesKey | AES key to use for Kerberos Authentication (128 or 256 bits) |
-dc-ip | IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter |
詳細な処理フロー
Section titled “詳細な処理フロー”LDAP/RPC から候補 machine または入力 target list を作り、worker thread と queue で各ホストへ接続します。WKST/SRVS/SAMR を使って session と user を収集し、filter に一致した結果を表示します。既定は周期実行、-noloop で一巡して終了します。
仕組みの詳細
Section titled “仕組みの詳細”目的は host の単純な生存確認ではなく、「指定 user がどの machine に session
または logon を持つか」を横断的に探すことです。最初に domain から machine
候補を得るか、-target(s) の明示リストを読み、別途 -user(s) から探したい
identity の filter を構築します。
各 worker は SMB/RPC で対象へ接続し、Server Service の session 情報と Workstation Service の logged-on user 情報を取得します。この二つは観測する 状態が違い、前者は network session、後者は machine 側で認識される user です。 結果を統合して filter に一致した host/user/source を表示しますが、権限不足で 片方だけ取得できる場合もあります。
queue、接続数上限、delay、loop は大規模 domain で負荷と取りこぼしを制御する
ための仕組みです。worker 例外で queue item が未完了になったり、停止 event 後に
新規接続を始めたりしないことが重要です。-noloop は一巡後に終わるため、
継続監視と snapshot の意味を混同しないでください。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
USERENUM | 111 | __init__()、getDomainMachines()、getTargets()、filterUsers()、run()、getSessions()、getLoggedIn()、stop() |
checkMachines() | 76 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_identity |
impacket | version |
impacket.smbconnection | SessionError |
impacket.dcerpc.v5 | samr, srvs, transport, wkst |
impacket.dcerpc.v5.ndr | NULL |
impacket.dcerpc.v5.rpcrt | DCERPCException |
impacket.nt_errors | STATUS_MORE_ENTRIES |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 後始末に関係する実装として
stop()があります。新しい早期 return や例外経路でも到達するか確認します。
実装を変更するとき
Section titled “実装を変更するとき”smbconnection、dcerpc.v5.wkst / srvs / samr、threading/queue に依存します。USERENUM.stop()、接続上限、delay の扱いは大量接続を避けるための重要な制御です。
- 構文:
python -m py_compile examples/netview.py - CLI:
python examples/netview.py -h - 関連テスト:
tests/SMB_RPC/test_ndr.py - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py

