Introduction to Osquery Workshop 1 2019 Pass the S ALT Workshop - - PowerPoint PPT Presentation

introduction to osquery workshop 1
SMART_READER_LITE
LIVE PREVIEW

Introduction to Osquery Workshop 1 2019 Pass the S ALT Workshop - - PowerPoint PPT Presentation

Introduction to Osquery Workshop 1 2019 Pass the S ALT Workshop Overview 2 Introduction to Osquery Osquery Basics S QL Refresher Osquery Configuration and Extensions Fleet Management Osquery and Elastic S tack Introductory Workshop! 3


slide-1
SLIDE 1

Introduction to Osquery Workshop

2019 Pass the S ALT Workshop

1

slide-2
SLIDE 2

Overview

Introduction to Osquery Osquery Basics S QL Refresher Osquery Configuration and Extensions Fleet Management Osquery and Elastic S tack

2

slide-3
SLIDE 3

Introductory Workshop!

  • This is an introductory workshop
  • Y
  • u probably won’ t hear/ see a

lot of new things if you have:

  • Already used osquery;
  • Followed S

ANS S EC599, etc.;

  • If you are stuck, please

do not suffer in silence!

3

slide-4
SLIDE 4

Workshop VM

  • ais_workshop_xubuntu-18.04.2-desktop-amd64
  • VMware Workstation, Player, or Fusion
  • Y
  • u can try VirtualBox too, but you are on your own with that…

sorry! 

  • 8 GB RAM
  • 30-50 GB disk space
  • Keyboard layout: EN-US !!!
  • Workshop VM (Ubuntu) user/ pass: user / Workshop1234%
  • Normally, it should not require password for login and sudo

4

slide-5
SLIDE 5

About David

  • Managing partner at Alzette Information S

ecurity (@ AlzetteInfoS ec)

  • Network penetration testing, security architectures, security

monitoring, incident response

  • Instructor at S

ANS Institute: FOR572

  • BS

ides Luxembourg organizer https:/ / bsideslux.lu

  • Twitter: @

DavidS zili

  • E-mail: david.szili@

alzetteinfosec.com

  • Blog: http:/ / j umpespj ump.blogspot.com

5

slide-6
SLIDE 6

Introduction to Osquery

2019 Pass the S ALT Workshop

6

slide-7
SLIDE 7

About Osquery

What is osquery?

  • Build for:
  • S

ecurity

  • Compliance
  • Operations (DevOps)
  • Everything in S

QL!

  • Exposes the operating system as

a relational database

  • Developed by Facebook

Why osquery?

  • (Free) Open S
  • urce S
  • ftware
  • Cross-platform
  • One platform for monitoring
  • Native packages for supported
  • perating systems
  • Large-scale host monitoring or

threat hunting

  • Growing Community

7

slide-8
SLIDE 8

Osquery History

2014 OCT 29: Announcement 2016 SEP 27 / 2016 Oct 4: Osquery for Windows (Trail of Bits) 2018 APR 25: v3.2.4 - First stable release in 3.0.0 series 2019 JUN 28:

  • squery 4.0.0

released

8

slide-9
SLIDE 9

Osquery flavours

Carbon Black LiveOps™

  • sql
  • Osquery open source "soft -fork"

from Trail of Bits

  • https:/ / blog.trailofbits.com/ 2019/

04/ 18/ announcing-the-community-

  • riented-osquery-fork-osql/
  • https:/ / osql.io

9

slide-10
SLIDE 10

Osquery Basics

2019 Pass the S ALT Workshop

10

slide-11
SLIDE 11

Installation

  • Built and signed by the osquery team
  • Uses minimal number of run-time library

dependencies

  • Binaries are a bit big (~20MB)
  • Packages for:
  • macOS
  • Linux (Tarball, RPM, DEB)
  • Windows (MS

I)

  • https:/ / osquery.io/ downloads
  • Alternative downloads: darwin, apt,

yum, freebsd, chocolatey repositories

11

slide-12
SLIDE 12

Getting Help

  • Osquery Documentation
  • https:/ / osquery.readthedocs.io/ en/ stable/
  • Osquery S

lack

  • https:/ / osquery-slack.herokuapp.com/
  • Osquery E-mail (for long-form questions)
  • osquery@

fb.com

  • Osquery Github
  • https:/ / github.com/ facebook/ osquery/ issues

12

slide-13
SLIDE 13

Main Components

  • squeryi
  • Interactive query console
  • Provides an SQL interface
  • Completely standalone, no

communication with a daemon

  • Does not require elevated

privileges (root/ Administrator), but not every table can be queried in this case

  • squeryd
  • Host monitoring daemon
  • Distributed, high-performance,

low-footprint

  • S

chedules queries to be executed across an entire infrastructure

  • Aggregates query results and

generates logs

13

slide-14
SLIDE 14

Osquery S QL and schema

  • S

uperset of S QLite’s S QL

  • SELECT only! (without using

extensions)

  • Y
  • u can still create run-time

tables/ VIEWs

  • "S

QL As Understood By S QLite“ :

  • https:/ / www.sqlite.org/ lang.html
  • Osquery schema documentation:

https:/ / osquery.io/ schema

  • More than 200 tables in total!
  • All platforms: ~40
  • MacOS

: ~160

  • FreeBS

D: ~40

  • Linux: ~130
  • Windows: ~73

14

  • s que r y> . he l p
  • s que r y> . t a bl e s
  • s que r y> . s c he m

a

slide-15
SLIDE 15

Using osqueryi

  • Used for:

1. Developing queries 2. Exploring a single system

  • S

ide note:

  • There is no connection between

interactive and daemon mode

  • However, osqueryi and osqueryd are

the same binary!

  • Y
  • u can run osqueryi in daemon

mode and osqueryd interactively 

  • Linux/ BS

D/ MacOS :

  • $ {sudo} osqueryi
  • Windows:
  • Osqueryi is not in the path by default
  • C:\ProgramData\osquery\osqueryi.exe

{in an Administrator console}

15

slide-16
SLIDE 16

Osquery S hell and S chema Hands-On

2019 Pass the S ALT Workshop

16

slide-17
SLIDE 17

S QL Refresher

2019 Pass the S ALT Workshop

17

slide-18
SLIDE 18

S ELECT (1)

  • SELECT statement
  • FROM: defines input data
  • WHERE: boolean expression evaluated for

each row

  • GROUP BY: Groups the result-set by one or

more columns

  • HAVING: boolean expression evaluated once

for each group (can use aggregate functions)

  • DISTINCT/ALL: no duplicate rows/ all rows

displayed

  • https:/ / www.sqlite.org/ lang_select.html

Operator Description = Equal <> Not equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between a certain range LIKE S earch for a pattern IN S pecify multiple values

18

slide-19
SLIDE 19

S ELECT (2)

  • More on SELECT statement:
  • ORDER BY: the list of expressions

in the ORDER BY determine the

  • rder in which rows are returned
  • ASC: smaller values returned first
  • DESC: larger values returned first
  • LIMIT: upper bound on the number
  • f rows returned
  • OFFSET: the first X number of

rows are omitted from the results

  • Compound S

ELECT S tatements

  • UNION ALL: returns all the rows

from two S ELECTs

  • UNION: like UNION ALL, but

duplicate rows are removed

  • INTERSECT: returns the intersection
  • f the results of two S

ELECTs

  • EXCEPT: Returns the subset of rows

returned by the left S ELECT that are not returned by the right-hand S ELECT

19

slide-20
SLIDE 20

Aggregate Functions

Function Description avg(X) Returns the average value of all non-NULL X within a group count(X) Returns a count of the number of times that X is not NULL in a group count(*) Returns the total number of rows in the group group_concat(X) Returns a string which is the concatenation of all non-NULL values of X group_concat(X,Y) group_concat(X) and Y is used as the separator between instances of X max(X) Returns the maximum value of all values in the group min(X) Returns the minimum non-NULL value of all values in the group sum(X) Returns the (integer) sum of all non-NULL values in the group total(X) Returns the (float) sum of all non-NULL values in the group

20

slide-21
SLIDE 21

JOIN

  • INNER JOIN (or j ust JOIN):

combines column values of two tables based upon the j oin predicate (ON keyword)

  • USING: specifies a list of one or

more columns as a condition

  • NATURAL INNER JOIN:

automatically tests for equality between the values of every column that exists in both tables

  • LEFT OUTER JOIN (or j ust

LEFT JOIN): returns all values from the left table, even if there is no match with the right table

  • ON, USING, NATURAL: works the

same way as in INNER JOINs

  • CROSS JOIN: matches every

row of the first table with every row of the second table

21

slide-22
SLIDE 22

Osquery Complex Query Example 22

  • s que r y> SELECT da t e t i m

e ( l ogge d_i n_us e r s . t i m e , ' uni xe poc h' ) AS da t e t i m e , l ogge d_i n_us e r s . t ype , l ogge d_i n_us e r s . us e r , us e r s . ui d, l ogge d_i n_us e r s . t t y, l ogge d_i n_us e r s . pi d, pr oc e s s e s . na m e AS pr oc e s s _na m e , pr oc e s s e s . pa t h . . . > FROM l ogge d_i n_us e r s . . . > LEFT J OI N pr oc e s s e s USI NG( pi d) . . . > LEFT J OI N us e r s ON us e r s . us e r na m e = l ogge d_i n_us e r s . us e r ; +- - - - - - - - - - - - - - - - - - - - - +- - - - - - - - - - - +- - - - - - - - - - +- - - - - - +- - - - - - +- - - - - - +- - - - - - - - - - - - - - +- - - - - - - - - - - - - - + | da t e t i m e | t ype | us e r | ui d | t t y | pi d | pr oc e s s _na m e | pa t h | +- - - - - - - - - - - - - - - - - - - - - +- - - - - - - - - - - +- - - - - - - - - - +- - - - - - +- - - - - - +- - - - - - +- - - - - - - - - - - - - - +- - - - - - - - - - - - - - + | 2019- 03- 26 21: 35: 00 | boot _t i m e | r e boot | | ~ | 0 | | | | 2019- 03- 26 21: 35: 13 | l ogi n | LOGI N | | t t y1 | 834 | a ge t t y | / s bi n/ a ge t t y | | 2019- 03- 26 21: 35: 14 | us e r | us e r | 1000 | t t y7 | 1248 | s h | / bi n/ da s h | | 2019- 03- 26 21: 35: 39 | r unl e ve l | r unl e ve l | | ~ | 53 | | | +- - - - - - - - - - - - - - - - - - - - - +- - - - - - - - - - - +- - - - - - - - - - +- - - - - - +- - - - - - +- - - - - - +- - - - - - - - - - - - - - +- - - - - - - - - - - - - - +

slide-23
SLIDE 23

Osqueryi Hands-On

2019 Pass the S ALT Workshop

23

slide-24
SLIDE 24

Osquery Configuration and Extensions

2019 Pass the S ALT Workshop

24

slide-25
SLIDE 25

Using osqueryd

  • Osqueryd is the host monitoring

daemon

  • It aggregates query results over

time and generates logs

  • Allows to:

1. S chedule queries 2. Record OS state changes, including file and directory changes, hardware events, network events, etc.

  • Configuration and query schedule
  • Logging and reporting
  • Query Packs

25

{ " os que r y_i nf o" : { " que r y" : " SELECT * FROM

  • s que r y_i nf o; " ,

" i nt e r va l " : 300, " s na ps hot " : t r ue } }

slide-26
SLIDE 26

Flags and Flagfile

  • Osqueryi and osqueryd use
  • ptional command line

(CLI) flags to:

  • Control initialization
  • Disable/ enable features
  • S

elect plugins

  • List of flags:

https:/ / osquery.readthedocs.io/ en/ stable/ installation/ cli-flags/

  • Flagfile: flags can be set

within environment variables

  • r via a "master" flag file

26

  • - t l s _hos t na m

e =ws - vm

  • - t l s _s e r ve r _c e r t s =C: \ Pr ogr a m

Da t a \ os que r y\ ws - vm . pe m

  • - hos t _i de nt i f i e r =uui d
  • - e nr ol l _t l s _e ndpoi nt =/ a pi / v1/ os que r y/ e nr ol l
  • - c onf i g_pl ugi n=t l s
  • - c onf i g_t l s _e ndpoi nt =/ a pi / v1/ os que r y/ c onf i g
  • - c onf i g_t l s _r e f r e s h=10
  • - di s a bl e _di s t r i but e d=f a l s e
  • - di s t r i but e d_pl ugi n=t l s
  • - di s t r i but e d_i nt e r va l =10
  • - di s t r i but e d_t l s _m

a x_a t t e m pt s =3

  • - di s t r i but e d_t l s _r e a d_e ndpoi nt =/ a pi / v1/ os que r y/ di s t r i but e d/ r e a d
  • - di s t r i but e d_t l s _wr i t e _e ndpoi nt =/ a pi / v1/ os que r y/ di s t r i but e d/ wr i t e
  • - l ogge r _pl ugi n=t l s
  • - l ogge r _t l s _e ndpoi nt =/ a pi / v1/ os que r y/ l og
  • - l ogge r _t l s _pe r i od=10
  • - e nr ol l _s e c r e t _pa t h=C: \ Pr ogr a m

Da t a \ os que r y\ os que r y. s e c r e t

slide-27
SLIDE 27

Configuration

  • Osquery "configuration" is read

from a config plugin

  • S

et to filesystem by default

  • HTTP/ TLS

request using the tls config plugin

  • The response data must be in

JSON format

  • Configuration details:

https:/ / osquery.readthedocs.io/ en/ st able/ deployment/ configuration

  • Components in a configuration include
  • Daemon options and feature settings
  • Query Schedule: the set of S

QL queries and intervals

  • File Change Monitoring: categories and paths of

monitored files and directories

  • Filesystem config plugin default locations:
  • Windows: C:\ProgramData\osquery\osquery.conf
  • Linux: /etc/osquery/osquery.conf and

/etc/osquery/osquery.conf.d/

  • MacOS

: /var/osquery/osquery.conf and /var/osquery/osquery.conf.d/

27

slide-28
SLIDE 28

Packs

  • Configuration supports sets of

queries called packs

  • Packs are distributed with
  • squery and labeled based on

broad categories

  • In an osquery configuration JSON
  • Packs can be defined as a top-

level-key and consist of pack name to pack content JS ON data structures

  • Pack value may also be a string. In

case of the filesystem plugin, these strings are considered paths.

28

{ " opt i ons " : { " e na bl e _m

  • ni t or " : " t r ue “

}, " pa c ks " : { " os que r y- m

  • ni t or i ng" : {

" que r i e s " : {. . . } }, " i nc i de nt - r e s pons e " : { " que r i e s " : {. . . } } } } { " opt i ons " : { " e na bl e _m

  • ni t or " : " t r ue “

}, " pa c ks " : { " os que r y- m

  • ni t or i ng" : " / us r / s ha r e / os que r y/ pa c ks / os que r y- m
  • ni t or i ng. c onf " ,

" i nc i de nt - r e s pons e " : " / us r / s ha r e / os que r y/ pa c ks / i nc i de nt - r e s pons e . c onf “ } }

slide-29
SLIDE 29

Logging

  • Osqueryd uses logger plugins:
  • filesystem (default)
  • tls
  • syslog (for POS

IX),

  • windows_event_log (for Windows)
  • kinesis
  • firehose
  • kafka_producer
  • Log types: status and result logs
  • Status logs:
  • Generated by the Glog logging framework
  • Logger plugins may intercept these
  • Results logs: Results of scheduled

queries are logged to the "results log"

  • Differential logs: Differential changes

between the last (most recent) query execution and the current execution

  • Snapshot logs: A snapshot is an 'exact

point in time' set of results, no differentials

29

slide-30
SLIDE 30

Eventing Framework

  • Scheduled queries have limitations
  • Volatile events like process

execution

  • To overcome this, osquery has the

Eventing (pubsub) Framework

  • Aggregating operating system

information asynchronously at event time

  • S

toring related event details in the

  • squery backing store
  • Performing a lookup to report

stored rows query time

  • Almost every pubsub-based table

ends with a _events or _changes

  • Note that this reporting pipeline

is much more complicated!

1) Requires additional configuration 2) As events occur, the rows returned by a query will compound, so queries should always include a time range 3) The buffered events will eventually expire! Buffer is set to 1 day by default 4) Eventing Framework will not really work with osqueryi

30

slide-31
SLIDE 31

Eventing Framework Example

File Integrity Monitoring

  • Available for Linux and Darwin
  • The list of files/ directories to monitor is

defined in the osquery configuration

  • Can use standard wildcards "*" or S

QL-style wildcards "% “ for the path definitions

  • %

: Match all files and folders for one level

  • %

% : Match all files and folders recursively

31

{ " s c he dul e " : {. . . }, " f i l e _pa t hs " : { " hom e s " : [ " / r oot / . s s h/ % % " , " / hom e / % / . s s h/ % % “ ] , " e t c " : [ " / e t c / % % “ ] }, " e xc l ude _pa t hs " : { " hom e s " : [ " / hom e / us e r / . s s h/ % % “ ] } }

slide-32
SLIDE 32

Extensions

  • Osquery supports proprietary

tables, config plugins, and logger plugins

  • Thrift-based extensions API
  • Osqueryd may "autoload" these

extensions and monitor their performance

  • Trail of Bits extensions:
  • https:/ / github.com/ osql/ extensions
  • CLI flags for extension auto-loading:
  • Extensions.load file example

(osquery.ext is an executable):

  • Manually Loading Extensions:

32

S

  • urce: https:/ / osquery.readthedocs.io/ en/ stable/ deployment/ extensions/
  • - e xt e ns i ons _a ut ol oa d=/ e t c / os que r y/ e xt e ns i ons . l oa d
  • - e xt e ns i ons _t i m

e out =3

  • - e xt e ns i ons _i nt e r va l =3

/ us r / l i b/ os que r y/ e xt e ns i ons / os que r y. e xt

  • s que r yi

{- - a l l ow_uns a f e } - - e xt e ns i on / pa t h/ t o/ e xt e ns i on. e xt

slide-33
SLIDE 33

Osquery Configuration and Extensions Hands-On

2019 Pass the S ALT Workshop

33

slide-34
SLIDE 34

Fleet Management

2019 Pass the S ALT Workshop

34

slide-35
SLIDE 35

Fleet Management Options 35

  • Kolide Fleet: https:/ / kolide.com/ fleet
  • (Free) Open S
  • urce S
  • ftware from Kolide: https:/ / github.com/ kolide/ fleet
  • Paid: Kolide Cloud (S

aaS )

  • Doorman: https:/ / github.com/ mwielgoszewski/ doorman
  • (Free) Open S
  • urce S
  • ftware from Marcin Wielgoszewski
  • S

TG: https:/ / github.com/ OktaS ecurityLabs/ sgt

  • (Free) Open S
  • urce S
  • ftware from Okta
  • "Built Entirely on AWS

"

  • (osquery-fleet?

: https:/ / github.com/ sandstorm/ osquery-fleet)

slide-36
SLIDE 36

About Kolide Fleet (and Kolide Launcher) 36

  • Open S
  • urce Osquery Manager
  • Compatible with every maj or platform
  • Designed to work with Launcher

(Osqery deployment)

  • Features:
  • Query dynamic sets of hosts
  • Run queries repeatedly with Packs
  • Create labels populated with hosts

matching a query

  • Export results
  • fleetctl: provides scriptable, CLI based

access to osquery on your entire fleet

slide-37
SLIDE 37

Kolide Fleet Installation and Configuration

1) Install and configure MyS QL 2) Install Redis 3) Generate TLS certificate for Kolide Fleet server 4) Install Kolide Fleet (https:/ / dl.kolide.co/ bin/ fleet_latest.zip) 5) Configure Kolide Fleet

a) Create fleet.config b) Create MyS QL database c) Create fleet.service

6) S tart Kolide Fleet

37

slide-38
SLIDE 38

Kolide Fleet Interface and Deployment 38

slide-39
SLIDE 39

Kolide Fleet Hands-On

2019 Pass the S ALT Workshop

39

slide-40
SLIDE 40

Osquery and Elastic S tack

2019 Pass the S ALT Workshop

40

slide-41
SLIDE 41

Filebeat Configuration 41

  • Filebeat osquery module can be used
  • JS

ON messages can be sent to:

  • Elasticsearch
  • Logstash
slide-42
SLIDE 42

Logstash Pipeline Configuration

  • Logstash file needs to be

placed to:

  • / etc/ logstash/ conf.d/
  • / etc/ logstash/ logstash.yml

has:

  • config.reload.automatic: true
  • config.reload.interval: 5s

42

slide-43
SLIDE 43

Kibana Discovery 43

slide-44
SLIDE 44

Osquery and Elastic S tack Hands-On

2019 Pass the S ALT Workshop

44

slide-45
SLIDE 45

Questions and Answers

2019 Pass the S ALT Workshop

45

slide-46
SLIDE 46

References

  • Osquery Website and Osquery S

chema

  • https:/ / osquery.io
  • https:/ / osquery.io/ schema
  • Osquery Docs
  • https:/ / osquery.readthedocs.io
  • Kolide Website
  • https:/ / kolide.com
  • Elastic Website
  • https:/ / www.elastic.co

46