Uptycs Intro To Osquery - Course Slides
Uptycs Intro To Osquery - Course Slides
Go to File, Import Appliance, and point the wizard at the .ova file
(you can copy the file locally first if you want).
After install and start, you can access your virtual box locally via ssh
PART ONE
Why osquery?
Open-source endpoint
Originally developed at Facebook
Ask Questions and Get Answers!
Turns system calls into virtual SQL tables
(Structured Query Language)
Universal Endpoint
Cross-platform
Cross-virtualization (level)
Cross-maturity
Design Principles of osquery
Read Only
Only modifies files needed to run
Polite & respectful of privacy
Developer choice of tables/content
Non-intrusive
user mode, controls impact on machine
osquery_ tables
How to capture events and use _event tables
Add-on Utilities
Augeas, Prometheus, Docker, Extensions and more!
acpi_tables curl etc_protocols launchd plist system_controls
ad_config curl_certificate etc_services launchd_overrides power_sensors system_info
alf device_file event_taps listening_ports preferences temperature_sensors
alf_exceptions device_firmware extended_attributes lldp_neighbors process_envs time
alf_explicit_auths device_hash fan_speed_sensors load_average process_events time_machine_backups
alf_services device_partitions file logged_in_users process_memory_map time_machine_destinations
app_schemes disk_encryption file_events magic process_open_files uptime
apps disk_events firefox_addons managed_policies process_open_sockets usb_devices
apt_sources dns_resolvers gatekeeper mounts processes user_events
arp_cache docker_container_labels gatekeeper_approved_apps nfs_shares prometheus_metrics user_groups
asl docker_container_mounts groups nvram python_packages user_interaction_events
augeas docker_container_networks hardware_events opera_extensions quicklook_cache user_ssh_keys
authorization_mechanisms docker_container_ports hash os_version routes users
authorizations docker_container_processes homebrew_packages osquery_events safari_extensions virtual_memory_info
authorized_keys docker_container_stats interface_addresses osquery_extensions sandboxes wifi_networks
block_devices docker_containers interface_details osquery_flags shared_folders wifi_status
browser_plugins docker_image_labels iokit_devicetree osquery_info sharing_preferences wifi_survey
carbon_black_info docker_images iokit_registry osquery_packs shell_history xprotect_entries
carves docker_info kernel_extensions osquery_registry signature xprotect_meta
certificates docker_network_labels kernel_info osquery_schedule sip_config xprotect_reports
chrome_extensions docker_networks kernel_panics package_bom smbios_tables yara
cpu_time docker_version keychain_acls package_install_history smc_keys yara_events
cpuid docker_volume_labels keychain_items package_receipts startup_items
crashes docker_volumes known_hosts pci_devices sudoers
crontab etc_hosts last platform_info suid_bin
Osquery Files
Binaries: /usr/bin/
osqueryi
osqueryd
Config: /etc/osquery/
osquery.conf
osquery.flags
Database /var/osquery/
osquery.db
Logs /var/log/osquery
osquery.INFO
In depth config docs: https://osquery.readthedocs.io/en/stable/deployment/configuration/
Osquery Flags
There are a LOT of flags – too many to cover here*
--disable_events
event listeners
* https://github.com/facebook/osquery/blob/master/docs/wiki/installation/cli-flags.md
Queries vs Query Packs
you'll hear references to both queries and query packs
PART TWO
setting up the virtual machine
Install Virtual Box (or VMWare Workstation should work as well)
Go to File, Import Appliance, and point the wizard at the .ova file
(you can copy the file locally first if you want).
After install and start, you can access your virtual box locally via ssh
To install
sudo dpkg -i /var/tmp/osquery.deb
To verify
$ osqueryi <enter>
osquery>
osquery> select * from uptime; <enter>
*Otherwise, the best place to start is at https://osquery.io/downloads/
Shockingly Easy (hopefully)
So, that took what, 2 minutes?
osquery> select
...> *
...> from
...> uptime
...> ;
Why Run osquery with sudo?
Try this:
$ sudo osqueryi
What is different? Why?
SQL - Simple Queries
select * from users;
This gets you the one specific row. However, what if you
want all the “systemd” accounts?
SQL - WHERE and LIKE
You can use the LIKE operator and wildcards before or
after a string to find partial matches
Can you figure out how to get the same results using the
directory column?
SQL - JOINing Table Data
Take a look at processes table
You may want to see what the username is for a given process.
uid pid
gid name
uid_signed path
gid_signed cmdline
username state
description cwd
directory root
shell uid
uuid gid
SQL - JOINing Table Data
Both tables have a "uid" column for the user ID number
Let's take the process data we need with user id, and then map
the corresponding user name from the users table.
account_policy_data firefox_addons
authorized_keys known_hosts
browser_plugins opera_extensions
crashes safari_extensions
chrome_extensions shell_history
Date Functions
osquery> .mode line
select local_time from time;
PART THREE
Special Tables
osquery_
_events
"File" tables
Extensions
Special Tables - osquery_
tables that start with "osquery_" are diagnostic tables for osquery
osquery_
events – shows current event publishers and subscribers
extensions – show registered extensions
flags – show all recognized flags, and current status
info – status of current installation
packs – shows any registered query packs
registry – summary of components registered with osquery
schedule – scheduled queries from config & query packs
Special Tables - _events
_events tables do not work like “normal tables”
The file table give information about a file when you do the query
The file_events table gives you information about changes to specific files
and file paths
The carves table gives you the ability to carve files from an operating system
(but not trivial)
Extensions
Extensions are code that runs alongside osquery, but is not a part
of the osquery code
Can be written in Python or Go (and possibly other languages)
Extensions can do all sorts of things – including things that
violate osquery design principles
Extensions can read things that are not in osquery core tables
Extensions can now _WRITE_ to the endpoint, changing configurations
Extensions can allow for the capture of additional forensic data
Uptycs Intro to osquery
PART THREE
Uptycs Intro to osquery
--disable_events=false
--disable_audit=false
--audit_allow_config=true
These can be set from either command line or the flags file.
*https://osquery.readthedocs.io/en/stable/deployment/process-auditing/
Configuring osqueryi to See Events
Take a look at these file:
/etc/osquery/osquery.conf
/etc/osquery/osquery.flags
What is different?
Querying Events
let's refine the events we are looking at
$ less /etc/osquery/osquery.conf
Type ~/Documents/backdoor.sh
(NO PEEKING)
Let's Check File Events
in the osquery terminal, look at osquery_events again
you should now see some file events as well.
processes
process_open_sockets
Let's Investigate Further
What if I told you that almost no service on this server ran on
a high-order port?
(greater than 1024)
(take a look)
Let's Investigate Further
What about process_events?
PART FOUR
Uptycs Intro to osquery
Prometheus exports counters and publishes them to a local API endpoint on a small server it runs.
You can query this API in a table built into osquery.
Node Exporter is a Prometheus module that gathers a large variety of metrics from the
computer in question and publishes them into Prometheus.
Prometheus publishes to
http://localhost:9100/metrics
http://localhost:9090/metrics
You can see the entries telling osquery about this in the
/etc/osquery/osquery.conf file.
Prometheus
let's try to take a look at prometheus in osquery.
PART FIVE
Uptycs Intro to osquery
*https://www.uptycs.com/blog/deploying-osquery-at-scale-a-comprehensive-list-of-open-source-tools
Data over time
If you gather enough data over time using osquery, you can recreate
most of the state of a machine at different points in time.
Your data store and retrieval method has to take this into account.
However, with the same tool you can go back and query in real time.
Osquery and Community
Can osquery become the “Apache for Endpoint?”
One of the top open-source projects for security (as per github)
Facebook has designated some “starter” items for less experienced coders
Contribute a "query pack" (IOC) to find mac (or other) malware
Help improve documentation
Write a blog post about solving a problem w/ osquery and share it
See Uptycs Live!
Want to see how Uptycs can deliver osquery
analytics at scale?
Click here to register for a Live Demo!