Skip to content

Commit 672256d

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
Process plugins - Introduce OSQuery process plugin
1 parent f2ca4e2 commit 672256d

16 files changed

+1352
-1081
lines changed

src/plugins/process/osquery/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ project(ipfixprobe-process-osquery VERSION 1.0.0 DESCRIPTION "ipfixprobe-process
33
add_library(ipfixprobe-process-osquery MODULE
44
src/osquery.cpp
55
src/osquery.hpp
6+
src/osqueryContext.hpp
7+
src/osqueryFields.hpp
8+
src/osqueryRequestManager.hpp
9+
src/osqueryRequestManager.cpp
10+
src/fileDescriptor.hpp
11+
src/fileDescriptor.cpp
12+
src/osqueryStateHandler.hpp
13+
src/process.cpp
14+
src/process.hpp
615
)
716

817
set_target_properties(ipfixprobe-process-osquery PROPERTIES
918
CXX_VISIBILITY_PRESET hidden
1019
VISIBILITY_INLINES_HIDDEN YES
1120
)
1221

13-
target_include_directories(ipfixprobe-process-osquery PRIVATE
22+
target_include_directories(ipfixprobe-process-osquery PRIVATE
1423
${CMAKE_SOURCE_DIR}/include/
24+
${CMAKE_SOURCE_DIR}/include/ipfixprobe/processPlugin
25+
${CMAKE_SOURCE_DIR}/include/ipfixprobe/pluginFactory
26+
${CMAKE_SOURCE_DIR}/src/plugins/process/common
27+
${adaptmon_SOURCE_DIR}/lib/include/public/
1528
)
1629

1730
if(ENABLE_NEMEA)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# OSQuery Plugin
2+
3+
Plugin for querying operating system about the flows.
4+
5+
## Features
6+
7+
- Uses osqueryi to query the operating system and exports relevant information.
8+
9+
## Output Fields
10+
11+
| Field Name | Data Type | Description |
12+
| -------------------------- | ---------- | ----------------------------------------- |
13+
| `OSQUERY_PROGRAM_NAME` | `string` | Name of the program generating the flow. |
14+
| `OSQUERY_USERNAME` | `string` | Username of the user running the program. |
15+
| `OSQUERY_OS_NAME` | `string` | Operating system name. |
16+
| `OSQUERY_OS_MAJOR` | `uint16_t` | Operating system major version. |
17+
| `OSQUERY_OS_MINOR` | `uint16_t` | Operating system minor version. |
18+
| `OSQUERY_OS_BUILD` | `string` | Operating system build. |
19+
| `OSQUERY_OS_PLATFORM` | `string` | Operating system platform. |
20+
| `OSQUERY_OS_PLATFORM_LIKE` | `string` | Windows/Linux/Darwin. |
21+
| `OSQUERY_OS_ARCH` | `string` | Operating system architecture. |
22+
| `OSQUERY_KERNEL_VERSION` | `string` | Operating system kernel version. |
23+
| `OSQUERY_SYSTEM_HOSTNAME` | `string` | System hostname. |
24+
25+
## Usage
26+
27+
### YAML Configuration
28+
29+
Add the plugin to your ipfixprobe YAML configuration:
30+
31+
```yaml
32+
process_plugins:
33+
- osquery
34+
```
35+
36+
### CLI Usage
37+
38+
You can also enable the plugin directly from the command line:
39+
40+
`ipfixprobe -p osquery ...`
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @file
3+
* @author Damir Zainullin <[email protected]>
4+
* @brief This file defines the FileDescriptor base classed used as wrapper for UNIX file
5+
* descriptors that manage its lifetime
6+
*
7+
* @copyright Copyright (c) 2024 CESNET, z.s.p.o.
8+
*/
9+
10+
#include "fileDescriptor.hpp"
11+
12+
namespace ipxp::process::osquery {
13+
14+
FileDescriptor::operator bool() const noexcept
15+
{
16+
return hasValue();
17+
};
18+
19+
bool FileDescriptor::hasValue() const noexcept
20+
{
21+
return m_fileDescriptor >= 0;
22+
};
23+
24+
FileDescriptor::operator int() const noexcept
25+
{
26+
return get();
27+
};
28+
29+
int FileDescriptor::get() const noexcept
30+
{
31+
return m_fileDescriptor;
32+
};
33+
34+
int FileDescriptor::release()
35+
{
36+
const auto originalValue = m_fileDescriptor;
37+
m_fileDescriptor = INVALID_FILE_DESCRIPTOR;
38+
return originalValue;
39+
}
40+
41+
void FileDescriptor::close() const noexcept
42+
{
43+
if (m_fileDescriptor != INVALID_FILE_DESCRIPTOR) {
44+
::close(m_fileDescriptor);
45+
}
46+
}
47+
48+
FileDescriptor::FileDescriptor(const int fileDescriptor) noexcept
49+
: m_fileDescriptor(fileDescriptor)
50+
{
51+
}
52+
53+
FileDescriptor::FileDescriptor() noexcept
54+
: m_fileDescriptor(INVALID_FILE_DESCRIPTOR)
55+
{
56+
}
57+
58+
FileDescriptor::FileDescriptor(FileDescriptor&& other) noexcept
59+
{
60+
std::swap(m_fileDescriptor, other.m_fileDescriptor);
61+
}
62+
63+
FileDescriptor& FileDescriptor::operator=(FileDescriptor&& other) noexcept
64+
{
65+
if (this != &other) {
66+
close();
67+
std::swap(m_fileDescriptor, other.m_fileDescriptor);
68+
}
69+
70+
return *this;
71+
}
72+
73+
FileDescriptor::~FileDescriptor() noexcept
74+
{
75+
close();
76+
}
77+
78+
} // namespace ipxp::process::osquery
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @file
3+
* @author Damir Zainullin <[email protected]>
4+
* @brief This file declares the FileDescriptor base classed used as wrapper for UNIX file
5+
* descriptors that manage its lifetime
6+
*
7+
* @copyright Copyright (c) 2024 CESNET, z.s.p.o.
8+
*/
9+
10+
#pragma once
11+
12+
#include <string>
13+
14+
#include <unistd.h>
15+
16+
namespace ipxp::process::osquery {
17+
18+
/**
19+
* @brief Wrapper that owns and manages a file descriptor.
20+
*
21+
* It makes sure that the descriptor is closed, when the lifetime of the wrapper
22+
* instance goes out of scope.
23+
*/
24+
class FileDescriptor {
25+
public:
26+
explicit FileDescriptor() noexcept;
27+
28+
/**
29+
* @brief Construct wrapper with given file descriptor.
30+
* @param fileDescriptor File descriptor to take ownership
31+
*/
32+
explicit FileDescriptor(const int fileDescriptor) noexcept;
33+
34+
explicit FileDescriptor(FileDescriptor&& other) noexcept;
35+
36+
FileDescriptor& operator=(FileDescriptor&& other) noexcept;
37+
38+
virtual ~FileDescriptor() noexcept;
39+
40+
FileDescriptor(const FileDescriptor& other) = delete;
41+
42+
/** @brief Test whether the wrapper holds a valid file descriptor. */
43+
operator bool() const noexcept;
44+
45+
/** @brief Test whether the wrapper holds a valid file descriptor.
46+
* @return True if holds valid file descriptor, false otherwise
47+
*/
48+
bool hasValue() const noexcept;
49+
50+
/**
51+
* @brief Get the managed file descriptor.
52+
* @note It may return an invalid file descriptor if it doesn't hold any.
53+
*/
54+
operator int() const noexcept;
55+
56+
/**
57+
* @brief Get the managed file descriptor.
58+
* @note It may return an invalid file descriptor if it doesn't hold any.
59+
* @return Underlying file descriptor
60+
*/
61+
int get() const noexcept;
62+
63+
/**
64+
* @brief Return the managed file descriptor and release its ownership.
65+
* @note It may return an invalid file descriptor if it doesn't hold any.
66+
* @return Underlying file descriptor
67+
*/
68+
int release();
69+
70+
/**
71+
* @brief Close the file descriptor.
72+
* @note If it doesn't hold any descriptor, no action is performed.
73+
*/
74+
void close() const noexcept;
75+
76+
private:
77+
constexpr static int INVALID_FILE_DESCRIPTOR = -1;
78+
int m_fileDescriptor = INVALID_FILE_DESCRIPTOR;
79+
};
80+
81+
} // namespace ipxp::process::osquery

0 commit comments

Comments
 (0)