Lucene search
K

SMB Directory Listing Utility

🗓️ 04 Aug 2012 01:00:11Reported by mubix <[email protected]>, hdm <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 17 Views

SMB Directory Listing Utility module for Metasploit Framewor

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary

  # Exploit mixins should be called first
  include Msf::Exploit::Remote::SMB::Client
  include Msf::Auxiliary::Report

  # Aliases for common classes
  SIMPLE = Rex::Proto::SMB::Client
  XCEPT  = Rex::Proto::SMB::Exceptions
  CONST  = Rex::Proto::SMB::Constants


  def initialize
    super(
      'Name'        => 'SMB Directory Listing Utility',
      'Description' => %Q{
        This module lists the directory of a target share and path. The only reason
      to use this module is if your existing SMB client is not able to support the features
      of the Metasploit Framework that you need, like pass-the-hash authentication.
      },
      'Author'      =>
        [
          'mubix',
          'hdm'
        ],
      'References'  =>
        [
        ],
      'License'     => MSF_LICENSE
    )

    register_options([
      OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),
      OptString.new('RPATH', [false, 'The name of the remote directory relative to the share']),
    ])

    deregister_options('SMB::ProtocolVersion')
  end

  def as_size( s )
    prefix = %W(TB GB MB KB B)
    s = s.to_f
    i = prefix.length - 1
    while s > 512 && i > 0
      s /= 1024
      i -= 1
    end
    ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + prefix[i]
  end

  def run
    print_status("Connecting to the server...")
    begin
      connect(versions: [1])
      smb_login()
      print_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
            self.simple.connect("\\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}")
      if datastore['RPATH']
        print_status("Listing \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}'...")
      end
      listing = self.simple.client.find_first("\\#{datastore['RPATH']}\\*")
      directory = Rex::Text::Table.new(
            'Header' => "Directory Listing of \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}\\#{datastore['RPATH']}",
            'Indent' => 2,
            'SortIndex' => 2,
            'Columns' => ['SIZE','TYPE','TIME','FILENAME']
      )
      listing.each_pair do |key,val|
        file_lastmodified = ::Time.at(Rex::Proto::SMB::Utils.time_smb_to_unix(val["info"][9],val["info"][10]))
        size = val['info'][10]
        if val['attr'] == 16
          type = 'DIR'
          size = ''
        else
          type = 'FILE'
        end
        directory << [as_size(size.to_s),val["type"],file_lastmodified.strftime("%Y-%m-%d %H:%m:%S%p"),key]
      end
      print_status(directory.to_s)
    rescue Rex::Proto::SMB::Exceptions::Error => e
      # SMB has very good explanations in error messages, don't really need to
      # prefix with anything here.
      print_error("#{e}")
    end
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

09 Jun 2020 12:18Current
6.9Medium risk
Vulners AI Score6.9
17