README
¶
Fake News Generator - Go Version
This is a Go implementation of the fake_news.py script that simulates load for osctrl using goroutines for concurrent execution.
Features
- Concurrent Execution: Uses goroutines instead of Python threads for better performance
- Node Simulation: Generates random nodes with different platforms (Ubuntu, CentOS, Debian, FreeBSD, Darwin, Windows)
- Multiple Operations: Simulates status logs, result logs, config requests, and query operations
- osquery Integration: Executes real osquery commands for query responses
- JSON Persistence: Can save/load node configurations to/from JSON files
- Command Line Interface: Full CLI support with all original Python script options
Prerequisites
- Go 1.19 or later
- osquery installed and accessible via
osqueryicommand - osctrl-tls server running
Installation
-
Clone the repository
-
Install dependencies:
go mod tidy
Usage
Basic Usage
go run tools/fake_news.go --secret YOUR_SECRET
Advanced Usage
go run tools/fake_news.go \
--secret YOUR_SECRET \
--env YOUR_ENV_UUID \
--url http://localhost:9000/ \
--nodes 10 \
--status 30 \
--result 45 \
--config 60 \
--query 20 \
--verbose
Command Line Options
--secret, -s: Secret to enroll nodes for osctrl-tls (required)--env, -e: Environment UUID for osctrl-tls (optional)--url, -u: URL for osctrl-tls used to enroll nodes (default: http://localhost:9000/)--nodes, -n: Number of random nodes to simulate (default: 5)--status, -S: Interval in seconds for status requests to osctrl (default: 60)--result, -R: Interval in seconds for result requests to osctrl (default: 60)--config, -c: Interval in seconds for config requests to osctrl (default: 45)--query, -q: Interval in seconds for query requests to osctrl (default: 30)--state <file>: JSON file to persist and resume node state. If provided, the program will attempt to load node state from this file on startup and periodically save node state during execution. (default: state.json)--insecure: Skip TLS certificate verification--verbose, -v: Enable verbose output
Examples
Generate 10 nodes and save configuration
go run tools/fake_news.go --secret mysecret --nodes 10 --state nodes.json
Load existing nodes and run simulation
go run tools/fake_news.go --secret mysecret --state nodes.json
High-frequency simulation with verbose output
go run tools/fake_news.go \
--secret mysecret \
--env YOUR_ENV_UUID \
--nodes 20 \
--status 10 \
--result 15 \
--config 20 \
--query 5 \
--verbose
Architecture
Goroutines
The Go version uses goroutines for concurrent execution:
- Status Log Goroutine: Sends status logs for each node
- Result Log Goroutine: Sends result logs for each node
- Config Goroutine: Sends config requests for each node
- Query Read Goroutine: Sends query read requests and spawns query write goroutines
Key Improvements over Python Version
- Better Concurrency: Goroutines are more efficient than Python threads
- Type Safety: Strong typing prevents runtime errors
- Better Error Handling: Comprehensive error handling throughout
- Memory Efficiency: Lower memory footprint than Python
- Faster Execution: Go's compiled nature provides better performance
Data Structures
Node: Represents a simulated osctrl nodeSystemInfo: System information for enrollmentOSQueryInfo: osquery-specific informationOSVersion: OS version details for different platformsHTTPClient: Custom HTTP client with debug capabilities
Building
To build a standalone binary:
go build -o fake_news tools/fake_news.go
./fake_news --secret YOUR_SECRET
Dependencies
github.com/google/uuid: For generating UUIDs- Standard Go libraries:
net/http,encoding/json,os/exec, etc.
Error Handling
The Go version includes comprehensive error handling:
- HTTP request failures are logged and operations continue
- Invalid node responses trigger re-enrollment
- osquery execution failures are handled gracefully
- File I/O operations include proper error checking
Performance
The Go version typically provides:
- 2-3x faster execution compared to Python
- Lower memory usage
- Better CPU utilization through efficient goroutines
- More stable concurrent execution
Migration from Python
The Go version maintains full compatibility with the Python script:
- Same command line interface
- Same JSON file formats
- Same API endpoints and data structures
- Same simulation behavior
Simply replace python tools/fake_news.py with go run tools/fake_news.go in your scripts.
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.