Skip to content

Commit 9e987c2

Browse files
authored
doc: create initial documentation with mkdocs (#177)
* doc: create initial documentation with mkdocs - add intro page - add setup page - add configuration page - add extension and faqs * fix: update docs to remove redundancy - update logger in extension.md - remove redundant stuff in README and add readthedocs link - update FAQs
1 parent 5e66979 commit 9e987c2

File tree

8 files changed

+335
-36
lines changed

8 files changed

+335
-36
lines changed

.readthedocs.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version, and other tools you might need
8+
build:
9+
os: ubuntu-24.04
10+
tools:
11+
python: "3.13"
12+
13+
# Build documentation with Mkdocs
14+
mkdocs:
15+
configuration: mkdocs.yml

README.md

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,13 @@
22
![Tests](https://github.com/mushorg/glutton/actions/workflows/workflow.yml/badge.svg)
33
[![GoDoc](https://godoc.org/github.com/mushorg/glutton?status.svg)](https://godoc.org/github.com/mushorg/glutton)
44

5-
Setup `go 1.21`.
5+
Glutton is a protocol-agnostic, low-interaction honeypot that intercepts network traffic and logs interactions to help analyze malicious activities. It's built using Golang and leverages iptables and TPROXY to redirect all traffic to specific protocol handlers.
66

7-
Install required system packages:
7+
## Documentation
8+
For more details, please read the [documentation](https://go-glutton.readthedocs.io/en/latest/), which provides the following sections:
89

9-
Debian:
10-
```
11-
apt-get install gcc libpcap-dev iptables
12-
```
13-
14-
Arch:
15-
```
16-
pacman -S gcc libpcap iptables
17-
```
18-
19-
Fedora:
20-
```
21-
sudo dnf install gcc libpcap-devel iptables
22-
```
23-
24-
Build glutton:
25-
```
26-
make build
27-
```
28-
29-
To run/test glutton:
30-
```
31-
sudo bin/server
32-
```
33-
34-
To get this to work on WSL, use this kernel: https://github.com/Locietta/xanmod-kernel-WSL2
35-
36-
### Setting up the Dev Container environment with VS Code
37-
38-
Since this project requires a Linux environment to build and run, you need to use a Docker container on other operating systems. For development, we recommend using the Dev Container Extension for VS Code.
39-
40-
First, install the Dev Container extension. To learn more about setting up and using dev containers, check out the following resources:
41-
- [Install Dev Container](https://code.visualstudio.com/docs/devcontainers/containers)
42-
- [Learn More](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
10+
* [Introduction](https://go-glutton.readthedocs.io/en/latest/)
11+
* [Setup](https://go-glutton.readthedocs.io/en/latest/setup/)
12+
* [Configuration](https://go-glutton.readthedocs.io/en/latest/configuration/)
13+
* [Extension](https://go-glutton.readthedocs.io/en/latest/extension/)
14+
* [FAQs](https://go-glutton.readthedocs.io/en/latest/faq/)

docs/configuration.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Configuration
2+
3+
Glutton’s behavior is controlled by several configuration files written in YAML (and JSON for schema validation). This page details the available configuration options, how they’re loaded, and best practices for customizing your setup.
4+
5+
## Configuration Files
6+
7+
### config/config.yaml
8+
9+
This file holds the core settings for Glutton. Key configuration options include:
10+
11+
- **ports:** Defines the network ports used for traffic interception.
12+
- **tcp:** The TCP port for intercepted connections (default: `5000`).
13+
- **udp:** The UDP port for intercepted packets (default: `5001`).
14+
- **ssh:** Typically excluded from redirection to avoid interfering with SSH (default: `22`).
15+
- **interface:** The network interface Glutton listens on (default: `eth0`).
16+
- **max_tcp_payload:** Maximum TCP payload size in bytes (default: `4096`).
17+
- **conn_timeout:** The connection timeout duration in seconds (default: `45`).
18+
- **confpath:** The directory path where the configuration file resides.
19+
- **producers:**
20+
- **enabled**: Boolean flag to enable or disable logging/producer functionality.
21+
- **http:** HTTP producer for sending logs to a remote endpoint, like [Ochi](https://github.com/honeynet/ochi).
22+
- **hpfeeds:** [HPFeeds](https://github.com/hpfeeds/hpfeeds) producer for sharing data with other security tools.
23+
- **addresses:** A list of additional public IP addresses for traffic handling.
24+
25+
Example configuration:
26+
27+
```yaml
28+
# config/config.yaml
29+
30+
ports:
31+
tcp: 5000
32+
udp: 5001
33+
ssh: 22
34+
35+
rules_path: config/rules.yaml
36+
37+
addresses: ["1.2.3.4"]
38+
39+
interface: eth0
40+
41+
producers:
42+
enabled: true # enables producers
43+
http:
44+
enabled: true # enables http producer
45+
# Connect with Ochi here or other remote log aggregation servers
46+
remote: http://localhost:3000/publish?token=token
47+
hpfeeds:
48+
enabled: false # disables HPFeeds
49+
host: 172.26.0.2
50+
port: 20000
51+
# HPFeeds specific details go here
52+
ident: ident
53+
auth: auth
54+
channel: test
55+
56+
conn_timeout: 45
57+
max_tcp_payload: 4096
58+
```
59+
60+
### config/rules.yaml
61+
62+
This file defines the rules that Glutton uses to determine which protocol handler should process incoming traffic.
63+
64+
Key elements include:
65+
66+
- **type**: `conn_handler` to pass off to the appropriate protocol handler or `drop` to ignore packets.
67+
- **target**: Indicates the protocol handler (e.g., "http", "ftp") to be used.
68+
- **match**: Define criteria such as source IP ranges or destination ports to match incoming traffic, according to [BPF syntax](https://biot.com/capstats/bpf.html).
69+
70+
Example rule:
71+
72+
```yaml
73+
# config/rules.yaml
74+
75+
rules:
76+
- name: Telnet filter
77+
match: tcp dst port 23 or port 2323 or port 23231
78+
type: conn_handler # will find the appropriate target protocol handler
79+
target: telnet
80+
- match: tcp dst port 6969
81+
type: drop # drops any matching packets
82+
target: bittorrent
83+
```
84+
85+
## Configuration Loading Process
86+
Glutton uses the [Viper](https://github.com/spf13/viper) library to load configuration settings. The process works as follows:
87+
88+
- **Default Settings**: Glutton initializes with default values for critical parameters.
89+
- **File-based Overrides**: Viper looks for `config.yaml` in the directory specified by confpath. If found, the settings from the file override the defaults.
90+
- **Additional Sources**: Environment variables or command-line flags can further override file-based configurations, allowing for flexible deployments.
91+
92+
## Best Practices
93+
94+
- **Backup Your Files**: Always save a backup of your configuration files before making changes.
95+
- **Validate Configurations**: Use YAML validators and the provided JSON schema to ensure your configuration is error-free.
96+
- **Test Changes**: After modifying your configuration, restart Glutton and review the logs to confirm that your changes have been applied as expected.

docs/extension.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Extension
2+
3+
Glutton is built to be easily extensible. Developers can add new protocol handlers or modify existing behavior to suit custom requirements.
4+
5+
## Adding a New Protocol Handler
6+
7+
### Create a New Module
8+
9+
- Add your new protocol handler in the appropriate subdirectory under `protocols/` (e.g., `protocols/tcp` or `protocols/udp`).
10+
- Implement the handler function conforming to the expected signature:
11+
- For TCP: `func(context.Context, net.Conn, connection.Metadata, logger interfaces.Logger, h interfaces.Honeypot) error`
12+
- For UDP: `func(context.Context, *net.UDPAddr, *net.UDPAddr, []byte, connection.Metadata) error`
13+
14+
For example:
15+
16+
17+
// protocols/tcp/new_protocol.go
18+
19+
package tcp
20+
21+
import (
22+
"context"
23+
"net"
24+
25+
"github.com/mushorg/glutton/connection"
26+
"github.com/mushorg/glutton/protocols/interfaces"
27+
)
28+
29+
// HandleNewProtocol handles incoming connections.
30+
func HandleNewProtocol(ctx context.Context, conn net.Conn, md connection.Metadata, logger interfaces.Logger, h interfaces.Honeypot) error {
31+
// Log the connection for demonstration purposes.
32+
logger.Info("Received NewProtocol connection from %s", conn.RemoteAddr().String())
33+
// Here you could add protocol-specific handling logic.
34+
// For now, simply close the connection.
35+
return conn.Close()
36+
}
37+
38+
39+
### Register the Handler
40+
- Modify the mapping function (e.g., `protocols.MapTCPProtocolHandlers` or `protocols.MapUDPProtocolHandlers` in `protocols/protocols.go`) to include your new handler.
41+
- Update configuration or rules (in `config/rules.yaml` or `rules/rules.yaml`) if needed to route specific traffic to your handler.
42+
43+
For example:
44+
45+
func MapTCPProtocolHandlers(log interfaces.Logger, h interfaces.Honeypot) map[string]TCPHandlerFunc {
46+
protocolHandlers := map[string]TCPHandlerFunc{}
47+
protocolHandlers["smtp"] = func(ctx context.Context, conn net.Conn, md connection.Metadata) error {
48+
return tcp.HandleSMTP(ctx, conn, md, log, h)
49+
}
50+
...
51+
protocolHandlers["new"] = func(ctx context.Context, conn net.Conn, md connection.Metadata) error {
52+
return tcp.HandleNewProtocol(ctx, conn, md, log, h)
53+
}
54+
...
55+
}
56+
57+
3. **Test Your Extension:**
58+
- Write tests similar to those in `protocols/protocols_test.go` to verify your new handler’s functionality.
59+
- Use `go test` to ensure that your changes do not break existing functionality.
60+
61+
## Customizing Logging and Rules
62+
63+
- **Logging:** The logging mechanism is provided by the Producer (located in `producer/`). You can modify or extend it to suit your logging infrastructure.
64+
- **Rules Engine:** The rules engine (found in `rules/`) can be extended to support additional matching criteria or custom rule types.
65+

docs/faq.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Frequently Asked Questions
2+
3+
### Q: What is Glutton?
4+
**A:** Glutton is a protocol-agnostic honeypot that intercepts network traffic, applies customizable rules, and logs interactions to help analyze malicious activities.
5+
6+
### Q: Which protocols does Glutton support?
7+
**A:** Out of the box, Glutton supports multiple protocols via its TCP and UDP handlers. The repository includes handlers for protocols such as HTTP, FTP, SMTP, Telnet, MQTT, and more. You can extend support to additional protocols as needed.
8+
9+
### Q: How do I add a new protocol or extend existing functionality?
10+
**A:** You can add a new protocol handler by implementing the appropriate interface in the `protocols/` directory and registering your handler in the corresponding mapping function. See the [Extension](extension.md) section for detailed instructions.
11+
12+
### Q: How do I configure Glutton?
13+
**A:** Configuration is managed through YAML files:
14+
15+
- **config/config.yaml:** General settings such as port numbers and interface names.
16+
- **config/rules.yaml:** Defines rules for matching and processing network traffic.
17+
18+
See the [Configuration](configuration.md) section for detailed instructions.
19+
20+
### Q: What are the system prerequisites?
21+
**A:** Glutton requires a Linux system, so if you're using a different OS, you'll have to use Docker to set it up. Specific installation commands are provided in the [Setup](setup.md) section.

docs/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Introduction
2+
3+
Glutton is a protocol-agnostic honeypot designed to emulate various network services and protocols. It is built in Go and aims to capture and analyze malicious network activity by intercepting connections and logging detailed interaction data. Glutton is highly configurable, allowing users to define custom rules and extend its functionality by adding new protocol handlers.
4+
5+
Key features include:
6+
7+
- **Protocol Agnostic:** Supports TCP and UDP traffic across a variety of protocols.
8+
- **Rule-Based Processing:** Uses configurable rules to determine how incoming connections are handled.
9+
- **Extensibility:** Easily extend the tool by adding new protocol handlers.
10+
- **Logging and Analysis:** Captures connection metadata and payloads for further analysis.
11+
12+
This documentation will guide you through the installation, deployment, understanding its network interactions, extending its functionality, and addressing common questions.
13+

docs/setup.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Setup
2+
3+
Follow these steps to install Glutton on your system.
4+
5+
## Environment Requirements
6+
7+
8+
- **Linux Required:** Glutton must be built and run on a Linux system.
9+
- **Non-Linux Users:** For Windows or macOS, use Docker or the VSCode Dev Container Extension.
10+
- **WSL Users:** When using WOS, we recommend running glutton with the [xanmod-kernel-WSL2](https://github.com/Locietta/xanmod-kernel-WSL2)
11+
- For setting up the development environment using VS Code Dev Containers, refer to:
12+
- [Install Dev Container](https://code.visualstudio.com/docs/devcontainers/containers)
13+
- [Learn More](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
14+
15+
## Prerequisites
16+
17+
Ensure you have [Go](https://go.dev/dl/) installed (recommended version: **Go 1.21** or later). In addition, you will need system packages for building and running Glutton:
18+
19+
### Debian/Ubuntu
20+
21+
```bash
22+
sudo apt-get update
23+
sudo apt-get install gcc libpcap-dev iptables
24+
```
25+
26+
### Arch Linux
27+
```bash
28+
sudo pacman -S gcc libpcap iptables
29+
```
30+
31+
### Fedora
32+
```bash
33+
sudo dnf install gcc libpcap-devel iptables
34+
```
35+
36+
## Building Glutton
37+
38+
Clone the repository and build the project:
39+
40+
```bash
41+
git clone https://github.com/mushorg/glutton.git
42+
cd glutton
43+
make build
44+
```
45+
46+
This will compile the project and place the server binary in the `bin/` directory.
47+
48+
## Testing the Installation
49+
50+
```bash
51+
bin/server --version
52+
```
53+
Replace `<network_interface>` (e.g., `eth0`) with the interface you want to monitor. You should see output similar to:
54+
55+
```bash
56+
_____ _ _ _
57+
/ ____| | | | | |
58+
| | __| |_ _| |_| |_ ___ _ __
59+
| | |_ | | | | | __| __/ _ \| '_ \
60+
| |__| | | |_| | |_| || (_) | | | |
61+
\_____|_|\__,_|\__|\__\___/|_| |_|
62+
63+
64+
glutton version v1.0.1+d2503ba 2025-02-21T05:48:07+00:00
65+
```
66+
67+
## Usage
68+
69+
Glutton can be configured using several command-line flags:
70+
71+
- **--interface, -i**: `string` - Specifies the network interface (default: `eth0`)
72+
- **--ssh, -s**: `int` - If set, it overrides the default SSH port
73+
- **--logpath, -l**: `string` - Sets the file path for logging (default: `/dev/null`)
74+
- **--confpath, -c**: `string` - Defines the path to the configuration directory (default: `config/`)
75+
- **--debug, -d**: `bool` - Enables debug mode (default: `false`)
76+
- **--version**: `bool` - Prints the version and exits
77+
- **--var-dir**: `string` - Sets the directory for variable data storage (default: `/var/lib/glutton`)
78+
79+
For example, to run Glutton with a custom interface and enable debug mode, you might use the following command:
80+
81+
```bash
82+
bin/server --interface <network_interface> --debug
83+
```
84+
85+
Replace `<network_interface>` (e.g., `eth0`) with the interface you want to monitor. The command starts the Glutton server, which sets up TCP/UDP listeners and applies iptables rules for transparent proxying.
86+
87+
**Configuration:** Before deployment, ensure your configuration files, in the `config/` folder by default, are properly set up. For detailed instructions, refer to the [Configuration](configuration.md) page.
88+
89+
## Docker
90+
91+
To deploy using Docker:
92+
93+
1. Build the Docker image:
94+
95+
```
96+
docker build -t glutton .
97+
```
98+
99+
2. Run the Container:
100+
101+
```
102+
docker run --rm --cap-add=NET_ADMIN -it glutton
103+
```
104+
105+
The Docker container is preconfigured with the necessary dependencies (iptables, libpcap, etc.) and copies the configuration and rules files into the container.
106+

mkdocs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
site_name: Glutton Documentation
2+
version: 1.0
3+
nav:
4+
- Introduction: index.md
5+
- Setup: setup.md
6+
- Configuration: configuration.md
7+
- Extension: extension.md
8+
- FAQs: faq.md
9+
theme:
10+
name: readthedocs
11+

0 commit comments

Comments
 (0)