An osquery deployment can help you establish an infrastructural baseline, allowing you to detect malicious activity using scheduled queries.

This approach will help you catch known malware (WireLurker, IceFog, Imuler, etc.), and more importantly, unknown malware. Let's look at MacOS startup items for a given laptop using osqueryi:

  1. $ osqueryi
  2. osqueryi> SELECT * FROM startup_items;
  3. +--------------+----------------------------------------------------------+
  4. | name | path |
  5. +--------------+----------------------------------------------------------+
  6. | Quicksilver | /Applications/Quicksilver.app |
  7. | iTunesHelper | /Applications/iTunes.app/Contents/MacOS/iTunesHelper.app |
  8. | Dropbox.app | /Applications/Dropbox.app |
  9. +--------------+----------------------------------------------------------+

We see some pretty standard applications that run at boot, like iTunes and Dropbox.

Now imagine this same system is compromised at a later date.

We can use osquery's log aggregation capabilities to easily pinpoint when the attack occurred and what was installed.

Looking at the logs

Using the log aggregation guide, you will receive log lines like the following in your datastore (ElasticSearch, Splunk, etc.):

  1. {
  2. "name": "startup_items",
  3. "action": "added",
  4. "columns": {
  5. "name": "Phone.app",
  6. "path": "/Applications/Phone.app"
  7. },
  8. "hostname": "ted-osx.local",
  9. "calendarTime": "Fri Nov 7 09:42:42 2014",
  10. "unixTime": "1415382685",
  11. "epoch": "314159265",
  12. "counter": "1"
  13. }

It's clear that a suspicious application called "Phone" was added to this host's set of startup items on Nov 7th at 09:42 AM.

Case-study: WireLurker

In November 2015, Palo Alto Networks discovered a new piece of macOS malware called Wirelurker.

If you have osquery deployed, you can search for their static IOCs (indicators of compromise):

  1. SELECT *
  2. FROM launchd
  3. WHERE path = '/Library/LaunchDaemons/com.apple.machook_damon.plist'
  4. OR path = '/Library/LaunchDaemons/com.apple.globalupdate.plist';

Better yet, you can generically detect WireLurker or other persistent malware using launchd and the following scheduled query, which will keep track of new, unique additions to your infrastructure:

  1. SELECT path, label, program_arguments, inetd_compatibility, root_directory
  2. FROM launchd;

This method has the distinct advantage of detecting malicious applications like WireLurker based on their behaviors rather than specific IOCs.