Commit Graph

214 Commits

Author SHA1 Message Date
Zach Wasserman
d2d904f59f
Allow table info PRAGMAs (#6814)
Set up an allowlist for PRAGMA commands in the authorizer. Allow the
PRAGMAs for listing table schema and available functions.
2020-12-17 22:13:24 -05:00
Zach Wasserman
c3f9a3dae2
Merge pull request from GHSA-4g56-2482-x7q8
* Proposed fix for attach tables vulnerability

* Add authorizer to ATC tables and cleanups

- Add unit test for authorizer function
2020-12-14 15:41:57 -05:00
Stefano Bonicatti
35417f589b
Remove boost workaround introduced in #5591 for string_view (#6771) 2020-11-29 15:13:03 +01:00
Stefano Bonicatti
e96a963dfa
Do not use memset on VirtualTable, a non-POD type (#6760)
Reported by cppcheck:
[osquery/sql/virtual_table.cpp:557]: (error) Using 'memset' on struct that contains a 'std::shared_ptr'
2020-11-24 13:49:03 -05:00
Teddy Reed
14804127d8
Reduce linkage requirements for tests (#6715) 2020-10-18 10:47:00 -04:00
Teddy Reed
aa27b07ed2
carver: Refactor carver to use the Scheduler (#6671) 2020-10-14 13:26:39 -04:00
Teddy Reed
8e504ff814
Add broad exception catching for table execution (#6689) 2020-10-04 11:36:36 -04:00
Teddy Reed
18319be84c
carver: Emit an error if the carve function is disabled (#6658) 2020-09-21 19:30:04 -04:00
Teddy Reed
5b8f20bfce
refactor: Move ephemeral database plugin into core and simplify tests (#6648) 2020-09-21 18:25:08 -04:00
Teddy Reed
b36678d707
refactor: Rename database APIs to not use DatabasePlugin class (#6620) 2020-08-31 22:45:43 -04:00
Teddy Reed
160ac6c906
refactor: Change the include path for osquery/core/plugins (#6619) 2020-08-29 20:24:39 -04:00
seph
29f4694df2
Update copyright notices (#6589)
Bulk update copyright notices from Facebook to "The osquery authors"
2020-08-11 16:46:54 -04:00
Teddy Reed
8ee7e3a3b0
refactor: Move osquery/include files to appropriate places (#6557) 2020-08-11 11:54:54 -04:00
Teddy Reed
1f5645f7f1
tables: Refactor shell_history to use generators (#6541) 2020-07-13 22:21:39 -04:00
Ted Reed
5cd2d6cbd3 detangle: Move platform setup and teardown out of Initializer 2020-07-09 10:38:53 -04:00
Ted Reed
3fbe55a108 detangle: Move tooltype setter and getters out of Initializer 2020-07-09 10:38:53 -04:00
Teddy Reed
25eb7b3aae
tables: Only populate table cache with star-like selects (#6513) 2020-06-24 22:00:34 -04:00
seph
f54d904b21
Update some sqlite types (#6392)
Correct SQL data types.
2020-04-28 14:01:39 -04:00
Stefano Bonicatti
52f310a5a8
First steps to remove the Buck build system (#6361)
* First steps to remove the Buck build system

* Azure Pipelines: Rename jobs for consistency
2020-04-09 01:56:21 +02:00
Breakwell
893744238b
Return error detaching table, only use primary database (#6373) 2020-04-08 19:47:53 -04:00
Breakwell
b35d968876
Remove errors when converting empty numeric rows (#6371) 2020-04-08 18:59:19 -04:00
Stefano Bonicatti
ef2763afbc
Hotfix a use-after-free accessing rows data (#6328)
When a query triggers multiple xFilter calls
and there's an operation that has to work on the sum of rows
resulting from all those calls, we trigger a use-after-free
when such operation tries to access the rows data.

This happens because each xFilter call we clear the rows
resulting from the previous xFilter call, and because
when returning the values of a text column we don't copy it,
but return a pointer to it.

A contrived example of a query with the issue is:
SELECT path=count(*) FROM file WHERE path = '/' OR path = '1'

This changes the last sqlite3_result_text parameter
from SQLITE_STATIC to SQLITE_TRANSIENT.

Addresses https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20833
2020-03-26 22:17:13 -04:00
seph
ae66d8f3bc
Add path to ATC generated specs (#6278)
Add the `path` column to the ATC generate specs. This matches the existing data, as it is already includes in the returned rows.
2020-03-01 08:42:21 -05:00
Oleg Dolgov
d3a10a33e7
check for errors return status from extension table. (#6108) 2020-02-28 11:03:04 -05:00
Stefano Bonicatti
edf5de0a28
Limit regex_match and regex_split regex size (#6267)
* Limit regex_match and regex_split regex size

Add a new HIDDEN_FLAG, regex_max_size, with a default of 256 bytes,
which limits the size of the regex that can be used
with regex_match and regex_split SQL functions.

This is done since it's possible to create a regex
which makes the std::regex destruction go into a stack overflow,
due to too many alternate states (|).

Add a couple of tests to verify that the limit is correctly respected.

Restore the test for regex_split that was originally hanging when using
boost.
2020-02-27 01:37:49 +01:00
Zachary Wasserman
c296693bd5
Add community_id_v1 hash function to SQLite (#6211)
Implements the Community ID hash that will allow correlating network connections detected by osquery with other tools that support the standard (Zeek, Suricata, etc.).
2020-02-08 11:16:30 -05:00
Stefano Bonicatti
9f30fd3f57
Fix heap buffer overflow in callDoubleFunc and powerFunc (#6225)
sqlite3_result_error() third parameter is the length
of the string of the second parameter, not the error code.

We set that to -1, which means that the length of the string
will be taken using strlen().

Addresses https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18694
2020-02-05 15:09:09 -05:00
scoders-tob
ccffaf7d8a
replacing boost::regex with std::regex for SQL StringExtensions (#6227) 2020-02-05 15:08:45 -05:00
calve
600f21dcfb flags: Implement enable_tables (#6150)
Adds an ``--enable_tables`` CLI flag to specify a limited set of
tables to expose. This is the contrary of ``--disable_tables``.
2020-01-17 18:59:20 -05:00
Teddy Reed
2933614301
tables: Remove INDEX requirement for ADDITIONAL option (#6104)
We do not need an explicit INDEX column for ADDITIONAL to work.
If the ADDITIONAL option is set the constraint should be passed
into the virtual table context.
2019-12-10 15:43:35 -05:00
Teddy Reed
d3959d578d
tables: Re-enable required-column warning message (#6038) 2019-11-19 00:24:53 -05:00
packetzero
de54b643e5 extensions compatibility : default columns to INDEX (#6006)
Recent changes in INDEX enforcement broke extensions.

This fix adds a compatibility flag that defaults to the old behavior of INDEX on all columns.
This only affects extension virtual tables, all built in tables have index constraints enforced.
2019-11-12 13:40:48 -05:00
Teddy Reed
c964db2a49
logging: Change logNumericsAsNumbers to numerics and add docs (#6002)
This is an API change for the format of logged events.
The top-level log field "logNumericsAsNumbers" was introduced to help
migrate from string-encoded numerics to JSON numbers.

This change updates the field to be "numerics", updates the flag to
conform to flag naming conventions, and documents the expectation.
2019-11-09 13:29:14 -05:00
packetzero
08e0b9078b Fix WHERE in(N items) results in table query running N times (#5924) 2019-10-26 10:33:56 -04:00
howar6hill
ebbc12a94a remove the value_max flag (#5926) 2019-10-25 19:30:43 -04:00
Teddy Reed
13290ed7ac
leak: Fix memory leak when SQL query fails (#5911)
There is a memory leak when a SQL statement is evaluated and returns an
error while stepping. An example includes returning sqlite3_result_error
from regexStringMatchFunc. The root cause is not finalizing a prepared
statement.
2019-10-20 14:59:07 -04:00
Alessandro Gario
6481b34e23
Refactor third-party libraries to build from source on Linux (#5706)
Add a way to compile third-party libraries from source instead of downloading prebuilt ones.
Each library source code is downloaded with git into a submodule at configure time,
in response to the find_package(library_name) CMake call,
except for OpenSSL where the official source archive is used.
Each submodule is attached to a release tag on its own upstream repository.
All the libraries are built using CMake directly, except for OpenSSL which uses a formula system,
which permits to build libraries with a separate build system
when there's no easy way to integrate it directly with CMake.

This new dependency system determines which library is fetched from where using the concept of "layers".
Currently we have three of them: source, formula, facebook,
where the last layer represents the pre-built libraries.
The provided order will be used when looking for libraries.

A system to patch submodule source code has been added and it's currently used with googletest, libudev and util-linux.
Patches should be put under libraries/cmake/source/<library name>/patches/<submodule>,
where <submodule> is often one and is "src", but in other cases, like AWS,
there are multiple with a more specific name.
If for whatever reason the submodule cloning or the patching fails,
the submodule has to be unregistered and its folder should be cleared.
This should be achievable with "git submodule deinit -f <submodule path>"

Following some other changes on existing functionality:

- Changed the CMake variable BUILD_TESTING to OSQUERY_BUILD_TESTS
  to avoid enabling tests on third party libraries.
  Due to an issue with glog the BUILD_TESTING variable
  will be always forced to OFF.
- Moved compiler and linker flags to their own file cmake/flags.cmake
- Moved all the third-party CMakeLists.txt used for pre-built libraries under libraries/cmake/facebook
- Added the --exclude-folders option to tools/format-check.py and tools/git-clang-format.py,
  so that it's possible to ignore any third party library source code.
- The format and format_check target use the new --exclude-folders option
  to exclude libraries/cmake/source from formatting.
- The test and osquery binaries are properly compiled with PIE (osquery/osquery#5611)

Co-authored-by: Stefano Bonicatti <stefano.bonicatti@gmail.com>
Co-authored-by: Teddy Reed <teddy@casualhacking.io>
2019-08-30 16:25:19 +02:00
seph
7a96a9660e sql function regex_match (and some tests for other sql functions) (#5444) 2019-08-14 11:51:21 -04:00
Matteo Piano
880f003a09 allow mounting SQLite DBs using WAL journaling with ATC 2019-07-17 10:12:48 -07:00
Stefano Bonicatti
942878854b Add CMake support
Taken from osql-experimental.

- Change CMake code license to the one present in osquery right now

- Package metadata doesn't mention Trail of Bits or osql anymore

- Set specific ACLs for the osqueryd on Windows when packaging

- Remove LLVM_INSTALL_PATH support on macOS, since we are using AppleClang

- Remove OSQUERY_SOURCE_DIR variable need and source in a submodule support

- Add targets format_check and format to check code formatting and
  format it with clang-format

- Do not warn about not using Clang on macOS when using AppleClang
2019-06-26 21:49:06 -04:00
Alessandro Gario
33fbbecb5f Initial commit
Taken from osql-experimental.

Initial support for Linux and macOS.
2019-06-26 21:49:06 -04:00
Ted Reed
b938ff11e5 Fix sqlite API usage errors (#5551)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5551

This handles exceptional error cases when using SQLite APIs in MacOS's Gatekeeper inspection and in osquery's added SQLite functions.

Reviewed By: marekcirkos

Differential Revision: D14641507

fbshipit-source-id: ac5ba661966ab374ef6bb33676b73c365278864a
2019-03-31 11:56:03 -07:00
Jesse Kornblum
9f58f0cc0a Use Status::success throughout osquery (#5542)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5542

We replace deprecated calls to the Status class with newer ones. This will stop Lint from nagging me every time I open these files. There should be no change to functionality.

Specifically, we use a codemod on `.cpp` files to replace any instance of `return Status();` with `return Status::success();`.

Reviewed By: guliashvili

Differential Revision: D14652922

fbshipit-source-id: 243576195ed201d6b82fc942a785742c6b01cf83
2019-03-29 04:28:39 -07:00
Jeremy Calvert
c8bb439442 OSQueryd changes for encoding type in JSON syntax
Summary:
Add log_numerics_as_numbers flag.

Internal SQLite query has method that returns QueryDataTyped (instead of QueryData), which are boost::variant<string, double, long long>.

Ints are encoded as such if and only if new log_numerics_as_numbers flag is set to true.

Reviewed By: fmanco

Differential Revision: D13778323

fbshipit-source-id: 7d7bb31781486f63fcc088cd479d3b6f255a5cb4
2019-03-04 09:15:21 -08:00
Filipe Manco
d14fd5d538 Move plugins to a separate directory [5/?] (#5483)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5483

Initial steps to separate plugins from the rest of osquery. On the long run separating plugins will provide more build flexibility such that we can have configurable builds that include only the bits and pieces we actually need per deployment. Reducing the attack surface, possibility of supply chain attacks, binary size, etc.

Move killswitch

Reviewed By: guliashvili

Differential Revision: D14259760

fbshipit-source-id: deaaa148fac25b3f534a8881a1ea9eda0ec6bdc9
2019-03-02 04:23:06 -08:00
Jesse Kornblum
ecbc65cf39 Replace Status(0) calls with Status::success() to appease Lint (#5487)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5487

I got tired of Lint telling me to update the calls to the Status class, so I wrote some codemods to update the vast majority of them:

  $ cd ~/fbsource
  $ codemod -d xplat/osquery/oss/osquery --extensions cpp,h "return Status\(0\, \".*\"\);" "return Status::success();"

**Blindly accepted all changes**.

FWIW, I tried to do something similar with the failure return values, but the unit tests were failing afterward.

Reviewed By: guliashvili

Differential Revision: D14278739

fbshipit-source-id: b023f6e969be697eeb67d66ea3ad10d16c69ff0c
2019-03-01 04:29:33 -08:00
Alexander Kindyakov
b7d635ec2b remove thrift_impl from osquery plugin_sdk
Summary: To be able to build with different `thrift_impl` modules in extensions (like facebook does with fbthrift) I removed implementation from `extensions` lib and explicitly used for `osqueryd` and for all tests. This allows us to remove `thrift_impl` from sdk dependencies list. If you need it - please use explicitly as I did for `osqueryd`. If you want to use your own implementation of `thrift_impl` - build it and link against it and sdk simultaneously.

Reviewed By: marekcirkos

Differential Revision: D14224206

fbshipit-source-id: 218dc05d87e1ffaca37783185fc672a20684d757
2019-02-26 11:20:08 -08:00
Jeremy Calvert
67447bbd96 Custom cast so that 0.0 as a double casts as "0.0"
Summary:
This fixes a regression introduced in D13586036 .

The tailer downstream sometimes determines type by trying to parse the string as an int.  We want this to consistently fail to do so when the value is in fact a float.

Reviewed By: SAlexandru

Differential Revision: D14161125

fbshipit-source-id: 8e2bb9c59559a5774813a7c7777257742f885c35
2019-02-22 10:23:07 -08:00
Jesse Kornblum
c7355b19aa Update osquery licensing wording (#5452)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5452

As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of

//This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.//

to

//This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.//

We accomplish this with a codemod:

  $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree."

Reviewed By: fmanco

Differential Revision: D14131290

fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
2019-02-19 10:59:48 -08:00
Filipe Manco
be07c2938a Move plugins to a separate directory [1/?]
Summary:
Initial steps to separate plugins from the rest of osquery. On the long run separating plugins will provide more build flexibility such that we can have configurable builds that include only the bits and pieces we actually need per deployment. Reducing the attack surface, possibility of supply chain attacks, binary size, etc.

Move config and config_parser plugins

Reviewed By: marekcirkos

Differential Revision: D14119102

fbshipit-source-id: 0bc956398b3829c6f1013b38ebba2f0fc1071a93
2019-02-19 00:55:27 -08:00