Commit Graph

3079 Commits

Author SHA1 Message Date
seph
bf7e9f5c96
Don't return a battery row, if there are no results (#5650)
If there are no battery results, don't return a nil row. Return an empty set.
2019-07-20 21:23:05 -07:00
Stefano Bonicatti
9cf33c84f8 Restore AugeasTests test
PR: osquery/osquery#5629
2019-07-19 22:36:40 +02:00
Stefano Bonicatti
c56020cac3 Restore WindowsEventLogTests test
PR: osquery/osquery#5629
2019-07-19 22:36:40 +02:00
Stefano Bonicatti
36bb0b8b1e Restore ProcessTests test
Also add the same process name checks done on Windows to Linux.

PR: osquery/osquery#5629
2019-07-19 22:36:40 +02:00
Stefano Bonicatti
55e066322c Restore RegistryTablesTest test
PR: osquery/osquery#5629
2019-07-19 22:36:40 +02:00
seph
d10dab8443
Update WTSFreeMemoryEx to WTSFreeMemory (#5642)
Change `WTSFreeMemoryEx` to `WTSFreeMemory` as documented.

More context in:
- https://github.com/osquery/osquery/issues/4655
- http://redplait.blogspot.com/2018/06/interesting-case-of-memory-leak.html

Thanks for the bug report (redplait)[https://github.com/redplait]
2019-07-19 09:51:18 -07:00
Matteo Piano
880f003a09 allow mounting SQLite DBs using WAL journaling with ATC 2019-07-17 10:12:48 -07:00
uptycs-nishant
e5eb30ea5f Replacing sync calls by async ones and some cleanup (#5606) 2019-07-16 18:22:30 -07:00
Mark Mossberg
a60b940290 windows/certificates: Fix enumeration bugs, add columns (#5631)
* Initial implementation

* Use case insensitive comparisons for all service names

Fixes a bug where certificates for services that correspond to Local Service or
Network Service may not have their sids appear correctly. This is because the
services table is inconsistent with its user_account column.

* Make service name cache query-local

Previously, the service name cache existed for the lifetime of the
osquery process, which made it susceptible to stale reads if a service
restarted under a different user during osquery's lifetime. Now the
cache is created for each query. Also refactor it to directly map to the
sid, rather than the account name, which removes the need to translate
from account name to sid every row.

* Fix reference to destroyed object

Previously, getCurrentUserInfo took a reference to data from a local
vector, whose data is free'd after the function. This refactors the code
to use a unique_ptr (similar to how getSidFromUsername) does it.
2019-07-16 17:34:39 +02:00
Stefano Bonicatti
2f681e7bdc Fix SystemsTablesTests.test_abstract_joins
The code was failing on Windows because the '\Windows\%' pattern
is relative and presumes that the Windows folder is on the same
drive (C:\) as the test process.
This might not be true, so we find where precisely is the Windows
directory and use the full path to it as a pattern.

The failing test checks that were testing the equal and LIKE operator
have been moved to a new test, test_table_constraints, since they
are not related to joins.
2019-07-09 12:59:45 +02:00
Stefano Bonicatti
65aa1cfa3f Fix several integer conversions in process_ops
Fix UsersTest.test_sanity on Windows.

uid and gid were returned as int (while they normally are unsigned int)
and converted to signed integers in the table row.
This is wrong because beyond uid and gid not being ints,
they are taken from the RID part of the SID which in some cases,
like for a Service SID, it can have a value higher than then maximum
value of an int, so in the end the number shown in table is negative.

Now they are returned as uint32_t and converted as BIGINTs for the table
that uses them.

Fix other functions return values and conversions depending on the meaning of
the value.
On Windows stick to its specific types where possible.

Convert CRLF to LF on some of the files modified.
2019-07-09 12:59:45 +02:00
Gustavo Grieco
cc1693a805 Fix typo in base64 log message (#5622) 2019-07-03 01:34:25 +02:00
Stefano Bonicatti
e7fde8ad8e Fix wrong error code returned when querying the Windows registry (#5621)
Calling GetLastError() will not return the error code for the Windows registry APIs,
since they return a LSTATUS value which already the error code.

This also fixes the RegistryTablesTest.test_registry_non_existing_key
test case which was incorrectly expecting success when querying
for a non-existent registry key.

Ported from https://github.com/osql/osql/pull/50
2019-07-01 22:23:02 +02:00
Will-Low
ae25976afd Fixing port logic (#5576) 2019-06-28 08:31:25 -04:00
Stefano Bonicatti
826723c29a Fix boost asio string_view detection hack
Only define BOOST_ASIO_DISABLE_STD_STRING_VIEW.

We shouldn't define BOOST_ASIO_HAS_STD_STRING_VIEW,
because even if we define BOOST_ASIO_DISABLE_STD_STRING_VIEW
the first define will actually enable parts of code that will use string_view.
This won't work on Windows and in general, string_view should not be
used unless compiling with C++17.

The hack has been also added to a test that was previously missed.
2019-06-26 21:49:06 -04: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
Teddy Reed
e6fe15eb49
macos: Add hack for boost asio string_view detection (#5592) 2019-06-23 01:05:42 -04:00
Nick Anderson
214302bdeb
windows: updating more references to osquery installation path (#5580) 2019-06-05 12:45:40 -07:00
Alexander Kindyakov
c55eb57e40 Unify namspaces in events experimental module
Summary:
osquery::experimental::tracing -> osquery::events
osquery::experimental::events -> osquery::events

That's already a bit messy, let's put some order.

Reviewed By: guliashvili

Differential Revision: D14722735

fbshipit-source-id: 02b7e8199e7153e3aeeddd1fa7cb6f197c191ce7
2019-04-09 08:23:50 -07:00
Alexander Kindyakov
ce6eabb58b Struct [HostIdentity] to represent minimal info to identify a certain host in osquery
Summary:
I'm going to it as one of the decorators for streaming events. To be able to associate event with a certain machine on the backend side.

Why a new directory in osquery/? There are some libraries that depend on
core/database and any monster modules. To be able to keep utils simple,
lightweight and independent we should not put stuff like filesystem or network
under utils/ directory. But we need a single place to put all system assosiated
libs. So, let's make a `system` in the root of osquery.

Reviewed By: guliashvili

Differential Revision: D14706186

fbshipit-source-id: d40fde3872ca6b6677a1d8f89cfd8eda63c6b83d
2019-04-09 08:23:50 -07:00
Ted Reed
a6171de32e Handle bad fds in md_tables (#5553)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5553

Infer flagged this use of `unique_ptr` as potentially leaking the FD. I do not think this is the case but there is a missing check for a failed `open`. I am unsure of what the `ioctl` would do in this case.

I removed the custom decl to make the logic in this table easier (opinion).

Reviewed By: guliashvili

Differential Revision: D14700412

fbshipit-source-id: cfcfe9d2629aa27f18d39058830cb5c63881f163
2019-04-03 15:16:49 -07:00
Ted Reed
4698a55979 Fix lock resource leak in events/syslog (#5552)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5552

This fixes a potential resource leak in the `syslog` event type. If the process is unable to `flock` then the FD is reset (overwritten to -1) and not closed.

Reviewed By: guliashvili

Differential Revision: D14700407

fbshipit-source-id: 092a22c3059d29aca748ee23ba30c5301cd065af
2019-04-03 15:16:49 -07:00
Alexander Kindyakov
5ec514e714 Support of nested type in schemer json formatter (#5547)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5547

Since this diff an object of a class with defined schema (see type trait
schemer::has_schema) are allowed as memebers of anoter class with schema.

Example. C++ classes:
```
class Simple {
  int alpha = 1;

 public:
  template <typename Archive, typename ValueType>
  static void discloseSchema(Archive& a, ValueType& value) {
    schemer::record(a, "alpha", value.alpha);
  }
};

class Nested {
  Frist beta;
  int gama = 2;

 public:
  template <typename Archive, typename ValueType>
  static void discloseSchema(Archive& a, ValueType& value) {
    schemer::record(a, "beta", value.beta);
    schemer::record(a, "gama", value.gama);
  }
};
```

Json representation of `Nested`:
```
{
  "beta": {
    "alpha": 1
  },
  "gama": 2
}
```

Reviewed By: SAlexandru

Differential Revision: D14683589

fbshipit-source-id: 1f9e2f862d2bf64be166a717e49cf0f470f8ee36
2019-04-01 09:30:27 -07:00
Alexander Kindyakov
eca9296a88 Type trait to check if a class has defined schema for schemer (#5546)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5546

Recursive formatters require it to support nested classes.

Reviewed By: SAlexandru

Differential Revision: D14683348

fbshipit-source-id: 840a3e32729b07a3407ca6899d0cfaa73ab3afe4
2019-04-01 09:30:26 -07:00
Alexander Kindyakov
b9a78f2388 schemer formatters: json deserializer (#5548)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5548

This is a JSON deserializing formatter for schemer. It parse C++ object from
JSON object according to defined in C++ class schema. The implementation based
on rapidjson library.

Two methods with the same name: `osquery::schemer::fromJson`

Reviewed By: SAlexandru

Differential Revision: D14664162

fbshipit-source-id: ba73490dc19127a04a43b7ba1807d1f1a0bf4f43
2019-04-01 09:30:26 -07:00
Alexander Kindyakov
079a81db2f Remove dangling noisy log line
Reviewed By: guliashvili

Differential Revision: D14703542

fbshipit-source-id: 134b59dd568edfe844c908c95d9cabb9d96b6719
2019-04-01 05:55:20 -07:00
Alexander Kindyakov
7671a1af3c schemer formatters: json serializer (#5545)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5545

This is a JSON serializing formatter for schemer. It represents C++ object as JSON object according to defined in C++ class schema. The implementation based on rapidjson library. It is very simple - just print all key:value pairs directly to rapidjson stream (it could be files stream or string stream). The second method of formatter converts C++ objects directly to JSON in string.

Two methods with the same name: `osquery::schemer::toJson`

Reviewed By: SAlexandru

Differential Revision: D14663996

fbshipit-source-id: 7a902b0777c9094faf39ee3111bbc09d8c3c7a55
2019-04-01 03:05:05 -07:00
Alexander Kindyakov
45d22373e6 "schemer" serialisation framework (#5544)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5544

 This is a framework to declare a serialization and deserialization
 schema for C++ classes. The schema can be used by different implementations
 to represent C++ object as data-interchange format or to parse an object from
 formatted representation.

 It works without macro or any verbose transformation code. All you need to
 do to be able to serialize and deserialize some C++ class is to define a
 template static method `discloseSchema` in the class. Which describe all
 members that have to be read by serializer and written by deserializer.
 Everything else is a job of schemer formatters.

 Support of specific types, including nested types support depends on the formatter implementation.

   1. One place to describe class members instead of two different methods for serializer and deserializer.
   2. One way do describe schema for many formatters (JSON, TOML, hasher, etc).
   3. Schemer also sets the order of elements of class, therefore even binary formatters can use it, just ignoring the names.
   4. It is simple - just one method, nothing more. Therefore there is zero dependencies. Everything is in formatters.

  - JSON serializer/deserializer.
  - Hasher - it helps to impelement transformation of osquery events in hash form for probabilistic filters.

Reviewed By: SAlexandru

Differential Revision: D14663949

fbshipit-source-id: effcc7e91a85514cee700a0d5484ab4d317ac199
2019-04-01 03:05:05 -07: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
Ted Reed
f70150de65 Fix memory leak in macos keychain_items (#5550)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5550

This fixes a potential memory leak in keychain_items similar to D14567925. This leak was identified with the default options for OSS infer.

Reviewed By: guliashvili

Differential Revision: D14641455

fbshipit-source-id: 3fd776fe8a2af300435907ecd1d7746b3045066e
2019-03-31 10:30:42 -07:00
Alexander Kindyakov
93fd8a27ee Move osquery/events/linux/probes/ to osquery/experimental/tracing/linux/
Summary: To clean it up, they are parts of the same experimental subsystem and shoul be close to each other in experimental directory.

Reviewed By: marekcirkos

Differential Revision: D14668951

fbshipit-source-id: 404be1f3c24699557edc0b9e5ada823ea04533f1
2019-03-29 09:14:45 -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
Filipe Manco
9b881deff5 Store results for differential queries serialized with types
Summary: Every time a differential query runs we save the results to the database. We were serializing those results with or without types based on the `FLAGS_log_numerics_as_numbers` flag. However we always collect results with proper types therefore, on subsequent executions of the same query, the new results (typed) were being compared with the results retrieved from the DB (untyped if FLAGS_log_numerics_as_numbers == false), causing all results to be "different" and therefore osquery to report all results as "added" (and eventually all old results as "removed").

Reviewed By: SAlexandru

Differential Revision: D14669476

fbshipit-source-id: 8abc68cbcac90c73bd92fc8d34572ba3ee2f2c75
2019-03-28 15:11:15 -07:00
Jesse Kornblum
8cd5f6b20f Remove dead code for deserializeQueryLogItem functions (#5543)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5543

This diff removes two vestigial functions from the osquery core. There are no references to these functions except for the unit test, which we also update.

Reviewed By: marekcirkos

Differential Revision: D14664005

fbshipit-source-id: 4e176014c803e5ec8cebdf0bd064874b483c8f76
2019-03-28 14:19:16 -07:00
Teddy Reed
9a252a34b9 Add dependency for pthread in osquery/core (#5540)
Summary:
This fixes the linking error described in #5536.
Pull Request resolved: https://github.com/facebook/osquery/pull/5540

Reviewed By: jessek

Differential Revision: D14658581

Pulled By: theopolis

fbshipit-source-id: 76792696faaf834c22356c0090773a1a5fe40900
2019-03-28 07:21:24 -07:00
George Guliashvili
08eb8ff7ee Help packs class be immutable
Summary: setName was not used, other than the test, testing setName. Removing it to make class immutable

Reviewed By: jessek

Differential Revision: D14640959

fbshipit-source-id: d684939ed31e8ad275650847fadb2fb8c11b6fdc
2019-03-28 06:59:50 -07:00
Ted Reed
ac56c87949 Fix memory leak in macos extended_attributes (#5538)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5538

This bug was found using the OSS version of infer with default options.

Reviewed By: guliashvili

Differential Revision: D14567925

fbshipit-source-id: 64272880464577207552e3436754b7f6d32ef4ec
2019-03-27 07:31:36 -07:00
Alessandro Gario
507638dda0 chrome_extensions: Add the profile name to the table (#5213)
Summary:
This PR adds a new column to the `chrome_extensions` table named `profile`, used to show the name of the Chrome profile that owns each extension.

```
osqueryi --verbose 'SELECT profile, name, version FROM chrome_extensions;'
```
```
+---------------+---------------------+--------------+
| profile       | name                | version      |
+---------------+---------------------+--------------+
| trail_of_bits | Slides              | 0.10         |
| trail_of_bits | Docs                | 0.10         |
| trail_of_bits | Google Drive        | 14.1         |
| trail_of_bits | YouTube             | 4.2.8        |
| trail_of_bits | Sheets              | 1.2          |
| trail_of_bits | HTTPS Everywhere    | 2018.8.22    |
| trail_of_bits | Google Docs Offline | 1.7          |
| trail_of_bits | __MSG_APP_NAME__    | 1.0.0.4      |
| trail_of_bits | Gmail               | 8.1          |
| trail_of_bits | Chrome Media Router | 6818.528.0.0 |
| Person 1      | Slides              | 0.10         |
| Person 1      | Docs                | 0.10         |
| Person 1      | Google Drive        | 14.1         |
| Person 1      | YouTube             | 4.2.8        |
| Person 1      | Sheets              | 1.2          |
| Person 1      | Google Docs Offline | 1.7          |
| Person 1      | __MSG_APP_NAME__    | 1.0.0.4      |
| Person 1      | Gmail               | 8.1          |
| Person 1      | Chrome Media Router | 6818.528.0.0 |
+---------------+---------------------+--------------+
```
Pull Request resolved: https://github.com/facebook/osquery/pull/5213

Reviewed By: mkareta

Differential Revision: D14224080

Pulled By: guliashvili

fbshipit-source-id: 8f831163ccf38c7ba6c8d17aeb8c90c43031529f
2019-03-27 03:02:16 -07:00
George Guliashvili
3824c2e6cc Fix osquery exit with wrong status
Summary:
osquery returned status 1(error) always when osqueryd service install uninstall was requested by the flags.
Even if install/uninstall was successfull.

Add extra logging in case of success.
Exit with status 0 when successfully installed/uninstalled

Reviewed By: jessek

Differential Revision: D14622771

fbshipit-source-id: c0c7569a2b13434e2ad28ba92cba308024b044ec
2019-03-26 15:15:20 -07:00
George Guliashvili
85eb77a02f Do additional flag incompatibility check
Summary:
User could have requested install and uninstall of osqueryd service together. However it does not make sense and actually osquery would only install the service.
This additional check, will exit osquery in case when install and uninstall are requested together.

Reviewed By: jessek

Differential Revision: D14622634

fbshipit-source-id: b88dc519bd1ef38653eb1660712bbf2e75bad36f
2019-03-26 15:15:20 -07:00
George Guliashvili
a4adf7c79e Remove uneccessary c libraries
Summary:
Replaced fprint(stderr with std::cerr
Other than that, could not find any use of
```
```

Reviewed By: akindyakov, fmanco

Differential Revision: D14621228

fbshipit-source-id: e996b2507757dc6af710e7ab0e25fc8136bbb92e
2019-03-26 13:57:16 -07:00
George Guliashvili
64b98263aa Revert D14577520 failing osquery
Summary: Somehow, still looking for how, D14577520 broke communication between osqueryi/osqueryd -S and extension. Revert.

Reviewed By: akindyakov

Differential Revision: D14620885

fbshipit-source-id: 98392f6e1e5da1b0ea68ee54dc00b3bbcd687315
2019-03-26 10:35:53 -07:00
CameronPH
45c0b3d636 Fix key_strength bug for windows certificates table (#5304)
Summary:
Modifying the "key_strength" query to retrieve the bit length of the encoded public key.

Fixes #5103

Postcondition Test:
![key_strength_post](https://user-images.githubusercontent.com/37255169/48812380-18673500-ed00-11e8-8fda-65951467198b.PNG)
Pull Request resolved: https://github.com/facebook/osquery/pull/5304

Reviewed By: mkareta

Differential Revision: D13701633

Pulled By: fmanco

fbshipit-source-id: cebaa39e3f0ab0abcf1f3e7c201970e6e72f28bb
2019-03-25 09:32:57 -07:00
Alexander Kindyakov
a9b5309418 mute [c99-extensions] and [undeclared-selector] for macos system tables
Summary: It requires some effort to fix warnings properly, let's just mute them for now.

Reviewed By: marekcirkos

Differential Revision: D14596617

fbshipit-source-id: 184937d15cc186afe045131d6d648cdbfb4ad574
2019-03-25 09:28:27 -07:00
Alexander Kindyakov
2a624f2f18 Fix warning with constants initialisation in magic.cpp
Summary: More constness to everything :)

Reviewed By: marekcirkos

Differential Revision: D14596602

fbshipit-source-id: 96738448ea79dfa085fb0333637111374da5a284
2019-03-25 09:28:27 -07:00
Alexander Kindyakov
b93069b3f4 Fix sign compare warning in file_compression.cpp
Summary: Fairly easy, just use explicit type cast.

Reviewed By: jessek

Differential Revision: D14596603

fbshipit-source-id: 7cc430040c0c6cca12b4776ef64ba3a9daef1a19
2019-03-25 09:28:26 -07:00
George Guliashvili
08dc11b7ac Fix disable_watcher flag
Summary:
Working to offering thrift service validating queries. It will be used by query canary service and helldriver.

For that, I need to execute osqueryd -S with the given query. However, osqueryd -S (with extension) crashes while it exits. I can filter out crash output, but it means, I will not be able to catch if query really crashes the osqueryd.

I also don't want to really fix osquery watcher, as we have the watcher 2.0 as an intern project.

Fixing the current problem by stopping osquery to ignore FLAGS_disable_watchdog flag when extension is avaliable.

Reviewed By: marekcirkos

Differential Revision: D14577520

fbshipit-source-id: 588c31319b875b8af9d73da6d691f22bcfdb8fc9
2019-03-22 07:33:36 -07:00
Alexander Kindyakov
645e2531dc Switch off signal handling by default in osquery (in order to remove it later) (#5532)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5532

Ok, this is overcomplicated code for signal handling. Besides untested magic
with signals it makes quite a lot of assumptions about program state when it is
called. For instance, it uses instance of Watcher and Dispatcher singleton
which can be already destroyed or corrupted at the that time.
This complexity cause rare unpredictable and hardly reproducible problems, that
lead to data losses, cross process deadlocks, crashes of osqueryd because of
crash an extensions and os on ans so far.
Couple of examples.
When extensions killed by signal it 2 time from 3 lead to crash of osqueryd. It
very well reproducible but quite not very well diagnosable.
Another example is std::terminate called at shutdown of extensions. Something
could not be destroyed correctly and call std::terminate, which is already bad
but sometimes reasonable. After it everything goes to signal handler which use
already destroyed Watcher and cause another std::terminate. It leads to
recursive signal handler call and eventually to stack overflow.
Solution.
I believe it could be fixed less radical, absolutely. It takes some time,
though. And because it will cost us a lot there is a question: do we really
need it here? I could not find a place in osquery code where it is important to
finish something before shutdown. Moreover it is pretty rare case when code
handle shutdown condition correctly. That makes me think that we don't need
signal handling at all or at least not like this.

Reviewed By: mkareta

Differential Revision: D14458287

fbshipit-source-id: daf8388323e4dacabeee3338d185577335503da3
2019-03-20 10:43:36 -07:00
George Guliashvili
4fa237a164 Total(user+kernel) time ODS timeseries
Summary: Before, we sent the user and kernel time in a separate time series. They are usefull separately, in order to measure which queries are syscall extensive. However, for measuring the total time we need them together. We have wall time, but user + kernel time is more precise as they measure resource usage of the thread.

Reviewed By: jessek

Differential Revision: D14502715

fbshipit-source-id: 7a03ec5b1d7b328e9657d94f752d33e7aa771e97
2019-03-18 07:59:24 -07:00