|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Labs |
| 4 | +--- |
| 5 | + |
| 6 | +# Labs: DNS enumeration without touching real infrastructure |
| 7 | + |
| 8 | +These exercises teach subdomain enumeration on fictional zones. `-simulate-zone` |
| 9 | +loads a scenario file and answers every query from a DNS server that subenum |
| 10 | +runs on `127.0.0.1` for the length of the scan. **No DNS traffic leaves your |
| 11 | +machine**, so labs are safe in a classroom, a CTF or an air-gapped VM. |
| 12 | + |
| 13 | +Unlike `-simulate`, which invents results from a hit rate, a lab runs the real |
| 14 | +resolver against the scenario. Wildcard detection, `-rate` pacing, retries, the |
| 15 | +reliability guard and the run-quality report all behave exactly as they would |
| 16 | +against a live zone, and the results are the same on every run. |
| 17 | + |
| 18 | +## Setup |
| 19 | + |
| 20 | +You need a subenum binary (see [Installation](https://github.com/TMHSDigital/subenum#installation)) |
| 21 | +and a copy of the repository for the scenario files. For a zero-install |
| 22 | +classroom, [open the repository in GitHub Codespaces](https://codespaces.new/TMHSDigital/subenum): |
| 23 | +the container builds `./subenum` for you. |
| 24 | + |
| 25 | +Every lab scans `lab.example` with the short wordlist `examples/labs/words.txt`. |
| 26 | +Run the commands from the repository root: |
| 27 | + |
| 28 | +```bash |
| 29 | +L=examples/labs |
| 30 | +W="-w $L/words.txt" |
| 31 | +``` |
| 32 | + |
| 33 | +Each lab ends with questions. The answers are folded underneath; try first. |
| 34 | + |
| 35 | +## Lab 1: a first scan |
| 36 | + |
| 37 | +```bash |
| 38 | +subenum $W -simulate-zone $L/lab1-first-scan.zone -show-records lab.example |
| 39 | +``` |
| 40 | + |
| 41 | +`-show-records` prints the records behind each name. |
| 42 | + |
| 43 | +1. How many subdomains did the scan find? |
| 44 | +2. Which host has an IPv6 address? |
| 45 | +3. `shop` has the same address as `www`. Why? |
| 46 | +4. The scenario file defines `blog`, but it is not in the results. Rerun with |
| 47 | + `-type A,AAAA,CNAME`. What is `blog`, and why did the default scan miss it? |
| 48 | + |
| 49 | +<details markdown="1"> |
| 50 | +<summary>Answers</summary> |
| 51 | + |
| 52 | +1. Five: `www`, `mail`, `vpn`, `jenkins` and `shop`. |
| 53 | +2. `www` (`2001:db8::10`). |
| 54 | +3. `shop` is a CNAME (an alias) for `www`. The resolver follows the alias and |
| 55 | + returns `www`'s addresses. The CNAME run shows `CNAME=www.lab.example`. |
| 56 | +4. `blog` is a CNAME to `ghost-lab.example.net`, a host that does not exist. |
| 57 | + The default lookups (A and AAAA) find no address, so the name looks empty. |
| 58 | + With CNAME lookups, subenum shows the alias and flags it |
| 59 | + `TAKEOVER?=dangling`: the alias points at a name nobody has registered. If |
| 60 | + that were a cloud service, whoever claimed the name would control |
| 61 | + `blog.lab.example`. This is how subdomain takeovers start. See |
| 62 | + [takeover hints](https://github.com/TMHSDigital/subenum#subdomain-takeover-hints) |
| 63 | + in the README. |
| 64 | + |
| 65 | +</details> |
| 66 | + |
| 67 | +## Lab 2: spot the wildcard |
| 68 | + |
| 69 | +```bash |
| 70 | +subenum $W -simulate-zone $L/lab2-wildcard.zone lab.example |
| 71 | +``` |
| 72 | + |
| 73 | +1. What does subenum report, and why does it refuse to continue? |
| 74 | +2. Rerun with `-force`. Which names are reported now, and how does subenum tell |
| 75 | + them apart from the wildcard? |
| 76 | + |
| 77 | +<details markdown="1"> |
| 78 | +<summary>Answers</summary> |
| 79 | + |
| 80 | +1. "Wildcard DNS detected": the zone has a `*` record, so every name, even a |
| 81 | + random one, resolves to `192.0.2.250`. Without filtering, every word in the |
| 82 | + list would be reported as a "finding". |
| 83 | +2. `www`, `portal` and `intranet`. Before scanning, subenum queries several |
| 84 | + random names to fingerprint the wildcard's answer. With `-force` it then |
| 85 | + drops every result that matches that fingerprint; these three have their |
| 86 | + own addresses, so they are real hosts. The `wildcard-filtered` line counts |
| 87 | + the rest. |
| 88 | + |
| 89 | +</details> |
| 90 | + |
| 91 | +## Lab 3: rate limits |
| 92 | + |
| 93 | +This resolver answers REFUSED once it gets more than 40 queries in a second, |
| 94 | +as many public and corporate resolvers do. |
| 95 | + |
| 96 | +```bash |
| 97 | +subenum $W -simulate-zone $L/lab3-rate-limit.zone -stats lab3.json lab.example |
| 98 | +subenum $W -simulate-zone $L/lab3-rate-limit.zone -stats lab3-paced.json -rate 30 lab.example |
| 99 | +``` |
| 100 | + |
| 101 | +1. Compare the `refused` counts of the two runs. |
| 102 | +2. Open both `-stats` reports. What is each run's `verdict`? |
| 103 | +3. Why can the first run still list some real names, and why should you not |
| 104 | + trust it anyway? |
| 105 | + |
| 106 | +<details markdown="1"> |
| 107 | +<summary>Answers</summary> |
| 108 | + |
| 109 | +1. The first run bursts with 100 workers and most of its lookups are refused. |
| 110 | + The paced run (`-rate 30`, under the resolver's 40-per-second limit) has |
| 111 | + none. |
| 112 | +2. `unreliable` for the burst, `complete` for the paced run. |
| 113 | +3. The first queries arrived before the limit kicked in, so whatever they |
| 114 | + found is real. But a REFUSED name was never actually checked: it might |
| 115 | + exist. A run with many refusals says nothing about the names it missed, |
| 116 | + which is why the report calls it unreliable. Slower is faster here. |
| 117 | + |
| 118 | +</details> |
| 119 | + |
| 120 | +## Lab 4: recursive discovery |
| 121 | + |
| 122 | +```bash |
| 123 | +subenum $W -simulate-zone $L/lab4-recursive.zone lab.example |
| 124 | +subenum $W -simulate-zone $L/lab4-recursive.zone -recursive -depth 3 lab.example |
| 125 | +``` |
| 126 | + |
| 127 | +1. How many names does the flat scan find? How many does the recursive scan |
| 128 | + find? |
| 129 | +2. Which name needed `-depth 3`? |
| 130 | +3. Try the recursive scan with the bundled 5,000-word list (drop `$W`). What |
| 131 | + happens, and why? |
| 132 | + |
| 133 | +<details markdown="1"> |
| 134 | +<summary>Answers</summary> |
| 135 | + |
| 136 | +1. Three (`www`, `dev`, `corp`) against eight. Recursion takes every name it |
| 137 | + finds and enumerates the wordlist under it, which turns up `api.dev`, |
| 138 | + `git.dev`, `staging.dev` and `vpn.corp`, then `admin.staging.dev`. |
| 139 | +2. `admin.staging.dev`, three labels below `lab.example`. |
| 140 | +3. subenum refuses to start: with 5,000 words, depth 3 could mean over 100 |
| 141 | + billion queries. Recursion multiplies the wordlist at every level, so it |
| 142 | + asks you to set `-max-queries` (or `-force`) first. Against a real target, |
| 143 | + that guard is what keeps a scan from becoming a flood. |
| 144 | + |
| 145 | +</details> |
| 146 | + |
| 147 | +## Lab 5: when lookups fail |
| 148 | + |
| 149 | +```bash |
| 150 | +subenum $W -simulate-zone $L/lab5-failures.zone -timeout 300 -stats lab5.json lab.example |
| 151 | +``` |
| 152 | + |
| 153 | +1. Which outcome lines in the breakdown are non-zero besides `resolved` and |
| 154 | + `nxdomain`? |
| 155 | +2. What is the run's `verdict` in `lab5.json`, and what does it mean for the |
| 156 | + names that failed? |
| 157 | + |
| 158 | +<details markdown="1"> |
| 159 | +<summary>Answers</summary> |
| 160 | + |
| 161 | +1. `timeout` (`legacy` and `old` never answer), `refused` (`beta`) and `other` |
| 162 | + (`backup` answers SERVFAIL). |
| 163 | +2. `degraded`: the scan finished, but some names could not be checked. A |
| 164 | + failed lookup is not "does not exist". Those names need a retry |
| 165 | + (`-attempts`) or a different resolver before you can rule them out. |
| 166 | + |
| 167 | +</details> |
| 168 | + |
| 169 | +## Writing your own scenario |
| 170 | + |
| 171 | +A scenario is a plain text file. Names are relative to the domain you scan, |
| 172 | +and `#` starts a comment: |
| 173 | + |
| 174 | +```text |
| 175 | +$DELAY 20ms # every answer waits this long |
| 176 | +$REFUSE-ABOVE 50 # answer REFUSED past 50 queries a second |
| 177 | +@ A 192.0.2.1 # the scanned domain itself |
| 178 | +www A 192.0.2.10 |
| 179 | +www AAAA 2001:db8::10 |
| 180 | +shop CNAME www # relative target |
| 181 | +blog CNAME ghost.example.net. # absolute target (trailing dot) |
| 182 | +*.dev A 192.0.2.99 # wildcard under dev |
| 183 | +slow TIMEOUT # never answered |
| 184 | +broken SERVFAIL # also: REFUSED, NXDOMAIN |
| 185 | +``` |
| 186 | + |
| 187 | +Names the file does not define are NXDOMAIN. The scenario is the whole world |
| 188 | +during a lab, so names outside the scanned domain (such as an external CNAME |
| 189 | +target) are NXDOMAIN too. Use the |
| 190 | +documentation ranges (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`, |
| 191 | +`2001:db8::/32`) and reserved names such as `lab.example`, so nothing in a |
| 192 | +lab points at a real host. |
| 193 | + |
| 194 | +Scenarios work with every other flag, such as `-dL` (each listed domain gets |
| 195 | +the same zone), `-permute`, `-diff`, `-format json` and `-stats`, which |
| 196 | +records the scenario file under `zone`. `-simulate-zone` cannot be combined |
| 197 | +with `-simulate`, `-dns-server` or `-r`. |
0 commit comments