■sambaのリッスンポートを「tcp/445」のみに制限する(for Squeeze)。
注意点は以下の通り。タイトルは紛らわしいが読めば分かるので、ここでは触れない。
ポート445(ダイレクト・ホスティングSMBサービス)に注意
http://www.atmarkit.co.jp/fwin2k/win2ktips/088directhostedsmb/088directhostedsmb.html
■現状の設定の確認。
これを使わないようにする。
$ sudo testparm -s -v 2>&1 | grep "smb ports\|netbios"
netbios name = VMAMDDEBIAN
netbios aliases =
netbios scope =
smb ports = 445 139
disable netbios = No
■「smb.conf」には無い設定項目。つまりデフォルト。
$ sudo grep -v "^#\|\\$" /etc/samba/smb.conf | grep -i "ports\|netbios"
■netbios関連のポート。
$ grep '13[789]/' /etc/services
netbios-ns 137/tcp
netbios-ns 137/udp
netbios-dgm 138/tcp
netbios-dgm 138/udp
netbios-ssn 139/tcp
netbios-ssn 139/udp
■「global」に設定。
$ sudo grep -v "^#\|\\$" /etc/samba/smb.conf | grep "ports\|netbios"
smb ports = 445
disable netbios = yes
■broadcastも止めたい。
$ sudo testparm -v -s 2>&1 | grep "broad\|multi\|cast"
nmbd bind explicit broadcast = Yes
■リッスンポートを確認。
$ netstat -an | grep "13[789]\|445"
tcp 0 0 192.168.188.188:445 0.0.0.0:* LISTEN
■「hosts allow」と「hosts deny」
後述するが、「LAN Manager」によるSambaバージョンの隠蔽は
オプションの変更が推奨されていない。
パスワード制限でゲストは許可していないにしても、IP制限は必須。
デフォルトでは「smb.conf」内に設定項目すら無いので注意する。
$ sudo testparm -s -v 2>&1 | grep hosts
name resolve order = lmhosts host
init logon delayed hosts =
hosts allow = 192.168., 172.16.
hosts deny = ALL
□以下、確認方法。
■「smbstatus」にデバッグオプションをつけると、「testparm」と同様の結果が見れる。
※今回行った変更すべてを検索。
$ sudo smbstatus -d 10 2>&1 | grep "ports\|netbios\|broad\|hosts [ad]" | sort -u
doing parameter disable netbios = yes
doing parameter hosts allow = 192.168.,172.16.
doing parameter hosts deny = ALL
doing parameter nmbd bind explicit broadcast = no
doing parameter smb ports = 445
■以下で示した警告は「smbstatus」でも出る。
samba3のtestparmで出る「rlimit_max」を無視する理由
http://d.hatena.ne.jp/labunix/20121012
$ sudo smbstatus -d 10 2>&1 | grep rlimit | sort -u
rlimit_max: rlimit_max (1024) below minimum Windows limit (16384)
■「445/tcp」は「net view」出来ます。
「server string = %h server」が表示される。「%v」(バージョン情報)は含まない。
> net view \\192.168.188.188
\\192.168.188.188 の共有リソース
vmamddebian server
共有名 タイプ 使用 コメント
-------------------------------------------------------------------------------
labunix Disk Home Directories
コマンドは正常に終了しました。
■「netbios」が使えないことを確認(debian)。
$ nmblookup -S `hostname`
querying vmamddebian on 192.168.188.255
name_query failed to find name vmamddebian
■「netbios」が使えないことを確認(WinXP)。
> nbtstat -a 192.168.188.188
ローカル エリア接続:
Node IpAddress: [192.168.188.155] Scope Id: []
Host not found.
■WinXP自身による「netbios」問い合わせは可能(WinXP)
※「ぼっち」なので、ワークグループ「MSHOME」のマスターブラウザ。
> nbtstat -a 192.168.188.155
ローカル エリア接続:
Node IpAddress: [192.168.188.155] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
DUMMY-WINXP <00> UNIQUE Registered
MSHOME <00> GROUP Registered
DUMMY-WINXP <20> UNIQUE Registered
MSHOME <1E> GROUP Registered
MSHOME <1D> UNIQUE Registered
..__MSBROWSE__.<01> GROUP Registered
MAC Address = XX-XX-XX-XX-XX-XX
■WinXPへの「netbios」問い合わせは可能(debian)。
$ nmblookup -S -W MSHOME -A 192.168.188.155
Looking up status of 192.168.188.155
DUMMY-WINXP <00> - B <ACTIVE>
MSHOME <00> - <GROUP> B <ACTIVE>
DUMMY-WINXP <20> - B <ACTIVE>
MSHOME <1e> - <GROUP> B <ACTIVE>
MSHOME <1d> - B <ACTIVE>
..__MSBROWSE__. <01> - <GROUP> B <ACTIVE>
MAC Address = XX-XX-XX-XX-XX-XX
■脆弱性チェックを行う。
$ w3m -dump https://raw.github.com/labunix/penetration/master/penetration.sh > penetration.sh
$ chmod +x penetration.sh
$ sudo ./penetration.sh 192.168.188.188
...
Host script results:
|_ nbstat: ERROR: Name query failed: ERROR
| smb-os-discovery: Unix
| LAN Manager: Samba 3.5.6
| Name: WORKGROUP\Unknown
|_ System time: 2012-10-13 20:54:37 UTC+9
...
■「smbstatus」で誰も参照していない場合の応答。
$ sudo smbstatus
Samba version 3.5.6
PID Username Group Machine
-------------------------------------------------------------------
Service pid machine Connected at
-------------------------------------------------------
No locked files
■「smbstatus」でWinXPからdebianのファイル共有を行ったところ。
$ sudo smbstatus
[sudo] password for labunix:
Samba version 3.5.6
PID Username Group Machine
-------------------------------------------------------------------
10850 labunix labunix dummy-winxp (192.168.188.155)
Service pid machine Connected at
-------------------------------------------------------
IPC$ 10850 dummy-winxp Sat Oct 13 22:04:55 2012
No locked files
■該当箇所の確認。
「lm announce」行がそれのようだ。
$ sudo testparm -s -v 2>&1 | grep announce
announce version = 4.9
announce as = NT
lm announce = Auto
remote announce =
■「lm announce」は受信のみ行い、受け取った情報を以降送信するようになる。
この値の変更は行わない。
$ man smb.conf | grep -A 12 "lm announce .*G"
lm announce (G)
This parameter determines if nmbd(8) will produce Lanman announce
broadcasts that are needed by OS/2 clients in order for them to see
the Samba server in their browse list. This parameter can have
three values, yes, no, or auto. The default is auto. If set to no
Samba will never produce these broadcasts. If set to yes Samba will
produce Lanman announce broadcasts at a frequency set by the
parameter lm interval. If set to auto Samba will not send Lanman
announce broadcasts by default but will listen for them. If it
hears such a broadcast on the wire it will then start sending them
at a frequency set by the parameter lm interval.
■「lm interval = 0」にすれば実質停止するのだが、上記脆弱性チェックには影響が無いので、設定はしない。
$ man smb.conf | grep -A 10 "lm interval .*G"
lm interval (G)
If Samba is set to produce Lanman announce broadcasts needed by
OS/2 clients (see the lm announce parameter) then this parameter
defines the frequency in seconds with which they will be made. If
this is set to zero then no Lanman announcements will be made
despite the setting of the lm announce parameter.
Default: lm interval = 60
Example: lm interval = 120
■ところでnetbios名が使えなくなったので、「hosts」かDNSで名前解決を行う。
Windowsで「hosts」の設定は例えば以下のようになる。
Windowsはnetbios名が使えるので、最後の行は実際には不要。
管理場所をバラバラにしないようにする以外の意味は無い。
> type c:\WINDOWS\system32\drivers\etc\hosts | find /V "#" | findstr "[0-9]"
127.0.0.1 localhost
192.168.188.188 vmamddebian
192.168.188.155 demmy-winxp