Commit Graph

4873 Commits

Author SHA1 Message Date
Nick Anderson
6075f31393 addressing deadlock regression in windows dispatcher threads (#5421)
Summary:
This addresses a slight regression to ensure that we set `set_terminate_threads` on Windows. Without this flag being set, Windows threads will deadlock on exit as the boost managed io service threads never receive termination notifications.

I'm opening this PR up against the old master as I feel we should likely cut a 3.3.3, and I'm happy to re-open this PR against the upstream experimental as well, but we'll want a fix for this released as quickly as possible to Windows deployments.
Pull Request resolved: https://github.com/facebook/osquery/pull/5421

Reviewed By: marekcirkos

Differential Revision: D13972916

Pulled By: muffins

fbshipit-source-id: 55e3b23c80091d5fb51a97d1efc043b52dc48ba3
2019-02-12 12:59:56 -08:00
George Guliashvili
e98f439caf Revert small db optimization
Summary: Revert rocksdb small db optimization for osquery.

Reviewed By: marekcirkos

Differential Revision: D14045578

fbshipit-source-id: baec8f22658844bc202dd099001ea361661d2d72
2019-02-12 12:45:35 -08:00
Jesse Kornblum
5b992021b2 Cleanup grammar, acronyms in CONTRIBUTING (#5432)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5432

This diff makes some minor changes to the CONTRIBUTING file. Specifically:
* Clean up the grammar in a few places for clarity.
* Spell out some acronyms the first time they are used.

There shouldn't be any changes to the actual ideas presented.

Reviewed By: guliashvili

Differential Revision: D14030423

fbshipit-source-id: 9d7e4d7c6cf4853b7f5695919a675b5716d90f19
2019-02-12 06:04:01 -08:00
Alexander Kindyakov
e44cbe0f3f Add thirdparty [boost] dependency to osquery/utils:utils
Summary: It was apparently missed

Reviewed By: guliashvili

Differential Revision: D13991104

fbshipit-source-id: aadc22de6a679e2ede97c483bbedf17d066ea0ae
2019-02-12 04:08:17 -08:00
Alexander Kindyakov
77279b034f linux tracing probes control (#5419)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5419

to load new programs, enable native events and attach program to them.

Reviewed By: SAlexandru

Differential Revision: D13787783

fbshipit-source-id: cfc001da15b343e5c80fd0ab6a276f263aa0ef7a
2019-02-11 03:17:37 -08:00
Alexander Kindyakov
760e877ae5 prototype of osquery/plugin_sdk
Summary:
Build osquery extensions/plugins against all osquery is an apparently bad idea.
Because plugins usually are not require full set of thirdparty libs of osquery. Most of osquery code is also not necesarry for plugins. And the main thing, clear definition of public interface of osquery plugins will force us to keep it clear and short, change it carefully and consciously, crate a tests for it.

Reviewed By: fmanco

Differential Revision: D13990668

fbshipit-source-id: ed6ed3f6f75178d829fc6bcbd1af20ef2e268fa8
2019-02-11 02:33:20 -08:00
Alexander Kindyakov
6ee0fd18ea Do not mess with namaspace which comes from thirdparty library (rapidjson) (#5424)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5424

Let's use `SizeType` definition from rapidjson itself

Reviewed By: marekcirkos, fmanco

Differential Revision: D13986840

fbshipit-source-id: 53b3bf4dcb41c27e2cf18fee3aed97b9e2e42202
2019-02-11 02:33:19 -08:00
Nick Anderson
992d2d3396 ux: adding generated buck config to .gitignore (#5423)
Summary:
As we're expecting to be auto-generating the buck VS toolchain files, we should add this file to the .gitignore, as it'll potentially be system specific.
Pull Request resolved: https://github.com/facebook/osquery/pull/5423

Reviewed By: marekcirkos

Differential Revision: D13973094

Pulled By: muffins

fbshipit-source-id: 98325a4dbe444915d066cd259d9312b09347b080
2019-02-07 09:17:23 -08:00
George Guliashvili
758706331f Remove unused flag enable_monitor
Summary: Removing flag which was declared but never used. enable_monitor

Reviewed By: marekcirkos

Differential Revision: D13958265

fbshipit-source-id: 3a812330950b101abdbd83ada4afd5b262cabd26
2019-02-07 08:16:00 -08:00
George Guliashvili
52ef26e96e Use SQLITE_CONSTRAINT when required constraint does not exist (#5422)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5422

We were just de-prioritizing type of queries not constraining required columns. However, when the query is just useless without specific constraint, sqlite suggestion is to return SQLITE_CONSTRAINT status.

Reviewed By: marekcirkos

Differential Revision: D13964562

fbshipit-source-id: ee0e5f8baf9abbf83c34f7a39d2b5bd705cbac6d
2019-02-07 03:14:38 -08:00
Max Kareta
a2a37fd6a4 added comments for xcode support
Reviewed By: marekcirkos

Differential Revision: D13957835

fbshipit-source-id: 2ffa94728aaaa3a8a9e5a40d36bf6e7c11393e2c
2019-02-05 08:48:47 -08:00
Max Kareta
6ade85a5f3 fixed crash in virtual table implementaion
Summary:
Fixed crash in virtual tables that occurs after following steps:
1. sqlite opens VT with xCreate
2. during query executions invokes xFilter with multiple tables
3. Few tables accumulated in affectedTables
4. xDestroy called before finishing query (last step of query execution)
5. query execution finished, SQL instance try to cleanup affected tables, but they were already destroyed by xDestory

This is only hotfix for this crash and this code base require full memory management review in future

Reviewed By: SAlexandru

Differential Revision: D13917015

fbshipit-source-id: 15396e47e4c4e592cf30608a783bc80d560c776f
2019-02-05 07:20:00 -08:00
Max Kareta
40742aa582 temp solution for xcode support
Summary:
This diff adds Xcode support for osquery.
Part of this diff will be reverted in future after adding prebuilt library and platform deps support to buck.

To use it you need to build osquery in debug mode and then run buck with following flags:
  --config osquery.xcode=true --config project.ide=xcode

Reviewed By: SAlexandru

Differential Revision: D13903315

fbshipit-source-id: 4d131964d7a61236f25d917dc060a2f3c3d782bc
2019-02-05 07:20:00 -08:00
Max Kareta
13dbc5a887 Do not optimize debug builds
Summary: before this diff we were using -O flag, which equals to -O2, and our debug builds were optimized, which make debug much harder

Reviewed By: fmanco

Differential Revision: D13956134

fbshipit-source-id: b358d8fd68c8f5d51ae6d4c2033e7ec3afdd50d2
2019-02-05 04:35:29 -08:00
Max Kareta
e79d0ae5ce add feature that allow to mark tables foreign at build time
Summary:
Not every environment requires all tables, this diff introduce flag that allows you mark table as foreign. New option should be used in conjunction with target filer.

Example:
> buck build ... --config osquery.target_ignore_list="smart" --config osquery.spec_ignore_list="smart/smart_drive_info.table" -- -S

Reviewed By: fmanco

Differential Revision: D13942107

fbshipit-source-id: fb34d6b7a296f69f6b95bf17bfd19cee31b34dec
2019-02-05 04:03:50 -08:00
Max Kareta
0ee22f3172 added feature that allow ignore specific targets during build
Summary:
Not every environment require all osquery feature, with this diff you can specify targets that you want to ignore, together with all sub tree of deps. To use this you need to specify new osquery config like:
  [osquery]
  target_ignore_list="kafka_producer"

Or from command line:
   --config osquery.target_ignore_list="kafka_producer"

This also includes killswitch that force buck to build all targets. This is needed when you have local buckcofig with ignore list and want to build all without modifying config.
  --config osquery.force_build_all=true

Reviewed By: fmanco

Differential Revision: D13941689

fbshipit-source-id: 3c4e1b4cda4d74f33fb914ba2c3a17df4710d5d3
2019-02-05 04:03:50 -08:00
Alexander Kindyakov
51b35f8664 More assertive sanity check for process abs start time column
Summary: We fixed the meaning of `start_time` in previous PR/diffs, let's check it in the integration test.

Reviewed By: SAlexandru

Differential Revision: D13918628

fbshipit-source-id: 60f4ff74eadfbe286dfb325d713389f01142a0f8
2019-02-05 03:50:20 -08:00
Alexander Kindyakov
9d12502139 Fix up start_time column for macos (#5412)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5412

Now on different platforms column `start_time` in `processes` table means different things. On Linux it is seconds since system boot, but it works correct only for some platforms, because the number of clock ticks per second was hardcoded. On windows it was abs unix time in seconds since Epoch. On macos it is a time in milliseconds (may be?) since system boot. On freeBSD as far as I can see it an abs time since boot, but also I'm not sure.

In order to make it consistent for all OS we changed to more convenient format - absolute time since Epoch. This commit is about macos.

Reviewed By: marekcirkos

Differential Revision: D13918625

fbshipit-source-id: eacb297358b36ce72cb0d5a7d9171553688ab2a3
2019-02-05 03:50:20 -08:00
Alexander Kindyakov
84b7f4f7a4 Change semantics of 'start_time' colume in processes table (#5414)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5414

Now on different platforms column `start_time` in `processes` table means different things. On Linux it is seconds since system boot, but it works correct only for some platforms, because the number of clock ticks per second was hardcoded. On windows it was abs unix time in seconds since Epoch. On macos it is a time in milliseconds (may be?) since system boot. On freeBSD as far as I can see it an abs time since boot, but also I'm not sure.

In order to make it consistent for all OS we changed to more convenient format - absolute time since Epoch. This commit is about Linux. Next diffs going to be about Darwin and freeBSD.

Reviewed By: guliashvili

Differential Revision: D13918626

fbshipit-source-id: a9cf0570dc6ac9fa125bc8233e9965c4e01566a6
2019-02-05 03:50:20 -08:00
Alexander Kindyakov
59afbfb3b3 Sanity checks for processess table (#5411)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5411

Just uncommented sanity checks

Reviewed By: guliashvili

Differential Revision: D13918627

fbshipit-source-id: f3b7f406598f81e6ed55c828a7c1df3da810317f
2019-02-05 03:50:19 -08:00
Max Kareta
8e81e5b259 fixed last gtest direct dependency
Summary: Another fix for multiple mains in osqueryd binary

Reviewed By: guliashvili

Differential Revision: D13901871

fbshipit-source-id: 8802bf8a9de6c333b6c592195435071fcc1b57ca
2019-02-05 03:18:49 -08:00
Alexander Kindyakov
00bb3991ec Let's EbpfTracepoint own the ebpf::Program and tracing::NativeEvent (#5418)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5418

Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13787759

fbshipit-source-id: 35bb4b41f7cebfeb91aa848a1583c9eae3e2a363
2019-02-05 02:16:54 -08:00
Alexander Kindyakov
fbd5b99231 Class to join exit-enter event pairs (#5417)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5417

Hash multimap based joiner with ability to perform clean up old unpaired events from time to time.

Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13761675

fbshipit-source-id: f4b17cbeed495b2a9e6616a005f001963849875e
2019-02-05 02:16:54 -08:00
George Guliashvili
6f8b044a4c Use machine identity for monitoring
Summary: For some monitoring, we need to include machine identity. Two example, I found is hostname or similar hostnames schema name.

Reviewed By: SAlexandru

Differential Revision: D13880705

fbshipit-source-id: e1d0238f4981adad1554d73f0ef6e5ef65a98c33
2019-02-04 11:08:32 -08:00
Alexander Kindyakov
344fbed429 Add flipType, isTypeEnter, isTypeExit for the systemcall event types (#5416)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5416

To able to invert type from enter to exit and determine if type is exit or enter.

Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13761673

fbshipit-source-id: 2bf668219fd996d9d5b67e0e1ccf5c1161a41481
2019-02-04 07:56:39 -08:00
Alexander Kindyakov
8871a1a493 Linux eBPF program to track setuid syscall (#5415)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5415

Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13669863

fbshipit-source-id: aadd14734cdc3586526be59f76f3176fa981a57f
2019-02-04 07:56:39 -08:00
Alexander Kindyakov
79cd575790 Make message realated methods of class Error shorter and less diverse (#5410)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5410

 - get rid of *Short* methods
 - getFullMessage -> getNonRecursiveMessage
 - getFullMessageRecursive -> getMessage

Reviewed By: mkareta

Differential Revision: D13897854

fbshipit-source-id: 3e97ceefb2a48a16cd400f7ba7dd730724957ef0
2019-02-01 07:33:53 -08:00
Alexander Kindyakov
da91d8cfe8 to<std::string>() conversion template for c++ enums (#5408)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5408

Move out c++ enums to std::string conversion function from
osquery/utils/error.h to separate module. To be able to use it somewhere else.

Reviewed By: guliashvili

Differential Revision: D13896772

fbshipit-source-id: 0a9f6327d5b2f115ce688446a67677879411eb1f
2019-02-01 07:33:53 -08:00
Alexander Kindyakov
32385bd9ca Hash function for enum classes (#5409)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5409

This is just a ad-hoc fix up to handle libc++ and libstdc++ bug:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
Eventually it will be removed.

Reviewed By: guliashvili

Differential Revision: D13896844

fbshipit-source-id: 38b3cd43b913e5e64d8d9ac40417e6ed0fcb6c41
2019-02-01 03:47:02 -08:00
Max Kareta
188a229d8c fixed double main function
Summary: before this diff osqueryd was relying on linker order to use right main function, since gtest also contains main function

Reviewed By: guliashvili

Differential Revision: D13897622

fbshipit-source-id: d260b7496f513c7052f4db87c8e7ff9300493671
2019-01-31 15:09:12 -08:00
Alexander Kindyakov
ee2756f95c eBPF tracking program for any syscall exit event (#5403)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5403

Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13690684

fbshipit-source-id: 039fc89929de49fcc7bd2287a98ffc68450fcada
2019-01-31 07:37:25 -08:00
Alexander Kindyakov
3719770c06 Linux kill() enter/exit ebpf programs definitions (#5386)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5386

 Part of a linux  tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: SAlexandru

Differential Revision: D13654124

fbshipit-source-id: 8db63e584bd772132c1ba1c80853c60613e8036a
2019-01-31 07:37:25 -08:00
Alexandru Stefanica
4dd69ab2cc use new vs toolchain flag file (#5406)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5406

use new flag file for windows toolchain configuration

Reviewed By: mkareta

Differential Revision: D13859827

fbshipit-source-id: 7560c989e2590663d511b5b644ba6bc3c6b5e5f4
2019-01-31 03:32:32 -08:00
Alexandru Stefanica
a61f527554 automatically generate buck flags for windows (#5405)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5405

this should find where VS is installed and set the buck flags properly.
Have tested on my VM and the paths are ok.  This only works for 2017 and newer (hopefully)
I'm not sure how future proof this is, Microsoft usually changes directory structures randomly.

Reviewed By: muffins

Differential Revision: D13762391

fbshipit-source-id: 894e6a6d5888e13ab646ca9cb4a0d604bcf53ee5
2019-01-31 02:06:46 -08:00
drakearonhalt
e205458be0 Added is_hidden column to the users and groups tables on macOS. (#5368)
Summary:
This PR is the result of the discussion in a previous PR (#5348) after we determined account_policy_data was the wrong place for the column.

Add `is_hidden` column to the users and groups tables in macOS. `is_hidden` is populated by looking for the `dsAttrTypeNative:IsHidden` attribute in the OpenDirectory record for the user/group if the value is `1`, `True`, or `Yes` is_hidden is 1. If the value is anything else it's set to 0. Invalid values have the same affect as the attribute not existing at all.

The `dsAttrTypeNative:IsHidden` attribute controls whether a user account is is visible in the preferences panel similar to having a uid < 500.

One test failed when running buck test:
```
====STANDARD OUT====
tests/integration/tables/helper.cpp:159: Failure
Value of: boost::get<CustomCheckerType>(validator)(value)
  Actual: false
Expected: true
Custom validator of the column "mask" with value "" failed
```
This also fails when I ran the test on the current experimental branch as well.

Important to note I had to remove the optimization on both the user and group tables that just called `getpwnam` if the query specified the `uid` or `gid` since the struct returned doesn't contain the `IsHidden` attribute.  I'm not sure if or how much this will affect performance since I wasn't able to get the profiling to work with the new version (very likely I'm just doing it incorrectly).
Pull Request resolved: https://github.com/facebook/osquery/pull/5368

Differential Revision: D13862375

Pulled By: akindyakov

fbshipit-source-id: 1fec88a6ba71884f7e611e1d96ea00630c5be655
2019-01-30 09:07:56 -08:00
George Guliashvili
5ec525aaed Rename profiler.[cpp|h] to code_profiler.[cpp|h]
Summary: profiler file contained the CodeProfiler class, which is a bit odd. Thanks alecx

Reviewed By: akindyakov

Differential Revision: D13861320

fbshipit-source-id: 11d711fd1d15830d4cce0be084cc6da3b1c6589c
2019-01-30 08:11:21 -08:00
George Guliashvili
7edf72ed6d Split query name and pack name
Summary:
Split query name and pack name with the delimiter(dot) which should not accrue inside their names(instead of _ or -).
Also log things per pack name

Reviewed By: SAlexandru

Differential Revision: D13854471

fbshipit-source-id: 181e7e19fcfb5d57a779cea6a2804eda09dc5a91
2019-01-30 06:50:08 -08:00
George Guliashvili
c7a9338819 Split query name and pack name
Summary:
Split query name and pack name with the delimiter(dot) which should not accrue inside their names(instead of _ or -).
Also log things per pack name

Reviewed By: mkareta

Differential Revision: D13854389

fbshipit-source-id: 35ba80813d98371dd36a83ec32aad677f24aa6eb
2019-01-30 06:50:07 -08:00
George Guliashvili
745758d5cd Allow CodeProfiler to send the same thing for multiple keys
Reviewed By: SAlexandru

Differential Revision: D13844446

fbshipit-source-id: aabdde2aa1e5480868d2363c88891559ce12b4f6
2019-01-30 06:50:07 -08:00
George Guliashvili
11cc046992 Add pack name in the ScheduledQuery
Reviewed By: SAlexandru

Differential Revision: D13859408

fbshipit-source-id: 74ddf8e308aca01df17ec96ce095c0b963740e08
2019-01-30 06:50:07 -08:00
George Guliashvili
87ed5ebd30 Remove duplicated ScheduledQuery
Summary: ScheduledQuery was declared both in query.h and in scheduled_query.h. Let's keep scheduled_query.h only.

Reviewed By: mkareta

Differential Revision: D13859371

fbshipit-source-id: 241b948d21fe619be360037a4e2e52a833a23b2b
2019-01-30 06:50:07 -08:00
Jeremy Calvert
2e31aa40da New QueryDataTyped methods
Summary: In the interest of making changes smaller, I'm replicating stuff around QueryData to QueryDataTyped in intermediate commits.  I'll come back and remove stuff that's no longer used when subsequent changes eliminate use of them.

Reviewed By: guliashvili

Differential Revision: D13741994

fbshipit-source-id: de0b00ddb0ad4b344d68ce799fe9fac759bb6199
2019-01-29 18:12:44 -08:00
Filipe Manco
438a6e1464 Basic ev2 framework (#5401)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5401

Extremely rough implementation of the basic componenets to get things going.

Blueprint issue #5158 .

Reviewed By: akindyakov

Differential Revision: D13779295

fbshipit-source-id: c7373794e8152ffea8a7c5d97f0c937bf97a2a0a
2019-01-29 09:30:20 -08:00
Alexander Kindyakov
e1045be13e Do not run tryTo on invalid string if status is not ok
Summary: Also it causes debug failure on unchecked Expected when status is not ok

Reviewed By: mkareta

Differential Revision: D13859377

fbshipit-source-id: 596410350cb91d469dc0a19f0e8eec558e8627bd
2019-01-29 08:22:47 -08:00
Zachary Wasserman
04f632f16e Fix typo in provision script
Summary: Pull Request resolved: https://github.com/facebook/osquery/pull/5392

Reviewed By: mkareta

Differential Revision: D13838392

Pulled By: guliashvili

fbshipit-source-id: 0ad56503cd9bb0120e4ef669dea02e759131c823
2019-01-28 04:31:02 -08:00
Filipe Manco
aad04ed428 Fix link to expected tests on comment. (#5398)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5398

The file moved to a different location.

Reviewed By: marekcirkos

Differential Revision: D13817331

fbshipit-source-id: 6bd3947894daa712edae84b71502af997947b9b0
2019-01-27 06:53:38 -08:00
George Guliashvili
238b7b00ae sqlite dependency for windows (#5402)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5402

sqlite dependency for windows

Reviewed By: SAlexandru

Differential Revision: D13829704

fbshipit-source-id: 2c35ab214ca3a2b862bbdcef0ae2e619103a6628
2019-01-26 13:04:10 -08:00
Alexander Kindyakov
5744099183 wrapper around perf_event socket to bind ebpf program to some linux event (#5384)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5384

Part of a linux `syscalls` tracing system, blueprint: [#5218](https://github.com/facebook/osquery/issues/5218)

Reviewed By: guliashvili

Differential Revision: D13622999

fbshipit-source-id: 905bbb3a3763fdd6fbe2ba5211f091184275f246
2019-01-25 09:25:18 -08:00
George Guliashvili
c1765ed0f7 Buckify sqlite 3.26.0 (#5396)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5396

Buckify new version of the sqlite.

Reviewed By: marekcirkos

Differential Revision: D13801135

fbshipit-source-id: 0acb5c90c962b114dc2a699cfe84f9264efae336
2019-01-25 07:23:20 -08:00
George Guliashvili
a6069b85bc Remove duplication of the target names (#5391)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5391

Make target names unique

Reviewed By: marekcirkos

Differential Revision: D13785378

fbshipit-source-id: 5bdf02d57ecbf574a1376feb13d07331b43ff89d
2019-01-25 07:23:20 -08:00