# oz9un/log-slapper architecture

> Architecture diagram of the GitHub repository oz9un/log-slapper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oz9un/log-slapper
- Repository: https://github.com/oz9un/log-slapper

## Overview

1. **What this repo is**
   - `log-slapper` is a Go-based CLI tool for offensive log injection into Splunk/SIEM environments.
   - Its core job is to generate plausible security/log telemetry, then deliver it to a target Splunk indexer/heavy forwarder or HEC endpoint.

2. **Top-level execution path**
   - `main.go` is the entrypoint and hands off to the CLI framework in `pkg/cmd/root.go`.
   - From there, user input is routed into command handlers in `pkg/command`, which choose between interactive use, direct attack execution, or raw transport modes.

3. **CLI and command boundary**
   - `pkg/cmd/root.go` defines the main command surface.
   - `pkg/command/execute.go` and `pkg/command/execute_raw.go` separate “normal” scenario execution from lower-level/raw injection paths.
   - This is the main boundary between user intent and the attack-generation pipeline.

4. **Bootstrap and environment detection**
   - `pkg/initialize` handles first-run and host setup concerns:
     - `detect.go` likely discovers the target Splunk endpoint or local network context.
     - `prereqs.go` checks runtime dependencies.
     - `iptables.go` suggests network/path manipulation or traffic handling when root privileges are available.
   - README indicates a `log.settings` file stores the target indexer/HF IP and optional HEC token.

5. **Attack definition layer**
   - The repo supports both built-in attacks and custom scenarios.
   - `example-attack-templates/*.yaml` shows the custom scenario format used to describe sequences of logs/events.
   - `pkg/replacer/replacer.go` likely performs template-variable substitution so attack definitions can be parameterized and reused.

6. **Built-in attack generators**
   - `pkg/attacks` contains concrete payload generators for specific telemetry types:
     - `win_loginspam.go`
     - `win_processcreate.go`
     - `nix_execve.go`
     - `raw_tcp.go`
   - These represent the “event semantics” layer: they create believable Windows/Linux security events or raw traffic patterns rather than directly handling transport details.

7. **Splunk event modeling**
   - `pkg/splunk` is the formatting and serialization layer that turns attack intent into Splunk-compatible records.
   - Files like `event.go`, `logfile.go`, `encodings.go`, `randomip.go`, and `rawtraffic.go` suggest responsibilities such as:
     - shaping log/event fields,
     - encoding them for transport,
     - generating plausible source IPs,
     - and preparing raw traffic payloads.

8. **Transport and delivery**
   - The repo supports multiple delivery styles:
     - direct TCP communication to Splunk ingestion endpoints,
     - HEC-based submission when a token is available,
     - and raw traffic-oriented injection paths.
   - `pkg/network/listen.go` and `callback.go` imply a listener/callback channel used for interactive or “target shell playzone” style workflows.

9. **Data flow through the system**
   - User chooses an attack interactively or via CLI flags/YAML.
   - Command layer loads config and initializes the environment.
   - Attack/template logic generates one or more synthetic events.
   - Splunk formatting converts those events into the expected wire format.
   - Network/transport code sends the logs to the target Splunk service.

10. **Extensibility model**
    - The design is deliberately modular: new attack types can be added under `pkg/attacks`, while new scenario templates can be added in YAML without changing the CLI surface.
    - That makes the repo useful both as a fixed set of demos and as a framework for composing custom telemetry injection scenarios.

11. **External boundaries**
    - The main external dependency is the target Splunk environment itself: indexer/heavy forwarder and optionally HEC.
    - The tool also depends on OS/network capabilities for some modes, especially where packet handling or interface detection is needed.
    - There is no evidence of a backend database or web service; the architecture is primarily a local CLI orchestrator plus network emitter.

12. **How to draw it**
    - A good architecture diagram would center on the CLI orchestrator, split into:
      - configuration/bootstrap,
      - attack generation,
      - Splunk event formatting,
      - transport delivery,
      - and optional interactive/listener support.
    - The only persistent artifact worth showing is the local settings/template files; the rest is runtime orchestration toward Splunk.

Main entry points: [`pkg/command/execute.go`](https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute.go) (execute), [`pkg/splunk/event.go`](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/event.go) (event model), [`pkg/cmd/root.go`](https://github.com/oz9un/log-slapper/blob/main/pkg/cmd/root.go) (root cmd), [`pkg/command/execute_raw.go`](https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute_raw.go) (raw execute)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["CLI entry"]
  node_n1["main<br/>entrypoint<br/>[main.go]"]
  node_n2["root cmd<br/>cli surface<br/>[root.go]"]
  node_n3["execute<br/>command flow<br/>[execute.go]"]
  node_n4["raw execute<br/>raw command<br/>[execute_raw.go]"]
end

subgraph group_g2["Setup"]
  node_n5["detect<br/>bootstrap<br/>[detect.go]"]
  node_n6["prereqs<br/>bootstrap<br/>[prereqs.go]"]
  node_n7["iptables<br/>host setup<br/>[iptables.go]"]
end

subgraph group_g3["Attack defs"]
  node_n8["replacer<br/>templating<br/>[replacer.go]"]
  node_n9["win login<br/>attack generator<br/>[win_loginspam.go]"]
  node_n10["win process<br/>attack generator"]
  node_n11["nix exec<br/>attack generator<br/>[nix_execve.go]"]
  node_n12["raw tcp<br/>raw injector<br/>[raw_tcp.go]"]
end

subgraph group_g4["Splunk model"]
  node_n13["event model<br/>splunk record<br/>[event.go]"]
  node_n14["logfile<br/>splunk format<br/>[logfile.go]"]
  node_n15["encodings<br/>serialization<br/>[encodings.go]"]
  node_n16(("random ip<br/>data helper<br/>[randomip.go]"))
  node_n17["raw traffic<br/>traffic model<br/>[rawtraffic.go]"]
end

subgraph group_g5["Delivery"]
  node_n18["listen<br/>[listen.go]"]
  node_n19["callback<br/>[callback.go]"]
end

subgraph group_g6["Artifacts"]
  node_n20["settings<br/>local config"]
  node_n21["attack templates<br/>yaml scenarios<br/>[template.yaml]"]
end

node_n1 -->|"starts"| node_n2
node_n2 -->|"routes"| node_n3
node_n2 -->|"routes"| node_n4
node_n3 -->|"prepares"| node_n5
node_n3 -->|"checks"| node_n6
node_n3 -->|"parameterizes"| node_n8
node_n4 -->|"emits"| node_n12
node_n3 -->|"generates"| node_n9
node_n3 -->|"generates"| node_n10
node_n3 -->|"generates"| node_n11
node_n8 -->|"loads"| node_n21
node_n3 -->|"formats"| node_n13
node_n13 -->|"wraps"| node_n14
node_n14 -->|"encodes"| node_n15
node_n13 -->|"enriches"| node_n16
node_n13 -->|"maps"| node_n17
node_n3 -.->|"may listen"| node_n18
node_n18 -->|"supports"| node_n19
node_n3 -->|"reads"| node_n20
node_n4 -->|"reads"| node_n20
node_n7 -.->|"affects"| node_n18

click node_n1 "https://github.com/oz9un/log-slapper/blob/main/main.go"
click node_n2 "https://github.com/oz9un/log-slapper/blob/main/pkg/cmd/root.go"
click node_n3 "https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute.go"
click node_n4 "https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute_raw.go"
click node_n5 "https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/detect.go"
click node_n6 "https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/prereqs.go"
click node_n7 "https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/iptables.go"
click node_n8 "https://github.com/oz9un/log-slapper/blob/main/pkg/replacer/replacer.go"
click node_n9 "https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/win_loginspam.go"
click node_n10 "https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/win_processcreate.go"
click node_n11 "https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/nix_execve.go"
click node_n12 "https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/raw_tcp.go"
click node_n13 "https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/event.go"
click node_n14 "https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/logfile.go"
click node_n15 "https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/encodings.go"
click node_n16 "https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/randomip.go"
click node_n17 "https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/rawtraffic.go"
click node_n18 "https://github.com/oz9un/log-slapper/blob/main/pkg/network/listen.go"
click node_n19 "https://github.com/oz9un/log-slapper/blob/main/pkg/network/callback.go"
click node_n21 "https://github.com/oz9un/log-slapper/blob/main/example-attack-templates/template.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1,node_n2,node_n3,node_n4 toneBlue
class node_n5,node_n6,node_n7 toneAmber
class node_n8,node_n9,node_n10,node_n11,node_n12 toneMint
class node_n13,node_n14,node_n15,node_n16,node_n17 toneRose
class node_n18,node_n19 toneIndigo
class node_n20,node_n21 toneTeal
```

## Components

### CLI entry

Command-line entrypoint and command routing

- [main](https://github.com/oz9un/log-slapper/blob/main/main.go): entrypoint · Program startup and handoff to CLI command handling · `main.go`
- [root cmd](https://github.com/oz9un/log-slapper/blob/main/pkg/cmd/root.go): cli surface · Defines the top-level command interface and user options · `pkg/cmd/root.go`
- [execute](https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute.go): command flow · Runs the standard attack execution path · `pkg/command/execute.go`
- [raw execute](https://github.com/oz9un/log-slapper/blob/main/pkg/command/execute_raw.go): raw command · Handles lower-level or raw injection execution · `pkg/command/execute_raw.go`

### Setup

Environment detection and host preparation

- [detect](https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/detect.go): bootstrap · Discovers target or host context before execution · `pkg/initialize/detect.go`
- [prereqs](https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/prereqs.go): bootstrap · Checks runtime and system prerequisites · `pkg/initialize/prereqs.go`
- [iptables](https://github.com/oz9un/log-slapper/blob/main/pkg/initialize/iptables.go): host setup · Optional network or traffic-path manipulation on capable hosts · `pkg/initialize/iptables.go`

### Attack defs

Built-in and template-driven attack generation

- [replacer](https://github.com/oz9un/log-slapper/blob/main/pkg/replacer/replacer.go): templating · Substitutes variables in attack definitions and payloads · `pkg/replacer/replacer.go`
- [win login](https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/win_loginspam.go): attack generator · Generates Windows login-style telemetry · `pkg/attacks/win_loginspam.go`
- [win process](https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/win_processcreate.go): attack generator · Generates Windows process creation telemetry · `pkg/attacks/win_processcreate.go`
- [nix exec](https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/nix_execve.go): attack generator · Generates Linux execve-style telemetry · `pkg/attacks/nix_execve.go`
- [raw tcp](https://github.com/oz9un/log-slapper/blob/main/pkg/attacks/raw_tcp.go): raw injector · Generates raw TCP-oriented traffic patterns · `pkg/attacks/raw_tcp.go`

### Splunk model

Event shaping and serialization for Splunk delivery

- [event model](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/event.go): splunk record · Shapes synthetic events into Splunk-compatible records · `pkg/splunk/event.go`
- [logfile](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/logfile.go): splunk format · Wraps events in log file style output for delivery · `pkg/splunk/logfile.go`
- [encodings](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/encodings.go): serialization · Encodes payloads for transport and wire compatibility · `pkg/splunk/encodings.go`
- [random ip](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/randomip.go): data helper · Produces plausible source IP values for synthetic telemetry · `pkg/splunk/randomip.go`
- [raw traffic](https://github.com/oz9un/log-slapper/blob/main/pkg/splunk/rawtraffic.go): traffic model · Prepares raw traffic payload representations · `pkg/splunk/rawtraffic.go`

### Delivery

Transport and callback/listener paths

- [listen](https://github.com/oz9un/log-slapper/blob/main/pkg/network/listen.go): listener · Receives inbound interactive or callback traffic · `pkg/network/listen.go`
- [callback](https://github.com/oz9un/log-slapper/blob/main/pkg/network/callback.go): callback channel · Supports interactive callback or playzone workflows · `pkg/network/callback.go`

### Artifacts

Persistent local templates and runtime settings

- **settings**: local config · Persistent target and token settings used at runtime
- [attack templates](https://github.com/oz9un/log-slapper/blob/main/example-attack-templates/template.yaml): yaml scenarios · Example scenario templates for custom attack definitions · `example-attack-templates/template.yaml`

## Connections

- main → root cmd: starts · Entry point initializes the CLI command surface
- root cmd → execute: routes · Standard command path executes the main scenario flow
- root cmd → raw execute: routes · Raw mode is dispatched through a separate command path
- execute → detect: prepares · Execution may detect target or host context before running
- execute → prereqs: checks · Runtime prerequisites are validated before use
- execute → replacer: parameterizes · Templates and scenarios are expanded with variable substitution
- raw execute → raw tcp: emits · Raw execution uses the raw TCP attack path
- execute → win login: generates · Built-in scenarios can produce Windows login telemetry
- execute → win process: generates · Built-in scenarios can produce process creation telemetry
- execute → nix exec: generates · Built-in scenarios can produce Linux execve telemetry
- replacer → attack templates: loads · Scenario definitions are sourced from YAML templates
- execute → event model: formats · Generated intent is shaped into Splunk records
- event model → logfile: wraps · Events are packaged for log-file style output
- logfile → encodings: encodes · Payloads are serialized into transport-friendly forms
- event model → random ip: enriches · Synthetic events can be assigned plausible source IPs
- event model → raw traffic: maps · Raw telemetry is represented in a transport-specific model
- execute → listen: may listen · Some workflows use a local listener or callback channel
- listen → callback: supports · Listener and callback paths support interactive flows
- execute → settings: reads · Runtime uses local settings for target and token configuration
- raw execute → settings: reads · Raw mode also depends on local target settings
- iptables → listen: affects · Host network setup can influence listener and callback behavior
