Geolocation of Mac OS assets with wifi_survey in Osquery.

As with most tables in Osquery. You can gleam a whole load more information by joining tables together. Or enriching results with external data sources.

The wifi_survey table is a perfect example of this. We’re given all the data we need in order to work out the exact location of our asset via Google’s geolocation services.

Using wifi_survey to get an assets geolocation.

The wifi_survey table is currently only available for Mac OS as of Osquery 4.6.0. It also goes without saying the asset you’re querying will need a working WiFi card. Which you can check the status of by querying the wifi_status table.

Now onto the wifi_survey table. This table provides you with a full breakdown of all the available WiFi access points that your computer has access too. Including hidden SSIDs.

There are a quite few fields available to you. However, the ones we’re interested in and the ones we’ll be sending to Google via their API are:

  • bssid (mac address)
    This is the remote access points MAC address. Which can actually be used to identify the manufacture of the device. Moreover, the MAC address is used to uniquely identity the device. This information was and still is being collected by Google. As Google identifies devices they also record their location. Which when we send Google a list of MAC address through their API call they can work out where they’ve seen that device before and send us back the geolocation. The rssi and noise help improve the accuracy.
  • rssi (signal strength)
    The current received signal strength indication (dbm). The rssi is a measure of power level that an asset is receiving from the access point. At larger distances, the signal gets weaker. The smaller the value the closer the asset is to the device.
  • noise (signal to noise ratio)
    The current noise measurement — desired signal to the level of background noise. (dBm).

Once you’ve got that data. We can pass the result to Google’s geolocate API. Which you can get a free API key for here:

Its a single API call. Which we’ve put together an example for in Python. Its important that within the wifiAccessPoints key, you provide as many WiFi access points as you can. In order to get the best (accurate) results.

Running this Python code will yield Google’s best effort at a geolocation of the asset. If you’re using the above code example you can wrap the requests.post method in a print statement to get the following:

This geolocation result can then be used further to translate the lat (latitude) and lng (longitude) into a complete street address. This time we’re using the geocode API. Also provided by Google — though you could use others. The same API key can be used.

Which will yield (this repose is quite large and we’ve trimmed the result in our example):

Which of course you can then also use to display the exact location visually using the Google Maps API or embed within your own applications.

Using the wifi_survey table to geolocate assets with Osquery

Its all over!

Hopefully you’ve enjoyed that short post on how the wifi_survey table can be used to geolocate Mac assets. However, that’s all for now. Please feel free to get in touch if you have any questions.

Real-time security and compliance delivered.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store