sherlockscan 0.2.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.
- sherlockscan-0.2.0/LICENSE +21 -0
- sherlockscan-0.2.0/MANIFEST.in +28 -0
- sherlockscan-0.2.0/PKG-INFO +377 -0
- sherlockscan-0.2.0/README.md +343 -0
- sherlockscan-0.2.0/pyproject.toml +97 -0
- sherlockscan-0.2.0/requirements.txt +23 -0
- sherlockscan-0.2.0/setup.cfg +4 -0
- sherlockscan-0.2.0/setup.py +144 -0
- sherlockscan-0.2.0/sherlockscan/__init__.py +53 -0
- sherlockscan-0.2.0/sherlockscan/cli.py +319 -0
- sherlockscan-0.2.0/sherlockscan/config/__init__.py +101 -0
- sherlockscan-0.2.0/sherlockscan/config/approved_packages.yaml +116 -0
- sherlockscan-0.2.0/sherlockscan/config/risk_patterns.yaml +191 -0
- sherlockscan-0.2.0/sherlockscan/exceptions.py +62 -0
- sherlockscan-0.2.0/sherlockscan/report/__init__.py +36 -0
- sherlockscan-0.2.0/sherlockscan/report/json_formatter.py +140 -0
- sherlockscan-0.2.0/sherlockscan/report/markdown_formatter.py +210 -0
- sherlockscan-0.2.0/sherlockscan/scanner/__init__.py +42 -0
- sherlockscan-0.2.0/sherlockscan/scanner/ast_scanner.py +343 -0
- sherlockscan-0.2.0/sherlockscan/scanner/deps.py +203 -0
- sherlockscan-0.2.0/sherlockscan/scanner/explainer.py +167 -0
- sherlockscan-0.2.0/sherlockscan/scanner/heuristics.py +282 -0
- sherlockscan-0.2.0/sherlockscan/scanner/install_script_analyzer.py +343 -0
- sherlockscan-0.2.0/sherlockscan/utils.py +313 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/PKG-INFO +377 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/SOURCES.txt +28 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/dependency_links.txt +1 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/entry_points.txt +2 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/requires.txt +8 -0
- sherlockscan-0.2.0/sherlockscan.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Arockia Liborious
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# MANIFEST.in
|
|
2
|
+
#
|
|
3
|
+
# Specifies which non-code files to include in source distributions (sdists).
|
|
4
|
+
# This works in conjunction with include_package_data=True in setup.py.
|
|
5
|
+
|
|
6
|
+
# Include important top-level files.
|
|
7
|
+
include README.md
|
|
8
|
+
include LICENSE
|
|
9
|
+
include requirements.txt
|
|
10
|
+
|
|
11
|
+
# Recursively include all files within the sherlockscan/config directory.
|
|
12
|
+
# This ensures the default YAML configuration files are packaged.
|
|
13
|
+
graft sherlockscan/config
|
|
14
|
+
|
|
15
|
+
# Exclude compiled Python files globally
|
|
16
|
+
global-exclude *.py[cod]
|
|
17
|
+
# Exclude __pycache__ directories globally
|
|
18
|
+
global-exclude __pycache__
|
|
19
|
+
|
|
20
|
+
# Exclude test files and directories from the distribution
|
|
21
|
+
# (find_packages in setup.py already excludes tests from installation,
|
|
22
|
+
# but pruning them from the sdist is also good practice).
|
|
23
|
+
prune tests
|
|
24
|
+
|
|
25
|
+
# One can add other files here if needed, like documentation files, examples etc. if needed during enhancements
|
|
26
|
+
# Example: graft docs
|
|
27
|
+
# Example: prune docs/_build
|
|
28
|
+
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sherlockscan
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Static supply-chain risk scanner for Python packages.
|
|
5
|
+
Home-page: https://github.com/itsual/sherlockscan
|
|
6
|
+
Author: Arockia Liborious
|
|
7
|
+
Author-email: arockialiborious@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/itsual/sherlockscan
|
|
10
|
+
Project-URL: Issues, https://github.com/itsual/sherlockscan/issues
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: typer<1.0,>=0.12
|
|
24
|
+
Requires-Dist: PyYAML<7.0,>=6.0
|
|
25
|
+
Requires-Dist: packaging>=23.0
|
|
26
|
+
Requires-Dist: toml>=0.10.2
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
30
|
+
Dynamic: author-email
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-python
|
|
34
|
+
|
|
35
|
+
# 🕵️ SherlockScan: Investigate Your Python Dependencies!
|
|
36
|
+
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
[](https://pypi.org/project/sherlockscan/)
|
|
39
|
+
[](https://travis-ci.com/yourusername/sherlockscan)
|
|
40
|
+
[](https://codecov.io/gh/yourusername/sherlockscan)
|
|
41
|
+
|
|
42
|
+
**Uncover hidden risks lurking within your Python packages before they compromise your projects — especially crucial for Data Science, Machine Learning, and regulated environments.**
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## ❓ The Mystery: What's Hiding in Your Dependencies?
|
|
47
|
+
|
|
48
|
+
In the world of software development, especially in Python's rich ecosystem, we often rely on third-party packages from sources like PyPI. We `pip install` them, trusting they do what they claim. But what if they do *more*?
|
|
49
|
+
|
|
50
|
+
Imagine inviting a helpful stranger into your house. They might fix your plumbing, but they might also secretly copy your keys or map out your valuables. Similarly, Python packages can contain:
|
|
51
|
+
|
|
52
|
+
* **Malicious Code:** Viruses, ransomware, or spyware hiding within seemingly useful functions.
|
|
53
|
+
* **Hidden Backdoors:** Secret ways for attackers to access your systems later.
|
|
54
|
+
* **Leaked Secrets:** Hardcoded API keys, passwords, or tokens accidentally left in the code.
|
|
55
|
+
* **Unexpected Behavior:** Code that sends your data to unknown servers or runs cryptocurrency miners during your ML training jobs.
|
|
56
|
+
|
|
57
|
+
These "supply chain attacks" are a growing threat. Regulated industries like banking and healthcare, and sensitive fields like AI/ML dealing with valuable data and models, *cannot afford* to be compromised by a dependency.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🔍 Enter SherlockScan: Your Code Detective
|
|
62
|
+
|
|
63
|
+
SherlockScan acts like a detective for your Python dependencies. It doesn't just check for known vulnerabilities (like a standard security guard checking an ID list); it actively investigates the *code itself* to find suspicious patterns, hidden logic, and potential malice *before* you integrate it deeply into your projects.
|
|
64
|
+
|
|
65
|
+
It's designed with **Data Science and Machine Learning** workflows in mind, looking for risks particularly relevant to data handling, model integrity, and common DS/ML libraries — but its core analysis is valuable for any Python project.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## ✨ Key Features
|
|
70
|
+
|
|
71
|
+
* **📜 Static Code Analysis (AST):** Parses Python code to understand its structure and identify dangerous function calls (`eval`, `exec`, `pickle.load`, `os.system`, `subprocess`), risky imports (networking, ctypes), and suspicious patterns relevant to DS/ML.
|
|
72
|
+
* **🕵️ Heuristic Scanning:** Uses configurable rules (regex, keywords, entropy analysis) to find hardcoded secrets (API keys, passwords for AWS, GCP, Azure, common SaaS platforms), suspicious comments, and potentially obfuscated code.
|
|
73
|
+
* **🔗 Dependency Vetting:** Checks a package's direct dependencies against configurable `allow` and `block` lists, ensuring you only rely on approved packages.
|
|
74
|
+
* **📦 Installation Script Analysis:** Examines `setup.py` and `pyproject.toml` for commands or custom build steps that might execute malicious code during installation.
|
|
75
|
+
* **⚙️ Configurable Rules:** Easily customize detection patterns, keywords, severity levels, and approved dependencies via simple YAML files (`risk_patterns.yaml`, `approved_packages.yaml`).
|
|
76
|
+
* **📄 Multiple Report Formats:** Generates human-readable Markdown reports and machine-readable JSON reports.
|
|
77
|
+
* **🗣️ Explainable Results:** Provides clear messages explaining *why* something was flagged and an overall risk assessment with recommendations.
|
|
78
|
+
* **💻 CLI & Library:** Use it as a command-line tool or integrate its scanning functions into your own Python scripts and CI/CD pipelines.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 🤔 Why SherlockScan?
|
|
83
|
+
|
|
84
|
+
While other tools exist (like SAST and SCA scanners), SherlockScan aims to fill a specific niche:
|
|
85
|
+
|
|
86
|
+
1. **Focus on *Intent* & Hidden Logic:** Goes beyond known CVEs to look for patterns *suggesting* malicious intent or dangerous practices (like network calls on import, obfuscation, setup script execution).
|
|
87
|
+
2. **DS/ML Context Aware (Planned):** While the core is general, future development aims to add more checks relevant to data leakage, model tampering, and common ML library vulnerabilities.
|
|
88
|
+
3. **Explainability:** Provides clearer context on *why* a pattern is considered risky.
|
|
89
|
+
4. **Configuration Flexibility:** Easily tailor detection rules to your organization's specific needs and risk tolerance without complex setup.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## ⚙️ How It Works: The Investigation Process
|
|
94
|
+
|
|
95
|
+
SherlockScan follows a multi-stage process to analyze a target package:
|
|
96
|
+
|
|
97
|
+
```mermaid
|
|
98
|
+
graph TD
|
|
99
|
+
A[Input: Package Target - Name/Path] --> B{Resolve Package Target};
|
|
100
|
+
B --> C{Find/Extract Package Source};
|
|
101
|
+
C --> D[Scan Install Scripts - setup.py, pyproject.toml];
|
|
102
|
+
C --> E[Scan Dependencies - Metadata + Allow/Block List];
|
|
103
|
+
C --> F[Find Python Files .py];
|
|
104
|
+
F --> G[For Each .py File];
|
|
105
|
+
G -- AST Analysis --> H(Identify Risky Calls/Imports);
|
|
106
|
+
G -- Heuristic Analysis --> I(Find Secrets, Keywords, Entropy);
|
|
107
|
+
D --> J{Aggregate Findings};
|
|
108
|
+
E --> J;
|
|
109
|
+
H --> J;
|
|
110
|
+
I --> J;
|
|
111
|
+
J --> K{Calculate Summary & Risk Level};
|
|
112
|
+
K --> L[Generate Explanation];
|
|
113
|
+
L --> M{Format Report - JSON/MD};
|
|
114
|
+
M --> N[Output: Report - Console/File];
|
|
115
|
+
style B fill:#f9f,stroke:#333,stroke-width:2px
|
|
116
|
+
style J fill:#ccf,stroke:#333,stroke-width:2px
|
|
117
|
+
style K fill:#ccf,stroke:#333,stroke-width:2px
|
|
118
|
+
style M fill:#fcf,stroke:#333,stroke-width:2px
|
|
119
|
+
style N fill:#9f9,stroke:#333,stroke-width:2px
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Stage-by-stage breakdown:**
|
|
123
|
+
|
|
124
|
+
1. **Resolve Package Target:** Determines if the input is a local directory, an archive file, or a package name from PyPI. Downloads and extracts if necessary using `pip download` and standard archive libraries. Finds the package source root.
|
|
125
|
+
2. **Scan Install Scripts:** Analyzes `setup.py` (using AST) and `pyproject.toml` (using TOML parsing) for risky commands or configurations executed during build/installation.
|
|
126
|
+
3. **Scan Dependencies:** Parses package metadata (using `importlib.metadata` on the installed package) to find direct dependencies. Checks these against `approved_packages.yaml`.
|
|
127
|
+
4. **Scan Source Files:** Recursively finds all `.py` files.
|
|
128
|
+
5. **AST Analysis:** Parses each file into an Abstract Syntax Tree. Traverses the tree to find specific function calls (`eval`, `pickle.load`, `os.system`, etc.) and module imports (`requests`, `socket`, `subprocess`, etc.) defined as risky.
|
|
129
|
+
6. **Heuristic Analysis:** Reads each file line-by-line. Applies regex patterns (from `risk_patterns.yaml`) to detect secrets. Checks for suspicious keywords. Calculates Shannon entropy to flag potentially obfuscated lines/strings.
|
|
130
|
+
7. **Aggregate & Report:** Collects all findings from all stages. Calculates a summary (counts by severity) and determines an overall risk level. Generates a human-readable explanation. Formats the final report in JSON or Markdown.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🚀 Installation
|
|
135
|
+
|
|
136
|
+
Ensure you have Python 3.8+ installed. You can install SherlockScan using pip:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install sherlockscan
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or install directly from source:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
git clone https://github.com/yourusername/sherlockscan.git # TODO: Update URL
|
|
146
|
+
cd sherlockscan
|
|
147
|
+
pip install .
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
SherlockScan requires the following libraries, which are installed automatically:
|
|
151
|
+
|
|
152
|
+
* `typer` (for the CLI)
|
|
153
|
+
* `PyYAML` (for configuration files)
|
|
154
|
+
* `packaging` (for dependency parsing)
|
|
155
|
+
* `toml` (for `pyproject.toml` parsing)
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 💻 Usage
|
|
160
|
+
|
|
161
|
+
### Command Line Interface (CLI)
|
|
162
|
+
|
|
163
|
+
The primary way to use SherlockScan is via the `sherlockscan` command:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
sherlockscan scan <package_target> [OPTIONS]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Arguments:**
|
|
170
|
+
|
|
171
|
+
* `PACKAGE_TARGET`: *(Required)* The package to scan. This can be:
|
|
172
|
+
* A package name from PyPI (e.g., `requests`)
|
|
173
|
+
* A path to a local directory containing the package source
|
|
174
|
+
* A path to a local archive file (`.whl`, `.tar.gz`, `.zip`)
|
|
175
|
+
|
|
176
|
+
**Options:**
|
|
177
|
+
|
|
178
|
+
| Flag | Description |
|
|
179
|
+
|------|-------------|
|
|
180
|
+
| `-o, --output PATH` | Path to save the report file. If omitted, the report is printed to the console. |
|
|
181
|
+
| `-f, --format [json\|md]` | Output format. Default is `md` (Markdown). |
|
|
182
|
+
| `-c, --config PATH` | Path to the directory containing configuration files (`risk_patterns.yaml`, `approved_packages.yaml`). Defaults to `./config`. |
|
|
183
|
+
| `-s, --severity [CRITICAL\|HIGH\|MEDIUM\|LOW\|INFO]` | Minimum severity level to report. Default is `INFO` (shows all). |
|
|
184
|
+
| `--include-tests` | Include bundled test and fixture code. Tests are excluded by default to reduce noise. |
|
|
185
|
+
| `--sbom PATH` | Write a CycloneDX 1.5 JSON software bill of materials. |
|
|
186
|
+
|
|
187
|
+
**Examples:**
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# Scan 'requests' from PyPI, print Markdown report to console (showing all findings)
|
|
191
|
+
sherlockscan scan requests
|
|
192
|
+
|
|
193
|
+
# Scan a local package directory, save JSON report, show only HIGH severity or above
|
|
194
|
+
sherlockscan scan ./my_local_package/ -f json -o report.json -s HIGH
|
|
195
|
+
|
|
196
|
+
# Scan a downloaded wheel file using custom config, print MD to console
|
|
197
|
+
sherlockscan scan ./downloads/some_package-1.0-py3-none-any.whl -c ./my_configs/
|
|
198
|
+
|
|
199
|
+
# Generate a report and a CycloneDX SBOM for CI or an audit trail
|
|
200
|
+
sherlockscan scan requests --format json --output report.json --sbom sbom.cdx.json
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### Library Usage
|
|
206
|
+
|
|
207
|
+
You can also integrate SherlockScan's core logic into your own Python scripts.
|
|
208
|
+
|
|
209
|
+
> ⚠️ **Note:** The library API is less stable in early versions and may change.
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
import os
|
|
213
|
+
|
|
214
|
+
from sherlockscan import utils
|
|
215
|
+
from sherlockscan.scanner import ast_scanner, heuristics, deps, install_script_analyzer
|
|
216
|
+
from sherlockscan.scanner import explainer
|
|
217
|
+
from sherlockscan.report import json_formatter # or markdown_formatter
|
|
218
|
+
|
|
219
|
+
# 1. Resolve the package target to get its source directory, name, version.
|
|
220
|
+
# WARNING: The current implementation returns a path in a temp dir
|
|
221
|
+
# which needs manual cleanup after use.
|
|
222
|
+
try:
|
|
223
|
+
if hasattr(utils, 'resolve_package_target') and callable(utils.resolve_package_target):
|
|
224
|
+
pkg_dir, pkg_name, pkg_version = utils.resolve_package_target("requests")
|
|
225
|
+
else:
|
|
226
|
+
raise ImportError("utils.resolve_package_target not found or not callable.")
|
|
227
|
+
except Exception as e:
|
|
228
|
+
print(f"Error resolving package: {e}")
|
|
229
|
+
exit()
|
|
230
|
+
|
|
231
|
+
# Define config paths
|
|
232
|
+
config_dir = "./config" # Or your custom path
|
|
233
|
+
risk_patterns_path = os.path.join(config_dir, "risk_patterns.yaml")
|
|
234
|
+
approved_packages_path = os.path.join(config_dir, "approved_packages.yaml")
|
|
235
|
+
|
|
236
|
+
# 2. Run scanners
|
|
237
|
+
all_findings = []
|
|
238
|
+
all_findings.extend(install_script_analyzer.scan_install_scripts(str(pkg_dir)))
|
|
239
|
+
|
|
240
|
+
if hasattr(deps, 'scan_dependencies') and callable(deps.scan_dependencies):
|
|
241
|
+
all_findings.extend(deps.scan_dependencies(pkg_name, approved_packages_path))
|
|
242
|
+
else:
|
|
243
|
+
print("Warning: Dependency scanner not found.")
|
|
244
|
+
|
|
245
|
+
if hasattr(utils, 'find_python_files') and callable(utils.find_python_files):
|
|
246
|
+
python_files = utils.find_python_files(pkg_dir)
|
|
247
|
+
for py_file in python_files:
|
|
248
|
+
all_findings.extend(ast_scanner.scan_file_ast(str(py_file)))
|
|
249
|
+
all_findings.extend(heuristics.scan_file_heuristics(str(py_file), risk_patterns_path))
|
|
250
|
+
else:
|
|
251
|
+
print("Warning: Python file finder not found.")
|
|
252
|
+
|
|
253
|
+
# 3. Process results
|
|
254
|
+
# summary = _calculate_summary(all_findings)
|
|
255
|
+
# overall_risk_level = _determine_overall_risk(summary)
|
|
256
|
+
# explanation = explainer.generate_overall_explanation(...)
|
|
257
|
+
|
|
258
|
+
# 4. Format report
|
|
259
|
+
# json_report = json_formatter.format_report_json(...)
|
|
260
|
+
|
|
261
|
+
# Remember to clean up temporary directories created by resolve_package_target!
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 🔧 Configuration
|
|
267
|
+
|
|
268
|
+
SherlockScan uses YAML files in a configuration directory (default `./config/`) for customization.
|
|
269
|
+
|
|
270
|
+
### `risk_patterns.yaml`
|
|
271
|
+
|
|
272
|
+
* Defines regex patterns for secret detection (e.g., API keys, passwords).
|
|
273
|
+
* Defines suspicious keywords to search for in code and comments.
|
|
274
|
+
* Sets the `entropy_threshold` for detecting potentially obfuscated code.
|
|
275
|
+
* Allows specifying `type`, `severity`, and `message` for each pattern/keyword.
|
|
276
|
+
|
|
277
|
+
```yaml
|
|
278
|
+
settings:
|
|
279
|
+
entropy_threshold: 4.0
|
|
280
|
+
|
|
281
|
+
regex_patterns:
|
|
282
|
+
- name: AWS Access Key ID
|
|
283
|
+
type: Hardcoded Secret
|
|
284
|
+
pattern: '(A3T[A-Z0-9]|AKIA|...)[A-Z0-9]{16}'
|
|
285
|
+
severity: CRITICAL
|
|
286
|
+
message: "Potential AWS Access Key ID detected."
|
|
287
|
+
# ... more patterns
|
|
288
|
+
|
|
289
|
+
keywords:
|
|
290
|
+
- name: TODO Security
|
|
291
|
+
type: Security Comment
|
|
292
|
+
keyword: "TODO: security"
|
|
293
|
+
severity: LOW
|
|
294
|
+
message: "Comment indicates a potential security task."
|
|
295
|
+
# ... more keywords
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### `approved_packages.yaml` *(Optional)*
|
|
299
|
+
|
|
300
|
+
* Defines an **allowlist** of explicitly approved dependency package names. If present and non-empty, any dependency not on this list will be flagged.
|
|
301
|
+
* Defines a **blocklist** of explicitly forbidden dependency package names. Any dependency on this list will be flagged with high severity.
|
|
302
|
+
* The DS/ML allowlist is supplied as a policy template. Set `enforce_allowlist: true` only when you want dependencies outside that policy to be reported.
|
|
303
|
+
|
|
304
|
+
### Safety and report semantics
|
|
305
|
+
|
|
306
|
+
SherlockScan does not install or import the package it analyzes. Downloads are extracted into a temporary directory with path traversal, links/devices, member-count, and uncompressed-size checks. Run the scanner in an isolated environment when investigating untrusted artifacts.
|
|
307
|
+
|
|
308
|
+
Severity filtering controls the detailed findings shown in a report. The overall risk and `full_summary` always cover the complete scan, so a filtered report remains auditable even when lower-severity findings are hidden.
|
|
309
|
+
* Package names are canonicalized (lowercase, hyphens) before comparison.
|
|
310
|
+
|
|
311
|
+
```yaml
|
|
312
|
+
allowlist:
|
|
313
|
+
- numpy
|
|
314
|
+
- pandas
|
|
315
|
+
- requests
|
|
316
|
+
# ... more approved packages
|
|
317
|
+
|
|
318
|
+
blocklist:
|
|
319
|
+
- malicious-lib
|
|
320
|
+
- outdated-insecure-package
|
|
321
|
+
# ... more blocked packages
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## 📊 Output Formats
|
|
327
|
+
|
|
328
|
+
SherlockScan provides two output formats:
|
|
329
|
+
|
|
330
|
+
* **Markdown (`md`):** *(Default)* Human-readable report suitable for documentation, manual review, or pasting into issues/wikis. Includes a summary table and detailed findings with code snippets.
|
|
331
|
+
* **JSON (`json`):** Machine-readable format suitable for integration with other tools, dashboards, or automated processing. Contains all report details in a structured format.
|
|
332
|
+
|
|
333
|
+
```json
|
|
334
|
+
{
|
|
335
|
+
"package_name": "example-package",
|
|
336
|
+
"package_version": "1.0.0",
|
|
337
|
+
"scan_timestamp": "2025-04-13T21:00:00Z",
|
|
338
|
+
"overall_risk_level": "CRITICAL",
|
|
339
|
+
"findings": [
|
|
340
|
+
{
|
|
341
|
+
"type": "Hardcoded Secret",
|
|
342
|
+
"severity": "CRITICAL",
|
|
343
|
+
"file_path": "src/config.py",
|
|
344
|
+
"line_number": 15,
|
|
345
|
+
"code_snippet": "API_KEY = \"sk_live_...\"",
|
|
346
|
+
"message": "Potential Stripe API Key detected."
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"summary": {
|
|
350
|
+
"total_findings": 5,
|
|
351
|
+
"by_severity": { "CRITICAL": 1, "HIGH": 2, "MEDIUM": 1, "LOW": 1 }
|
|
352
|
+
},
|
|
353
|
+
"explanation": "Package analysis resulted in overall risk level CRITICAL..."
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## 🤝 Contributing
|
|
360
|
+
|
|
361
|
+
Contributions are welcome. Please see CONTRIBUTING.md for guidelines on reporting issues, proposing features, and submitting pull requests.
|
|
362
|
+
|
|
363
|
+
Key areas for contribution:
|
|
364
|
+
|
|
365
|
+
* Adding more detection rules (regex, keywords, AST patterns)
|
|
366
|
+
* Improving accuracy and reducing false positives of existing rules
|
|
367
|
+
* Enhancing the `resolve_package_target` utility for better robustness
|
|
368
|
+
* Adding support for analyzing C extensions
|
|
369
|
+
* Developing dynamic analysis (sandboxing) capabilities
|
|
370
|
+
* Improving report formatting and explainability
|
|
371
|
+
* Adding more tests!
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## 📜 License
|
|
376
|
+
|
|
377
|
+
This project is licensed under the **MIT License** — see the `LICENSE` file for details.
|