Commit Graph

26 Commits

Author SHA1 Message Date
Breakwell
6d57dc8066
Windows 32 bit Support (#6543) 2020-09-01 23:29:26 -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
Ryan Mack
c1b210cfa5
Fix call to LocalFree() on uninit ptr (#6579) 2020-08-07 23:34:00 -04:00
Ateeq Sharfuddin
f79d7e32ee
Define UNICODE and _UNICODE preprocessors for windows (#6338) 2020-07-23 21:23:23 -04:00
Breakwell
543dcc3087
Fix: Leak in psidToString on windows 2020-07-10 00:55:10 -04:00
Teddy Reed
25e0088e9f
Use LOAD_LIBRARY_SEARCH_SYSTEM32 for LoadLibrary (#6458) 2020-05-25 12:30:17 -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
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
0e5b048438
Copy the parent environment when launching worker 2020-04-08 19:46:09 -04:00
Breakwell
29933213df
Change process table log errors to info and fix typo (#6370) 2020-04-08 19:41:42 -04:00
Ateeq Sharfuddin
b63dc57e24
fix: on Windows use UTF-8 strings instead of system default locale strings (#6190) 2020-02-28 11:12:22 -05:00
Teddy Reed
d393d12f5c
Refactor and simplify shutdown logic (#6144)
The windows documentation mentions that ExitThread should not be
used in C++ code. When debugging these exit flows I saw exceptions
when running dtors.

When reviewing the shutdown code for Windows and POSIX there was a
lot of complexity. This change allows any part of code to request
a shutdown and simplifies the response.

We should expect the main thread to call ::waitForShutdown.
The exception is the shell, which waits in a repl.
2020-02-10 20:26:45 -05:00
Stefano Bonicatti
d0b42a98e2
Fix all TLS tests and framework (#6170) 2020-02-03 07:50:25 -08:00
Zachary Wasserman
7e18771f16 Migrate glibc from "facebook" dependencies (#5900) 2019-10-31 19:08:09 -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
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
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
Alexander Kindyakov
17850e3040 Let's use glibc:ld thirdparty dependency instead of linker flag -ldl
Summary: to be able to proxy it inside `osquery_tp_target` function.

Reviewed By: marekcirkos

Differential Revision: D14182918

fbshipit-source-id: d56b7135664ecd5afcc87b1c1cd2cde5394368a0
2019-02-25 03:05:40 -08:00
Alexander Kindyakov
0ae1de3d86 Remove Initializer::shutdown() from process.cpp
Summary:
It cause implicit dependency to osquery/core:core, that cause circular dependency :(. The point is to get rid of it. Let's use just exit() instead.

As far as we don't have decent implementation of Initializer::shutdown it will not cause us any more problems.
We can live with it for a while.

Reviewed By: marekcirkos

Differential Revision: D14182915

fbshipit-source-id: 22c54cde910ea29b1fb19d96598db381b9d1c60d
2019-02-25 03:05:40 -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
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
94683a22db remove unused include of boost/optional.hpp in process.h
Summary: Just to clean it up

Reviewed By: fmanco

Differential Revision: D13750145

fbshipit-source-id: a9aa5564f15334cf5da74147fcb28b2bf8f88b76
2019-01-23 04:49:47 -08:00
Filipe Manco
a67525fae1 Fix LICENSE information on file headers (#5375)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5375

LICENSE is now defined in a single file on the root of the project, update the
header to contain that information.

**Project LICENSE did not change.**

Reviewed By: akindyakov

Differential Revision: D13750575

fbshipit-source-id: 1e608a81b260b8395f9d008fc67f463160c1fc2b
2019-01-21 11:51:54 -08:00
George Guliashvili
971bee4441 Move build system to BUCK
fbshipit-source-id: 8ffef5e6a393ac67ce56dcb74845402e43d964a0
2018-12-07 16:12:35 +00:00