wazuh / wazuh-agent

Wazuh agent, the Wazuh agent for endpoints.
GNU Affero General Public License v3.0
22 stars 12 forks source link

Implement Windows Logcollector Module #206

Open cborla opened 2 days ago

cborla commented 2 days ago

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

  1. Wazuh Agent Executable with Windows Collector
    • [ ] An updated Wazuh Agent build that includes the implemented Windows collector within the Logcollector module.
  2. Design Documentation for Windows Collector
    • [ ] Comprehensive documentation detailing the architecture, components, and workflow of the Windows collector.

Acceptance Criteria

LucioDonda commented 2 days ago

Update 7/10/2024 and 8/10/2024

Analysis and comparisson of libraries:

1) *Windows Event Log API** (EvtQuery, EvtNext, etc.) :

2) Event Tracing for Windows (ETW):

3) krabsetw:

4) Integrating PowerShell:

First Approach

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
  1. EventChannelQuerySystem: The main class that orchestrates the entire querying process.
  2. Session: Manages the ETW session, including opening, closing, and enabling providers.
  3. Provider: Represents an ETW provider, which can be enabled or disabled.
  4. Consumer: Processes the events received from the ETW session.
  5. BookmarkManager: Handles the creation, saving, and loading of bookmarks.
  6. QueryBuilder: Constructs queries, including support for wildcard matches.

Flow chart:

  1. The system starts by initializing the ETWQuerySystem.
  2. It opens an ETW session and enables the required provider.
  3. The ETW consumer is set up to handle incoming events.
  4. Bookmarks are loaded from persistent storage.
  5. A query is built using the QueryBuilder, incorporating channel name and specific query conditions.
  6. The query is started, and the system enters an event processing loop.
  7. For each received event:
    • The event is processed.
    • Bookmarks are updated.
    • Log rotation is performed if needed.
  8. The system checks if reconnection is needed and performs it if necessary.
  9. When the query is stopped, bookmarks are saved, and the session is closed.
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
LucioDonda commented 1 day ago

Update 9/10/2024