dr-source 0.70.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.
- dr_source-0.70.0/LICENSE +21 -0
- dr_source-0.70.0/PKG-INFO +130 -0
- dr_source-0.70.0/README.md +112 -0
- dr_source-0.70.0/bin/dr_source +27 -0
- dr_source-0.70.0/dr_source/__init__.py +0 -0
- dr_source-0.70.0/dr_source/cli.py +172 -0
- dr_source-0.70.0/dr_source/core/__init__.py +0 -0
- dr_source-0.70.0/dr_source/core/codebase.py +29 -0
- dr_source-0.70.0/dr_source/core/db.py +202 -0
- dr_source-0.70.0/dr_source/core/detectors/__init__.py +28 -0
- dr_source-0.70.0/dr_source/core/detectors/base.py +10 -0
- dr_source-0.70.0/dr_source/core/detectors/command_injection.py +42 -0
- dr_source-0.70.0/dr_source/core/detectors/crypto.py +50 -0
- dr_source-0.70.0/dr_source/core/detectors/hardcoded_credentials.py +41 -0
- dr_source-0.70.0/dr_source/core/detectors/ldap_injection.py +41 -0
- dr_source-0.70.0/dr_source/core/detectors/path_traversal.py +41 -0
- dr_source-0.70.0/dr_source/core/detectors/serialization.py +41 -0
- dr_source-0.70.0/dr_source/core/detectors/sql_injection.py +65 -0
- dr_source-0.70.0/dr_source/core/detectors/ssrf.py +39 -0
- dr_source-0.70.0/dr_source/core/detectors/xss.py +46 -0
- dr_source-0.70.0/dr_source/core/detectors/xxe.py +40 -0
- dr_source-0.70.0/dr_source/core/scanner.py +50 -0
- dr_source-0.70.0/dr_source/core/taint.py +112 -0
- dr_source-0.70.0/dr_source/logging.py +22 -0
- dr_source-0.70.0/dr_source/reports/__init__.py +0 -0
- dr_source-0.70.0/dr_source/reports/sarif.py +61 -0
- dr_source-0.70.0/dr_source.egg-info/PKG-INFO +130 -0
- dr_source-0.70.0/dr_source.egg-info/SOURCES.txt +40 -0
- dr_source-0.70.0/dr_source.egg-info/dependency_links.txt +1 -0
- dr_source-0.70.0/dr_source.egg-info/entry_points.txt +2 -0
- dr_source-0.70.0/dr_source.egg-info/not-zip-safe +1 -0
- dr_source-0.70.0/dr_source.egg-info/requires.txt +5 -0
- dr_source-0.70.0/dr_source.egg-info/top_level.txt +1 -0
- dr_source-0.70.0/setup.cfg +4 -0
- dr_source-0.70.0/setup.py +20 -0
- dr_source-0.70.0/tests/test_ast_scanner.py +30 -0
- dr_source-0.70.0/tests/test_ast_sql_injection_taint.py +25 -0
- dr_source-0.70.0/tests/test_db.py +64 -0
- dr_source-0.70.0/tests/test_detectors.py +144 -0
- dr_source-0.70.0/tests/test_hardcoded_credentials.py +20 -0
- dr_source-0.70.0/tests/test_scanner.py +24 -0
- dr_source-0.70.0/tests/test_taint.py +22 -0
dr_source-0.70.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Paolo Perego
|
|
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,130 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: dr_source
|
|
3
|
+
Version: 0.70.0
|
|
4
|
+
Summary: Java and JSP Vulnerability Static Analyzer
|
|
5
|
+
Author: Paolo Perego
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: click
|
|
9
|
+
Requires-Dist: javalang
|
|
10
|
+
Requires-Dist: beautifulsoup4
|
|
11
|
+
Requires-Dist: scikit-learn
|
|
12
|
+
Requires-Dist: PyYAML
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: description
|
|
15
|
+
Dynamic: description-content-type
|
|
16
|
+
Dynamic: requires-dist
|
|
17
|
+
Dynamic: summary
|
|
18
|
+
|
|
19
|
+
# DRSource
|
|
20
|
+
|
|
21
|
+
DRSource is a static analysis tool designed to detect vulnerabilities in Java and JSP projects. It combines multiple detection techniques—including regex‑based detection and AST‑based taint propagation analysis—to identify security issues such as SQL Injection, Cross‑Site Scripting (XSS), Path Traversal, Command Injection, Serialization Issues, LDAP Injection, XXE, SSRF, and unsafe cryptographic/hashing functions.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Regex‑Based Detection**
|
|
26
|
+
Utilizes carefully crafted regular expressions to identify known vulnerability patterns in source code.
|
|
27
|
+
|
|
28
|
+
- **AST‑Based Taint Analysis**
|
|
29
|
+
Leverages [javalang](https://github.com/c2nes/javalang) to parse Java source files into an Abstract Syntax Tree (AST) and performs forward data‑flow analysis to propagate taint from user input sources (e.g., `request.getParameter`) to sensitive sinks (e.g., `executeQuery`).
|
|
30
|
+
|
|
31
|
+
- **Data‑Flow Analysis Framework**
|
|
32
|
+
A simplified yet robust framework that tracks tainted variables through declarations and assignments to flag dangerous data flows.
|
|
33
|
+
|
|
34
|
+
- **Multi‑Detector Support**
|
|
35
|
+
Detects various vulnerabilities including:
|
|
36
|
+
- SQL Injection
|
|
37
|
+
- Cross‑Site Scripting (XSS)
|
|
38
|
+
- Path Traversal
|
|
39
|
+
- Command Injection
|
|
40
|
+
- Serialization Issues
|
|
41
|
+
- LDAP Injection
|
|
42
|
+
- XXE (XML External Entity) Attacks
|
|
43
|
+
- SSRF (Server-Side Request Forgery)
|
|
44
|
+
- Unsafe Crypto/Hashing functions
|
|
45
|
+
|
|
46
|
+
- **Parallel Scanning & Progress Bar**
|
|
47
|
+
Files are scanned in parallel with a progress bar for faster analysis on large codebases.
|
|
48
|
+
|
|
49
|
+
- **Robust CLI**
|
|
50
|
+
The command‑line interface offers options to:
|
|
51
|
+
- Initialize the database (`--init-db`)
|
|
52
|
+
- View scan history (`--history`)
|
|
53
|
+
- Compare scans (`--compare`)
|
|
54
|
+
- Export results in SARIF, JSON, or HTML formats (`--export`)
|
|
55
|
+
- Enable AST‑based detection (`--ast`)
|
|
56
|
+
- Enable debug logging (`--debug`)
|
|
57
|
+
- Display version information (`--version`)
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Clone the repository and navigate to the project root:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/thesp0nge/dr_source.git
|
|
65
|
+
cd dr_source
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Install the package in editable mode:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install --editable .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
Run dr_source using the CLI:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
dr_source [OPTIONS] TARGET_PATH
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Options
|
|
83
|
+
|
|
84
|
+
- TARGET_PATH: The path of the codebase (directory containing Java/JSP files) to analyze.
|
|
85
|
+
- --init-db: Initialize the database from scratch (drops and recreates tables).
|
|
86
|
+
- --history: Display the scan history for the project.
|
|
87
|
+
- --compare <ID>: Compare the latest scan with a previous scan specified by ID.
|
|
88
|
+
- --export [sarif|json|html]: Export scan results in the specified format.
|
|
89
|
+
- --ast: Enable AST‑based detection (in addition to regex‑based detection).
|
|
90
|
+
- --debug: Enable debug logging.
|
|
91
|
+
- --version: Show DRSource version (as defined in setup.py) and exit.
|
|
92
|
+
|
|
93
|
+
### Examples
|
|
94
|
+
|
|
95
|
+
- Scan a Codebase Using AST‑Based Detection with Debug Logging:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
dr_source --ast --debug /path/to/codebase
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- Initialize the Database:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
dr_source --init-db /path/to/codebase
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- Export Results as SARIF:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
dr_source --export sarif /path/to/codebase
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Contributing
|
|
114
|
+
|
|
115
|
+
Contributions are welcome! To contribute:
|
|
116
|
+
|
|
117
|
+
- Fork the repository.
|
|
118
|
+
- Create a new branch for your feature or bugfix.
|
|
119
|
+
- Make your changes with clear commit messages.
|
|
120
|
+
- Submit a pull request for review.
|
|
121
|
+
- For major changes, please open an issue first to discuss your proposed changes.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
dr_source is licensed under the MIT License.
|
|
126
|
+
|
|
127
|
+
## Acknowledgments
|
|
128
|
+
|
|
129
|
+
Special thanks to the maintainers of [javalang](https://github.com/c2nes/javalang) for their work on Java AST parsing.
|
|
130
|
+
Inspired by various static analysis and security tools.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# DRSource
|
|
2
|
+
|
|
3
|
+
DRSource is a static analysis tool designed to detect vulnerabilities in Java and JSP projects. It combines multiple detection techniques—including regex‑based detection and AST‑based taint propagation analysis—to identify security issues such as SQL Injection, Cross‑Site Scripting (XSS), Path Traversal, Command Injection, Serialization Issues, LDAP Injection, XXE, SSRF, and unsafe cryptographic/hashing functions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Regex‑Based Detection**
|
|
8
|
+
Utilizes carefully crafted regular expressions to identify known vulnerability patterns in source code.
|
|
9
|
+
|
|
10
|
+
- **AST‑Based Taint Analysis**
|
|
11
|
+
Leverages [javalang](https://github.com/c2nes/javalang) to parse Java source files into an Abstract Syntax Tree (AST) and performs forward data‑flow analysis to propagate taint from user input sources (e.g., `request.getParameter`) to sensitive sinks (e.g., `executeQuery`).
|
|
12
|
+
|
|
13
|
+
- **Data‑Flow Analysis Framework**
|
|
14
|
+
A simplified yet robust framework that tracks tainted variables through declarations and assignments to flag dangerous data flows.
|
|
15
|
+
|
|
16
|
+
- **Multi‑Detector Support**
|
|
17
|
+
Detects various vulnerabilities including:
|
|
18
|
+
- SQL Injection
|
|
19
|
+
- Cross‑Site Scripting (XSS)
|
|
20
|
+
- Path Traversal
|
|
21
|
+
- Command Injection
|
|
22
|
+
- Serialization Issues
|
|
23
|
+
- LDAP Injection
|
|
24
|
+
- XXE (XML External Entity) Attacks
|
|
25
|
+
- SSRF (Server-Side Request Forgery)
|
|
26
|
+
- Unsafe Crypto/Hashing functions
|
|
27
|
+
|
|
28
|
+
- **Parallel Scanning & Progress Bar**
|
|
29
|
+
Files are scanned in parallel with a progress bar for faster analysis on large codebases.
|
|
30
|
+
|
|
31
|
+
- **Robust CLI**
|
|
32
|
+
The command‑line interface offers options to:
|
|
33
|
+
- Initialize the database (`--init-db`)
|
|
34
|
+
- View scan history (`--history`)
|
|
35
|
+
- Compare scans (`--compare`)
|
|
36
|
+
- Export results in SARIF, JSON, or HTML formats (`--export`)
|
|
37
|
+
- Enable AST‑based detection (`--ast`)
|
|
38
|
+
- Enable debug logging (`--debug`)
|
|
39
|
+
- Display version information (`--version`)
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
Clone the repository and navigate to the project root:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/thesp0nge/dr_source.git
|
|
47
|
+
cd dr_source
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Install the package in editable mode:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install --editable .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
Run dr_source using the CLI:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
dr_source [OPTIONS] TARGET_PATH
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Options
|
|
65
|
+
|
|
66
|
+
- TARGET_PATH: The path of the codebase (directory containing Java/JSP files) to analyze.
|
|
67
|
+
- --init-db: Initialize the database from scratch (drops and recreates tables).
|
|
68
|
+
- --history: Display the scan history for the project.
|
|
69
|
+
- --compare <ID>: Compare the latest scan with a previous scan specified by ID.
|
|
70
|
+
- --export [sarif|json|html]: Export scan results in the specified format.
|
|
71
|
+
- --ast: Enable AST‑based detection (in addition to regex‑based detection).
|
|
72
|
+
- --debug: Enable debug logging.
|
|
73
|
+
- --version: Show DRSource version (as defined in setup.py) and exit.
|
|
74
|
+
|
|
75
|
+
### Examples
|
|
76
|
+
|
|
77
|
+
- Scan a Codebase Using AST‑Based Detection with Debug Logging:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
dr_source --ast --debug /path/to/codebase
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- Initialize the Database:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
dr_source --init-db /path/to/codebase
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- Export Results as SARIF:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
dr_source --export sarif /path/to/codebase
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Contributing
|
|
96
|
+
|
|
97
|
+
Contributions are welcome! To contribute:
|
|
98
|
+
|
|
99
|
+
- Fork the repository.
|
|
100
|
+
- Create a new branch for your feature or bugfix.
|
|
101
|
+
- Make your changes with clear commit messages.
|
|
102
|
+
- Submit a pull request for review.
|
|
103
|
+
- For major changes, please open an issue first to discuss your proposed changes.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
dr_source is licensed under the MIT License.
|
|
108
|
+
|
|
109
|
+
## Acknowledgments
|
|
110
|
+
|
|
111
|
+
Special thanks to the maintainers of [javalang](https://github.com/c2nes/javalang) for their work on Java AST parsing.
|
|
112
|
+
Inspired by various static analysis and security tools.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
DRSource - Main executable script
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
dr_source [OPTIONS] TARGET_PATH
|
|
7
|
+
|
|
8
|
+
This script launches the DRSource CLI.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
# Add the project root to the sys.path so that "dr_source" can be imported.
|
|
15
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
16
|
+
project_root = os.path.abspath(os.path.join(current_dir, ".."))
|
|
17
|
+
sys.path.insert(0, project_root)
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from dr_source.cli import main
|
|
21
|
+
except ModuleNotFoundError as e:
|
|
22
|
+
sys.exit(
|
|
23
|
+
f"Error: {e}\nMake sure the package is installed or that your PYTHONPATH includes the project root."
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
sys.exit(main())
|
|
File without changes
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import click
|
|
3
|
+
import time
|
|
4
|
+
import os
|
|
5
|
+
import json
|
|
6
|
+
from dr_source.core.codebase import Codebase
|
|
7
|
+
from dr_source.core.scanner import Scanner
|
|
8
|
+
from dr_source.core.db import ScanDatabase
|
|
9
|
+
from dr_source.logging import setup_logging
|
|
10
|
+
|
|
11
|
+
# Use importlib.metadata to get version information from the installed package
|
|
12
|
+
try:
|
|
13
|
+
from importlib.metadata import version as get_version
|
|
14
|
+
except ImportError:
|
|
15
|
+
from importlib_metadata import version as get_version
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@click.command(context_settings=dict(ignore_unknown_options=True))
|
|
19
|
+
@click.argument("target_path", required=False, type=click.Path(exists=True))
|
|
20
|
+
@click.option("--init-db", is_flag=True, help="Initialize the database from scratch.")
|
|
21
|
+
@click.option("--history", is_flag=True, help="Show the scan history for this project.")
|
|
22
|
+
@click.option(
|
|
23
|
+
"--compare", type=int, help="Compare the latest scan with the scan specified by ID."
|
|
24
|
+
)
|
|
25
|
+
@click.option(
|
|
26
|
+
"--export",
|
|
27
|
+
type=click.Choice(["sarif", "json", "html"]),
|
|
28
|
+
help="Export results in the specified format.",
|
|
29
|
+
)
|
|
30
|
+
@click.option("--verbose", is_flag=True, help="Show detailed output during comparison.")
|
|
31
|
+
@click.option(
|
|
32
|
+
"--output",
|
|
33
|
+
type=click.Path(),
|
|
34
|
+
help="Output file for the exported report (if not specified, a default name is used).",
|
|
35
|
+
)
|
|
36
|
+
@click.option("--debug", is_flag=True, help="Enable debug logging.")
|
|
37
|
+
@click.option(
|
|
38
|
+
"--version", "show_version", is_flag=True, help="Show DRSource version and exit."
|
|
39
|
+
)
|
|
40
|
+
@click.option(
|
|
41
|
+
"--ast", is_flag=True, help="Enable AST-based detection (instead of regex-based)."
|
|
42
|
+
)
|
|
43
|
+
def main(
|
|
44
|
+
target_path,
|
|
45
|
+
init_db,
|
|
46
|
+
history,
|
|
47
|
+
compare,
|
|
48
|
+
export,
|
|
49
|
+
verbose,
|
|
50
|
+
output,
|
|
51
|
+
debug,
|
|
52
|
+
show_version,
|
|
53
|
+
ast,
|
|
54
|
+
):
|
|
55
|
+
"""
|
|
56
|
+
DRSource - A static analysis tool for detecting vulnerabilities in Java/JSP projects.
|
|
57
|
+
|
|
58
|
+
TARGET_PATH is the path of the codebase to analyze.
|
|
59
|
+
"""
|
|
60
|
+
if show_version:
|
|
61
|
+
try:
|
|
62
|
+
pkg_version = get_version("dr_source")
|
|
63
|
+
except Exception:
|
|
64
|
+
pkg_version = "unknown"
|
|
65
|
+
click.echo(f"DRSource version {pkg_version}")
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
setup_logging(debug=debug)
|
|
69
|
+
|
|
70
|
+
# Enforce target_path if not provided for non--version operations
|
|
71
|
+
if not target_path:
|
|
72
|
+
ctx = click.get_current_context()
|
|
73
|
+
ctx.fail("Missing argument 'TARGET_PATH'.")
|
|
74
|
+
|
|
75
|
+
project_name = os.path.basename(os.path.abspath(target_path))
|
|
76
|
+
db = ScanDatabase(project_name)
|
|
77
|
+
|
|
78
|
+
if init_db:
|
|
79
|
+
click.echo("🔄 Initializing the database...")
|
|
80
|
+
db.initialize()
|
|
81
|
+
click.echo("✅ Database initialized successfully.")
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
if history:
|
|
85
|
+
click.echo(f"\n📌 Scan history for '{project_name}':")
|
|
86
|
+
history_records = db.get_scan_history()
|
|
87
|
+
if not history_records:
|
|
88
|
+
click.echo("🔍 No scan history found for this project.")
|
|
89
|
+
else:
|
|
90
|
+
for scan in history_records:
|
|
91
|
+
click.echo(
|
|
92
|
+
f"[{scan[1]}] ID {scan[0]} | Vulnerabilities found: {scan[2]}"
|
|
93
|
+
)
|
|
94
|
+
return
|
|
95
|
+
|
|
96
|
+
if compare:
|
|
97
|
+
latest_scan_id = db.get_latest_scan_id()
|
|
98
|
+
if not latest_scan_id:
|
|
99
|
+
click.echo("❌ No scan history available.")
|
|
100
|
+
return
|
|
101
|
+
click.echo(f"🔍 Comparing scan {compare} with latest scan {latest_scan_id}...")
|
|
102
|
+
comparison = db.compare_scans(compare, latest_scan_id)
|
|
103
|
+
click.echo(f"📌 New vulnerabilities: {len(comparison['new'])}")
|
|
104
|
+
click.echo(f"✅ Resolved: {len(comparison['resolved'])}")
|
|
105
|
+
click.echo(f"⚠️ Persistent: {len(comparison['persistent'])}")
|
|
106
|
+
if verbose:
|
|
107
|
+
if comparison["new"]:
|
|
108
|
+
click.echo("\n🆕 New vulnerabilities:")
|
|
109
|
+
for vuln in comparison["new"]:
|
|
110
|
+
click.echo(f" - {vuln}")
|
|
111
|
+
if comparison["resolved"]:
|
|
112
|
+
click.echo("\n✅ Resolved vulnerabilities:")
|
|
113
|
+
for vuln in comparison["resolved"]:
|
|
114
|
+
click.echo(f" - {vuln}")
|
|
115
|
+
if comparison["persistent"]:
|
|
116
|
+
click.echo("\n⚠️ Persistent vulnerabilities:")
|
|
117
|
+
for vuln in comparison["persistent"]:
|
|
118
|
+
click.echo(f" - {vuln}")
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
start_time = time.time()
|
|
122
|
+
click.echo(f"🔍 Starting scan on {target_path}...")
|
|
123
|
+
|
|
124
|
+
if ast:
|
|
125
|
+
click.echo("🔎 Using AST-based detection mode.")
|
|
126
|
+
else:
|
|
127
|
+
click.echo("🔎 Using regex-based detection mode.")
|
|
128
|
+
|
|
129
|
+
codebase = Codebase(target_path)
|
|
130
|
+
codebase.load_files()
|
|
131
|
+
|
|
132
|
+
scanner = Scanner(codebase, ast_mode=ast)
|
|
133
|
+
# Use a progress bar while scanning files in parallel (implemented in scanner.scan)
|
|
134
|
+
results = scanner.scan()
|
|
135
|
+
|
|
136
|
+
scan_duration = time.time() - start_time
|
|
137
|
+
num_files = len(codebase.files)
|
|
138
|
+
num_vulns = len(results)
|
|
139
|
+
|
|
140
|
+
click.echo(
|
|
141
|
+
f"\n✅ Scan completed: {num_files} files analyzed, {num_vulns} vulnerabilities found in {scan_duration:.2f} seconds."
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
scan_id = db.start_scan()
|
|
145
|
+
db.store_vulnerabilities(scan_id, results)
|
|
146
|
+
db.update_scan_summary(scan_id, num_vulns, num_files, scan_duration)
|
|
147
|
+
|
|
148
|
+
if export:
|
|
149
|
+
out_file = output if output else f"{project_name}_scan_{scan_id}.{export}"
|
|
150
|
+
if export == "sarif":
|
|
151
|
+
from dr_source.reports.sarif import SARIFReport
|
|
152
|
+
|
|
153
|
+
reporter = SARIFReport()
|
|
154
|
+
report_content = reporter.generate(results)
|
|
155
|
+
with open(out_file, "w") as f:
|
|
156
|
+
f.write(report_content)
|
|
157
|
+
click.echo(f"📄 Results exported to {out_file}")
|
|
158
|
+
elif export == "json":
|
|
159
|
+
with open(out_file, "w") as f:
|
|
160
|
+
json.dump(results, f, indent=2)
|
|
161
|
+
click.echo(f"📄 Results exported to {out_file}")
|
|
162
|
+
elif export == "html":
|
|
163
|
+
click.echo("📄 HTML export not yet implemented.")
|
|
164
|
+
else:
|
|
165
|
+
for res in results:
|
|
166
|
+
click.echo(
|
|
167
|
+
f"[{res['vuln_type']}] {res['file']}:{res['line']} -> {res['match']}"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
if __name__ == "__main__":
|
|
172
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# dr_source/core/codebase.py
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FileObject:
|
|
6
|
+
def __init__(self, path, content):
|
|
7
|
+
self.path = path
|
|
8
|
+
self.content = content
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Codebase:
|
|
12
|
+
def __init__(self, root_path):
|
|
13
|
+
self.root_path = root_path
|
|
14
|
+
self.files = []
|
|
15
|
+
|
|
16
|
+
def load_files(self):
|
|
17
|
+
for root, _, files in os.walk(self.root_path):
|
|
18
|
+
for file in files:
|
|
19
|
+
if file.endswith(".java") or file.endswith(".jsp"):
|
|
20
|
+
file_path = os.path.join(root, file)
|
|
21
|
+
try:
|
|
22
|
+
with open(
|
|
23
|
+
file_path, "r", encoding="utf-8", errors="ignore"
|
|
24
|
+
) as f:
|
|
25
|
+
content = f.read()
|
|
26
|
+
self.files.append(FileObject(file_path, content))
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"Error reading {file_path}: {e}")
|
|
29
|
+
return self.files
|