credhunter 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: credhunter
3
+ Version: 0.1.0
4
+ Summary: Automated secrets detection and reporting tool
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: typer>=0.9.0
8
+ Requires-Dist: pyyaml>=6.0
9
+ Requires-Dist: fpdf2>=2.7.0
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest>=8.0; extra == "dev"
12
+
13
+ # credhunter
14
+
15
+ credhunter is a Python command-line tool for scanning files and directories for potential hardcoded secrets. It combines pattern-based detection with context and entropy signals, assigns confidence and severity, masks detected values in output, and can generate JSON and HTML reports.
16
+
17
+ credhunter is a detection aid, not a guarantee that every secret will be found. Review findings before taking action, and never use real production credentials in test fixtures.
18
+
19
+ ## Features
20
+
21
+ - Scan a single file or directory.
22
+ - Detect configured secret patterns using rules packaged with credhunter.
23
+ - Use context analysis and Shannon entropy as detection signals.
24
+ - Assign confidence scores and severity levels.
25
+ - Filter configured placeholder values to reduce some false positives.
26
+ - Mask detected values in console output and reports.
27
+ - Generate JSON and HTML reports.
28
+ - Configure CI failure behavior with `--fail-on`.
29
+ - Display the installed package version with `--version`.
30
+
31
+ ## Requirements
32
+
33
+ - Python 3.10 or newer.
34
+ - Windows, Linux, or macOS with a compatible Python installation.
35
+
36
+ ## Installation
37
+
38
+ ### Install from PyPI
39
+
40
+ Once credhunter has been published to PyPI, install it with:
41
+
42
+ ```bash
43
+ python -m pip install credhunter
44
+ ```
45
+
46
+ Verify the installation:
47
+
48
+ ```bash
49
+ credhunter --version
50
+ credhunter --help
51
+ ```
52
+
53
+ ### Install from source for development
54
+
55
+ If you have cloned or downloaded the source repository, open a terminal in the project directory.
56
+
57
+ **Windows PowerShell**
58
+
59
+ ```powershell
60
+ python -m venv .venv
61
+ .\.venv\Scripts\Activate.ps1
62
+ python -m pip install --upgrade pip
63
+ python -m pip install -e .
64
+ ```
65
+
66
+ **Linux/macOS**
67
+
68
+ ```bash
69
+ python3 -m venv .venv
70
+ source .venv/bin/activate
71
+ python -m pip install --upgrade pip
72
+ python -m pip install -e .
73
+ ```
74
+
75
+ To install development and test dependencies:
76
+
77
+ ```bash
78
+ python -m pip install -e ".[dev]"
79
+ ```
80
+
81
+ The editable installation is intended for development. It allows changes to the source code to be used without rebuilding and reinstalling the package.
82
+
83
+ ## Usage
84
+
85
+ The command accepts a file or directory path as its positional argument.
86
+
87
+ ### Show the installed version
88
+
89
+ ```bash
90
+ credhunter --version
91
+ ```
92
+
93
+ ### Show help
94
+
95
+ ```bash
96
+ credhunter --help
97
+ ```
98
+
99
+ ### Scan the current directory
100
+
101
+ ```bash
102
+ credhunter .
103
+ ```
104
+
105
+ ### Scan a directory
106
+
107
+ **Windows PowerShell**
108
+
109
+ ```powershell
110
+ credhunter .\examples\vulnerable_project
111
+ ```
112
+
113
+ ### Scan a single file
114
+
115
+ ```powershell
116
+ credhunter .\path\to\file.py
117
+ ```
118
+
119
+ ### Generate JSON and HTML reports
120
+
121
+ ```powershell
122
+ credhunter .\examples\vulnerable_project --json report.json --html report.html
123
+ ```
124
+
125
+ Choose report destinations that are writable. Review generated reports before sharing them, as they can contain sensitive repository details even when detected secret values are masked.
126
+
127
+ ### Configure the CI/CD failure threshold
128
+
129
+ ```powershell
130
+ credhunter .\examples\vulnerable_project --fail-on high
131
+ ```
132
+
133
+ Supported thresholds:
134
+
135
+ - `critical`
136
+ - `high`
137
+ - `medium`
138
+ - `low`
139
+ - `none`
140
+
141
+ The command returns exit code `1` when at least one finding meets or exceeds the selected threshold; otherwise, it returns `0`. Use `--fail-on none` to complete a scan without failing based on findings:
142
+
143
+ ```powershell
144
+ credhunter .\examples\vulnerable_project --fail-on none
145
+ ```
146
+
147
+ ## How Detection Works
148
+
149
+ credhunter uses several signals to evaluate potential secrets:
150
+
151
+ 1. **Pattern matching:** configured regular expressions identify values that match known secret formats.
152
+ 2. **Context analysis:** nearby names or text, such as `password`, `token`, and `api_key`, can help assess whether a value is a credential.
153
+ 3. **Entropy analysis:** Shannon entropy helps assess how random-looking a string is.
154
+ 4. **Confidence and severity:** findings include a confidence score and severity classification.
155
+ 5. **Placeholder filtering:** configured placeholder markers can suppress common test or example values.
156
+ 6. **Masking:** console output and reports use masked snippets rather than intentionally displaying the complete detected value.
157
+ 7. **Fingerprinting:** SHA-256 fingerprints can help identify repeated values without storing the raw secret as the fingerprint.
158
+
159
+ These signals do not guarantee that every secret will be detected or that every finding is correct. False positives and false negatives are possible.
160
+
161
+ ## Detection Rules
162
+
163
+ Detection rules are stored in the package at:
164
+
165
+ ```text
166
+ credhunter/rules/secrets.yaml
167
+ ```
168
+
169
+ The rule file defines patterns and related metadata used by the scanner. Configured rules may cover credential types such as cloud access keys, tokens, private-key blocks, database connection strings, passwords, and generic API keys. Actual detection depends on the rules and the scanner's filtering and scoring logic.
170
+
171
+ When adding a rule, use a unique ID, a descriptive name, a severity, a detection pattern, and any context keywords required by the rule format. Add or update tests to verify the expected detection and check for false positives.
172
+
173
+ ## Reports
174
+
175
+ ### Console output
176
+
177
+ The CLI displays findings with details such as severity, confidence, location, and a masked snippet.
178
+
179
+ ### JSON report
180
+
181
+ Generate a machine-readable report with:
182
+
183
+ ```powershell
184
+ credhunter .\examples\vulnerable_project --json report.json --fail-on none
185
+ ```
186
+
187
+ ### HTML report
188
+
189
+ Generate a human-readable report with:
190
+
191
+ ```powershell
192
+ credhunter .\examples\vulnerable_project --html report.html --fail-on none
193
+ ```
194
+
195
+ To generate both formats in one scan:
196
+
197
+ ```powershell
198
+ credhunter .\examples\vulnerable_project --json report.json --html report.html --fail-on none
199
+ ```
200
+
201
+ ## Testing
202
+
203
+ Install the development dependencies:
204
+
205
+ ```bash
206
+ python -m pip install -e ".[dev]"
207
+ ```
208
+
209
+ Run the test suite:
210
+
211
+ ```bash
212
+ python -m pytest
213
+ ```
214
+
215
+ Before releasing a version, confirm that all tests pass. Also perform manual checks in a clean virtual environment:
216
+
217
+ 1. Run `credhunter --version` and `credhunter --help`.
218
+ 2. Scan a test project containing synthetic secrets.
219
+ 3. Scan a clean test project and review unexpected findings.
220
+ 4. Generate JSON and HTML reports.
221
+ 5. Confirm the original synthetic secret is not exposed in console output or either report.
222
+ 6. Check exit codes for `--fail-on none` and severity thresholds that should and should not be triggered.
223
+ 7. Confirm an installed package can locate its bundled YAML rules.
224
+
225
+ Use only fake, nonfunctional test values in examples and tests.
226
+
227
+ ## Security Response Guidance
228
+
229
+ If credhunter identifies a real credential:
230
+
231
+ 1. Revoke or rotate the credential promptly.
232
+ 2. Remove it from the source code and use an appropriate secrets-management solution.
233
+ 3. Review repository history and access logs where appropriate.
234
+ 4. Assess whether the credential may have been accessed by an unauthorized party.
235
+ 5. Update tests or detection rules if the finding reveals a coverage gap.
236
+
237
+ Removing a secret from the latest version of a file does not necessarily remove it from version-control history.
238
+
239
+ ## Known Limitations
240
+
241
+ - Detection depends on configured rules and may miss custom or proprietary credential formats.
242
+ - False positives and false negatives are possible.
243
+ - Placeholder filtering may suppress a value if it contains a configured placeholder marker.
244
+ - Masking should be verified for each output format.
245
+ - A successful scan does not prove that a repository contains no secrets.
246
+
247
+ ## Project Structure
248
+
249
+ The core package follows this general layout:
250
+
251
+ ```text
252
+ credhunter/
253
+ ├── credhunter/
254
+ │ ├── cli.py
255
+ │ ├── scanner.py
256
+ │ ├── masking.py
257
+ │ ├── models.py
258
+ │ ├── scoring.py
259
+ │ ├── detectors/
260
+ │ │ ├── regex_detector.py
261
+ │ │ ├── entropy.py
262
+ │ │ └── context.py
263
+ │ ├── reporters/
264
+ │ │ ├── json_reporter.py
265
+ │ │ ├── html_reporter.py
266
+ │ │ └── pdf_reporter.py
267
+ │ └── rules/
268
+ │ └── secrets.yaml
269
+ ├── tests/
270
+ ├── examples/
271
+ ├── pyproject.toml
272
+ └── README.md
273
+ ```
274
+
275
+ The exact structure may change as development continues.
276
+
277
+ ## License
278
+
279
+ Add a license file and the corresponding package metadata before publishing if you intend others to use, modify, or redistribute credhunter.
@@ -0,0 +1,267 @@
1
+ # credhunter
2
+
3
+ credhunter is a Python command-line tool for scanning files and directories for potential hardcoded secrets. It combines pattern-based detection with context and entropy signals, assigns confidence and severity, masks detected values in output, and can generate JSON and HTML reports.
4
+
5
+ credhunter is a detection aid, not a guarantee that every secret will be found. Review findings before taking action, and never use real production credentials in test fixtures.
6
+
7
+ ## Features
8
+
9
+ - Scan a single file or directory.
10
+ - Detect configured secret patterns using rules packaged with credhunter.
11
+ - Use context analysis and Shannon entropy as detection signals.
12
+ - Assign confidence scores and severity levels.
13
+ - Filter configured placeholder values to reduce some false positives.
14
+ - Mask detected values in console output and reports.
15
+ - Generate JSON and HTML reports.
16
+ - Configure CI failure behavior with `--fail-on`.
17
+ - Display the installed package version with `--version`.
18
+
19
+ ## Requirements
20
+
21
+ - Python 3.10 or newer.
22
+ - Windows, Linux, or macOS with a compatible Python installation.
23
+
24
+ ## Installation
25
+
26
+ ### Install from PyPI
27
+
28
+ Once credhunter has been published to PyPI, install it with:
29
+
30
+ ```bash
31
+ python -m pip install credhunter
32
+ ```
33
+
34
+ Verify the installation:
35
+
36
+ ```bash
37
+ credhunter --version
38
+ credhunter --help
39
+ ```
40
+
41
+ ### Install from source for development
42
+
43
+ If you have cloned or downloaded the source repository, open a terminal in the project directory.
44
+
45
+ **Windows PowerShell**
46
+
47
+ ```powershell
48
+ python -m venv .venv
49
+ .\.venv\Scripts\Activate.ps1
50
+ python -m pip install --upgrade pip
51
+ python -m pip install -e .
52
+ ```
53
+
54
+ **Linux/macOS**
55
+
56
+ ```bash
57
+ python3 -m venv .venv
58
+ source .venv/bin/activate
59
+ python -m pip install --upgrade pip
60
+ python -m pip install -e .
61
+ ```
62
+
63
+ To install development and test dependencies:
64
+
65
+ ```bash
66
+ python -m pip install -e ".[dev]"
67
+ ```
68
+
69
+ The editable installation is intended for development. It allows changes to the source code to be used without rebuilding and reinstalling the package.
70
+
71
+ ## Usage
72
+
73
+ The command accepts a file or directory path as its positional argument.
74
+
75
+ ### Show the installed version
76
+
77
+ ```bash
78
+ credhunter --version
79
+ ```
80
+
81
+ ### Show help
82
+
83
+ ```bash
84
+ credhunter --help
85
+ ```
86
+
87
+ ### Scan the current directory
88
+
89
+ ```bash
90
+ credhunter .
91
+ ```
92
+
93
+ ### Scan a directory
94
+
95
+ **Windows PowerShell**
96
+
97
+ ```powershell
98
+ credhunter .\examples\vulnerable_project
99
+ ```
100
+
101
+ ### Scan a single file
102
+
103
+ ```powershell
104
+ credhunter .\path\to\file.py
105
+ ```
106
+
107
+ ### Generate JSON and HTML reports
108
+
109
+ ```powershell
110
+ credhunter .\examples\vulnerable_project --json report.json --html report.html
111
+ ```
112
+
113
+ Choose report destinations that are writable. Review generated reports before sharing them, as they can contain sensitive repository details even when detected secret values are masked.
114
+
115
+ ### Configure the CI/CD failure threshold
116
+
117
+ ```powershell
118
+ credhunter .\examples\vulnerable_project --fail-on high
119
+ ```
120
+
121
+ Supported thresholds:
122
+
123
+ - `critical`
124
+ - `high`
125
+ - `medium`
126
+ - `low`
127
+ - `none`
128
+
129
+ The command returns exit code `1` when at least one finding meets or exceeds the selected threshold; otherwise, it returns `0`. Use `--fail-on none` to complete a scan without failing based on findings:
130
+
131
+ ```powershell
132
+ credhunter .\examples\vulnerable_project --fail-on none
133
+ ```
134
+
135
+ ## How Detection Works
136
+
137
+ credhunter uses several signals to evaluate potential secrets:
138
+
139
+ 1. **Pattern matching:** configured regular expressions identify values that match known secret formats.
140
+ 2. **Context analysis:** nearby names or text, such as `password`, `token`, and `api_key`, can help assess whether a value is a credential.
141
+ 3. **Entropy analysis:** Shannon entropy helps assess how random-looking a string is.
142
+ 4. **Confidence and severity:** findings include a confidence score and severity classification.
143
+ 5. **Placeholder filtering:** configured placeholder markers can suppress common test or example values.
144
+ 6. **Masking:** console output and reports use masked snippets rather than intentionally displaying the complete detected value.
145
+ 7. **Fingerprinting:** SHA-256 fingerprints can help identify repeated values without storing the raw secret as the fingerprint.
146
+
147
+ These signals do not guarantee that every secret will be detected or that every finding is correct. False positives and false negatives are possible.
148
+
149
+ ## Detection Rules
150
+
151
+ Detection rules are stored in the package at:
152
+
153
+ ```text
154
+ credhunter/rules/secrets.yaml
155
+ ```
156
+
157
+ The rule file defines patterns and related metadata used by the scanner. Configured rules may cover credential types such as cloud access keys, tokens, private-key blocks, database connection strings, passwords, and generic API keys. Actual detection depends on the rules and the scanner's filtering and scoring logic.
158
+
159
+ When adding a rule, use a unique ID, a descriptive name, a severity, a detection pattern, and any context keywords required by the rule format. Add or update tests to verify the expected detection and check for false positives.
160
+
161
+ ## Reports
162
+
163
+ ### Console output
164
+
165
+ The CLI displays findings with details such as severity, confidence, location, and a masked snippet.
166
+
167
+ ### JSON report
168
+
169
+ Generate a machine-readable report with:
170
+
171
+ ```powershell
172
+ credhunter .\examples\vulnerable_project --json report.json --fail-on none
173
+ ```
174
+
175
+ ### HTML report
176
+
177
+ Generate a human-readable report with:
178
+
179
+ ```powershell
180
+ credhunter .\examples\vulnerable_project --html report.html --fail-on none
181
+ ```
182
+
183
+ To generate both formats in one scan:
184
+
185
+ ```powershell
186
+ credhunter .\examples\vulnerable_project --json report.json --html report.html --fail-on none
187
+ ```
188
+
189
+ ## Testing
190
+
191
+ Install the development dependencies:
192
+
193
+ ```bash
194
+ python -m pip install -e ".[dev]"
195
+ ```
196
+
197
+ Run the test suite:
198
+
199
+ ```bash
200
+ python -m pytest
201
+ ```
202
+
203
+ Before releasing a version, confirm that all tests pass. Also perform manual checks in a clean virtual environment:
204
+
205
+ 1. Run `credhunter --version` and `credhunter --help`.
206
+ 2. Scan a test project containing synthetic secrets.
207
+ 3. Scan a clean test project and review unexpected findings.
208
+ 4. Generate JSON and HTML reports.
209
+ 5. Confirm the original synthetic secret is not exposed in console output or either report.
210
+ 6. Check exit codes for `--fail-on none` and severity thresholds that should and should not be triggered.
211
+ 7. Confirm an installed package can locate its bundled YAML rules.
212
+
213
+ Use only fake, nonfunctional test values in examples and tests.
214
+
215
+ ## Security Response Guidance
216
+
217
+ If credhunter identifies a real credential:
218
+
219
+ 1. Revoke or rotate the credential promptly.
220
+ 2. Remove it from the source code and use an appropriate secrets-management solution.
221
+ 3. Review repository history and access logs where appropriate.
222
+ 4. Assess whether the credential may have been accessed by an unauthorized party.
223
+ 5. Update tests or detection rules if the finding reveals a coverage gap.
224
+
225
+ Removing a secret from the latest version of a file does not necessarily remove it from version-control history.
226
+
227
+ ## Known Limitations
228
+
229
+ - Detection depends on configured rules and may miss custom or proprietary credential formats.
230
+ - False positives and false negatives are possible.
231
+ - Placeholder filtering may suppress a value if it contains a configured placeholder marker.
232
+ - Masking should be verified for each output format.
233
+ - A successful scan does not prove that a repository contains no secrets.
234
+
235
+ ## Project Structure
236
+
237
+ The core package follows this general layout:
238
+
239
+ ```text
240
+ credhunter/
241
+ ├── credhunter/
242
+ │ ├── cli.py
243
+ │ ├── scanner.py
244
+ │ ├── masking.py
245
+ │ ├── models.py
246
+ │ ├── scoring.py
247
+ │ ├── detectors/
248
+ │ │ ├── regex_detector.py
249
+ │ │ ├── entropy.py
250
+ │ │ └── context.py
251
+ │ ├── reporters/
252
+ │ │ ├── json_reporter.py
253
+ │ │ ├── html_reporter.py
254
+ │ │ └── pdf_reporter.py
255
+ │ └── rules/
256
+ │ └── secrets.yaml
257
+ ├── tests/
258
+ ├── examples/
259
+ ├── pyproject.toml
260
+ └── README.md
261
+ ```
262
+
263
+ The exact structure may change as development continues.
264
+
265
+ ## License
266
+
267
+ Add a license file and the corresponding package metadata before publishing if you intend others to use, modify, or redistribute credhunter.