Commit Graph

67 Commits

Author SHA1 Message Date
Alessandro Gario
5c1bf4ff0c
Initial implementations for BPF-based socket and process events tables (#6571)
* deb_packages: Fix include order issue

* bpf_socket_events, bpf_process_events: Initial implementation

* BPF: Add process tracking to process events, remove sockets_event

* CMake: Upgrade the C++ standard to C++17

* BPF: Improve initial system state snapshot and event collection

* BPF: Add tests for SystemStateTracker

* BPF: Add tests for BPFEventPublisher

* BPF: Refactor, add tests for ProcessContextFactory

* Refactor: Improve initial scan/event handling, fix openat

* BPF: Improve event ordering

* BPF: Fix test issue in BPFEventPublisher::processOpenAt

* BPF: Mark WIP functions as deprecated

* BPF: Improve tests

* BPF: Add back bpf_socket_events and connect() support

* BPF: Add Netlink addr support, add bind()

* BPF: Add accept/accept4 support

* BPF: Add tests for BPFEventPublisher::processOpenat2Event

* BPF: Add remaining tests for BPFEventPublisher

* BPF: Add configuration flags for memory management

* BPF: Add cmdline support to ProcessContextFactory

* BPF: Add additional tests

* BPF: Add unit test for SystemStateTracker::accept

* BPF: Update cwd handling

* BPF: Add tests for bpf_socket_events

* BPF: Add tests for bpf_process_events

* BPF: Add json_cmdline hidden column to bpf_process_events

* BPF: Update all copyright headers

* BPF: Add syscall duration in socket_events/process_events

* BPF: Code review changes

* BPF: Update ebpfpub to the latest version

* BPF: Removed unused functions

* BPF: Code review changes

Add whitespace around namespaces

* BPF: Revert header changes in rot13.cpp

* BPF: Code review changes

Rename the bpf_ntime column in bpf_socket_events/bpf_process_events
to ntime and make it the last visible column

* BPF: Code review changes

Update the dependencies for the BPF tests

* BPF: Code review changes

Update the dependencies for the BPF table tests

* BPF: Code review changes

Update how characters are appended to strings in the
system state tracker class

* BPF: Code review changes

Update the string -> integer conversion utilities in the
process context factory class.

* BPF: Hide failed exec syscalls from bpf_process_events results

* BPF: Do not log an error for invalid sockaddr structures

* BPF: Code review changes

Remove clang-format ignore block

* BPF: Code review changes

Update log messages in the BPFEventPublisher class

* BPF: Code review changes

Remove clang-format ignore block around the function tracer
descriptors

* BPF: Code review changes

Document the IFilesystem interface

* BPF: Code review changes

Document the IProcessContextFactory interface

* BPF: Code review changes

Document the ISystemStateTracker interface
2020-10-16 01:14:00 -07:00
Mike Myers
73d997ca5c
Enable cppcheck target in macOS builds (#6685) 2020-10-04 16:33:42 -04:00
Nabil Schear
49a02f7000
Add timeout and a timeout column to curl_certificate (#6641) 2020-09-23 10:55:22 -04:00
Artemis Tosini
7af153bd1b cmake: Use TARGET_PROCESSOR to set Linux .tgz name suffix
Instead of hard-wiring "x86_64"

Co-Authored-By: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2020-09-05 16:50:28 -04:00
Artemis Tosini
588f06b177 cmake: Add TARGET_PROCESSOR
Currently recognizes AMD64 and x86_64 for x86 and aarch64 for ARM.

Co-Authored-By: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2020-09-05 16:50:28 -04:00
Stefano Bonicatti
d0b4e327a2
Fix Windows build removing non existing C11 conformance (#6629)
thirdparty_librdkafka_c was failing to compile
due to the C11 keyword _Thread_local not being recognized.
2020-09-03 19:02:00 -04:00
Stefano Bonicatti
d3f394026e
Restore PIE support being dropped on Linux (#6611)
CMake ignores the sysroot when testing the support of PIE,
so the link test fails when it tries to check for PIE support
and decides that it's not supported.
Therefore we tell CMake that PIE is supported when using the
osquery-toolchain and leave the automatic test for other toolchains.

Temporarily disable PIE on executables built with the
osquery-toolchain libFuzzer, since it has not been compiled with PIE/PIC
support.
2020-08-28 17:14:37 -04:00
seph
c63709894b
Manual copyright changes (#6590) 2020-08-12 11:21:40 -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
Ateeq Sharfuddin
f79d7e32ee
Define UNICODE and _UNICODE preprocessors for windows (#6338) 2020-07-23 21:23:23 -04:00
Teddy Reed
c250dac2e7
build: Support ASAN for boost coroutine2 using ucontext (#6531) 2020-07-01 15:45:57 -04:00
Stefano Bonicatti
4a03194ba3
CPack: Use specific RPM variables to set the package name (#6527) 2020-06-27 10:31:29 -04:00
Stefano Bonicatti
efe9a98290
CMake: Correct macOS framework linking (#6522)
target_link_libraries correctly consider "-framework <library>"
as a library, instead of a flag; lets use that instead of
target_link_options.
2020-06-25 09:08:14 -04:00
Stefano Bonicatti
0654c20501
CMake: Fix and cleanup compile flags (#6521)
Add a description to the function preparing the targets carrying the
main compiler and linker flags.

Convert CMake default flags to the ones we use, instead of overriding
them later via targets.
This can also avoid having us use the wrong CRT on Windows if we forget to link
against osquery_cxx_settings.

Reduce the "overriding <flagX> with <flagY>" messages on Windows by
removing the warning level from the default flags, and adding that
to the specific osquery_<c|cxx>_settings target, so that non internal
targets can choose their own level.

Minor cleanups

Fix osquery/osquery#6509
2020-06-24 21:54:47 -04:00
Stefano Bonicatti
7f21ccfe67
Drop the facebook and source_migration layers (#6473)
We have ported all platforms to use the source layer.
The facebook layer is not needed anymore since we build everything from source now,
the same is for the transitional source_migration layer.

Minor cleanups about the recently removed python modules.
2020-06-01 09:58:56 -04:00
Stefano Bonicatti
11bdf32188
Fix rpm and deb package name format (#6468)
By using RPM-DEFAULT and DEB-DEFAULT as package names,
CPack leaves the naming of the packages to the underlying
packaging tools which will use the standard naming format.
2020-05-28 12:06:21 -04:00
Nick Anderson
d1feab7bf2
release: adding nupkg cpack build option, updating win deployment script (#6262) 2020-05-25 12:42:06 -04:00
Stefano Bonicatti
46c1e6d8be Implement container access from tables on Linux
- Add the possibility of running table logic inside a container
  namespace, so that's possible to query it instead of the host.
  Needs minor modifications to each table logic and how they use logging.

  In practice it works by having a pid_with_namespace column, which should
  contain pids that are in the same mount namespace of the container one
  wants to query.
  The worker receives that column as a constraint, prepares two unnamed
  pipes for read/write communications with the future child, then forks
  into a new process.

  While the parent sends a query job to the just created child and then waits
  for results, the child receives the job, takes all the values given in the
  pid_with_namespace constraint, retrieves the fd of the mount namespace
  under "/proc/<constraint pid>/ns/mnt", then switches to it.
  Finally it runs the table logic, sending the results back to the parent
  through the pipe with a JSON message.

  Important to note that the logging in the table logic is not GLOG
  directly, because in the child this is in an unknown state; a custom
  logging system that resembles glog and that takes advantage of the
  existing communication channel is used to send the messages in JSON
  format to the parent, which will take care to forward to GLOG.

- Add FLAGS_keep_container_worker_open so that the process used for
  accessing a container is kept open, until the queries are for the same
  table; when the table changes, the process will be closed
  and a new one created.
  This is off by default, which means that a new process will be always
  created.

- Implemented a way to run tests that require root separated
  from the others.
  The OSQUERY_BUILD_ROOT_TESTS has been added to requests such tests to
  be built.
  To run only tests which require a normal user, one has to use
  `ctest -LE "root-required"`, while `sudo ctest -L "root-required"`
  to run those who need root.

PR: osquery/osquery#6209
2020-04-20 17:49:57 +02:00
Stefano Bonicatti
dcca9f1124
Do not force a specific path to install osquery on Windows (#6379)
Do not set CPACK_WIX_SKIP_PROGRAM_FOLDER to true and a specific install path,
this will break the Program Files folder drive resolution
to the system drive, and instead will enable the ROOTDRIVE logic
which chooses the disk with the most space available.

Fixes osquery/osquery#6314
Fixes osquery/osquery#6342
2020-04-08 18:56:49 -04:00
Stefano Bonicatti
ab47c6db6f Fix format folder exclusion and format check self test (#6201) 2020-01-27 14:21:38 -08:00
Teddy Reed
b8eacfa1f8
toolchain: Add CMake options for linking (#6112) 2020-01-16 23:09:35 -05:00
Stefano Bonicatti
46430df8c5 Restore WEL logger plugin (#6164)
- Restore the ability of osquery to log to the Windows Event Log.
- Restore the information normally shown on the Details tab
of the Properties of the osquery executable.
- Add and refactor utility functions to parse and transform
  the osquery version, needed by the Windows resource files
  and packaging.
2020-01-12 01:42:44 -05:00
Teddy Reed
80ed884273
build: Pin Linux builds to use libc++ (#6158) 2020-01-03 19:57:09 -05:00
Stefano Bonicatti
668a1d86e6 CMake: Future proof Python finding mechanism (#6120)
CMake 3.16 doesn't set Python3_EXECUTABLE as cache variable anymore,
it has changed to _Python3_EXECUTABLE which is for internal use.
The module returns Python3_EXECUTABLE as a local variable,
so we share that value through a new custom cache variable,
OSQUERY_PYTHON_EXECUTABLE.
2019-12-11 22:32:08 -05:00
Teddy Reed
62ba77cbe6
cpack: Add RPM and DEB postinstall script (#6097)
Co-Authored-By: Stefano Bonicatti <smjert@gmail.com>
2019-12-11 15:44:44 -05:00
Stefano Bonicatti
e7cef1a906 Prepare CMake and Python framework for Python tests
test_base.py received several fixes and now supports and requires
a custom folder where to find the config files that the tests need.
It has been also updated to use Python 3.

Fixed the gen_api function in genapi.py missing the path to the spec
file when evaluating blacklisted tables.

Co-Authored-By: SS <sahil.suneja@trailofbits.com>
2019-12-07 20:51:09 -05:00
Stefano Bonicatti
515704954c Move the test config files in their own directory
This is to have better separation between them and the python tests.
BUCK files have been updated accordingly.

Changes to the internal generateCopyFileTarget function were needed.
The function now supports a base folder to be set so that the regex or file path
is appended to that base path, without having it included in the destination.
It will also not use a library target anymore, but a custom one so
that's possible to set properties with custom names.

Use only one copy target to copy test config files instead of having
multiple that overlaps.
It may give issues when copying and tests in the end will need all of
them.
2019-12-07 20:51:09 -05:00
Teddy Reed
4a7c64b030
cpack: Revert renaming com.facebook.plist to com.osquery.plist (#6093) 2019-12-03 23:22:17 -05:00
Stefano Bonicatti
501b92465b CMake: Change Python version required to be at least 3.5 (#6081)
Removed the restriction for the Python version to be >= 3.6 but < 3.8.
Now it has to be >=3.5, lower versions are EOL.

Removed the search for Python2 too since nothing uses it anymore.

Fixes osquery/osquery#6079
2019-11-26 13:50:21 -05:00
Stefano Bonicatti
8e6fefb47a CMake: explicitly enable ASM_MASM language on Windows (#6065)
This is needed by some third party libraries and
when using Ninja on Windows.
CMake complains that it cannot find the internal variable
for CMAKE_ASM_MASM_COMPILE_OBJECT if it's not active for the whole
project.
2019-11-23 00:14:56 -05:00
Stefano Bonicatti
93ceef7e5f CMake: Prefer Python 3.7 then 3.6 (#6057)
We are not currently ready for Python 3.8,
so we prefer either the newest 3.7 or 3.6.
2019-11-19 12:54:40 -05:00
Teddy Reed
f8d9bd7a15 windows: Add WIN32_LEAN_AND_MEAN to common defines 2019-11-12 08:15:53 -05:00
SS
39405447f9 formatting functions py2->3 (PR #6011) 2019-11-09 01:26:45 +01:00
Stefano Bonicatti
3c3c7a7d29 Use a custom defined manifest for executables on Windows (#6010)
This uniforms the manifest that gets embedded using msbuild
or Ninja, while also letting us customize it if necessary.
2019-11-06 19:11:27 -05:00
Stefano Bonicatti
b857409cad Fix build with Ninja on Windows (#6007) 2019-11-06 19:07:04 -05:00
Zachary Wasserman
7e18771f16 Migrate glibc from "facebook" dependencies (#5900) 2019-10-31 19:08:09 -04:00
Teddy Reed
9a336877fd
cpack: Update build-id and create debug RPMs (#5936) 2019-10-31 11:39:46 -04:00
Teddy Reed
b47e34936c
cpack: Add Debian copyright file and Augeas license (#5951) 2019-10-29 19:03:27 -04:00
Teddy Reed
1803972b2f
cpack: Use productbuild shim to override package_id (#5934) 2019-10-27 13:23:01 -04:00
Tom Ritter
1642382ff9 Move fuzzing harness to a new directory and refactor fuzzing constants (#5909) (#5910)
This commit creates a new osquery/main/harnesses directory and moves fuzz-config there.

It removes OSQUERY_FUZZ for a new option OSQUERY_ENABLE_FUZZER_SANITIZERS
It creates a new option OSQUERY_ENABLE_ADDRESS_SANITIZER

The following behaviors are intended:

OSQUERY_BUILD_TESTS=ON will build the fuzzing harness. This configuration is not
intended for fuzzing purposes. OSQUERY_ENABLE_FUZZER_SANITIZERS=ON will also build
the fuzzing harness. However if this variable is true, it also requires
OSQUERY_ENABLE_ADDRESS_SANITIZER=ON and either CMAKE_BUILD_TYPE=Release or
RelWithDebInfo This configuration is actually intended for fuzzing.
2019-10-20 14:09:45 -04:00
Stefano Bonicatti
974bdef901 Various fixes and CI steps for packaging (#5881)
* Fix packaging regression on Windows

Component variables should be set only for Linux and macOS,
otherwise on Windows the internal WiX IDs change and the
WiX fragment patch won't work.

Cleanup the version patch component, since WiX doesn't support
version components that are not digits.

* Add the rpm package to the CI Dockerfile, to test rpm packaging

* Fix TGZ generation on other platforms

* Add dpkg-dev and file packages to the CI Dockerfile

They are needed for creating DEB debug packages.

* Add a packaging steps to the CI

Set TGZ as a default packaging system when one cannot detected.

Fix generatePackageTarget indentation.
2019-10-13 12:53:16 +02:00
Stefano Bonicatti
56c69e3cfa Add ccache support also for compiling C (#5872) 2019-10-08 22:39:28 +02:00
Alessandro Gario
225bbaf992
Integrate cppcheck and clang-tidy within the CMake project (#5730) 2019-10-08 18:17:11 +02:00
Teddy Reed
846c392903
cpack: Update package logic to build DEB debuginfo (#5843)
This enables a component install for DEB (only). This is required in
CMake version 3.17.0 (planned) and lower to produce a debuginfo version.

One side-effect is we have to gate the stripping for DEB.
2019-10-07 22:36:18 -07: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
bb25075599
linux: Add --build-id linker option (#5823) 2019-09-25 15:20:22 -04:00
Stefano Bonicatti
6f3063bef7 Specify PATH when calling format_check if using the custom toolchain (#5834)
The script would not find clang-format or it would use the system one,
which it shouldn't.
2019-09-24 19:17:55 -04:00
Teddy Reed
835ae84635
CPack: Linux package nitpicks and docs (#5822)
This fixes the license for RPMs, sets the homepage for DEBs, and sets
the package revision correctly.
2019-09-23 17:39:27 -04:00
seph
8e678847c2 Fix MSI Service Error handling
When ErrorControl is set to `critical`, a failure to start osquery results in a system reboot. Instead, this should be set to `normal` where it is logged and the startup proceeds.

Upstream docs are Docs are http://wixtoolset.org/documentation/manual/v3/xsd/wix/serviceinstall.html

This was fixed in https://github.com/osquery/osquery/pull/5467 and seems to have gotten lost.
2019-09-19 12:32:35 -04:00
Zachary Wasserman
010949cc4e Suppress Boost warnings about newer compiler (#5816) 2019-09-19 01:19:26 +02:00