apihunter 0.1.1

Async API security scanner with passive and active checks for CORS, CSP, GraphQL, JWT, OpenAPI, and API posture.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# How-to guide

Practical recipes for common tasks.

---

## Run a basic scan

Note: `--urls` expects a file path. For a single URL, use `--stdin`:

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin
```

Findings are written to **stdout** (default `pretty`; use `--format ndjson` for NDJSON);
diagnostics to **stderr**.

---

## Run with Docker

```bash
docker build -t apihunter:local .
docker run --rm apihunter:local --help
```

```bash
docker run --rm -v "$PWD:/work" apihunter:local \
  --urls /work/targets.txt \
  --format ndjson \
  --output /work/results.ndjson
```

---

## Scan scripts

Helper scripts live in `ScanScripts/` and accept either a URL file or `--stdin`.

```bash
./ScanScripts/defaultscan.sh ./targets/targets.txt
cat ./targets/targets.txt | ./ScanScripts/defaultscan.sh --stdin
```

```bash
./ScanScripts/quickscan.sh ./targets/targets.txt
./ScanScripts/deepscan.sh ./targets/targets.txt
```

```bash
./ScanScripts/baselinescan.sh ./targets/targets.txt
./ScanScripts/diffscan.sh ./targets/targets.txt baseline.ndjson
```

```bash
./ScanScripts/inaccessiblescan.sh ./targets/inaccessible.txt
./ScanScripts/authscan.sh ./targets/targets.txt --auth-flow ./flows/auth.json
```

```bash
./ScanScripts/sarifscan.sh ./targets/targets.txt
./ScanScripts/scan-and-report.sh ./targets/targets.txt
```

```bash
./ScanScripts/split-by-host.sh ./targets/targets.txt --out-dir split-targets
./ScanScripts/split-by-host.sh ./targets/targets.txt --scan-cmd ./ScanScripts/quickscan.sh --jobs 4
```

---

## Save results to a file

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --output report.ndjson
```

When `--output` is set, the report is written to the file. Stdout still prints
unless `--quiet` is used.

To disable automatic local report persistence in CI/non-interactive runs:

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --no-auto-report
```

---

## Stream findings as NDJSON

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --format ndjson --stream
```

---

## SARIF output (GitHub Code Scanning)

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --format sarif --output results.sarif
```

---

## Baseline diff mode

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --baseline last.ndjson --format ndjson
```

---

## Filter by severity

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --min-severity high
```

Accepted values (low → critical): `low` `medium` `high` `critical`

---

## Scan multiple targets

```bash
cat <<'EOF' > targets.txt
https://app.example.com
https://api.example.com
EOF

./target/release/apihunter --urls ./targets.txt --concurrency 40
```

---

## Import endpoints from HAR

```bash
./target/release/apihunter --har ./session.har
```

HAR import reads `log.entries[].request.url` and automatically keeps likely API/business endpoints while excluding static/CDN noise.

---

## Use in CI

```bash
printf "%s\n" "$TARGET" | ./target/release/apihunter --stdin --quiet --min-severity medium
EXIT=$?

if (( EXIT & 1 )); then echo "Findings detected"; fi
if (( EXIT & 2 )); then echo "Scanner errors occurred"; fi
```

---

## Scan through a proxy (Burp, mitmproxy, etc.)

```bash
printf "https://target.example.com\n" | ./target/release/apihunter \
  --stdin \
  --proxy http://127.0.0.1:8080 \
  --danger-accept-invalid-certs
```

---

## Enable active checks (opt-in)

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --active-checks
```

---

## Dry-run active checks (no mutation probes)

Use this mode to preview active-check behavior without sending mutation requests.

```bash
printf "https://target.example.com/users\n" | ./target/release/apihunter \
  --stdin \
  --active-checks \
  --dry-run \
  --format ndjson
```

---

## Skip discovery for targeted checks

Use this when you want to test only the seed URLs you provide (for example, focused WebSocket checks) without endpoint expansion.

```bash
printf "https://target.example.com/ws\n" | ./target/release/apihunter \
  --stdin \
  --active-checks \
  --no-discovery \
  --no-cors --no-csp --no-graphql --no-api-security --no-jwt --no-openapi \
  --no-mass-assignment --no-oauth-oidc --no-rate-limit --no-cve-templates
```

---

## Import a Nuclei CVE template into ApiHunter TOML

Use `template-tool` to translate scanner-compatible Nuclei YAML into `assets/cve_templates/*.toml`.

```bash
cargo run --bin template-tool -- import-nuclei \
  --input tests/fixtures/upstream_nuclei/CVE-2022-24288.yaml \
  --output assets/cve_templates/cve-2022-24288.toml \
  --check-suffix airflow-example-dag-params-rce-signal \
  --context-hints /airflow,/admin,/dags,/code
```

Current importer scope:
- GET-compatible request import (first GET with importable matchers from `http` list)
- safe preflight request-chain extraction (`GET`/`HEAD`/`OPTIONS` only, capped)
- request path extraction (`path` or first `raw` request line)
- request headers (structured `headers` map or `raw` request header lines)
- status matchers
- body word matchers
- header word matchers with explicit `Header: Value` pairs
- body/header regex matchers
- `dsl` matcher subset (`status_code == ...`, `contains(...)`, `regex(...)`)

---

## Auth helpers and session cookies

```bash
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --auth-bearer "$TOKEN"
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --auth-basic "user:pass"
printf "https://target.example.com\n" | ./target/release/apihunter --stdin --session-file excalibur-session-...-cookies.json
./target/release/apihunter --har ./session.har --session-file ./excalibur-session-...-cookies.json
```

ApiHunter accepts one session JSON schema (Excalibur output from your HAR folder):

```json
{
  "hosts": {
    "example.com": {
      "session": "abc123"
    }
  }
}
```

---

## Write a custom scanner

1. Create `src/scanner/my_check.rs`
2. Implement the `Scanner` trait:

```rust
use async_trait::async_trait;
use crate::{
    config::Config,
    error::CapturedError,
    http_client::HttpClient,
    reports::Finding,
    scanner::Scanner,
};

pub struct MyCheck;

#[async_trait]
impl Scanner for MyCheck {
    async fn scan(
        &self,
        url: &str,
        client: &HttpClient,
        _config: &Config,
    ) -> (Vec<Finding>, Vec<CapturedError>) {
        // your logic here
        (vec![], vec![])
    }
}
```

3. Register it in `src/runner.rs` inside the scanner list.

---

## Run tests

```bash
# Unit + integration (requires network for wiremock-based tests)
cargo test

# Only unit tests
cargo test --lib

# With logs visible
RUST_LOG=debug cargo test -- --nocapture
```

---

## Configuration reference

See [`docs/configuration.md`](docs/configuration.md) for every config field,
its type, default, and environment variable override.
---

## Advanced Examples

### Run with active checks (intrusive probes)

```bash
printf "https://staging.example.com\n" | ./target/release/apihunter \
  --stdin \
  --active-checks \
  --concurrency 10
```

Use only on staging or with explicit production team approval. Active checks may:
- Generate high request volume
- Trigger WAF/IDS alerts  
- Be detected as attack traffic

---

### Parse results with jq

Count findings by severity:
```bash
cat results.ndjson | jq -r 'select(.type != "meta") | .severity' | sort | uniq -c
```

Extract critical findings only:
```bash
cat results.ndjson | jq 'select(.severity == "CRITICAL")'
```

List unique checks:
```bash
cat results.ndjson | jq -r '.check' | sort -u
```

---

### Scan with custom headers and bearer token

```bash
printf "https://api.example.com\n" | ./target/release/apihunter \
  --stdin \
  --auth-bearer "eyJhbGciOiJIUzI1NiIs..." \
  --headers "X-Request-ID:scan-001" \
  --format ndjson
```

---

### Comparative scans (baseline diffing)

Run baseline on clean version:
```bash
printf "https://api.example.com\n" | ./target/release/apihunter \
  --stdin \
  --format ndjson \
  --output baseline.ndjson
```

Scan after changes and report only new/changed findings:
```bash
printf "https://api.example.com\n" | ./target/release/apihunter \
  --stdin \
  --baseline baseline.ndjson \
  --format ndjson \
  --output new-findings.ndjson
```

---

### Upload SARIF to GitHub Code Scanning

```bash
# Generate SARIF report
printf "https://github.com/my-org/my-repo\n" | ./target/release/apihunter \
  --stdin \
  --format sarif \
  --output results.sarif

# Upload to GitHub (requires gh CLI)
gh code-scanning upload-sarif results.sarif \
  --repository my-org/my-repo
```

---

## Troubleshooting

### High error rate / timeouts

**Problem:** Many endpoints fail with timeout errors.

**Solution:**
- Increase `--timeout-secs` (default 8)
- Decrease `--concurrency` (default 20)
- Add `--delay-ms` to slow down per-host requests (default 150)

```bash
./target/release/apihunter \
  --urls ./targets.txt \
  --timeout-secs 60 \
  --concurrency 5 \
  --delay-ms 500
```

---

### WAF blocking requests

**Problem:** Scanner gets 403/429 errors, WAF blocks requests.

**Solution:** Enable WAF evasion, rotate user agents, add delays:
Start conservatively (lower concurrency, higher delay) to avoid triggering rate limits.

```bash
printf "https://target.example.com\n" | ./target/release/apihunter \
  --stdin \
  --waf-evasion \
  --delay-ms 500 \
  --retries 5
```

---

### Scanner panics or crashes

**Problem:** Specific endpoint causes scanner to panic.

**Solution:**
- Check the error output for the failing URL
- Run with `RUST_LOG=debug` for more detail
- Report with reproduction steps to the project

```bash
printf "https://problematic-url.com\n" | RUST_LOG=debug ./target/release/apihunter \
  --stdin \
  2>&1 | tee debug.log
```

---

## Interpreting Results

See [`docs/findings.md`](docs/findings.md) for detailed guidance on:
- Severity level meanings
- Common finding types and remediations
- Output formats (NDJSON, SARIF)
- Reducing false positives