Impacket smbserver.py
ローカルディレクトリを SMB1/SMB2 共有として公開します。NTLM/Kerberos 認証や読み取り専用設定も指定できます。
| 項目 | 内容 |
|---|---|
| 実装 | examples/smbserver.py |
| カテゴリ | SMB / MSRPC / NTLM |
| 規模 | 138 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/smbserver.py -h で確認できます。
| 引数 | 説明 |
|---|---|
shareName | name of the share to add |
sharePath | path of the share to add |
-comment | share’s comment to display when asked for shares |
-username | Username to authenticate clients |
-password | Password for the Username |
-computeraccountname | computer account name to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-computeraccounthash | computer account NT hash to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-computeraccountaes | computer account AES key to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-computeraccountpassword | computer account NT hash to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-computeraccountdomain | computer account domain to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-dc-ip | IP of domain controller to authenticate arbitrary clients with signing via NetLogon/Kerberos |
-hashes | NTLM hashes for the Username, format is LMHASH:NTHASH |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-ip / --interface-address | ip address of listening interface (“0.0.0.0” or ”::” if omitted) |
-readonly | Only allow reading of files |
-disablekerberos | Do not offer Kerberos authentication |
-disablentlm | Do not offer NTLM authentication |
-port | TCP port for listening incoming connections (default 445) |
-dropssp | Disable NTLM ESS/SSP during negotiation |
-6 / --ipv6 | Listen on IPv6 |
-smb2support | SMB2 Support (experimental!) |
-outputfile | Output file to log smbserver output messages |
詳細な処理フロー
Section titled “詳細な処理フロー”share 名/path と server option から SimpleSMBServer を構築し、credential/hash、SMB2、listen address/port、authentication policy を設定します。Kerberos 時は machine account と DC 情報を登録し、start() で request loop に入ります。
仕組みの詳細
Section titled “仕組みの詳細”SimpleSMBServer は local directory を share namespace に割り当て、SMB
negotiate、session setup、tree connect、file operation を server 側で処理します。
CLI は share 名/path、listen address/port、SMB2 可否、read-only、認証 policy を
server configuration へ変換して request loop を開始します。
NTLM 認証では user と LM/NT hash を credential database に登録し、client の
challenge/response を検証します。Kerberos を使う場合は server SPN を表す
machine account key と domain/DC 情報が必要です。-disablekerberos と
-disablentlm は negotiation 可能な mechanism を変え、両方無効な構成を
どのように扱うかを明示する必要があります。
file operation は client path を share root 以下の local path へ安全に解決します。
..、symlink、case sensitivity、read-only enforcement は protocol access mask
だけでなく local filesystem と合わせて確認します。port 445 の bind 権限、
IPv4/IPv6、複数 client の session/file ID、log file の秘密情報も server
lifecycle の一部です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
| module-level entry | 1 | トップレベルで引数解析と処理を実行 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket | smbserver, version |
impacket.ntlm | compute_lmhash, compute_nthash |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- 待受 socket または長時間 loop を開始します。bind address、port、停止方法、同時接続時の共有状態を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 停止要求、client 切断、partial read/write、worker 例外で listener 全体が不整合にならないことを確認します。
実装を変更するとき
Section titled “実装を変更するとき”impacket.smbserver、ntlm.compute_*hash に依存します。トップレベル CLI が server config を直接組み立てます。認証の enable/disable 組み合わせと privileged port の失敗を明示的に扱ってください。
- 構文:
python -m py_compile examples/smbserver.py - CLI:
python examples/smbserver.py -h - 関連テスト:
tests/SMB_RPC/test_smbserver.py - 関連テスト:
tests/SMB_RPC/test_ntlm.py

