2014-12-18 18:50:47 +00:00
|
|
|
/*
|
2016-02-11 19:48:58 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2014-12-18 18:50:47 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
2015-01-26 18:32:39 +00:00
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
2014-12-18 18:50:47 +00:00
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-08-02 18:28:38 +00:00
|
|
|
|
2014-09-10 01:54:53 +00:00
|
|
|
#pragma once
|
2014-08-02 18:28:38 +00:00
|
|
|
|
2014-08-13 04:30:30 +00:00
|
|
|
#include <map>
|
2015-03-02 05:15:42 +00:00
|
|
|
#include <set>
|
2014-08-02 18:28:38 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-11-03 20:08:46 +00:00
|
|
|
#include <boost/filesystem/path.hpp>
|
2014-08-13 04:30:30 +00:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2014-12-03 23:31:09 +00:00
|
|
|
#include <osquery/status.h>
|
2014-08-02 18:28:38 +00:00
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
namespace osquery {
|
2014-08-02 18:28:38 +00:00
|
|
|
|
2015-04-10 23:58:11 +00:00
|
|
|
/// Globbing directory traversal function recursive limit.
|
2016-02-17 07:10:08 +00:00
|
|
|
enum GlobLimits : size_t {
|
2015-06-22 07:54:19 +00:00
|
|
|
GLOB_FILES = 0x1,
|
|
|
|
GLOB_FOLDERS = 0x2,
|
|
|
|
GLOB_ALL = GLOB_FILES | GLOB_FOLDERS,
|
2016-02-17 07:10:08 +00:00
|
|
|
GLOB_NO_CANON = 0x4,
|
2015-02-28 01:28:51 +00:00
|
|
|
};
|
2015-02-21 00:55:13 +00:00
|
|
|
|
2016-02-17 07:10:08 +00:00
|
|
|
inline GlobLimits operator|(GlobLimits a, GlobLimits b) {
|
|
|
|
return static_cast<GlobLimits>(static_cast<size_t>(a) |
|
|
|
|
static_cast<size_t>(b));
|
|
|
|
}
|
|
|
|
|
2015-04-10 23:58:11 +00:00
|
|
|
/// Globbing wildcard character.
|
2016-11-22 17:35:03 +00:00
|
|
|
const std::string kSQLGlobWildcard{"%"};
|
2017-04-11 04:32:16 +00:00
|
|
|
|
2015-04-10 23:58:11 +00:00
|
|
|
/// Globbing wildcard recursive character (double wildcard).
|
2016-11-22 17:35:03 +00:00
|
|
|
const std::string kSQLGlobRecursive{kSQLGlobWildcard + kSQLGlobWildcard};
|
2015-01-26 18:32:39 +00:00
|
|
|
|
2014-09-16 07:28:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Read a file from disk.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path the path of the file that you would like to read.
|
2016-07-25 16:21:26 +00:00
|
|
|
* @param size Number of bytes to read from file.
|
2014-09-16 07:28:23 +00:00
|
|
|
* @param content a reference to a string which will be populated with the
|
2015-07-06 03:42:35 +00:00
|
|
|
* contents of the path indicated by the path parameter.
|
2015-07-14 19:50:13 +00:00
|
|
|
* @param dry_run do not actually read the file content.
|
2016-08-01 00:10:13 +00:00
|
|
|
* @param preserve_time Attempt to preserve file mtime and atime.
|
|
|
|
* @param blocking Request a blocking read.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2014-09-15 19:47:00 +00:00
|
|
|
*/
|
2015-07-14 19:50:13 +00:00
|
|
|
Status readFile(const boost::filesystem::path& path,
|
|
|
|
std::string& content,
|
2015-10-24 12:06:58 +00:00
|
|
|
size_t size = 0,
|
2015-12-12 02:04:43 +00:00
|
|
|
bool dry_run = false,
|
2016-07-28 23:04:34 +00:00
|
|
|
bool preserve_time = false,
|
|
|
|
bool blocking = false);
|
2015-12-12 02:04:43 +00:00
|
|
|
|
|
|
|
/// Read a file and preserve the atime and mtime.
|
|
|
|
Status forensicReadFile(const boost::filesystem::path& path,
|
2016-07-28 23:04:34 +00:00
|
|
|
std::string& content,
|
|
|
|
bool blocking = false);
|
2015-07-14 19:50:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return the status of an attempted file read.
|
|
|
|
*
|
|
|
|
* @param path the path of the file that you would like to read.
|
2016-08-01 00:10:13 +00:00
|
|
|
* @param blocking Request a blocking read.
|
2015-07-14 19:50:13 +00:00
|
|
|
*
|
|
|
|
* @return success iff the file would have been read. On success the status
|
|
|
|
* message is the complete/absolute path.
|
|
|
|
*/
|
2016-07-28 23:04:34 +00:00
|
|
|
Status readFile(const boost::filesystem::path& path, bool blocking = false);
|
2014-08-02 18:28:38 +00:00
|
|
|
|
2015-12-12 02:04:43 +00:00
|
|
|
/// Internal representation for predicate-based chunk reading.
|
2016-08-01 00:10:13 +00:00
|
|
|
Status readFile(const boost::filesystem::path& path,
|
|
|
|
size_t size,
|
|
|
|
size_t block_size,
|
|
|
|
bool dry_run,
|
|
|
|
bool preserve_time,
|
|
|
|
std::function<void(std::string& buffer, size_t size)> predicate,
|
|
|
|
bool blocking = false);
|
2015-12-12 02:04:43 +00:00
|
|
|
|
2014-10-30 22:03:05 +00:00
|
|
|
/**
|
|
|
|
* @brief Write text to disk.
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path the path of the file that you would like to write.
|
|
|
|
* @param content the text that should be written exactly to disk.
|
|
|
|
* @param permissions the filesystem permissions to request when opening.
|
|
|
|
* @param force_permissions always `chmod` the path after opening.
|
2014-10-30 22:03:05 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2014-10-30 22:03:05 +00:00
|
|
|
*/
|
2014-11-03 20:08:46 +00:00
|
|
|
Status writeTextFile(const boost::filesystem::path& path,
|
|
|
|
const std::string& content,
|
|
|
|
int permissions = 0660,
|
|
|
|
bool force_permissions = false);
|
2014-10-30 22:03:05 +00:00
|
|
|
|
2017-09-08 08:08:57 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if a path is writable.
|
|
|
|
*
|
|
|
|
* @param path The path of the file that you would like to write.
|
|
|
|
* @param effective If you would like to check using effective UID
|
|
|
|
*
|
|
|
|
* @return A status returning if it's writable
|
|
|
|
*/
|
|
|
|
Status isWritable(const boost::filesystem::path& path, bool effective = false);
|
2015-07-06 03:42:35 +00:00
|
|
|
|
2017-09-08 08:08:57 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if a path is readable.
|
|
|
|
*
|
|
|
|
* @param path The path of the file that you would like to read.
|
|
|
|
* @param effective If you would like to check using effective UID
|
|
|
|
*
|
|
|
|
* @return A status returning if it's readable
|
|
|
|
*/
|
|
|
|
Status isReadable(const boost::filesystem::path& path, bool effective = false);
|
2014-10-27 01:39:03 +00:00
|
|
|
|
2014-09-16 07:28:23 +00:00
|
|
|
/**
|
|
|
|
* @brief A helper to check if a path exists on disk or not.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path Target path.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return The code of the Status instance will be -1 if no input was supplied,
|
|
|
|
* assuming the caller is not aware of how to check path-getter results.
|
|
|
|
* The code will be 0 if the path does not exist on disk and 1 if the path
|
|
|
|
* does exist on disk.
|
2014-09-15 19:47:00 +00:00
|
|
|
*/
|
2014-11-03 20:08:46 +00:00
|
|
|
Status pathExists(const boost::filesystem::path& path);
|
2014-09-09 17:56:48 +00:00
|
|
|
|
2014-09-16 07:28:23 +00:00
|
|
|
/**
|
2015-10-30 06:18:54 +00:00
|
|
|
* @brief List all of the files in a specific directory.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2014-09-16 07:28:23 +00:00
|
|
|
* @param path the path which you would like to list.
|
|
|
|
* @param results a non-const reference to a vector which will be populated
|
|
|
|
* with the directory listing of the path param, assuming that all operations
|
|
|
|
* completed successfully.
|
2015-10-30 06:18:54 +00:00
|
|
|
* @param recursive should the listing descend recursively into the directory.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2014-09-15 19:47:00 +00:00
|
|
|
*/
|
2014-11-03 20:08:46 +00:00
|
|
|
Status listFilesInDirectory(const boost::filesystem::path& path,
|
2015-03-13 23:05:20 +00:00
|
|
|
std::vector<std::string>& results,
|
2015-10-30 06:18:54 +00:00
|
|
|
bool recursive = false);
|
2014-08-14 23:27:20 +00:00
|
|
|
|
2015-01-26 18:32:39 +00:00
|
|
|
/**
|
|
|
|
* @brief List all of the directories in a specific directory, non-recursively.
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path the path which you would like to list
|
2015-01-26 18:32:39 +00:00
|
|
|
* @param results a non-const reference to a vector which will be populated
|
|
|
|
* with the directory listing of the path param, assuming that all operations
|
|
|
|
* completed successfully.
|
2015-10-30 06:18:54 +00:00
|
|
|
* @param recursive should the listing descend recursively into the directory.
|
2015-01-26 18:32:39 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2015-01-26 18:32:39 +00:00
|
|
|
*/
|
|
|
|
Status listDirectoriesInDirectory(const boost::filesystem::path& path,
|
2015-03-13 23:05:20 +00:00
|
|
|
std::vector<std::string>& results,
|
2015-10-30 06:18:54 +00:00
|
|
|
bool recursive = false);
|
2015-01-26 18:32:39 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Given a filesystem globbing patten, resolve all matching paths.
|
2015-01-26 18:32:39 +00:00
|
|
|
*
|
|
|
|
* @code{.cpp}
|
|
|
|
* std::vector<std::string> results;
|
|
|
|
* auto s = resolveFilePattern("/Users/marpaia/Downloads/%", results);
|
|
|
|
* if (s.ok()) {
|
|
|
|
* for (const auto& result : results) {
|
|
|
|
* LOG(INFO) << result;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param pattern filesystem globbing pattern.
|
|
|
|
* @param results output vector of matching paths.
|
2015-01-26 18:32:39 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2015-01-26 18:32:39 +00:00
|
|
|
*/
|
2015-07-06 03:42:35 +00:00
|
|
|
Status resolveFilePattern(const boost::filesystem::path& pattern,
|
2015-01-26 18:32:39 +00:00
|
|
|
std::vector<std::string>& results);
|
|
|
|
|
2015-02-26 00:27:52 +00:00
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Given a filesystem globbing patten, resolve all matching paths.
|
2015-02-26 00:27:52 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* See resolveFilePattern, but supply a limitation to request only directories
|
2015-07-15 20:47:02 +00:00
|
|
|
* or files that match the path.
|
2015-02-26 00:27:52 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param pattern filesystem globbing pattern.
|
|
|
|
* @param results output vector of matching paths.
|
|
|
|
* @param setting a bit list of match types, e.g., files, folders.
|
2015-02-26 00:27:52 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2015-02-26 00:27:52 +00:00
|
|
|
*/
|
2015-07-06 03:42:35 +00:00
|
|
|
Status resolveFilePattern(const boost::filesystem::path& pattern,
|
2015-02-21 00:55:13 +00:00
|
|
|
std::vector<std::string>& results,
|
2015-06-22 07:54:19 +00:00
|
|
|
GlobLimits setting);
|
2015-02-21 00:55:13 +00:00
|
|
|
|
2015-07-06 03:42:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Transform a path with SQL wildcards to globbing wildcard.
|
|
|
|
*
|
|
|
|
* SQL uses '%' as a wildcard matching token, and filesystem globbing uses '*'.
|
|
|
|
* In osquery-internal methods the filesystem character is used. This helper
|
|
|
|
* method will perform the correct preg/escape and replace.
|
|
|
|
*
|
|
|
|
* This has a side effect of canonicalizing paths up to the first wildcard.
|
|
|
|
* For example: /tmp/% becomes /private/tmp/% on OS X systems. And /tmp/%.
|
|
|
|
*
|
|
|
|
* @param pattern the input and output filesystem glob pattern.
|
2016-07-25 16:21:26 +00:00
|
|
|
* @param limits osquery::GlobLimits to apply (currently only recognizes
|
|
|
|
* osquery::GLOB_NO_CANON)
|
2015-07-06 03:42:35 +00:00
|
|
|
*/
|
2016-02-17 07:10:08 +00:00
|
|
|
void replaceGlobWildcards(std::string& pattern, GlobLimits limits = GLOB_ALL);
|
2015-07-06 03:42:35 +00:00
|
|
|
|
|
|
|
/// Attempt to remove a directory path.
|
2017-09-02 05:31:03 +00:00
|
|
|
Status removePath(const boost::filesystem::path& path);
|
|
|
|
|
|
|
|
/// Move a file or directory to another path.
|
|
|
|
Status movePath(const boost::filesystem::path& from,
|
|
|
|
const boost::filesystem::path& to);
|
2015-02-04 03:55:16 +00:00
|
|
|
|
2014-10-06 21:23:26 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if an input path is a directory.
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path input path, either a filename or directory.
|
2014-10-06 21:23:26 +00:00
|
|
|
*
|
|
|
|
* @return If the input path was a directory.
|
|
|
|
*/
|
2014-11-03 20:08:46 +00:00
|
|
|
Status isDirectory(const boost::filesystem::path& path);
|
2014-10-06 21:23:26 +00:00
|
|
|
|
2014-10-01 02:59:52 +00:00
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Return a vector of all home directories on the system.
|
2014-10-01 02:59:52 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return a vector of string paths containing all home directories.
|
2014-10-01 02:49:38 +00:00
|
|
|
*/
|
2015-03-02 05:15:42 +00:00
|
|
|
std::set<boost::filesystem::path> getHomeDirectories();
|
2014-10-01 02:49:38 +00:00
|
|
|
|
2015-03-04 16:45:21 +00:00
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Check the permissions of a file and its directory.
|
2015-03-04 16:45:21 +00:00
|
|
|
*
|
|
|
|
* 'Safe' implies the directory is not a /tmp-like directory in that users
|
|
|
|
* cannot control super-user-owner files. The file should be owned by the
|
|
|
|
* process's UID or the file should be owned by root.
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param dir the directory to check `/tmp` mode.
|
|
|
|
* @param path a path to a file to check.
|
|
|
|
* @param executable true if the file must also be executable.
|
2015-03-04 16:45:21 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return true if the file is 'safe' else false.
|
2015-03-04 16:45:21 +00:00
|
|
|
*/
|
2017-04-11 04:32:16 +00:00
|
|
|
bool safePermissions(const boost::filesystem::path& dir,
|
|
|
|
const boost::filesystem::path& path,
|
2015-03-13 15:11:08 +00:00
|
|
|
bool executable = false);
|
2015-03-04 16:45:21 +00:00
|
|
|
|
2015-07-06 03:42:35 +00:00
|
|
|
/**
|
|
|
|
* @brief osquery may use local storage in a user-protected "home".
|
|
|
|
*
|
|
|
|
* Return a standard path to an "osquery" home directory. This path may store
|
|
|
|
* a protected extensions socket, backing storage database, and debug logs.
|
|
|
|
*/
|
2015-03-19 03:47:35 +00:00
|
|
|
const std::string& osqueryHomeDirectory();
|
|
|
|
|
2015-02-10 05:41:17 +00:00
|
|
|
/// Return bit-mask-style permissions.
|
|
|
|
std::string lsperms(int mode);
|
|
|
|
|
2015-04-10 23:58:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Parse a JSON file on disk into a property tree.
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path the path of the JSON file.
|
|
|
|
* @param tree output property tree.
|
2015-04-10 23:58:11 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure if malformed.
|
2015-04-10 23:58:11 +00:00
|
|
|
*/
|
|
|
|
Status parseJSON(const boost::filesystem::path& path,
|
|
|
|
boost::property_tree::ptree& tree);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Parse JSON content into a property tree.
|
|
|
|
*
|
2016-07-25 16:21:26 +00:00
|
|
|
* @param content JSON string data.
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param tree output property tree.
|
2015-04-10 23:58:11 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure if malformed.
|
2015-04-10 23:58:11 +00:00
|
|
|
*/
|
|
|
|
Status parseJSONContent(const std::string& content,
|
|
|
|
boost::property_tree::ptree& tree);
|
|
|
|
|
2014-08-13 04:30:30 +00:00
|
|
|
#ifdef __APPLE__
|
2014-09-16 07:28:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Parse a property list on disk into a property tree.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param path the input path to a property list.
|
|
|
|
* @param tree the output property tree.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure if malformed.
|
2014-09-15 19:47:00 +00:00
|
|
|
*/
|
2014-11-03 20:08:46 +00:00
|
|
|
Status parsePlist(const boost::filesystem::path& path,
|
|
|
|
boost::property_tree::ptree& tree);
|
|
|
|
|
2014-09-16 07:28:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Parse property list content into a property tree.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @param content the input string-content of a property list.
|
|
|
|
* @param tree the output property tree.
|
2014-09-15 19:47:00 +00:00
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure if malformed.
|
2014-09-15 19:47:00 +00:00
|
|
|
*/
|
2015-04-10 23:58:11 +00:00
|
|
|
Status parsePlistContent(const std::string& content,
|
2014-10-07 18:20:47 +00:00
|
|
|
boost::property_tree::ptree& tree);
|
2014-08-13 04:30:30 +00:00
|
|
|
#endif
|
2014-11-19 22:53:42 +00:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Iterate over `/proc` process, returns a list of pids.
|
2014-11-19 22:53:42 +00:00
|
|
|
*
|
|
|
|
* @param processes output list of process pids as strings (int paths in proc).
|
|
|
|
*
|
2015-07-06 03:42:35 +00:00
|
|
|
* @return an instance of Status, indicating success or failure.
|
2014-11-19 22:53:42 +00:00
|
|
|
*/
|
2015-03-26 23:18:28 +00:00
|
|
|
Status procProcesses(std::set<std::string>& processes);
|
2014-11-19 22:53:42 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-06 03:42:35 +00:00
|
|
|
* @brief Iterate over a `/proc` process's descriptors, return a list of fds.
|
2014-11-19 22:53:42 +00:00
|
|
|
*
|
|
|
|
* @param process a string pid from proc.
|
|
|
|
* @param descriptors output list of descriptor numbers as strings.
|
|
|
|
*
|
|
|
|
* @return status of iteration, failure if the process path did not exist.
|
|
|
|
*/
|
|
|
|
Status procDescriptors(const std::string& process,
|
2015-01-11 10:17:10 +00:00
|
|
|
std::map<std::string, std::string>& descriptors);
|
2014-11-19 22:53:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read a descriptor's virtual path.
|
|
|
|
*
|
|
|
|
* @param process a string pid from proc.
|
|
|
|
* @param descriptor a string descriptor number for a proc.
|
|
|
|
* @param result output variable with value of link.
|
|
|
|
*
|
|
|
|
* @return status of read, failure on permission error or filesystem error.
|
|
|
|
*/
|
|
|
|
Status procReadDescriptor(const std::string& process,
|
|
|
|
const std::string& descriptor,
|
|
|
|
std::string& result);
|
2015-01-19 02:19:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read bytes from Linux's raw memory.
|
|
|
|
*
|
2015-01-19 03:43:40 +00:00
|
|
|
* Most Linux kernels include a device node /dev/mem that allows privileged
|
2015-01-19 02:19:35 +00:00
|
|
|
* users to map or seek/read pages of physical memory.
|
|
|
|
* osquery discourages the use of physical memory reads for security and
|
|
|
|
* performance reasons and must first try safer methods for data parsing
|
|
|
|
* such as /sys and /proc.
|
|
|
|
*
|
|
|
|
* A platform user may disable physical memory reads:
|
|
|
|
* --disable_memory=true
|
|
|
|
* This flag/option will cause readRawMemory to forcefully fail.
|
|
|
|
*
|
|
|
|
* @param base The absolute memory address to read from. This does not need
|
2015-01-19 03:43:40 +00:00
|
|
|
* to be page aligned, readRawMem will take care of alignment and only
|
2015-01-19 02:19:35 +00:00
|
|
|
* return the requested start address and size.
|
|
|
|
* @param length The length of the buffer with a max of 0x10000.
|
|
|
|
* @param buffer The output buffer, caller is responsible for resources if
|
|
|
|
* readRawMem returns success.
|
|
|
|
* @return status The status of the read.
|
|
|
|
*/
|
|
|
|
Status readRawMem(size_t base, size_t length, void** buffer);
|
2014-11-19 22:53:42 +00:00
|
|
|
#endif
|
2017-07-31 18:11:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief A function to archive files specified into a single file
|
|
|
|
*
|
|
|
|
* @param path The paths that you want bundled into the archive
|
|
|
|
* @param out The path where the resulting tar will be written to
|
|
|
|
* Given a set of paths we bundle these into a tar archive.
|
|
|
|
*/
|
|
|
|
Status archive(const std::set<boost::filesystem::path>& path,
|
|
|
|
const boost::filesystem::path& out);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Given a path, compress it with zstd and save to out.
|
|
|
|
*
|
|
|
|
* @param in The file to compress
|
|
|
|
* @param out Where to write the compressed file to
|
|
|
|
* @return A status containing the success or failure of the operation
|
|
|
|
*/
|
|
|
|
Status compress(const boost::filesystem::path& in,
|
|
|
|
const boost::filesystem::path& out);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Given a path, decompress it with zstd and save to out.
|
|
|
|
*
|
|
|
|
* @param in The file to decompress
|
|
|
|
* @param out Where to write the decompressed file to
|
|
|
|
* @return A status containing the success or failure of the operation
|
|
|
|
*/
|
|
|
|
Status decompress(const boost::filesystem::path& in,
|
|
|
|
const boost::filesystem::path& out);
|
2017-10-30 05:25:49 +00:00
|
|
|
} // namespace osquery
|