blint 2.3.2__tar.gz → 2.4.1__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.
- {blint-2.3.2 → blint-2.4.1}/PKG-INFO +52 -25
- {blint-2.3.2 → blint-2.4.1}/README.md +25 -5
- {blint-2.3.2 → blint-2.4.1}/blint/cli.py +64 -7
- {blint-2.3.2 → blint-2.4.1}/blint/config.py +28 -4
- blint-2.4.1/blint/db.py +150 -0
- {blint-2.3.2 → blint-2.4.1}/blint/lib/analysis.py +23 -25
- {blint-2.3.2 → blint-2.4.1}/blint/lib/binary.py +28 -24
- {blint-2.3.2 → blint-2.4.1}/blint/lib/runners.py +22 -10
- {blint-2.3.2 → blint-2.4.1}/blint/lib/sbom.py +143 -79
- {blint-2.3.2 → blint-2.4.1}/blint/lib/utils.py +68 -23
- {blint-2.3.2 → blint-2.4.1}/blint/logger.py +1 -1
- {blint-2.3.2 → blint-2.4.1}/pyproject.toml +36 -28
- {blint-2.3.2 → blint-2.4.1}/LICENSE +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/__init__.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/cyclonedx/README.md +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/cyclonedx/__init__.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/cyclonedx/spdx.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/cyclonedx/spec.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/__init__.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/__init__.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_entries_generic.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_entries_pe.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_exe_go.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_imports_pe.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_methods_generic.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_methods_mips.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_monero_generic.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_monero_go.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_monero_rust.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_rootkits_win.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_symbols_antiforensic.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_symbols_generic.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_symbols_hooka.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_symbols_macho.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/annotations/review_symbols_rust.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/data/rules.yml +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/lib/__init__.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/lib/android.py +0 -0
- {blint-2.3.2 → blint-2.4.1}/blint/lib/checks.py +0 -0
|
@@ -1,36 +1,43 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: blint
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.1
|
|
4
4
|
Summary: Linter and SBOM generator for binary files.
|
|
5
|
-
Home-page: https://github.com/OWASP-dep-scan/blint
|
|
6
5
|
License: MIT
|
|
7
6
|
Keywords: linter,binary,security,sast
|
|
8
|
-
Author:
|
|
9
|
-
Author-email:
|
|
7
|
+
Author: Team AppThreat
|
|
8
|
+
Author-email: cloud@appthreat.com
|
|
10
9
|
Requires-Python: >=3.10,<3.14
|
|
11
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
12
|
Classifier: Intended Audience :: System Administrators
|
|
14
|
-
Classifier:
|
|
15
|
-
Classifier:
|
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Classifier: Topic :: Security
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
-
Classifier:
|
|
22
|
-
|
|
23
|
-
Requires-Dist: PyYAML (>=6.0.
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
Requires-Dist:
|
|
26
|
-
Requires-Dist:
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist:
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: PyYAML (>=6.0.2)
|
|
22
|
+
Requires-Dist: appdirs (>=1.4.4)
|
|
23
|
+
Requires-Dist: apsw (>=3.49.1.0)
|
|
24
|
+
Requires-Dist: ar (>=0.9.1)
|
|
25
|
+
Requires-Dist: black (>=25.1.0) ; extra == "dev"
|
|
26
|
+
Requires-Dist: custom-json-diff (>=2.1.5)
|
|
27
|
+
Requires-Dist: defusedxml (>=0.7.1)
|
|
28
|
+
Requires-Dist: flake8 (>=7.1.2) ; extra == "dev"
|
|
29
|
+
Requires-Dist: lief (>=0.16.4)
|
|
30
|
+
Requires-Dist: oras (>=0.2.25)
|
|
31
|
+
Requires-Dist: orjson (>=3.10.15)
|
|
32
|
+
Requires-Dist: packageurl-python (>=0.16.0)
|
|
33
|
+
Requires-Dist: pydantic[email] (>=2.10.6)
|
|
34
|
+
Requires-Dist: pyinstaller (>=6.12.0) ; extra == "dev"
|
|
35
|
+
Requires-Dist: pylint (>=3.3.4) ; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest (>=8.3.4) ; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov (>=6.0.0) ; extra == "dev"
|
|
38
|
+
Requires-Dist: rich (>=13.9.4)
|
|
31
39
|
Requires-Dist: symbolic (==10.2.1)
|
|
32
|
-
Project-URL: CI, https://github.com/
|
|
33
|
-
Project-URL: Repository, https://github.com/OWASP-dep-scan/blint
|
|
40
|
+
Project-URL: CI, https://github.com/owasp-dep-scan/blint/actions
|
|
34
41
|
Description-Content-Type: text/markdown
|
|
35
42
|
|
|
36
43
|
# BLint
|
|
@@ -77,28 +84,28 @@ You can download single binary builds from the [blint-bin releases](https://gith
|
|
|
77
84
|
## Usage
|
|
78
85
|
|
|
79
86
|
```shell
|
|
80
|
-
usage: blint [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o REPORTS_DIR] [--no-error] [--no-banner]
|
|
81
|
-
[--no-reviews] [--suggest-fuzzable]
|
|
82
|
-
{sbom} ...
|
|
87
|
+
usage: blint [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o REPORTS_DIR] [--no-error] [--no-banner] [--no-reviews] [--suggest-fuzzable] [--use-blintdb] {sbom} ...
|
|
83
88
|
|
|
84
89
|
Binary linter and SBOM generator.
|
|
85
90
|
|
|
86
91
|
options:
|
|
87
92
|
-h, --help show this help message and exit
|
|
88
|
-
-i
|
|
93
|
+
-i, --src SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]
|
|
89
94
|
Source directories, container images or binary files. Defaults to current directory.
|
|
90
|
-
-o
|
|
95
|
+
-o, --reports REPORTS_DIR
|
|
91
96
|
Reports directory. Defaults to reports.
|
|
92
97
|
--no-error Continue on error to prevent build from breaking.
|
|
93
98
|
--no-banner Do not display banner.
|
|
94
99
|
--no-reviews Do not perform method reviews.
|
|
95
100
|
--suggest-fuzzable Suggest functions and symbols for fuzzing based on a dictionary.
|
|
101
|
+
--use-blintdb Use blintdb for symbol resolution. Use environment variables: BLINTDB_IMAGE_URL, BLINTDB_HOME, and BLINTDB_REFRESH for customization.
|
|
96
102
|
|
|
97
103
|
sub-commands:
|
|
98
104
|
Additional sub-commands
|
|
99
105
|
|
|
100
106
|
{sbom}
|
|
101
107
|
sbom Command to generate SBOM for supported binaries.
|
|
108
|
+
db Command to manage the pre-compiled database.
|
|
102
109
|
```
|
|
103
110
|
|
|
104
111
|
### SBOM sub-command
|
|
@@ -121,6 +128,18 @@ options:
|
|
|
121
128
|
Directories containing pre-build and build BOMs. Use to improve the precision.
|
|
122
129
|
```
|
|
123
130
|
|
|
131
|
+
### DB sub-command
|
|
132
|
+
|
|
133
|
+
```shell
|
|
134
|
+
usage: blint db [-h] [--download] [--image-url IMAGE_URL]
|
|
135
|
+
|
|
136
|
+
options:
|
|
137
|
+
-h, --help show this help message and exit
|
|
138
|
+
--download Download the pre-compiled database to the /Volumes/Work/blintdb/ directory. Use the environment variable `BLINTDB_HOME` to override.
|
|
139
|
+
--image-url IMAGE_URL
|
|
140
|
+
Blintdb image url. Defaults to ghcr.io/appthreat/blintdb-vcpkg-arm64:v1. The environment variable `BLINTDB_IMAGE_URL` is an alternative way to set this value.
|
|
141
|
+
```
|
|
142
|
+
|
|
124
143
|
To test any binary, including default commands
|
|
125
144
|
|
|
126
145
|
```bash
|
|
@@ -155,12 +174,20 @@ To parse all files, including `.dex` files, pass `--deep` argument.
|
|
|
155
174
|
blint sbom -i /path/to/apk -o bom.json --deep
|
|
156
175
|
```
|
|
157
176
|
|
|
177
|
+
Component identification for C/C++ binaries could be improved with [blintdb](https://github.com/AppThreat/blint-db). To download the pre-compiled database (SQLite format), first run the `db` command followed by the `sbom` command.
|
|
178
|
+
|
|
179
|
+
```shell
|
|
180
|
+
blint db
|
|
181
|
+
blint sbom -i /path/to/binary -o bom.json --deep
|
|
182
|
+
```
|
|
183
|
+
|
|
158
184
|
The following binaries are supported:
|
|
159
185
|
|
|
160
186
|
- Android (apk/aab)
|
|
161
187
|
- Dotnet executable binaries
|
|
162
188
|
- Go binaries
|
|
163
189
|
- Rust binaries
|
|
190
|
+
- c/c++ binaries (WIP)
|
|
164
191
|
|
|
165
192
|
```shell
|
|
166
193
|
blint sbom -i /path/to/go-binaries -o bom.json --deep
|
|
@@ -42,28 +42,28 @@ You can download single binary builds from the [blint-bin releases](https://gith
|
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
44
44
|
```shell
|
|
45
|
-
usage: blint [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o REPORTS_DIR] [--no-error] [--no-banner]
|
|
46
|
-
[--no-reviews] [--suggest-fuzzable]
|
|
47
|
-
{sbom} ...
|
|
45
|
+
usage: blint [-h] [-i SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]] [-o REPORTS_DIR] [--no-error] [--no-banner] [--no-reviews] [--suggest-fuzzable] [--use-blintdb] {sbom} ...
|
|
48
46
|
|
|
49
47
|
Binary linter and SBOM generator.
|
|
50
48
|
|
|
51
49
|
options:
|
|
52
50
|
-h, --help show this help message and exit
|
|
53
|
-
-i
|
|
51
|
+
-i, --src SRC_DIR_IMAGE [SRC_DIR_IMAGE ...]
|
|
54
52
|
Source directories, container images or binary files. Defaults to current directory.
|
|
55
|
-
-o
|
|
53
|
+
-o, --reports REPORTS_DIR
|
|
56
54
|
Reports directory. Defaults to reports.
|
|
57
55
|
--no-error Continue on error to prevent build from breaking.
|
|
58
56
|
--no-banner Do not display banner.
|
|
59
57
|
--no-reviews Do not perform method reviews.
|
|
60
58
|
--suggest-fuzzable Suggest functions and symbols for fuzzing based on a dictionary.
|
|
59
|
+
--use-blintdb Use blintdb for symbol resolution. Use environment variables: BLINTDB_IMAGE_URL, BLINTDB_HOME, and BLINTDB_REFRESH for customization.
|
|
61
60
|
|
|
62
61
|
sub-commands:
|
|
63
62
|
Additional sub-commands
|
|
64
63
|
|
|
65
64
|
{sbom}
|
|
66
65
|
sbom Command to generate SBOM for supported binaries.
|
|
66
|
+
db Command to manage the pre-compiled database.
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### SBOM sub-command
|
|
@@ -86,6 +86,18 @@ options:
|
|
|
86
86
|
Directories containing pre-build and build BOMs. Use to improve the precision.
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
### DB sub-command
|
|
90
|
+
|
|
91
|
+
```shell
|
|
92
|
+
usage: blint db [-h] [--download] [--image-url IMAGE_URL]
|
|
93
|
+
|
|
94
|
+
options:
|
|
95
|
+
-h, --help show this help message and exit
|
|
96
|
+
--download Download the pre-compiled database to the /Volumes/Work/blintdb/ directory. Use the environment variable `BLINTDB_HOME` to override.
|
|
97
|
+
--image-url IMAGE_URL
|
|
98
|
+
Blintdb image url. Defaults to ghcr.io/appthreat/blintdb-vcpkg-arm64:v1. The environment variable `BLINTDB_IMAGE_URL` is an alternative way to set this value.
|
|
99
|
+
```
|
|
100
|
+
|
|
89
101
|
To test any binary, including default commands
|
|
90
102
|
|
|
91
103
|
```bash
|
|
@@ -120,12 +132,20 @@ To parse all files, including `.dex` files, pass `--deep` argument.
|
|
|
120
132
|
blint sbom -i /path/to/apk -o bom.json --deep
|
|
121
133
|
```
|
|
122
134
|
|
|
135
|
+
Component identification for C/C++ binaries could be improved with [blintdb](https://github.com/AppThreat/blint-db). To download the pre-compiled database (SQLite format), first run the `db` command followed by the `sbom` command.
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
blint db
|
|
139
|
+
blint sbom -i /path/to/binary -o bom.json --deep
|
|
140
|
+
```
|
|
141
|
+
|
|
123
142
|
The following binaries are supported:
|
|
124
143
|
|
|
125
144
|
- Android (apk/aab)
|
|
126
145
|
- Dotnet executable binaries
|
|
127
146
|
- Go binaries
|
|
128
147
|
- Rust binaries
|
|
148
|
+
- c/c++ binaries (WIP)
|
|
129
149
|
|
|
130
150
|
```shell
|
|
131
151
|
blint sbom -i /path/to/go-binaries -o bom.json --deep
|
|
@@ -5,11 +5,9 @@ import argparse
|
|
|
5
5
|
import os
|
|
6
6
|
|
|
7
7
|
from blint.lib.runners import run_default_mode, run_sbom_mode
|
|
8
|
-
from blint.
|
|
9
|
-
from blint.
|
|
8
|
+
from blint.config import BlintOptions, BLINTDB_HOME, BLINTDB_IMAGE_URL, BLINTDB_LOC
|
|
9
|
+
from blint.lib.utils import blintdb_setup
|
|
10
10
|
from blint.logger import LOG
|
|
11
|
-
from blint.lib.sbom import generate
|
|
12
|
-
from blint.lib.utils import gen_file_list
|
|
13
11
|
|
|
14
12
|
BLINT_LOGO = """
|
|
15
13
|
██████╗ ██╗ ██╗███╗ ██╗████████╗
|
|
@@ -40,7 +38,9 @@ def build_parser():
|
|
|
40
38
|
stdout_mode=False,
|
|
41
39
|
exports_prefix=[],
|
|
42
40
|
src_dir_boms=[],
|
|
43
|
-
sbom_mode=False
|
|
41
|
+
sbom_mode=False,
|
|
42
|
+
db_mode=False,
|
|
43
|
+
quiet_mode=False,
|
|
44
44
|
)
|
|
45
45
|
parser.add_argument(
|
|
46
46
|
"-i",
|
|
@@ -86,6 +86,21 @@ def build_parser():
|
|
|
86
86
|
dest="suggest_fuzzable",
|
|
87
87
|
help="Suggest functions and symbols for fuzzing based on a dictionary.",
|
|
88
88
|
)
|
|
89
|
+
parser.add_argument(
|
|
90
|
+
"--use-blintdb",
|
|
91
|
+
action="store_true",
|
|
92
|
+
default=os.path.exists(BLINTDB_LOC),
|
|
93
|
+
dest="use_blintdb",
|
|
94
|
+
help=f"Use blintdb for symbol resolution. Defaults to true if the file exists at {BLINTDB_LOC}. Use environment variables: BLINTDB_IMAGE_URL, BLINTDB_HOME, and BLINTDB_REFRESH for customization.",
|
|
95
|
+
)
|
|
96
|
+
parser.add_argument(
|
|
97
|
+
"-q",
|
|
98
|
+
"--quiet",
|
|
99
|
+
action="store_true",
|
|
100
|
+
default=False,
|
|
101
|
+
dest="quiet_mode",
|
|
102
|
+
help="Disable logging and progress bars.",
|
|
103
|
+
)
|
|
89
104
|
# sbom commmand
|
|
90
105
|
subparsers = parser.add_subparsers(
|
|
91
106
|
title="sub-commands",
|
|
@@ -125,6 +140,14 @@ def build_parser():
|
|
|
125
140
|
dest="stdout_mode",
|
|
126
141
|
help="Print the SBOM to stdout instead of a file.",
|
|
127
142
|
)
|
|
143
|
+
sbom_parser.add_argument(
|
|
144
|
+
"-q",
|
|
145
|
+
"--quiet",
|
|
146
|
+
action="store_true",
|
|
147
|
+
default=False,
|
|
148
|
+
dest="quiet_mode",
|
|
149
|
+
help="Disable logging and progress bars.",
|
|
150
|
+
)
|
|
128
151
|
sbom_parser.add_argument(
|
|
129
152
|
"--exports-prefix",
|
|
130
153
|
default=[],
|
|
@@ -140,7 +163,32 @@ def build_parser():
|
|
|
140
163
|
nargs="+",
|
|
141
164
|
help="Directories containing pre-build and build BOMs. Use to improve the precision.",
|
|
142
165
|
)
|
|
143
|
-
|
|
166
|
+
db_parser = subparsers.add_parser(
|
|
167
|
+
"db", help="Command to manage the pre-compiled database."
|
|
168
|
+
)
|
|
169
|
+
db_parser.set_defaults(db_mode=True)
|
|
170
|
+
db_parser.add_argument(
|
|
171
|
+
"--download",
|
|
172
|
+
action="store_true",
|
|
173
|
+
default=True,
|
|
174
|
+
dest="download_mode",
|
|
175
|
+
help=f"Download the pre-compiled database to the {BLINTDB_HOME} directory. Use the environment variable `BLINTDB_HOME` to override.",
|
|
176
|
+
)
|
|
177
|
+
db_parser.add_argument(
|
|
178
|
+
"--image-url",
|
|
179
|
+
dest="image_url",
|
|
180
|
+
choices=["ghcr.io/appthreat/blintdb-vcpkg:v1",
|
|
181
|
+
"ghcr.io/appthreat/blintdb-vcpkg-arm64:v1",
|
|
182
|
+
"ghcr.io/appthreat/blintdb-vcpkg-darwin-arm64:v1",
|
|
183
|
+
"ghcr.io/appthreat/blintdb-vcpkg-musl:v1",
|
|
184
|
+
"ghcr.io/appthreat/blintdb-meson:v1",
|
|
185
|
+
"ghcr.io/appthreat/blintdb-meson-arm64:v1",
|
|
186
|
+
"ghcr.io/appthreat/blintdb-meson-darwin-arm64:v1",
|
|
187
|
+
"ghcr.io/appthreat/blintdb-meson-musl:v1",
|
|
188
|
+
],
|
|
189
|
+
default=BLINTDB_IMAGE_URL,
|
|
190
|
+
help=f"Blintdb image url. Defaults to {BLINTDB_IMAGE_URL}. The environment variable `BLINTDB_IMAGE_URL` is an alternative way to set this value.",
|
|
191
|
+
)
|
|
144
192
|
return parser
|
|
145
193
|
|
|
146
194
|
|
|
@@ -183,10 +231,14 @@ def handle_args():
|
|
|
183
231
|
no_reviews=args.no_reviews,
|
|
184
232
|
reports_dir=args.reports_dir,
|
|
185
233
|
sbom_mode=args.sbom_mode,
|
|
234
|
+
quiet_mode=args.quiet_mode,
|
|
235
|
+
db_mode=args.db_mode,
|
|
236
|
+
image_url=args.image_url if args.db_mode else None,
|
|
186
237
|
sbom_output=args.sbom_output,
|
|
187
238
|
src_dir_boms=args.src_dir_boms,
|
|
188
239
|
src_dir_image=args.src_dir_image,
|
|
189
|
-
stdout_mode=args.stdout_mode
|
|
240
|
+
stdout_mode=args.stdout_mode,
|
|
241
|
+
use_blintdb=args.use_blintdb
|
|
190
242
|
)
|
|
191
243
|
return blint_options
|
|
192
244
|
|
|
@@ -194,10 +246,15 @@ def handle_args():
|
|
|
194
246
|
def main():
|
|
195
247
|
"""Main function of the blint tool"""
|
|
196
248
|
blint_options = handle_args()
|
|
249
|
+
if blint_options.quiet_mode:
|
|
250
|
+
LOG.disabled = True
|
|
251
|
+
blintdb_setup(blint_options)
|
|
197
252
|
|
|
198
253
|
# SBOM command
|
|
199
254
|
if blint_options.sbom_mode:
|
|
200
255
|
run_sbom_mode(blint_options)
|
|
256
|
+
elif blint_options.db_mode:
|
|
257
|
+
return
|
|
201
258
|
# Default case
|
|
202
259
|
else:
|
|
203
260
|
run_default_mode(blint_options)
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
import sys
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
4
|
import os
|
|
5
|
+
import platform
|
|
5
6
|
import re
|
|
6
7
|
from typing import List
|
|
8
|
+
from appdirs import user_data_dir
|
|
7
9
|
|
|
10
|
+
ARCH = platform.machine()
|
|
11
|
+
SYSTEM = platform.system().lower()
|
|
8
12
|
|
|
9
13
|
# Default ignore list
|
|
10
14
|
ignore_directories = [
|
|
@@ -1284,12 +1288,15 @@ class BlintOptions:
|
|
|
1284
1288
|
no_error (bool): Flag indicating whether to suppress error messages.
|
|
1285
1289
|
no_reviews (bool): Flag indicating whether to perform symbol reviews.
|
|
1286
1290
|
reports_dir (str): The path to the reports directory.
|
|
1287
|
-
sbom_mode (bool): Flag
|
|
1291
|
+
sbom_mode (bool): Flag for the sbom sub-command.
|
|
1292
|
+
quiet_mode (bool): Flag to disable all logging and progress bars.
|
|
1293
|
+
db_mode (bool): Flag for the db sub-command.
|
|
1294
|
+
image_url (str): blintdb download url. Must be OCI compatible.
|
|
1288
1295
|
src_dir_image (list): A list of source directories.
|
|
1289
1296
|
sbom_output (str): The path to the output file.
|
|
1290
1297
|
deep_mode (bool): Flag indicating whether to perform deep analysis.
|
|
1291
|
-
export_prefixes (list): Prefixes to determine exported symbols.
|
|
1292
1298
|
src_dir_boms (list): Directory containing pre-build and build sboms.
|
|
1299
|
+
use_blintdb (bool): Flag indicating whether or not to utilize blint-db
|
|
1293
1300
|
"""
|
|
1294
1301
|
deep_mode: bool = False
|
|
1295
1302
|
exports_prefix: List = field(default_factory=list)
|
|
@@ -1298,12 +1305,16 @@ class BlintOptions:
|
|
|
1298
1305
|
no_reviews: bool = False
|
|
1299
1306
|
reports_dir: str = ""
|
|
1300
1307
|
sbom_mode: bool = False
|
|
1308
|
+
quiet_mode: bool = False
|
|
1309
|
+
db_mode: bool = False
|
|
1310
|
+
image_url: str = ""
|
|
1301
1311
|
sbom_output: str = ""
|
|
1302
1312
|
sbom_output_dir: str = ""
|
|
1303
1313
|
src_dir_boms: List = field(default_factory=list)
|
|
1304
1314
|
src_dir_image: List = field(default_factory=list)
|
|
1305
1315
|
stdout_mode: bool = False
|
|
1306
|
-
|
|
1316
|
+
use_blintdb: bool = False
|
|
1317
|
+
|
|
1307
1318
|
def __post_init__(self):
|
|
1308
1319
|
if not self.src_dir_image and not (self.sbom_mode and self.src_dir_boms):
|
|
1309
1320
|
self.sources = [os.getcwd()]
|
|
@@ -1320,7 +1331,7 @@ class BlintOptions:
|
|
|
1320
1331
|
self.sbom_output = os.path.join(self.sbom_output, "bom-post-build.cdx.json")
|
|
1321
1332
|
else:
|
|
1322
1333
|
self.sbom_output_dir = os.path.dirname(self.sbom_output)
|
|
1323
|
-
|
|
1334
|
+
|
|
1324
1335
|
|
|
1325
1336
|
# PII related symbols
|
|
1326
1337
|
PII_WORDS = (
|
|
@@ -1392,3 +1403,16 @@ FIRST_STAGE_WORDS = (
|
|
|
1392
1403
|
"shlwapi.dll",
|
|
1393
1404
|
"DeleteCriticalSection"
|
|
1394
1405
|
)
|
|
1406
|
+
|
|
1407
|
+
# Setting blintdb
|
|
1408
|
+
BLINTDB_HOME = os.getenv("BLINTDB_HOME", user_data_dir("blintdb"))
|
|
1409
|
+
BLINTDB_LOC = os.path.join(BLINTDB_HOME, "blint.db")
|
|
1410
|
+
|
|
1411
|
+
BLINTDB_IMAGE_URL = os.getenv("BLINTDB_IMAGE_URL",
|
|
1412
|
+
"ghcr.io/appthreat/blintdb-vcpkg-darwin-arm64:v1" if SYSTEM == "darwin" else "ghcr.io/appthreat/blintdb-vcpkg:v1")
|
|
1413
|
+
BLINTDB_REFRESH = os.getenv("BLINTDB_REFRESH", False)
|
|
1414
|
+
if BLINTDB_REFRESH in ["true", "True", "1"]:
|
|
1415
|
+
BLINTDB_REFRESH = True
|
|
1416
|
+
|
|
1417
|
+
SYMBOLS_LOOKUP_BATCH_LEN = get_int_from_env("SYMBOLS_LOOKUP_BATCH_LEN", 32000)
|
|
1418
|
+
MIN_MATCH_SCORE = get_int_from_env("MIN_MATCH_SCORE", 10)
|
blint-2.4.1/blint/db.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: AppThreat <cloud@appthreat.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
import concurrent
|
|
5
|
+
import concurrent.futures
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from contextlib import closing
|
|
10
|
+
|
|
11
|
+
import apsw
|
|
12
|
+
|
|
13
|
+
from blint.config import BLINTDB_LOC, MIN_MATCH_SCORE, SYMBOLS_LOOKUP_BATCH_LEN
|
|
14
|
+
from blint.logger import LOG
|
|
15
|
+
|
|
16
|
+
DEBUG_MODE = os.getenv("SCAN_DEBUG_MODE") == "debug"
|
|
17
|
+
db_conn: apsw.Connection = None
|
|
18
|
+
DB_FILE_SEP = "///" if sys.platform == "win32" else "//"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get(db_file: str = BLINTDB_LOC, read_only=True) -> apsw.Connection:
|
|
22
|
+
if not os.path.exists(db_file):
|
|
23
|
+
return
|
|
24
|
+
if not db_file.startswith("file:") and db_file != ":memory:":
|
|
25
|
+
db_file = f"file:{DB_FILE_SEP}{os.path.abspath(db_file)}"
|
|
26
|
+
global db_conn
|
|
27
|
+
ro_flags = apsw.SQLITE_OPEN_URI | apsw.SQLITE_OPEN_NOFOLLOW | apsw.SQLITE_OPEN_READONLY
|
|
28
|
+
db_conn = apsw.Connection(db_file, flags=ro_flags)
|
|
29
|
+
return db_conn
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def return_batch_binaries_detected(symbols_list):
|
|
33
|
+
"""
|
|
34
|
+
Current scoring algorithm along with batching
|
|
35
|
+
"""
|
|
36
|
+
# Detected binaries and their score
|
|
37
|
+
binaries_detected_dict = {}
|
|
38
|
+
# The export ids that led to the match
|
|
39
|
+
binaries_eid_dict = {}
|
|
40
|
+
if not isinstance(symbols_list, list):
|
|
41
|
+
raise TypeError(f"Incorrect type symbols_lists should be List not {type(symbols_list)}")
|
|
42
|
+
|
|
43
|
+
# Errors not being caught here
|
|
44
|
+
output_list = get_bid_using_ename_batch(symbols_list)
|
|
45
|
+
|
|
46
|
+
eid_list = [it[0] for it in output_list]
|
|
47
|
+
bid_2d_list = [it[1] for it in output_list]
|
|
48
|
+
for it in range(len(eid_list)):
|
|
49
|
+
bid_list = bid_2d_list[it].split(",")
|
|
50
|
+
score = 1 / len(bid_list)
|
|
51
|
+
for bid in bid_list:
|
|
52
|
+
matching_binaries = find_binary_from_db(bid)
|
|
53
|
+
if matching_binaries:
|
|
54
|
+
for (bname, pname, purl) in matching_binaries:
|
|
55
|
+
binaries_eid_dict[purl] = eid_list
|
|
56
|
+
if purl in binaries_detected_dict:
|
|
57
|
+
binaries_detected_dict[purl] += score
|
|
58
|
+
else:
|
|
59
|
+
binaries_detected_dict[purl] = score
|
|
60
|
+
return binaries_detected_dict, binaries_eid_dict
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_bid_using_ename_batch(batch_export_name):
|
|
64
|
+
"""Retrieves binary IDs associated with a batch of export names from a SQLite database.
|
|
65
|
+
|
|
66
|
+
This function queries the database to find binary IDs linked to specific export names in a batch.
|
|
67
|
+
It uses the BLINTDB_LOC environment variable to connect to the SQLite database and performs a grouped query.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
batch_export_name (list): A list of export names to search for in the database.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
list: A list of tuples containing export IDs and their corresponding concatenated binary IDs.
|
|
74
|
+
|
|
75
|
+
Raises:
|
|
76
|
+
apsw.Error: If there are any database connection or query execution issues.
|
|
77
|
+
"""
|
|
78
|
+
connection = get()
|
|
79
|
+
if not connection:
|
|
80
|
+
return None
|
|
81
|
+
with closing(connection.cursor()) as c:
|
|
82
|
+
place_holders = "?, " * (len(batch_export_name) - 1) + "?"
|
|
83
|
+
if len(batch_export_name) > 0:
|
|
84
|
+
output_string = f"SELECT eid, group_concat(bid) from BinariesExports where eid IN (SELECT rowid from Exports where infunc IN ({place_holders})) group by eid"
|
|
85
|
+
c.execute(output_string, batch_export_name)
|
|
86
|
+
res = c.fetchall()
|
|
87
|
+
return res
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@lru_cache(maxsize=1000)
|
|
91
|
+
def find_binary_from_db(bid):
|
|
92
|
+
"""Retrieves the binary name for a given binary ID from a SQLite database. The function performs a lookup to fetch the corresponding binary name.
|
|
93
|
+
|
|
94
|
+
This function connects to a SQLite database using the BLINTDB_LOC environment variable and executes a query to retrieve the binary name based on the provided binary ID. If no matching binary is found, it returns None.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
bid (int): The binary identifier to search for in the database.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
str or None: The name of the binary if found, otherwise None.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
apsw.Error: If there are any database connection or query execution issues.
|
|
104
|
+
"""
|
|
105
|
+
connection = get()
|
|
106
|
+
if not connection:
|
|
107
|
+
return None
|
|
108
|
+
res = connection.execute(
|
|
109
|
+
"SELECT bname, pname, purl from Binaries JOIN Projects on Binaries.pid = Projects.pid WHERE Binaries.bid = ?",
|
|
110
|
+
(bid,))
|
|
111
|
+
return frozenset(res.fetchall())
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def detect_binaries_utilized(symbols_list) -> tuple[set, dict]:
|
|
115
|
+
"""Simple Voting algorithm
|
|
116
|
+
for a given symbols. e.g. XRenderAddGlyphs
|
|
117
|
+
we count the number of binaries associated to this function
|
|
118
|
+
e.g. which is one in this example XRenderAddGlyphs
|
|
119
|
+
is associated with 'libXrender-0.9.10/libxrender.so'.
|
|
120
|
+
so one is added to score, we want all the detections to have a score greater than MIN_MATCH_SCORE.
|
|
121
|
+
"""
|
|
122
|
+
if not symbols_list:
|
|
123
|
+
return set(), {}
|
|
124
|
+
bin_detected_dict = {}
|
|
125
|
+
binaries_eid_dict = {}
|
|
126
|
+
eid_list = [symbol["name"] for symbol in symbols_list]
|
|
127
|
+
LOG.debug(f"Attempting to find the binaries for {len(eid_list)} symbols.")
|
|
128
|
+
# creates a 2D array with SYMBOLS_LOOKUP_BATCH_LEN, SYMBOLS_LOOKUP_BATCH_LEN eids are processed in a single query
|
|
129
|
+
eid_2d_list = [eid_list[i: i + SYMBOLS_LOOKUP_BATCH_LEN] for i in range(0, len(eid_list), SYMBOLS_LOOKUP_BATCH_LEN)]
|
|
130
|
+
|
|
131
|
+
# for eid in eid_list:
|
|
132
|
+
with concurrent.futures.ProcessPoolExecutor() as executor:
|
|
133
|
+
futures_bin_detected = {
|
|
134
|
+
executor.submit(return_batch_binaries_detected, it_eid_list): it_eid_list
|
|
135
|
+
for it_eid_list in eid_2d_list
|
|
136
|
+
}
|
|
137
|
+
for future in concurrent.futures.as_completed(futures_bin_detected):
|
|
138
|
+
single_binaries_detected_dict, binaries_eid_dict = future.result()
|
|
139
|
+
for purl, score in single_binaries_detected_dict.items():
|
|
140
|
+
if purl in bin_detected_dict:
|
|
141
|
+
bin_detected_dict[purl] += score
|
|
142
|
+
else:
|
|
143
|
+
bin_detected_dict[purl] = score
|
|
144
|
+
# create a set() and remove false positives
|
|
145
|
+
binary_detected = {purl for purl, score in bin_detected_dict.items() if score > MIN_MATCH_SCORE}
|
|
146
|
+
binary_evidence_eids = {}
|
|
147
|
+
for purl, eids in binaries_eid_dict.items():
|
|
148
|
+
if purl in binary_detected:
|
|
149
|
+
binary_evidence_eids[purl] = eids
|
|
150
|
+
return binary_detected, binary_evidence_eids
|
|
@@ -134,33 +134,31 @@ for tmp_data in raw_rules:
|
|
|
134
134
|
# Load the default review methods
|
|
135
135
|
for review_methods_file in review_files:
|
|
136
136
|
raw_annotations = []
|
|
137
|
-
if DEBUG_MODE:
|
|
138
|
-
LOG.debug(f"Loading review file {review_methods_file}")
|
|
139
137
|
with get_resource("blint.data.annotations", review_methods_file) as fp:
|
|
140
138
|
raw_annotations = fp.read().split("---")
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
139
|
+
for tmp_data in raw_annotations:
|
|
140
|
+
if not tmp_data:
|
|
141
|
+
continue
|
|
142
|
+
methods_reviews_groups = yaml.safe_load(tmp_data)
|
|
143
|
+
exe_type_list = methods_reviews_groups.get("exe_type")
|
|
144
|
+
if isinstance(exe_type_list, str):
|
|
145
|
+
exe_type_list = [exe_type_list]
|
|
146
|
+
all_rules = methods_reviews_groups.get("rules")
|
|
147
|
+
method_rules_dict = {}
|
|
148
|
+
for rule in all_rules:
|
|
149
|
+
method_rules_dict[rule.get("id")] = rule
|
|
150
|
+
review_rules_cache[rule.get("id")] = rule
|
|
151
|
+
for etype in exe_type_list:
|
|
152
|
+
if methods_reviews_groups.get("group") == "METHOD_REVIEWS":
|
|
153
|
+
review_methods_dict[etype].append(method_rules_dict)
|
|
154
|
+
elif methods_reviews_groups.get("group") == "EXE_REVIEWS":
|
|
155
|
+
review_exe_dict[etype].append(method_rules_dict)
|
|
156
|
+
elif methods_reviews_groups.get("group") == "SYMBOL_REVIEWS":
|
|
157
|
+
review_symbols_dict[etype].append(method_rules_dict)
|
|
158
|
+
elif methods_reviews_groups.get("group") == "IMPORT_REVIEWS":
|
|
159
|
+
review_imports_dict[etype].append(method_rules_dict)
|
|
160
|
+
elif methods_reviews_groups.get("group") == "ENTRIES_REVIEWS":
|
|
161
|
+
review_entries_dict[etype].append(method_rules_dict)
|
|
164
162
|
|
|
165
163
|
|
|
166
164
|
def run_checks(f, metadata):
|