Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/recon/computer_browser_discovery.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Auxiliary::Report78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Recon Computer Browser Discovery',13'Description' => %q{14This module uses railgun to discover hostnames and IPs on the network.15LTYPE should be set to one of the following values: WK (all workstations), SVR (all servers),16SQL (all SQL servers), DC (all Domain Controllers), DCBKUP (all Domain Backup Servers),17NOVELL (all Novell servers), PRINTSVR (all Print Que servers), MASTERBROWSER (all Master Browsers),18WINDOWS (all Windows hosts), or UNIX (all Unix hosts).19},20'License' => MSF_LICENSE,21'Author' => [ 'mubix' ],22'Platform' => [ 'win' ],23'SessionTypes' => [ 'meterpreter' ],24'Compat' => {25'Meterpreter' => {26'Commands' => %w[27stdapi_net_resolve_host28stdapi_railgun_api29stdapi_railgun_memread30]31}32}33)34)3536register_options(37[38OptString.new('LTYPE', [true, 'Account informations (type info for known types)', 'WK']), # Enum would be a better choice39OptString.new('DOMAIN', [false, 'Domain to perform lookups on, default is current domain', nil]),40OptBool.new('SAVEHOSTS', [true, 'Save Discovered Hosts to the Database', false])41]42)43end4445def parse_netserverenum(startmem, count)46base = 047sys_list = []48mem = client.railgun.memread(startmem, 24 * count)4950count.times do |_i|51x = {}52x[:platform_id] = mem[(base + 0), 4].unpack('V*')[0]53cnameptr = mem[(base + 4), 4].unpack('V*')[0]54x[:major_ver] = mem[(base + 8), 4].unpack('V*')[0]55x[:minor_ver] = mem[(base + 12), 4].unpack('V*')[0]56x[:type] = mem[(base + 16), 4].unpack('V*')[0]57commentptr = mem[(base + 20), 4].unpack('V*')[0]5859x[:cname] = client.railgun.memread(cnameptr, 27).split("\0\0")[0].split("\0").join60x[:comment] = client.railgun.memread(commentptr, 255).split("\0\0")[0].split("\0").join61sys_list << x62base += 2463vprint_status("Identified: #{x[:cname]} - #{x[:comment]}")64end65return sys_list66end6768def run69### MAIN ###70client = session7172domain = nil7374# Default = SV_TYPE_NT75# Servers = SV_TYPE_ALL76# Workstations = SV_TYPE_WORKSTATION77# Domain Controllers = SV_TYPE_DOMAINCTRL78# Novell Server = SV_TYPE_NOVELL79# Terminal Servers = SV_TYPE_TERMINALSERVER80# SQL Servers = SV_TYPE_SQLSERVER81lookuptype = 18283case datastore['LTYPE']84when 'WK' then lookuptype = '1'.hex85when 'SVR' then lookuptype = '2'.hex86when 'SQL' then lookuptype = '4'.hex87when 'DC' then lookuptype = '8'.hex88when 'DCBKUP' then lookuptype = '10'.hex89when 'TIME' then lookuptype = '20'.hex90when 'NOVELL' then lookuptype = '80'.hex91when 'PRINTSVR' then lookuptype = '200'.hex92when 'MASTERBROWSER' then lookuptype = '40000'.hex93when 'WINDOWS' then lookuptype = '400000'.hex94when 'UNIX' then lookuptype = '800'.hex95when 'LOCAL' then lookuptype = '40000000'.hex96end9798if session.arch == ARCH_X6499nameiterator = 8100size = 64101addrinfoinmem = 32102else103nameiterator = 4104size = 32105addrinfoinmem = 24106end107108result = client.railgun.netapi32.NetServerEnum(nil, 101, 4, -1, 4, 4, lookuptype, datastore['DOMAIN'], 0)109110if result['totalentries'] == 0111print_error('No systems found of that type')112return113end114print_good("Found #{result['totalentries']} systems.")115116endofline = 0117i = nameiterator118netview = parse_netserverenum(result['bufptr'], result['totalentries'])119120## get IP for host121begin122netview.each do |x|123vprint_status("Looking up IP for #{x[:cname]}")124print '.'125result = client.net.resolve.resolve_host(x[:cname])126if result[:ip].nil? || result[:ip].blank?127print_error("There was an error resolving the IP for #{x[:cname]}")128next129else130x[:ip] = result[:ip]131end132end133rescue ::Exception => e134print_error(e)135print_status('Windows 2000 and prior does not support getaddrinfo')136end137138netview = netview.sort_by { |e| e[:type] }139140results = Rex::Text::Table.new(141'Header' => 'Netdiscovery Results',142'Indent' => 2,143'Columns' => ['TYPE', 'IP', 'COMPUTER NAME', 'VERSION', 'COMMENT']144)145146netview.each do |x|147results << [x[:type], x[:ip], x[:cname], "#{x[:major_ver]}.#{x[:minor_ver]}", x[:comment]]148report_host(host: x[:ip]) if datastore['SAVEHOSTS'] && !x[:ip].empty?149end150print_status(results.to_s)151store_loot('discovered.hosts', 'text/plain', session, results.to_s, 'discovered_hosts.txt', 'Computer Browser Discovered Hosts')152153print_status('If none of the IP addresses show up you are running this from a Win2k or older system')154print_status("If a host doesn't have an IP it either timed out or only has an IPv6 address assinged to it")155end156end157158159