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/wlan/wlan_probe_request.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Windows Send Probe Request Packets',12'Description' => %q{13This module send probe requests through the wlan interface.14The ESSID field will be use to set a custom message.15},16'License' => MSF_LICENSE,17'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>' ],18'Platform' => [ 'win' ],19'SessionTypes' => [ 'meterpreter' ],20'Compat' => {21'Meterpreter' => {22'Commands' => %w[23stdapi_railgun_api24stdapi_sys_process_attach25stdapi_sys_process_getpid26]27}28}29)30)3132register_options(33[34OptString.new('SSID', [true, 'Message to be embedded in the SSID field', '']),35OptInt.new('TIMEOUT', [false, 'Timeout in seconds running probes', '30'])36]37)38end3940def run41ssid = datastore['SSID']42time = datastore['TIMEOUT']4344if ssid.length > 3245print_error('The SSID must be equal to or less than 32 bytes')46return47end4849mypid = client.sys.process.getpid50@host_process = client.sys.process.open(mypid, PROCESS_ALL_ACCESS)51@wlanapi = client.railgun.wlanapi5253wlan_handle = open_handle54unless wlan_handle55print_error("Couldn't open WlanAPI Handle. WLAN API may not be installed on target")56print_error('On Windows XP this could also mean the Wireless Zero Configuration Service is turned off')57return58end5960# typedef struct _DOT11_SSID {61# ULONG uSSIDLength;62# UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];63# } DOT11_SSID, *PDOT11_SSID;64pDot11Ssid = [ssid.length].pack('L<') << ssid65wlan_iflist = enum_interfaces(wlan_handle)66if wlan_iflist.empty?67print_status('Wlan interfaces not found')68return69end7071print_status("Wlan interfaces found: #{wlan_iflist.length}")72print_status("Sending probe requests for #{time} seconds")73begin74::Timeout.timeout(time) do75loop do76wlan_iflist.each do |interface|77vprint_status("Interface Guid: #{interface['guid'].unpack('H*')[0]}")78vprint_status("Interface State: #{interface['state']}")79vprint_status("DOT11_SSID payload: #{pDot11Ssid.chars.map { |c| c.ord.to_s(16) }.join(':')}")80@wlanapi.WlanScan(wlan_handle, interface['guid'], pDot11Ssid, nil, nil)81sleep(10)82end83end84end85rescue ::Timeout::Error86closehandle = @wlanapi.WlanCloseHandle(wlan_handle, nil)87if closehandle['return'] == 088print_status('WlanAPI Handle closed successfully')89else90print_error('There was an error closing the Handle')91end92end93end9495# Function borrowed from @theLightCosine wlan_* modules96def open_handle97begin98wlhandle = @wlanapi.WlanOpenHandle(2, nil, 4, 4)99rescue StandardError100return nil101end102return wlhandle['phClientHandle']103end104105# Function borrowed from @theLightCosine wlan_* modules106def enum_interfaces(wlan_handle)107iflist = @wlanapi.WlanEnumInterfaces(wlan_handle, nil, 4)108pointer = iflist['ppInterfaceList']109110numifs = @host_process.memory.read(pointer, 4)111numifs = numifs.unpack('V')[0]112113interfaces = []114115# Set the pointer ahead to the first element in the array116pointer = (pointer + 8)117(1..numifs).each do |_i|118interface = {}119# Read the GUID (16 bytes)120interface['guid'] = @host_process.memory.read(pointer, 16)121pointer = (pointer + 16)122# Read the description(up to 512 bytes)123interface['description'] = @host_process.memory.read(pointer, 512)124pointer = (pointer + 512)125# Read the state of the interface (4 bytes)126state = @host_process.memory.read(pointer, 4)127pointer = (pointer + 4)128# Turn the state into human readable form129state = state.unpack('V')[0]130case state131when 0132interface['state'] = 'The interface is not ready to operate.'133when 1134interface['state'] = 'The interface is connected to a network.'135when 2136interface['state'] = 'The interface is the first node in an ad hoc network. No peer has connected.'137when 3138interface['state'] = 'The interface is disconnecting from the current network.'139when 4140interface['state'] = 'The interface is not connected to any network.'141when 5142interface['state'] = 'The interface is attempting to associate with a network.'143when 6144interface['state'] = 'Auto configuration is discovering the settings for the network.'145when 7146interface['state'] = 'The interface is in the process of authenticating.'147else148interface['state'] = 'Unknown State'149end150interfaces << interface151end152return interfaces153end154end155156157