Open cborla opened 1 month ago
1) *Windows Event Log API** (EvtQuery, EvtNext, etc.) :
2) Event Tracing for Windows (ETW):
3) krabsetw:
4) Integrating PowerShell:
Some basic design and tentative approach on how can this be achieved, this should be double checked based on the different libraries limitations and needs:
Class Diagram:
classDiagram
class EventChannelQuerySystem {
- Session session
- Provider provider
- Consumer consumer
-BookmarkManager bookmarkMgr
-QueryBuilder queryBuilder
+initialize()
+startQuery(channelName, queryString)
+stopQuery()
+getResults()
+setReconnectTime(time)
+rotateLog()
}
class Session {
-sessionName
-sessionProperties
+open()
+close()
+enableProvider(provider)
}
class Provider {
}
class Consumer {
-eventCallback
+processEvent(event)
+setEventCallback(callback)
}
class BookmarkManager {
-bookmarks
+createBookmark(event)
+getBookmark(id)
+saveBookmarks()
+loadBookmarks()
}
class QueryBuilder {
+buildQuery(channelName, conditions)
+addWildcardMatch(field, pattern)
}
EventChannelQuerySystem -- Session
EventChannelQuerySystem -- Provider
EventChannelQuerySystem -- Consumer
EventChannelQuerySystem -- BookmarkManager
EventChannelQuerySystem -- QueryBuilder
EventChannelQuerySystem
: The main class that orchestrates the entire querying process.Session
: Manages the ETW session, including opening, closing, and enabling providers.Provider
: Represents an ETW provider, which can be enabled or disabled.Consumer
: Processes the events received from the ETW session.BookmarkManager
: Handles the creation, saving, and loading of bookmarks.QueryBuilder
: Constructs queries, including support for wildcard matches.Flow chart:
ETWQuerySystem
.QueryBuilder
, incorporating channel name and specific query conditions.graph TD
A[init] --> B[Initialize - ETWQuerySystem]
B --> C[Open - ETWSession]
C --> D[Enable - ETWProvider]
D --> E[Set up - ETWConsumer]
E --> F[Load Bookmarks -> store]
E --> W[(Store)]
F --> G[Build N Queries]
G --> H[run]
H --> I{While Event Received?}
I -->|Yes| J[Process Event]
J --> K[Update Bookmark]
K --> I
I -->|No| N{Query Stopped or shutdown signal ?}
N -->|Yes| O[Save Bookmarks]
O --> P[Close Session]
P --> Q[End]
N -->|No| R{Reconnect Needed?}
R -->|Yes| S[Reconnect]
S --> I
R -->|No| I
Working on krabsetw aproach:
Code using krabsetw can be as simple as:
krabs::user_trace trace;
krabs::provider<> provider(krabs::guid(L"{A0C1853B-5C40-4B15-8766-3CF1C58F985A}"));
provider.any(0xf0010000000003ff);
provider.add_on_event_callback([](const EVENT_RECORD &record, const krabs::trace_context &trace_context) {
krabs::schema schema(record, trace_context.schema_locator);
std::wcout << L"Event " << schema.event_id();
std::wcout << L"(" << schema.event_name() << L") received." << std::endl;
if (schema.event_id() == 7937) {
krabs::parser parser(schema);
std::wstring context = parser.parse<std::wstring>(L"ContextInfo");
std::wcout << L"\tContext: " << context << std::endl;
}
});
trace.enable(provider);
trace.start();
Because we're using krabsetw and it needs to create a thread for each provider, this is the rework of the design:
```mermaid classDiagram class EventChannelQuerySystem { - Provider provider - Consumer consumer -BookmarkManager bookmarkMgr -QueryBuilder queryBuilder +initialize() +setEventCallback(callback) +start() +qttyOfResults() +setReconnectTime(time) +rotateLog() } class Provider { -channel -providerName } class Consumer { -eventCallback -queryString +processEvent(event) } class BookmarkManager { -bookmarks +createBookmark(event) +getBookmark(id) +saveBookmarks() +loadBookmarks() } class QueryBuilder { +buildQuery(channelName, conditions) +addWildcardMatch(field, pattern) } EventChannelQuerySystem -- Session EventChannelQuerySystem -- Provider EventChannelQuerySystem -- Consumer EventChannelQuerySystem -- BookmarkManager EventChannelQuerySystem -- QueryBuilder ```
Flow chart Changes:
```mermaid flowchart TD A["init"] --> C["Initialize Channel / Provider"] C --> E["Initialice Trace Session"] E --> F["Load Bookmarks"] & W[("Store")] F --> G["Build / Check Queries"] G --> H["Start Provider Thread"] H --> I{"Receiveing events"} & B["Next Provider"] I -- Yes --> J["Process Event"] J --> K["Update Bookmark"] K --> I I -- No --> N{"Stopped ?"} N -- Yes --> O["Save Bookmarks"] O --> P["Close Session"] P --> Q["End"] N -- No --> R{"Reconnection?"} R -- Yes --> S["Reconnect"] S --> I R -- No --> I B --> A I --> n1["Untitled Node"] ```
Example of reading Application events -> ⚠️ User should be SYSTEM:
void EventLogApplication::start()
{
// While Adminstrator is sufficent to view the Security EventLog,
// SYSTEM is required for the Microsoft-Windows-Security-Auditing provider.
char user_name[128] = { 0 };
DWORD user_name_length = 128;
if (!GetUserNameA(user_name, &user_name_length) || !strcmp(user_name, "SYSTEM") == 0)
{
std::wcout << L"Microsoft-Windows-Security-Auditing can only be traced by SYSTEM" << std::endl;
return;
}
krabs::user_trace trace(L"EventLog-Application");
krabs::provider<> provider(L"Microsoft-Windows-Security-SPP");
provider.any((ULONGLONG)-1);
provider.add_on_event_callback([](const EVENT_RECORD &record, const krabs::trace_context &trace_context) {
krabs::schema schema(record, trace_context.schema_locator);
std::wcout << L"Event " << schema.event_id();
std::wcout << L"(" << schema.event_name() << L") received." << std::endl;
if (schema.event_id() == 4703) {
krabs::parser parser(schema);
std::wstring enabled_privilege_list = parser.parse<std::wstring>(L"EnabledPrivilegeList");
std::wstring disabled_privilege_list = parser.parse<std::wstring>(L"DisabledPrivilegeList");
std::wcout << L"\tEnabledPrivilegeList=" << enabled_privilege_list << std::endl;
std::wcout << L"\tDisabledPrivilegeList=" << disabled_privilege_list << std::endl;
}
});
trace.enable(provider);
trace.start();
}
Moved to on hold until the release testing stage is completed.
Description
This issue is a section of #201, focuses on implementing the Windows Logcollector module in the Wazuh Agent 5.0.0. The Windows collector will utilize the Event Channel (eventchannel) API to gather system logs, ensuring seamless integration and log management on Windows platforms.
Functional Requirements
Non-functional Requirements
Deliverables
Acceptance Criteria