README.md 4.5 K raw
1
# Gargantua 
2
3
![cover](https://files.stevedylan.dev/gargantua-demo.jpg)
4
5
> This little maneuver's going to cost us 51 years
6
7
A simple scraper tarpit and maze written in Go
8
9
10
## Quick Start 
11
12
Clone the repo and install
13
14
```bash
15
git clone https://github.com/stevedylandev/gargantua
16
cd gargantua
17
go install .
18
```
19
20
Run the server
21
22
```bash
23
gargantua
24
```
25
26
Alternatively use Docker
27
28
```bash
29
docker compose up -d --build
30
```
31
32
## Running as a daemon 
33
34
Ready-made service files for systemd and OpenRC live in `deploy/`. Both raise the file-descriptor limit to 1,000,000, since that limit is the ceiling on how many crawlers the tarpit can hold at once. You can read more about this in the [reasoning](#Reasoning).
35
36
> [!NOTE]
37
> Gargantua only affects crawlers hitting your own server, but it intentionally holds large numbers of connections open for long periods. Check your hosting provider's acceptable-use policy before deploying, especially on shared infrastructure.
38
39
First, build and install the binary and corpus:
40
41
```bash
42
go build -o gargantua .
43
sudo mkdir -p /usr/local/share/gargantua
44
sudo cp gargantua /usr/local/bin/gargantua
45
sudo cp moby.txt /usr/local/share/gargantua/moby.txt
46
```
47
48
### systemd 
49
50
```bash
51
sudo cp deploy/systemd/gargantua.service /etc/systemd/system/
52
sudo systemctl enable --now gargantua
53
```
54
55
The unit uses `DynamicUser`, so no user account needs to be created. Tune behaviour by editing the `Environment=` lines in the unit.
56
57
### OpenRC
58
59
```bash
60
doas adduser -S -D -H gargantua
61
doas cp deploy/openrc/gargantua.initd /etc/init.d/gargantua
62
doas cp deploy/openrc/gargantua.confd /etc/conf.d/gargantua
63
doas rc-update add gargantua default
64
doas rc-service gargantua start
65
```
66
67
Configuration and the fd limit live in `/etc/conf.d/gargantua`, which OpenRC sources automatically on each start. Edit it and run `doas rc-service gargantua restart` to apply changes.
68
69
## Configuration 
70
71
Use the following environment variables to configure Gargantua
72
73
| Variable | Description | Default |
74
| --- | --- | --- |
75
| `GARGANTUA_CORPUS` | Text file used for the Markov babbler | `moby.txt` |
76
| `GARGANTUA_HOST` | Host to listen on | `127.0.0.1` |
77
| `GARGANTUA_PORT` | Port to listen on | `8090` |
78
| `GARGANTUA_LOG_LEVEL` | Minimum log level: `debug`, `info`, `warn` or `error` | `info` |
79
| `GARGANTUA_LOG_FORMAT` | Log format: `text` or `json` | `text` |
80
| `GARGANTUA_DELAY_MIN_MS` | Minimum delay between drip writes, in ms | `150` |
81
| `GARGANTUA_DELAY_MAX_MS` | Maximum delay between drip writes, in ms | `250` |
82
| `GARGANTUA_CHUNK_MAX_BYTES` | Maximum number of bytes in a written chunk | `45` |
83
84
Gargantua uses a slow drip method for writing the html that will keep the scraper longer. You can tweak the range of delay used between writes and the amount of data written with the `DELAY` and `CHUNK` variables above.
85
86
`robots.txt` defaults to `User-agent: * Disallow: /` to prevent indexing; the goal is to direct a disobedient crawler to this deployed server and get it stuck.
87
88
## Reasoning
89
90
LLM scrapers love to eat content, so this gives them something to feed on. Heavily inspired by Nepenthes, this sever will create an endless loop of content and relative links that are dripped slowly to consume resources and time. Instead of writing a proxy to go on top of a site, the idea of Gargantua is to have you set a trap like this in your HTML: 
91
92
```html
93
<a
94
  href="/gargantua"
95
  style="display: none;"
96
  aria-hidden="true"
97
  tabindex="-1"
98
>
99
  Lots of high quality data here
100
</a>
101
```
102
103
104
Then have that `/gargantua` path do a permanent redirect to a server running the program. An important piece is that your `robots.txt` has these values: 
105
106
```
107
User-agent: *
108
Disallow: /gargantua
109
```
110
111
Crawlers are supposed to obey the `robots.txt`, and by knowingly disregarding that rule, they are subject to Gargantua. 
112
113
I also wanted to write this in Go instead of Lua. Go's advantage here (apart from speed) is that blocking is cheap. Each tarpitted connection lives in its own goroutine, parked in a sleep or socket wait for the vast majority of its life at a few KB of memory each, with the runtime's netpoller handling I/O without dedicating threads. The Markov chain corpus is built once with `sync.OnceValue` and shared across every connection, and templates are embedded and parsed at compile time, so a request never touches disk. The result is a single static binary that makes the OS file-descriptor limit the ceiling on how many crawlers you can trap at once, not memory or CPU. 
114
115
We may not have a chance to stand again the onslaught of big AI, but it's fun to try. 
116
117
## Licence
118
119
[GNU GPL v3.0](LICENSE)