github-keyhunter 0.1.0

Fast GitHub API key leak scanner
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
# ๐Ÿ”‘ KeyHunter

[![GitHub stars](https://img.shields.io/github/stars/fadidevv/keyhunter?style=flat-square)](https://github.com/fadidevv/keyhunter/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/fadidevv/keyhunter?style=flat-square)](https://github.com/fadidevv/keyhunter/network)
[![GitHub issues](https://img.shields.io/github/issues/fadidevv/keyhunter?style=flat-square)](https://github.com/fadidevv/keyhunter/issues)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)

Fast GitHub API key leak scanner written in Rust. Find exposed API keys and help developers secure their secrets.

<p align="center">
  <img src="assets/screenshot.png" alt="KeyHunter scanning for API keys" width="800">
</p>

<p align="center">
  <strong>Find leaked API keys across all public GitHub repositories</strong>
</p>

<p align="center">
  <a href="#features">Features</a> โ€ข
  <a href="#quick-start">Quick Start</a> โ€ข
  <a href="#docker-setup">Docker</a> โ€ข
  <a href="#keyhunter-verify">Verify</a> โ€ข
  <a href="#supported-providers-45">Providers</a> โ€ข
  <a href="#configuration">Config</a> โ€ข
  <a href="#development">Development</a>
</p>

---

## Features

- ๐Ÿš€ **Blazing Fast**: Parallel scanning with token rotation
- ๐ŸŽฏ **45+ Providers**: AI/LLM, Cloud, Payment, Database, and more
- ๐Ÿ”„ **Rate Limit Bypass**: Use multiple GitHub tokens for unlimited scanning
- ๐Ÿ” **Smart Search**: Finds keys in ANY file, not just .env
- โœ… **Key Verification**: Test if found keys are still active (20+ providers)
- ๐ŸŽฏ **Verified-Only Mode**: Use `-V` to scan+verify and output only active keys
- ๐Ÿ“Š **Clean Output**: Table, JSON, or CSV formats
- ๐Ÿ’พ **Auto-save**: Results saved with timestamps
- โน๏ธ **Graceful Stop**: Press Ctrl+C anytime to stop and save collected results
- ๐Ÿ“ **Verbose Mode**: See detailed logs of every file and URL being processed
- ๐Ÿณ **Docker Ready**: No Rust installation required - just use Docker

---

## Why KeyHunter?

### Smart Search Strategy

Most tools search for patterns like `sk-proj-` which appear in tutorials, docs, and examples. KeyHunter uses **unique pattern segments** that only exist in real keys:

| Provider | Others Search | KeyHunter Searches |
|----------|---------------|-------------------|
| OpenAI | `sk-proj-` | `T3BlbkFJ` (unique Base64 in all keys) |
| Anthropic | `sk-ant-` | `sk-ant-api03-` (real key prefix) |
| Stripe | `sk_live_` | `sk_live_` + length validation |

### Multi-Query Approach

For each provider, KeyHunter runs multiple searches:
1. **Pattern search** - Unique identifier (`T3BlbkFJ`)
2. **Filename filter** - Pattern + `filename:.env`
3. **Env var search** - `OPENAI_API_KEY`

This catches keys that single-pattern tools miss.

### False Positive Filtering

KeyHunter automatically skips placeholder keys:
```
sk-proj-xxxxxxxxxxxxxxxx     โ† skipped (placeholder)
sk-proj-YOUR_API_KEY_HERE    โ† skipped (example)
sk-proj-test_1234567890      โ† skipped (test key)
sk-proj-T3BlbkFJx8Hn2m...    โ† โœ“ real key
```

### Modern Provider Coverage

KeyHunter includes AI providers that most tools don't have yet:

| Category | Providers |
|----------|-----------|
| **AI / LLM** | Anthropic, OpenAI, Google AI, Grok, DeepSeek, Groq, Perplexity, Replicate, HuggingFace, Fireworks, Cohere, Mistral, Together |
| **New** | Grok (xAI), DeepSeek, Groq, Perplexity |

### Offensive vs Defensive

| Tool Type | Purpose | Examples |
|-----------|---------|----------|
| **Hunters** (KeyHunter) | Find leaked keys across ALL public repos | Active scanning |
| **Defenders** | Scan YOUR repos to prevent leaks | TruffleHog, Gitleaks, git-secrets |

KeyHunter is built for **security researchers** who need to find exposed keys at scale.

## Quick Start

### 1. Get a GitHub Token

Go to: https://github.com/settings/tokens/new

- **Note**: `keyhunter`
- **Expiration**: 30 days
- **Scopes**: โœ… `public_repo` only

Click **Generate token** and copy it.

### 2. Configure

```bash
cp config.toml.example config.toml
```

Edit `config.toml`:

```toml
[github]
tokens = [
    "ghp_YOUR_ACTUAL_TOKEN_HERE",
]
```

### 3. Choose Your Installation

#### Option A: With Rust (Native)

```bash
# Build (first time takes ~2 min)
cargo build --release

# Run
./target/release/keyhunter scan -p openai
```

#### Option B: With Docker (No Rust Required)

```bash
# Build image (~3-5 min first time)
docker build -t keyhunter .

# Run
docker run -v $(pwd)/config.toml:/app/config.toml \
           -v $(pwd)/results:/app/results \
           keyhunter scan -p openai
```

### 4. Typical Workflow

**Option A: Two-step (recommended for large scans)**
```bash
# Step 1: Scan for keys
./target/release/keyhunter scan -p openai
# Output: results/findings_20260119_143022.json

# Step 2: Verify which keys are active
./target/release/keyhunter verify -i results/findings_20260119_143022.json
# Output: results/verified_20260119_143100.json
#         results/verified_20260119_143100_active.json (only active keys)
```

**Option B: One-step with `-V` (for smaller scans)**
```bash
# Scan + verify in one command (verifies first 50 keys)
./target/release/keyhunter scan -p openai -V
# Output: results/verified_active_20260119_143022.json (only active keys)

# Or verify ALL found keys (caution: may hit rate limits)
./target/release/keyhunter scan -p openai -V --verify-all
```

---

## Docker Setup

Full Docker documentation for those without Rust installed.

### Build & Run

```bash
# 1. Setup config
cp config.toml.example config.toml
# Edit config.toml with your GitHub token

# 2. Build image (~3-5 min first time)
docker build -t keyhunter .

# 3. Run scan
docker run -v $(pwd)/config.toml:/app/config.toml \
           -v $(pwd)/results:/app/results \
           keyhunter scan -p openai

# With verbose mode
docker run -v $(pwd)/config.toml:/app/config.toml \
           -v $(pwd)/results:/app/results \
           keyhunter scan -p openai -v

# Show help
docker run keyhunter --help

# Show patterns
docker run keyhunter patterns
```

### Docker Compose

Simpler syntax using docker-compose:

```bash
# Run with docker-compose
docker-compose run keyhunter scan -p openai

# With verbose
docker-compose run keyhunter scan -p openai -v

# Scan all providers
docker-compose run keyhunter scan

# Show patterns
docker-compose run keyhunter patterns
```

### Docker Commands Reference

| Command | Description |
|---------|-------------|
| `docker build -t keyhunter .` | Build image |
| `docker run keyhunter --help` | Show help |
| `docker run keyhunter patterns` | List providers |
| `docker run -v ... keyhunter scan` | Run scan |
| `docker run -v ... keyhunter scan -V` | Scan + verify (active only) |
| `docker run -v ... keyhunter verify -i ...` | Verify keys |
| `docker-compose run keyhunter scan` | Run with compose |

### Volume Mounts

| Mount | Purpose |
|-------|---------|
| `./config.toml:/app/config.toml` | Your config file |
| `./results:/app/results` | Save results locally |

Results are saved to your local `./results` folder.

### Docker Tips

```bash
# Create alias for easier usage
alias keyhunter='docker run -v $(pwd)/config.toml:/app/config.toml -v $(pwd)/results:/app/results keyhunter'

# Then just run:
keyhunter scan -p openai
keyhunter scan -v
keyhunter patterns
```

---

## CLI Reference

```
keyhunter <COMMAND>

COMMANDS:
    scan        Scan GitHub for leaked API keys
    verify      Verify if found keys are active
    patterns    Show all supported providers and patterns
    help        Show help for a command
```

---

### `keyhunter scan`

Scan GitHub for leaked API keys.

**Usage:**

```bash
# Scan all providers
./target/release/keyhunter scan

# Scan specific provider
./target/release/keyhunter scan -p openai
./target/release/keyhunter scan -p anthropic
./target/release/keyhunter scan -p stripe_live
./target/release/keyhunter scan -p aws

# Verbose mode - see detailed logs
./target/release/keyhunter scan -v
./target/release/keyhunter scan -p openai -v
./target/release/keyhunter scan --verbose

# Custom search query (any GitHub code search)
./target/release/keyhunter scan -q "T3BlbkFJ"
./target/release/keyhunter scan -q "sk-ant-api03"
./target/release/keyhunter scan -q "OPENAI_API_KEY filename:.env"
./target/release/keyhunter scan -q "mongodb+srv:// filename:config.js"

# Different output formats
./target/release/keyhunter scan -o table    # default, pretty
./target/release/keyhunter scan -o json     # machine readable
./target/release/keyhunter scan -o csv      # spreadsheet

# Use different config file
./target/release/keyhunter scan -c myconfig.toml

# Combine options
./target/release/keyhunter scan -p openai -o json -v
./target/release/keyhunter scan -p anthropic --verbose -c prod.toml

# Verified-only mode - only output active keys
./target/release/keyhunter scan -p openai -V
./target/release/keyhunter scan -p openai -V --verify-all
./target/release/keyhunter scan -p openai -V -o json

# Combine verbose + verified-only
./target/release/keyhunter scan -p openai -v -V
```

**Options:**

| Option | Description | Default |
|--------|-------------|---------|
| `-c, --config <FILE>` | Config file path | `config.toml` |
| `-p, --provider <n>` | Provider to scan | `all` |
| `-q, --query <QUERY>` | Custom GitHub search query | - |
| `-o, --output <FORMAT>` | Output: table, json, csv | `table` |
| `-v, --verbose` | Show detailed logs (files, URLs, etc.) | `false` |
| `-V, --verified-only` | Only save active (verified) keys | `false` |
| `--verify-all` | With -V: verify all keys (not just 50) | `false` |
| `-h, --help` | Show help | - |

**Verified-Only Mode (`-V`):**

Scan and verify in one command - only outputs keys that are confirmed active:

```bash
# Scan + verify first 50 keys, output only active
./target/release/keyhunter scan -p openai -V

# Scan + verify ALL keys (caution: may hit rate limits)
./target/release/keyhunter scan -p openai -V --verify-all
```

> **Note:** Without `-V`, scan outputs all found keys (unverified). Use `verify` command later to check which are active.

---

### `keyhunter patterns`

Show all supported providers and their regex patterns.

**Usage:**

```bash
./target/release/keyhunter patterns
```

**Output:**

```
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Provider    โ”‚ Pattern                 โ”‚ Example             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Anthropic   โ”‚ sk-ant-api03-[...]{93}  โ”‚ sk-ant-api03-xxxxx  โ”‚
โ”‚ OpenAI      โ”‚ sk-proj-[...]{48,180}   โ”‚ sk-proj-xxxxx       โ”‚
โ”‚ Google AI   โ”‚ AIza[...]{35}           โ”‚ AIzaSyDxxxxx        โ”‚
โ”‚ AWS         โ”‚ AKIA[0-9A-Z]{16}        โ”‚ AKIAIOSFODNN7       โ”‚
โ”‚ Stripe      โ”‚ sk_live_[...]{24,99}    โ”‚ sk_live_xxxxx       โ”‚
โ”‚ ...         โ”‚ ...                     โ”‚ ...                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
```

---

### `keyhunter verify`

Verify if found keys are still active by testing against provider APIs.

> **Tip:** For quick scans, use `scan -V` to scan+verify in one step. Use this separate `verify` command when you want more control over batch verification of large result files.

**Usage:**

```bash
# Verify first 50 keys (default, safe)
./target/release/keyhunter verify -i results/findings.json

# Verify only OpenAI keys
./target/release/keyhunter verify -i results/findings.json -p openai

# Verify first 100 keys
./target/release/keyhunter verify -i results/findings.json -l 100

# Verify ALL keys (careful - may hit rate limits)
./target/release/keyhunter verify -i results/findings.json -a

# More concurrent requests (faster but riskier)
./target/release/keyhunter verify -i results/findings.json -c 10

# Save to specific file
./target/release/keyhunter verify -i results/findings.json -o verified.json
```

**Options:**

| Option | Description | Default |
|--------|-------------|---------|
| `-i, --input <FILE>` | Results JSON file (required) | - |
| `-l, --limit <N>` | Verify first N keys | `50` |
| `-p, --provider <NAME>` | Verify only this provider | all |
| `-a, --all` | Verify all keys (ignore limit) | `false` |
| `-c, --concurrent <N>` | Parallel requests | `5` |
| `-o, --output <FILE>` | Save verified results | auto |
| `-h, --help` | Show help | - |

**Output:**

```
๐Ÿ“‚ Loaded 567 keys from results/findings.json
๐Ÿ” Verifying 50 keys with 5 concurrent requests

    OpenAI 35 keys
    Anthropic 10 keys
    Stripe 5 keys

  โœ“ ACTIVE sk-proj-...xxxx (OpenAI)
  โœ“ ACTIVE sk-ant-a...yyyy (Anthropic)

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
โœ“ Verification Complete

    ๐Ÿ”ด 12 keys are ACTIVE (leaked & working!)
    ๐ŸŸข 35 keys are revoked/invalid
    ๐ŸŸก 3 keys had errors (rate limited/timeout)

๐Ÿ’พ Results saved to: results/verified_20260119.json
๐Ÿ”ด Active keys saved to: results/verified_20260119_active.json
```

**Supported Verification:**

| Provider | Method | Status |
|----------|--------|--------|
| OpenAI | GET /v1/models | โœ… |
| Anthropic | POST /v1/messages | โœ… |
| Google AI | GET /v1/models | โœ… |
| Groq | GET /v1/models | โœ… |
| Perplexity | POST /chat/completions | โœ… |
| HuggingFace | GET /api/whoami-v2 | โœ… |
| Replicate | GET /v1/account | โœ… |
| Fireworks | GET /v1/models | โœ… |
| Cohere | GET /v1/models | โœ… |
| Mistral | GET /v1/models | โœ… |
| Together | GET /v1/models | โœ… |
| DeepSeek | GET /v1/models | โœ… |
| GitHub | GET /user | โœ… |
| GitLab | GET /api/v4/user | โœ… |
| Stripe | GET /v1/balance | โœ… |
| SendGrid | GET /v3/scopes | โœ… |
| Mailgun | GET /v3/domains | โœ… |
| Slack | GET /api/auth.test | โœ… |
| Discord | GET /users/@me | โœ… |
| Telegram | GET /getMe | โœ… |
| Mapbox | GET /tokens/v2 | โœ… |
| New Relic | GET /v2/users.json | โœ… |
| Datadog | GET /api/v1/validate | โœ… |
| AWS | โš ๏ธ Requires secret key pair | โŒ |
| Twilio | โš ๏ธ Requires Account SID | โŒ |
| Firebase | โš ๏ธ Requires project ID | โŒ |

---

## Provider Names

Use these names with `-p` flag:

**AI / LLM:**
```
anthropic, openai, google, grok, deepseek, huggingface, 
replicate, perplexity, groq, fireworks
```

**Cloud:**
```
aws
```

**Payment:**
```
stripe_live, stripe_restricted, paypal, square
```

**Communication:**
```
twilio, sendgrid, mailgun, mailchimp
```

**Developer Platforms:**
```
github_token, gitlab, npm, pypi
```

**Social / Messaging:**
```
slack_bot, slack_user, slack_webhook, discord, 
discord_webhook, telegram
```

**Database:**
```
mongodb, postgres, mysql, redis
```

**Other:**
```
firebase, mapbox, sentry, newrelic, planetscale, 
doppler, private_key
```

---

## Supported Providers (45+)

### AI / LLM

| Provider | Pattern | Search Term |
|----------|---------|-------------|
| Anthropic | `sk-ant-api03-...` | `sk-ant-api03-` |
| OpenAI | `sk-proj-...` | `T3BlbkFJ` |
| Google AI | `AIza...` | `AIzaSy` |
| xAI Grok | `xai-...` | `xai-` |
| DeepSeek | `sk-[hex]` | `DEEPSEEK_API_KEY` |
| HuggingFace | `hf_...` | `hf_` |
| Replicate | `r8_...` | `r8_` |
| Perplexity | `pplx-...` | `pplx-` |
| Groq | `gsk_...` | `gsk_` |
| Fireworks | `fw_...` | `fw_` |

### Cloud & Infrastructure

| Provider | Pattern |
|----------|---------|
| AWS | `AKIA...` |
| Azure | `...(86 chars)==` |

### Payment

| Provider | Pattern |
|----------|---------|
| Stripe | `sk_live_...` |
| Square | `sq0csp-...` |
| PayPal | `access_token$...` |

### Communication

| Provider | Pattern |
|----------|---------|
| Twilio | `SK[hex]{32}` |
| SendGrid | `SG....` |
| Mailgun | `key-...` |
| Mailchimp | `...-us14` |

### Developer Platforms

| Provider | Pattern |
|----------|---------|
| GitHub | `ghp_...`, `github_pat_...` |
| GitLab | `glpat-...` |
| NPM | `npm_...` |
| PyPI | `pypi-...` |

### Social / Messaging

| Provider | Pattern |
|----------|---------|
| Slack Bot | `xoxb-...` |
| Slack User | `xoxp-...` |
| Slack Webhook | `hooks.slack.com/...` |
| Discord | Bot tokens |
| Discord Webhook | `discord.com/api/webhooks/...` |
| Telegram | `123456789:ABC...` |

### Database

| Provider | Pattern |
|----------|---------|
| MongoDB | `mongodb+srv://...` |
| PostgreSQL | `postgres://...` |
| MySQL | `mysql://...` |
| Redis | `redis://...` |

### Other Services

| Provider | Pattern |
|----------|---------|
| Firebase | `AAAA...:...` |
| Mapbox | `pk.eyJ...` |
| Sentry | `https://...@sentry.io` |
| New Relic | `NRAK-...` |
| PlanetScale | `pscale_tkn_...` |
| Doppler | `dp.pt....` |
| Private Key | `-----BEGIN PRIVATE KEY-----` |

---

## Output Examples

### Normal Mode (default)

```
๐Ÿ” Scanning 1 provider(s), 6 queries total
โ„น Press Ctrl+C to stop and save results

โ†’ Provider: OpenAI (OpenAI API Key)
    โŸฉ Query 1/6: T3BlbkFJ
      โ ™ [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–“โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘] 3/10 pages | 28 keys
      โ†ณ 282 keys found
    โŸฉ Query 2/6: T3BlbkFJ filename:.env
      โ†ณ 285 keys found
    โœ“ Running total: 567 unique keys

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
๐Ÿ”‘ Found 567 potential leaked keys
```

### Verified-Only Mode (`-V`)

```
๐Ÿ” Scanning 1 provider(s), 6 queries total
โ„น Press Ctrl+C to stop and save results

โ†’ Provider: OpenAI (OpenAI API Key)
    โŸฉ Query 1/6: T3BlbkFJ
      โ†ณ 282 keys found
    โœ“ Running total: 248 unique keys

๐Ÿ” Verifying keys...

๐Ÿ” Verifying 50 keys (--verified-only mode)
  โœ“ ACTIVE sk-proj-SL...apsA (OpenAI)
  โœ“ ACTIVE sk-proj-KK..._uIA (OpenAI)

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
๐Ÿ”‘ Found 4 ACTIVE keys

๐Ÿ’พ Active keys saved to: results/verified_active_20260119_143022.json
```

### Verbose Mode (`-v`)

```
๐Ÿ” Scanning 1 provider(s), 6 queries total
โ„น Press Ctrl+C to stop and save results
๐Ÿ“ Verbose mode enabled - showing detailed logs

โ†’ Provider: OpenAI (OpenAI API Key)
    โŸฉ Query 1/6: T3BlbkFJ
      ยท Page 1/10 - 30 files to process
        โœ“ user/chatbot/.env โ†’ 2 key(s)
          https://github.com/user/chatbot/blob/main/.env
        โœ“ dev/project/config.js โ†’ 1 key(s)
          https://github.com/dev/project/blob/main/config.js
        ยท corp/docs/README.md โ†’ no keys
        โœ“ startup/api/.env.local โ†’ 3 key(s)
          https://github.com/startup/api/blob/main/.env.local
      โ†ณ Page 1 complete: 28 keys found
      ยท Page 2/10 - 30 files to process
        โœ“ another/repo/.env โ†’ 1 key(s)
          https://github.com/another/repo/blob/main/.env
        ...
      โ†ณ 282 keys found
    โŸฉ Query 2/6: T3BlbkFJ filename:.env
      ยท Page 1/10 - 30 files to process
        ...
    โœ“ Running total: 567 unique keys

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
๐Ÿ”‘ Found 567 potential leaked keys
```

---

## Graceful Stop (Ctrl+C)

Press `Ctrl+C` anytime during scanning to stop and save all collected results.

```
๐Ÿ” Scanning 1 provider(s), 6 queries total
โ„น Press Ctrl+C to stop and save results

โ†’ Provider: OpenAI (OpenAI API Key)
    โŸฉ Query 1/6: T3BlbkFJ
      โ†ณ 282 keys found
    โŸฉ Query 2/6: T3BlbkFJ filename:.env
^C
โš  Interrupted! Saving collected results...
๐Ÿ’พ Saved 450 keys to: results/findings_20260119_143022_interrupted.json
```

Results are saved to `*_interrupted.json` so you don't lose your progress.

---

## Configuration

### Config File: `config.toml`

```toml
[github]
tokens = [
    "ghp_YOUR_TOKEN_HERE",
]
concurrency = 5      # parallel requests
delay_ms = 500       # delay between requests

[scan]
max_results = 1000   # max results per query

[output]
format = "table"     # table, json, csv (CLI -o overrides)
save_to_file = true
output_path = "results"

[providers]
openai = true
anthropic = true
aws = true
# ... see config.toml.example for all options
```

### Results Volume

Control how many results to fetch with `max_results`:

| max_results | Pages | Speed | Keys (approx) |
|-------------|-------|-------|---------------|
| 30 | ~1 | Fast test | ~50 |
| 100 | ~3 | Quick scan | ~150 |
| 300 | ~10 | Medium | ~500 |
| 500 | ~17 | Good coverage | ~1000 |
| 1000 | ~33 | Maximum | ~2000+ |

```toml
[scan]
max_results = 300    # adjust as needed
```

### Speed Settings

| Setup | concurrency | delay_ms | Speed |
|-------|-------------|----------|-------|
| Safe (1 token) | 3 | 1000 | ~30/min |
| Normal (1 token) | 5 | 500 | ~60/min |
| Fast (3+ tokens) | 10 | 300 | ~150/min |
| Blazing (5+ tokens) | 20 | 100 | ~300/min |

### Multiple Tokens (Different Accounts)

For maximum speed, use tokens from different GitHub accounts:

```toml
[github]
tokens = [
    "ghp_from_account_1",
    "ghp_from_account_2",
    "ghp_from_account_3",
    "ghp_from_account_4",
    "ghp_from_account_5",
]
concurrency = 20
delay_ms = 100
```

| Setup | Speed | Keys Found |
|-------|-------|------------|
| 1 token, 1 account | 30/min | ~500/scan |
| 5 tokens, 5 accounts | 150/min | ~5000/scan |
| 10 tokens, 10 accounts | 300/min | ~10000/scan |

---

## Project Structure

```
keyhunter/
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ config.toml.example
โ”œโ”€โ”€ config.toml          # Your config (git-ignored)
โ”œโ”€โ”€ Dockerfile           # Docker build
โ”œโ”€โ”€ docker-compose.yml   # Docker compose
โ”œโ”€โ”€ .dockerignore
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ screenshot.png   # Screenshot for README
โ”œโ”€โ”€ results/             # Scan results saved here
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs          # CLI entry point
โ”‚   โ”œโ”€โ”€ config.rs        # Config parser
โ”‚   โ”œโ”€โ”€ patterns.rs      # 45+ provider patterns
โ”‚   โ”œโ”€โ”€ github.rs        # GitHub API client
โ”‚   โ”œโ”€โ”€ scanner.rs       # Core scanner
โ”‚   โ””โ”€โ”€ verifier.rs      # Key verification (20+ providers)
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ config_test.rs   # Configuration tests
    โ”œโ”€โ”€ filters_test.rs  # False positive filter tests
    โ””โ”€โ”€ patterns_test.rs # Regex pattern tests
```

---

## Development

### Prerequisites

**Option A: Native (Rust)**
- Rust 1.70+ (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`)

**Option B: Docker**
- Docker 20.10+

### Building

**Native:**
```bash
# Clone repository
git clone https://github.com/fadidevv/keyhunter.git
cd keyhunter

# Build debug (faster compile)
cargo build

# Build release (optimized)
cargo build --release
```

**Docker:**
```bash
# Clone repository
git clone https://github.com/fadidevv/keyhunter.git
cd keyhunter

# Build image
docker build -t keyhunter .
```

### Running Tests

```bash
# Run all tests
cargo test

# Run specific test file
cargo test --test patterns_test
cargo test --test filters_test
cargo test --test config_test

# Run with output
cargo test -- --nocapture
```

**Test Coverage:**
- `patterns_test.rs` - 34 tests for regex pattern matching
- `filters_test.rs` - 13 tests for false positive filtering
- `config_test.rs` - 12 tests for configuration parsing

### Code Quality

```bash
# Format code
cargo fmt

# Run linter
cargo clippy

# Check without building
cargo check
```

### Running in Development

**Native:**
```bash
# Setup config
cp config.toml.example config.toml
# Edit config.toml with your GitHub token

# Run debug build
cargo run -- scan -p openai

# Run release build
cargo run --release -- scan -p openai
```

**Docker:**
```bash
# Setup config
cp config.toml.example config.toml
# Edit config.toml with your GitHub token

# Run with Docker
docker run -v $(pwd)/config.toml:/app/config.toml \
           -v $(pwd)/results:/app/results \
           keyhunter scan -p openai
```

### Adding New Providers

1. Add pattern to `src/patterns.rs`:
```rust
KeyPattern {
    name: "new_provider",
    display_name: "New Provider",
    regex: r"prefix_[a-zA-Z0-9]{32}",
    confidence: "high",
    search_terms: vec!["prefix_", "NEW_PROVIDER_KEY"],
    example: "prefix_abc123...",
}
```

2. Add config toggle to `src/config.rs`:
```rust
pub new_provider: bool,
```

3. Add to `enabled_providers()` in `src/config.rs`

4. (Optional) Add verification in `src/verifier.rs`

5. Run tests: `cargo test`

---

## โš ๏ธ Disclaimer

This tool is for **security research and educational purposes only**.

- Only scan repositories you own or have permission to scan
- Report leaked keys responsibly to developers
- Never use found keys for unauthorized access
- Misuse may violate laws and GitHub Terms of Service

**The authors are not responsible for misuse of this tool.**

---

## Ethical Use

This tool is for:
- โœ… Security researchers finding and reporting leaked keys
- โœ… Developers scanning their own repositories
- โœ… Organizations auditing their code
- โœ… Helping developers secure their secrets

**NOT** for:
- โŒ Stealing or misusing credentials
- โŒ Unauthorized access to systems
- โŒ Any malicious purposes

---

## Contributing

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/new-provider`)
3. Make your changes
4. Run tests (`cargo test`)
5. Run linter (`cargo clippy`)
6. Format code (`cargo fmt`)
7. Commit changes (`git commit -m 'Add new provider'`)
8. Push to branch (`git push origin feature/new-provider`)
9. Open a Pull Request

**Ideas for contributions:**
- Add new API key providers
- Improve regex patterns
- Add verification for more providers
- Documentation improvements
- Bug fixes

---

## License

MIT License - see [LICENSE](LICENSE) for details.