|
| 1 | +name: subenum |
| 2 | +description: Subdomain enumeration you can trust, with change detection and a run-quality verdict that gates the job. |
| 3 | +author: TMHSDigital |
| 4 | +branding: |
| 5 | + icon: search |
| 6 | + color: blue |
| 7 | + |
| 8 | +inputs: |
| 9 | + domain: |
| 10 | + description: Domain to scan. Only scan domains you own or are authorized to test. |
| 11 | + required: false |
| 12 | + default: "" |
| 13 | + domains-file: |
| 14 | + description: File of apex domains, one per line (-dL), instead of domain. |
| 15 | + required: false |
| 16 | + default: "" |
| 17 | + wordlist: |
| 18 | + description: Wordlist file (-w). Empty uses the bundled top-5000 list. |
| 19 | + required: false |
| 20 | + default: "" |
| 21 | + args: |
| 22 | + description: Extra subenum flags, space-separated (no quoting), e.g. "-rate 200 -type A,AAAA,CNAME -ct". |
| 23 | + required: false |
| 24 | + default: "" |
| 25 | + previous: |
| 26 | + description: A previous results file to diff against (-diff). Overrides baseline-artifact. |
| 27 | + required: false |
| 28 | + default: "" |
| 29 | + baseline-artifact: |
| 30 | + description: >- |
| 31 | + Name of a workflow artifact holding the previous results. The newest one |
| 32 | + is downloaded and diffed against, and a complete run uploads its results |
| 33 | + under the same name for next time. Empty disables it. |
| 34 | + required: false |
| 35 | + default: "" |
| 36 | + sarif: |
| 37 | + description: Write takeover candidates to this SARIF file, for github/codeql-action/upload-sarif. Needs CNAME in -type. |
| 38 | + required: false |
| 39 | + default: "" |
| 40 | + fail-on: |
| 41 | + description: "Fail the step when the verdict is at least this bad: unreliable, degraded or never." |
| 42 | + required: false |
| 43 | + default: unreliable |
| 44 | + version: |
| 45 | + description: subenum release to install ("latest", or a tag such as v0.9.0), or "source" to build the action's own checkout (needs Go). |
| 46 | + required: false |
| 47 | + default: latest |
| 48 | + token: |
| 49 | + description: Token for downloading the release and the baseline artifact. |
| 50 | + required: false |
| 51 | + default: ${{ github.token }} |
| 52 | + |
| 53 | +outputs: |
| 54 | + verdict: |
| 55 | + description: Run-quality verdict, complete, degraded or unreliable. |
| 56 | + value: ${{ steps.scan.outputs.verdict }} |
| 57 | + found: |
| 58 | + description: Names found. |
| 59 | + value: ${{ steps.scan.outputs.found }} |
| 60 | + added: |
| 61 | + description: Names added since the previous results (with previous or baseline-artifact). |
| 62 | + value: ${{ steps.scan.outputs.added }} |
| 63 | + removed: |
| 64 | + description: Names removed since the previous results. |
| 65 | + value: ${{ steps.scan.outputs.removed }} |
| 66 | + results: |
| 67 | + description: Path of the full results (JSONL). |
| 68 | + value: ${{ steps.scan.outputs.results }} |
| 69 | + stats: |
| 70 | + description: Path of the run-quality report (JSON). |
| 71 | + value: ${{ steps.scan.outputs.stats }} |
| 72 | + |
| 73 | +runs: |
| 74 | + using: composite |
| 75 | + steps: |
| 76 | + - name: Install subenum |
| 77 | + shell: bash |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ inputs.token }} |
| 80 | + VERSION: ${{ inputs.version }} |
| 81 | + run: | |
| 82 | + set -euo pipefail |
| 83 | + bin="$RUNNER_TEMP/subenum-bin" |
| 84 | + mkdir -p "$bin" |
| 85 | + if [ "$VERSION" = source ]; then |
| 86 | + (cd "$GITHUB_ACTION_PATH" && go build -trimpath -o "$bin/" .) |
| 87 | + else |
| 88 | + if [ "$VERSION" = latest ]; then |
| 89 | + VERSION=$(gh release view --repo TMHSDigital/subenum --json tagName --jq .tagName) |
| 90 | + fi |
| 91 | + v="${VERSION#v}" |
| 92 | + case "$(uname -s)" in |
| 93 | + Linux) os=linux ext=tar.gz ;; |
| 94 | + Darwin) os=darwin ext=tar.gz ;; |
| 95 | + MINGW* | MSYS* | CYGWIN*) os=windows ext=zip ;; |
| 96 | + *) echo "unsupported runner OS $(uname -s)"; exit 1 ;; |
| 97 | + esac |
| 98 | + case "$(uname -m)" in |
| 99 | + x86_64 | amd64) arch=amd64 ;; |
| 100 | + arm64 | aarch64) arch=arm64 ;; |
| 101 | + *) echo "unsupported runner architecture $(uname -m)"; exit 1 ;; |
| 102 | + esac |
| 103 | + archive="subenum_${v}_${os}_${arch}.${ext}" |
| 104 | + dl="$RUNNER_TEMP/subenum-dl" |
| 105 | + mkdir -p "$dl" |
| 106 | + gh release download "v${v}" --repo TMHSDigital/subenum --dir "$dl" --clobber \ |
| 107 | + --pattern "$archive" --pattern checksums.txt |
| 108 | + (cd "$dl" && if command -v sha256sum > /dev/null; then sha256sum --check --ignore-missing checksums.txt; \ |
| 109 | + else shasum -a 256 --check --ignore-missing checksums.txt; fi) |
| 110 | + if [ "$ext" = zip ]; then unzip -o -q "$dl/$archive" -d "$dl/x"; else mkdir -p "$dl/x" && tar -xzf "$dl/$archive" -C "$dl/x"; fi |
| 111 | + find "$dl/x" -maxdepth 2 -name 'subenum*' -type f \( -name subenum -o -name subenum.exe \) -exec cp {} "$bin/" \; |
| 112 | + fi |
| 113 | + echo "$bin" >> "$GITHUB_PATH" |
| 114 | +
|
| 115 | + - name: Download the baseline |
| 116 | + if: inputs.baseline-artifact != '' && inputs.previous == '' |
| 117 | + shell: bash |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ inputs.token }} |
| 120 | + NAME: ${{ inputs.baseline-artifact }} |
| 121 | + run: | |
| 122 | + set -euo pipefail |
| 123 | + dir="$RUNNER_TEMP/subenum-baseline" |
| 124 | + mkdir -p "$dir" |
| 125 | + run=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$NAME&per_page=1" \ |
| 126 | + --jq '.artifacts[0] | select(.expired == false) | .workflow_run.id // empty') |
| 127 | + if [ -n "$run" ]; then |
| 128 | + gh run download "$run" --repo "$GITHUB_REPOSITORY" --name "$NAME" --dir "$dir" |
| 129 | + else |
| 130 | + echo "No baseline artifact named $NAME yet; this run sets it." |
| 131 | + fi |
| 132 | +
|
| 133 | + - name: Scan |
| 134 | + id: scan |
| 135 | + shell: bash |
| 136 | + env: |
| 137 | + DOMAIN: ${{ inputs.domain }} |
| 138 | + DOMAINS_FILE: ${{ inputs.domains-file }} |
| 139 | + WORDLIST: ${{ inputs.wordlist }} |
| 140 | + ARGS: ${{ inputs.args }} |
| 141 | + PREVIOUS: ${{ inputs.previous }} |
| 142 | + BASELINE: ${{ inputs.baseline-artifact }} |
| 143 | + SARIF: ${{ inputs.sarif }} |
| 144 | + FAIL_ON: ${{ inputs.fail-on }} |
| 145 | + run: | |
| 146 | + set -o pipefail |
| 147 | + out="$RUNNER_TEMP/subenum-out" |
| 148 | + mkdir -p "$out" |
| 149 | + flags=(-silent -format jsonl -o "$out/results.jsonl" -stats "$out/run.json") |
| 150 | + [ -n "$WORDLIST" ] && flags+=(-w "$WORDLIST") |
| 151 | + [ -n "$SARIF" ] && flags+=(-sarif "$SARIF") |
| 152 | + prev="$PREVIOUS" |
| 153 | + if [ -z "$prev" ] && [ -n "$BASELINE" ] && [ -s "$RUNNER_TEMP/subenum-baseline/results.jsonl" ]; then |
| 154 | + prev="$RUNNER_TEMP/subenum-baseline/results.jsonl" |
| 155 | + fi |
| 156 | + [ -n "$prev" ] && flags+=(-diff "$prev") |
| 157 | + read -r -a extra <<< "$ARGS" |
| 158 | + if [ -n "$DOMAINS_FILE" ]; then target=(-dL "$DOMAINS_FILE"); else target=("$DOMAIN"); fi |
| 159 | + if [ -z "$DOMAIN" ] && [ -z "$DOMAINS_FILE" ]; then echo "::error::set domain or domains-file"; exit 2; fi |
| 160 | +
|
| 161 | + subenum "${flags[@]}" "${extra[@]}" "${target[@]}" > "$out/changes.jsonl" |
| 162 | + code=$? |
| 163 | + if [ ! -s "$out/run.json" ]; then echo "::error::subenum exited $code without a report"; exit "$code"; fi |
| 164 | +
|
| 165 | + verdict=$(jq -r .verdict "$out/run.json") |
| 166 | + reason=$(jq -r .reason "$out/run.json") |
| 167 | + found=$(jq '[.targets[].found] | add // 0' "$out/run.json") |
| 168 | + added=$(jq '.diff.added // 0' "$out/run.json") |
| 169 | + removed=$(jq '.diff.removed // 0' "$out/run.json") |
| 170 | + { |
| 171 | + echo "verdict=$verdict"; echo "found=$found"; echo "added=$added"; echo "removed=$removed" |
| 172 | + echo "results=$out/results.jsonl"; echo "stats=$out/run.json" |
| 173 | + } >> "$GITHUB_OUTPUT" |
| 174 | +
|
| 175 | + { |
| 176 | + echo "### subenum: $verdict" |
| 177 | + echo |
| 178 | + echo "$reason" |
| 179 | + echo |
| 180 | + echo "| Target | Verdict | Found | Queries |" |
| 181 | + echo "|---|---|---|---|" |
| 182 | + jq -r '.targets[] | "| \(.domain) | \(.verdict) | \(.found // 0) | \(.queries_sent // 0) |"' "$out/run.json" |
| 183 | + if [ -n "$prev" ]; then |
| 184 | + echo |
| 185 | + echo "**Changes since the previous results:** $added added, $removed removed." |
| 186 | + jq -r 'select(.change == "added") | "- `+ \(.subdomain)`"' "$out/changes.jsonl" | head -50 |
| 187 | + jq -r 'select(.change == "removed") | "- `- \(.subdomain)`"' "$out/changes.jsonl" | head -50 |
| 188 | + fi |
| 189 | + } >> "$GITHUB_STEP_SUMMARY" |
| 190 | +
|
| 191 | + if [ -n "$BASELINE" ] && [ "$verdict" = complete ]; then |
| 192 | + echo "upload=true" >> "$GITHUB_OUTPUT" |
| 193 | + fi |
| 194 | + # 0 = ok, 4 = changes found; 3 = some -dL targets failed (the verdict says how bad). |
| 195 | + case "$code" in 0 | 3 | 4) ;; *) exit "$code" ;; esac |
| 196 | + case "$FAIL_ON:$verdict" in |
| 197 | + unreliable:unreliable | degraded:unreliable | degraded:degraded) |
| 198 | + echo "::error::subenum verdict is $verdict: $reason"; exit 1 ;; |
| 199 | + esac |
| 200 | +
|
| 201 | + - name: Save the baseline |
| 202 | + if: steps.scan.outputs.upload == 'true' |
| 203 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 204 | + with: |
| 205 | + name: ${{ inputs.baseline-artifact }} |
| 206 | + path: ${{ runner.temp }}/subenum-out/results.jsonl |
| 207 | + retention-days: 90 |
| 208 | + overwrite: true |
0 commit comments