Skip to content

Commit 4a0d173

Browse files
authored
blintdb command (#132)
* Adds blint db sub-command Signed-off-by: Prabhu Subramanian <[email protected]> * Include export id matches as properties Signed-off-by: Prabhu Subramanian <[email protected]> * Include export id matches as properties Signed-off-by: Prabhu Subramanian <[email protected]> * Readme update Signed-off-by: Prabhu Subramanian <[email protected]> --------- Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 79f2888 commit 4a0d173

File tree

9 files changed

+234
-236
lines changed

9 files changed

+234
-236
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL maintainer="appthreat" \
44
org.opencontainers.image.authors="Team AppThreat <[email protected]>" \
55
org.opencontainers.image.source="https://github.com/owasp-dep-scan/blint" \
66
org.opencontainers.image.url="https://github.com/owasp-dep-scan/blint" \
7-
org.opencontainers.image.version="2.3.x" \
7+
org.opencontainers.image.version="2.4.x" \
88
org.opencontainers.image.vendor="OWASP" \
99
org.opencontainers.image.licenses="MIT" \
1010
org.opencontainers.image.title="blint" \

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ sub-commands:
6363

6464
{sbom}
6565
sbom Command to generate SBOM for supported binaries.
66+
db Command to manage the pre-compiled database.
6667
```
6768
6869
### SBOM sub-command
@@ -85,6 +86,18 @@ options:
8586
Directories containing pre-build and build BOMs. Use to improve the precision.
8687
```
8788
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+
88101
To test any binary, including default commands
89102
90103
```bash
@@ -119,12 +132,20 @@ To parse all files, including `.dex` files, pass `--deep` argument.
119132
blint sbom -i /path/to/apk -o bom.json --deep
120133
```
121134
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+
122142
The following binaries are supported:
123143
124144
- Android (apk/aab)
125145
- Dotnet executable binaries
126146
- Go binaries
127147
- Rust binaries
148+
- c/c++ binaries (WIP)
128149
129150
```shell
130151
blint sbom -i /path/to/go-binaries -o bom.json --deep

blint/cli.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66

77
from blint.lib.runners import run_default_mode, run_sbom_mode
8-
from blint.config import BlintOptions
8+
from blint.config import BlintOptions, BLINTDB_HOME, BLINTDB_IMAGE_URL, BLINTDB_LOC
99
from blint.lib.utils import blintdb_setup
1010

1111
BLINT_LOGO = """
@@ -37,7 +37,8 @@ def build_parser():
3737
stdout_mode=False,
3838
exports_prefix=[],
3939
src_dir_boms=[],
40-
sbom_mode=False
40+
sbom_mode=False,
41+
db_mode=False,
4142
)
4243
parser.add_argument(
4344
"-i",
@@ -86,9 +87,9 @@ def build_parser():
8687
parser.add_argument(
8788
"--use-blintdb",
8889
action="store_true",
89-
default=False,
90+
default=os.path.exists(BLINTDB_LOC),
9091
dest="use_blintdb",
91-
help="Use blintdb for symbol resolution. Use environment variables: BLINTDB_IMAGE_URL, BLINTDB_HOME, and BLINTDB_REFRESH for customization.",
92+
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.",
9293
)
9394
# sbom commmand
9495
subparsers = parser.add_subparsers(
@@ -144,7 +145,24 @@ def build_parser():
144145
nargs="+",
145146
help="Directories containing pre-build and build BOMs. Use to improve the precision.",
146147
)
147-
148+
db_parser = subparsers.add_parser(
149+
"db", help="Command to manage the pre-compiled database."
150+
)
151+
db_parser.set_defaults(db_mode=True)
152+
db_parser.add_argument(
153+
"--download",
154+
action="store_true",
155+
default=True,
156+
dest="download_mode",
157+
help=f"Download the pre-compiled database to the {BLINTDB_HOME} directory. Use the environment variable `BLINTDB_HOME` to override.",
158+
)
159+
db_parser.add_argument(
160+
"--image-url",
161+
dest="image_url",
162+
choices=["ghcr.io/appthreat/blintdb-vcpkg-darwin-arm64:v1", "ghcr.io/appthreat/blintdb-meson-darwin-arm64:v1"],
163+
default=BLINTDB_IMAGE_URL,
164+
help=f"Blintdb image url. Defaults to {BLINTDB_IMAGE_URL}. The environment variable `BLINTDB_IMAGE_URL` is an alternative way to set this value.",
165+
)
148166
return parser
149167

150168

@@ -187,6 +205,8 @@ def handle_args():
187205
no_reviews=args.no_reviews,
188206
reports_dir=args.reports_dir,
189207
sbom_mode=args.sbom_mode,
208+
db_mode=args.db_mode,
209+
image_url=args.image_url if args.db_mode else None,
190210
sbom_output=args.sbom_output,
191211
src_dir_boms=args.src_dir_boms,
192212
src_dir_image=args.src_dir_image,
@@ -205,6 +225,8 @@ def main():
205225
# SBOM command
206226
if blint_options.sbom_mode:
207227
run_sbom_mode(blint_options)
228+
elif blint_options.db_mode:
229+
return
208230
# Default case
209231
else:
210232
run_default_mode(blint_options)

blint/config.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
import sys
33
from dataclasses import dataclass, field
44
import os
5+
import platform
56
import re
67
from typing import List
78
from appdirs import user_data_dir
89

10+
ARCH = platform.machine()
11+
SYSTEM = platform.system().lower()
912

1013
# Default ignore list
1114
ignore_directories = [
@@ -1285,7 +1288,9 @@ class BlintOptions:
12851288
no_error (bool): Flag indicating whether to suppress error messages.
12861289
no_reviews (bool): Flag indicating whether to perform symbol reviews.
12871290
reports_dir (str): The path to the reports directory.
1288-
sbom_mode (bool): Flag indicating whether to perform SBOM analysis.
1291+
sbom_mode (bool): Flag for the sbom sub-command.
1292+
db_mode (bool): Flag for the db sub-command.
1293+
image_url (str): blintdb download url. Must be OCI compatible.
12891294
src_dir_image (list): A list of source directories.
12901295
sbom_output (str): The path to the output file.
12911296
deep_mode (bool): Flag indicating whether to perform deep analysis.
@@ -1299,13 +1304,15 @@ class BlintOptions:
12991304
no_reviews: bool = False
13001305
reports_dir: str = ""
13011306
sbom_mode: bool = False
1307+
db_mode: bool = False
1308+
image_url: str = ""
13021309
sbom_output: str = ""
13031310
sbom_output_dir: str = ""
13041311
src_dir_boms: List = field(default_factory=list)
13051312
src_dir_image: List = field(default_factory=list)
13061313
stdout_mode: bool = False
13071314
use_blintdb: bool = False
1308-
1315+
13091316
def __post_init__(self):
13101317
if not self.src_dir_image and not (self.sbom_mode and self.src_dir_boms):
13111318
self.sources = [os.getcwd()]
@@ -1322,7 +1329,7 @@ def __post_init__(self):
13221329
self.sbom_output = os.path.join(self.sbom_output, "bom-post-build.cdx.json")
13231330
else:
13241331
self.sbom_output_dir = os.path.dirname(self.sbom_output)
1325-
1332+
13261333

13271334
# PII related symbols
13281335
PII_WORDS = (
@@ -1399,7 +1406,11 @@ def __post_init__(self):
13991406
BLINTDB_HOME = os.getenv("BLINTDB_HOME", user_data_dir("blintdb"))
14001407
BLINTDB_LOC = os.path.join(BLINTDB_HOME, "blint.db")
14011408

1402-
BLINTDB_IMAGE_URL = os.getenv("BLINTDB_IMAGE_URL", "ghcr.io/appthreat/blintdb-meson-arm64:v1")
1409+
BLINTDB_IMAGE_URL = os.getenv("BLINTDB_IMAGE_URL",
1410+
"ghcr.io/appthreat/blintdb-vcpkg-darwin-arm64:v1" if SYSTEM == "darwin" else "ghcr.io/appthreat/blintdb-vcpkg:v1")
14031411
BLINTDB_REFRESH = os.getenv("BLINTDB_REFRESH", False)
14041412
if BLINTDB_REFRESH in ["true", "True", "1"]:
14051413
BLINTDB_REFRESH = True
1414+
1415+
SYMBOLS_LOOKUP_BATCH_LEN = get_int_from_env("SYMBOLS_LOOKUP_BATCH_LEN", 32000)
1416+
MIN_MATCH_SCORE = get_int_from_env("MIN_MATCH_SCORE", 10)

0 commit comments

Comments
 (0)