Building a Cowrie SSH Honeypot with Secure Log Collection into Graylog
A small SOC-style project: deploying a honeypot on a cloud VPS, isolating it from my home network with WireGuard, and analysing attacker behaviour in Graylog.
Overview
The goal was to deploy an SSH honeypot, collect the logs safely, and analyse the attack traffic. I wanted to do this without exposing my home network, so the honeypot lives on a disposable VPS with digital ocean and only talks to my PC through wireguard vpn.
Stack
- DigitalOcean Droplet (London, Ubuntu 24.04, 1 vCPU / 1 GB): Hosts the honeypot
- Cowrie 3.1.1: Medium-interaction SSH/Telnet honeypot
- WireGuard: Encrypted tunnel between the Droplet and my PC
- Filebeat: Ships Cowrie’s JSON logs
- Graylog 7.1 (Docker Compose): Log management, search and dashboards
Design principles
- Least exposure. The Droplet is treated as untrusted and disposable. It can only reach one port on my PC, through the tunnel.
- Nothing on my PC faces the internet. Graylog’s web UI is bound to
127.0.0.1, and the Beats input is bound to the WireGuard address only, so hopefully nothing else gets in. - Cowrie never runs as root. It runs as an unprivileged user, and port 22 is redirected to it.
1. Provisioning the Droplet
- Region: London (LON1), Ubuntu 24.04 LTS, Basic shared CPU, 1 vCPU / 1 GB RAM / 25 GB SSD.
- Authentication: a dedicated SSH key generated just for this server, so the key can’t be linked to my other accounts.
- IPv6 and backups disabled, monitoring enabled (free, and useful for catching a full disk).
I chose 1 GB over the 512 MB tier because Cowrie, Filebeat and WireGuard are tight in 512 MB, and the logs and downloaded malware samples fill a 10 GB disk quickly.
2. Hardening the Droplet
Attackers were hitting the server within about a minute of it booting, so this came first.
- Updated the system and created a non-root admin user in the
sudogroup. - Copied my key to the new user and tested a second login before changing anything else.
- Applied SSH hardening via a drop-in file:
Port 22022
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowUsers <admin-user>
MaxAuthTries 3
- Enabled UFW (default deny incoming) and allowed only the ports I needed.
Lessons learned
- On Ubuntu 24.04, SSH is started by a systemd socket (
ssh.socket) that ignores thePortsetting. I had to disable the socket and enablessh.serviceinstead. sshd -Tshows the settings SSH is actually using, which is more reliable than reading the config files.- Also check that
ssh.serviceis enabled, or SSH won’t come back after a reboot (could get locked out).
3. Installing Cowrie
- Created a dedicated
cowrieuser with a disabled password, no sudo rights and no login shell, so a compromised honeypot process has minimal privileges on the host. - Cloned Cowrie, created a Python virtualenv, and installed the dependencies and the package (
pip install -e .). - Kept the shipped defaults (SSH on port 2222, Telnet disabled, JSON logging enabled) and added a small override in
etc/cowrie.cfgthat changes the fake hostname.
Lessons learned
- Defaults and overrides are separate. In 3.1.1 the defaults live in
src/cowrie/data/etc/, andetc/cowrie.cfgonly holds my overrides, so I never edit the shipped files. - No foreground flag. I couldn’t find one in 3.1.1, so for systemd I ran
twistd -ndirectly, which keeps the process in the foreground so systemd can supervise it.
Getting attackers onto port 22
Cowrie listens on 2222 because only root can bind to ports below 1024. Instead of running it as root, I redirected the port in the NAT table, using UFW’s before.rules:
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
COMMIT
My real SSH moved to port 22022, so port 22 is now exclusively the honeypot.
Running it as a service
[Service]
User=cowrie
Group=cowrie
WorkingDirectory=/home/cowrie/cowrie
ExecStart=/home/cowrie/cowrie/cowrie-env/bin/twistd -n --umask=0022 --pidfile= --logger cowrie.python.logfile.logger cowrie
Restart=on-failure
NoNewPrivileges=true
PrivateTmp=true
Verifying it survives a reboot. My first reboot test was done from inside the fake shell, which only pretends to reboot. The real test is running sudo reboot from the real SSH session and checking afterwards that Cowrie, the NAT redirect and sshd all came back.
4. The WireGuard tunnel
A point-to-point tunnel with the Droplet as the server (10.0.0.1) and my PC as the client (10.0.0.2).
- The PC initiates the connection, so no ports need opening on my home router.
PersistentKeepalive = 25keeps the tunnel alive through NAT.- On the PC,
AllowedIPs = 10.0.0.1/32means only tunnel traffic goes through it, and the rest of my internet is unaffected. - Private keys are generated on their own machines, stored with mode 600, and never shared. Only the public keys are exchanged.
5. Graylog
I used Graylog’s official docker-compose repo (the open-core single-node setup: MongoDB, Graylog Data Node, Graylog server).
Locking down the published ports. The default compose file exposes many inputs. I reduced the graylog service to two:
ports:
- "10.0.0.2:5044:5044/tcp" # Beats input, reachable only through WireGuard
- "127.0.0.1:9000:9000/tcp" # Web UI, local only
Binding to 10.0.0.2 is the important control. That address only exists on the WireGuard interface, and WireGuard drops any packet whose source isn’t the Droplet’s tunnel address. (I first tried to restrict this with firewalld, but Docker’s published ports bypass those rules, so binding is the reliable approach.)
Setup steps
- Set
vm.max_map_count=262144on the host, which OpenSearch requires. - Generated
GRAYLOG_PASSWORD_SECRETand the SHA-256 hash of the admin password in.env(file mode 600). - Completed the Data Node preflight setup (created a CA, certificate renewal policy and provisioned certificates).
- Created a Beats input and routed it to a dedicated
cowriestream with its own index set:- 1 shard, 0 replicas (a single node can’t host replicas)
- Retention: 30 to 40 days
Mistake worth noting: the compose file has two ports: blocks, and I first edited the Data Node’s by accident. Checking the merged result with docker compose config caught it before anything was exposed.
6. Shipping the logs
Filebeat on the Droplet reads Cowrie’s JSON log and sends it through the tunnel:
filebeat.inputs:
- type: filestream
id: cowrie-json
paths:
- /home/cowrie/cowrie/var/log/cowrie/cowrie.json
parsers:
- ndjson:
target: ""
overwrite_keys: true
add_error_key: true
output.logstash:
hosts: ["10.0.0.2:5044"]
The ndjson parser splits each event into separate fields (src_ip, eventid, username, password, input), so everything is searchable and chartable instead of being one text blob.
7. Security considerations
- Disposable server. No personal data, no reused credentials, and no SSH agent forwarding.
- Blast radius. If the Droplet were compromised, the only thing it could reach is one TCP port on my PC, over the tunnel.
- Filtering my own traffic. My test logins are in the logs, so I need to exclude my own IP from the analysis.
- Provider policy. I checked the hosting provider’s acceptable use policy before deploying.
8. Results

There we go! After a few adjustments and a month of idle we now have a dashboard to analyse all attempts on the honeypot! Write up soon!
9. What I’d do next
- Add alerting for sessions that download files.
- Enrich IPs with threat intelligence feeds.
- Try a second honeypot (for example OpenCanary or a web honeypot) alongside Cowrie.
Tools
Cowrie · WireGuard · Graylog · Filebeat · Docker Compose · UFW · DigitalOcean