Commit Graph

3117 Commits

Author SHA1 Message Date
Stefano Bonicatti
8de035ba94 Improve error reporting from extension manager (#5860)
Change the message that is logged when a required extension is not
loaded or found from "Extension not autoloaded: <extension id>" to
"Required extension not found or not loaded: <extension id>".

Change the message that is logged when the extension manager has an
error happening during startup from "Cannot start extension manager:
<error>" to "An error occurred during extension manager startup: <error>"

Add the possibility of startExtensionManager returning with an error
if the Dispatcher failed to properly add the ExtensionManagerWatcher
or ExtensionManagerRunner.

Fallback to logging the startExtensionManager error message with a
severity of INFO only if extensions are required to be disabled.

Add tests for starting the extension manager with a nonexistent
socket path and a nonexistent required extension.

Issue osquery/osquery#5679
2019-10-04 15:44:54 -04:00
William Woodruff
a9b23807b2 darwin/firewall: Fixes for alf_exceptions, make alf_services an alias for sharing_preferences (#5378) 2019-10-04 15:42:10 -04:00
William Woodruff
06dd05cd33 (Windows) New table: connectivity (#5500) 2019-10-04 15:18:15 -04:00
Teddy Reed
92e7b9033d
fuzzing: Restore simple libFuzzer-based config fuzzing (#5844)
This defines a new CMake option: OSQUERY_FUZZ, which appends compiler
and linker flags for libFuzzer to be effective.

There is one example harness that will fuzz config parsing.
2019-10-02 18:09:35 -04:00
Teddy Reed
0f3ad48b77
bug: Use RecursiveMutex and additional read locking on getEventSubscriber (#5841) 2019-10-02 01:02:24 -04:00
Zachary Wasserman
2a6ddd62ea Implementation of windows_security_products table (#5479)
Provides information about the security products registered on a Windows
system.
2019-09-23 17:44:31 -04:00
Nick Anderson
789f70f2d9 deploy: updating osquery --install to wrap binary path and flagfile (#5824) 2019-09-23 17:38:20 -04:00
Tomohito Nakayama
553ab52b38 Fix error with implicitly-deleted default constructor of glob_t (#5828) 2019-09-22 01:03:46 -04:00
Alessandro Gario
c83e70f91f
Intel ME table refactor (#5476)
Reimplement the intel_me_info table, adding support for all the
three available query protocols.
2019-09-08 10:26:56 +02:00
Teddy Reed
925250dc92 aws: Fix preprocessor define check 2019-09-07 02:08:00 -04:00
seph
6550462468 Don't return nil rows for the programs table (#5715) 2019-09-06 20:44:44 -04:00
pawel-lmcb
1a4b277ce2 Fix optional AWS table compilation on Windows (#5719) 2019-09-06 13:19:29 -07:00
Mike Myers
c8bcba151b Fix the reading of the Serial of a certificate (little-endian big int). Resolves #5104 (#5742) 2019-09-06 15:18:25 -04:00
Stefano Bonicatti
2a0e389c35 Fix registry table exception closing an uninitialized key handle (#5718) 2019-09-03 20:27:05 -07: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
Stefano Bonicatti
81e12f718c Add audit processeventstests-test to the running tests (#5726)
The test was built but wasn't running with the other tests.
2019-08-28 01:18:44 +02:00
Alessandro Gario
7cc21aa648 Update the license header used on smart_drives and windows_crashes (#5722) 2019-08-27 10:24:50 -04:00
Alessandro Gario
444b2cc017
Audit: Implement support for fork/vfork/clone/execveat (#5701)
* Audit: Implement support for fork/vfork/clone/execveat

Also implement a test target for the process_events table
2019-08-23 16:09:00 +02:00
Sharvil Shah
d9fdc5b8fd tables: implement ibridge table to report on T1/T2 chip for mac notebooks (#5707) 2019-08-19 17:41:24 -04:00
Stefano Bonicatti
4f78848794 Fix undefined-behavior in osquery::ebpf::consumeWrappedMessagesFromCircularBuffer
Issue highlighted by asan activated in PR osquery/osquery#5628

Ensure WrappedMessage has no padding since its members are written
consecutively in the buffer.
Also use memcpy when retrieving a WrappedMessage from a buffer, since
it could be written at a misaligned address.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
fb5585976b Fix undefined-behavior in osquery::tables::getCanonicalEfiDevicePath
Issue highlighted by asan activated in PR osquery/osquery#5628

EFI_DEVICE_PATH_PROTOCOL and HARDDRIVE_DEVICE_PATH were using
the wrong alignment/padding, since on disk they are written
with no padding.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
ea17c51bb8 Fix undefined-behavior in copyValueFromJValue
Issue highlighted by asan activated in PR osquery/osquery#5628

Imprecisions between float -> double -> json -> double -> float
lead to out of range values been saved into a float variable.
Since json has only the notion of doubles as floating point numbers,
it's better to require to use them.

Also forced the json parser to parse floating point numbers
with full precision, otherwise the test testing for precision would fail.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
0a302cd08e Fix undefined-behavior in smc_keys strtoul
Issue highlighted by asan activated in PR osquery/osquery#5628

When shifting left or right a byte, that must be positive, so
ensure it is.

Light cleanup of a bugged and unused function.
A deeper look into the table implementation is needed.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
2e88c4214f Fix heap-buffer-overflow in osquery::tables::netmaskFromIP
Issue highlighted by asan activated in PR osquery/osquery#5628

Do not try to read the destination address of a netmask if such address
is a default route.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
cc2787a27d Fix undefined-behavior in osquery::tables::genMemoryRegion
Issue highlighted by asan activated in PR osquery/osquery#5628

Reading a 8 byte field from a 4 byte aligned struct needs to be
done with memcpy.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
a322a951ec Fix heap-buffer-overflow in osquery::tables::genDetailsFromAddr
Issue highlighted by asan activated in PR osquery/osquery#5628

Do not use memcpy to copy strings around.
Also, ifa_name size is not guaranteed to be IFNAMSIZ.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
f4885df19d Fix container-overflow in Carver::carve
Issue highlighted by asan activated in PR osquery/osquery#5628

Do not use clear() on a vector inizialized with a fixed size to clear
it of its contents when using it as a char buffer.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
Stefano Bonicatti
3f5d2debc4 Fix stack-use-after-scope in procEnumerateProcesses
Issue highlighted by PR osquery/osquery#5628

Do not take a reference of a string which is owned by a temporary,
copy it instead.

PR: osquery/osquery#5665
2019-08-16 16:47:18 +02:00
seph
7a96a9660e sql function regex_match (and some tests for other sql functions) (#5444) 2019-08-14 11:51:21 -04:00
Mark Mossberg
c3b34763e8 windows/certificates: Fix bug in environment variable expansion (#5697) 2019-08-13 19:26:06 -04:00
Mark Mossberg
59a68ad5ef windows/certificates: Do not filter out system accounts
When proactively searching disk for personal certificates, there is no
need to filter system accounts (SYSTEM, Local Service, etc) anymore
because `findUserPersonalCertsOnDisk` is now capable of handling those
accounts by dynamically finding a user's home dir (as rather than
constructing a hard coded path).

This now makes the table even more complete; any certificates found in
the system accounts directories will always be found. Previously they
could be found but only if there was a store location other than the
`Users` store location that had a system store string that looked like
`S-1-5-18\My` or `.DEFAULT\My`.
2019-08-08 18:50:56 +02:00
Mark Mossberg
f9c1fd88cc windows/certificates: Improve table's coverage of Personal certificates (#5640) 2019-08-07 10:58:22 -04:00
@emptymonkey
f1cd3e1d86 Fix for mount table interacting with direct autofs. (#5635) 2019-08-05 22:23:34 -04:00
seph
2c0da99016 Light refactor and fixes for the users and groups table
- Lightly update the logic, to make the code paths similar between
  no-constraint, and specified uid cases.
- Add tests to the group table.
2019-08-05 22:15:13 -04:00
Teddy Reed
1145140016 tables: Add optimization back to macOS users and groups
This PR supersedes #5669 with an alternate approach of moving forward
without a revert of #5368.
2019-08-05 22:15:13 -04:00
Teddy Reed
d7c7a1de88
Remove cloud tables from windows (#5657)
It does not look like the EC2 tables are available on Windows
(due to spec-file configuration).

Please see https://osquery.io/schema/3.3.2#ec2_instance_tags

This removes the EC2 library linking requirement until we revisit this
feature.
2019-07-23 08:13:03 -07:00
Teddy Reed
22d51ddc20 rpm: Check for glibc version and librpm secure_getenv
The librpm dependency may be configured with a glibc version < 2.17. If
so then it will expect __secure_getenv to be available.
2019-07-23 14:19:57 +02:00
Stefano Bonicatti
a5dfb3da7e
Improve osquery version detection (#5630)
Add OSQUERY_VERSION cache variable to force the version to be set at
that value.
Add OSQUERY_VERSION_AUTODECTED cache variable to show the osquery
version that has been detected through git
Add OSQUERY_VERSION_SUFFIX cache variable to append its value to the
final version, if the version was autodected.
Add OSQUERY_VERSION_INTERNAL variable to globally store the final
osquery version, to be used in other CMake scripts.
Add OSQUERY_VERSION_COMPONENTS variable to globally store the components
of the final osquery version. Currently used by the packaging system.

Modify overwrite_cache_variable so that's possible to specify the type.

The version is always autodetected using "git describe --tags --always --dirty"
and OSQUERY_VERSION_SUFFIX is appended to it, unless OSQUERY_VERSION is manually set.

Incorporates suggestions by @directionless.

CMake part of osquery/osquery#5615
2019-07-23 13:01:20 +02:00
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