Skip to content

Commit 0ae357a

Browse files
authored
feat(package-list-parser): dpkg and rpm package list parser support (#1209)
* feat: Add package list support for distros that use rpm package manager * feat: Add package list parser support for Debian and PopOS * docs: rpm and dpkg package list parser changes
1 parent 81a34d7 commit 0ae357a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ You can also use `-m` or `--merge` along with `-f --format` and `-o --output-fil
8383

8484
> Note: For backward compatibility, we still support `csv2cve` command for producing CVEs from csv but we recommend using new `--input-file` command instead.
8585
86-
`-L` or `--package-list` option runs a CVE scan on installed packages listed in a package list. It takes a python package list (requirements.txt) or a package list of packages of an Ubuntu or CentOS system as an input for the scan. This option is much faster and detects more CVEs than the default method of scanning binaries.
86+
`-L` or `--package-list` option runs a CVE scan on installed packages listed in a package list. It takes a python package list (requirements.txt) or a package list of packages of systems that has rpm or dpkg package manager as an input for the scan. This option is much faster and detects more CVEs than the default method of scanning binaries.
8787

8888
You can get a package list of all installed packages in
89-
- an Ubuntu system by running `dpkg-query -W -f '${binary:Package}\n' > pkg-list`
90-
- a CentOS system by running `rpm -qa --queryformat '%{NAME}\n' > pkg-list`
89+
- a system using dpkg package mananger by running `dpkg-query -W -f '${binary:Package}\n' > pkg-list`
90+
- a system using rpm package mananger by running `rpm -qa --queryformat '%{NAME}\n' > pkg-list`
9191

9292
in the terminal and provide it as an input by running `cve-bin-tool -L pkg-list` for a full package scan.
9393

cve_bin_tool/package_list_parser/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
ROOT_PATH = join(dirname(__file__), "..")
2525
PYPI_CSV = join(ROOT_PATH, "package_list_parser", "pypi_list.csv")
26-
SUPPORTED_DISTROS = ["ubuntu", "centos"]
26+
27+
DEB_DISTROS = ["debian", "pop", "ubuntu"]
28+
RPM_DISTROS = ["centos", "fedora", "opensuse", "rhel"]
29+
SUPPORTED_DISTROS = RPM_DISTROS + DEB_DISTROS
2730

2831

2932
class PackageListParser:
@@ -53,7 +56,7 @@ def parse_list(self):
5356

5457
LOGGER.info(f"Scanning {distro.id().capitalize()} package list.")
5558

56-
if "ubuntu" in distro.id():
59+
if distro.id() in DEB_DISTROS:
5760
installed_packages = run(
5861
[
5962
"dpkg-query",
@@ -62,7 +65,7 @@ def parse_list(self):
6265
],
6366
stdout=PIPE,
6467
)
65-
elif "centos" in distro.id():
68+
elif distro.id() in RPM_DISTROS:
6669
installed_packages = run(
6770
[
6871
"rpm",
@@ -158,8 +161,8 @@ def check_file(self):
158161
raise EmptyTxtError(input_file)
159162

160163
if not input_file.endswith("requirements.txt"):
161-
if "ubuntu" in distro.id():
162-
# Simulate installation on Ubuntu using apt-get to check if the file is valid
164+
if distro.id() in DEB_DISTROS:
165+
# Simulate installation on Debian based system using apt-get to check if the file is valid
163166
output = run(
164167
[f"xargs", "-a", input_file, "apt-get", "install", "-s"],
165168
stderr=PIPE,
@@ -171,7 +174,7 @@ def check_file(self):
171174
raise InvalidListError(
172175
f"Invalid Package list\n{output.stderr.decode('utf-8')}"
173176
)
174-
elif "centos" in distro.id():
177+
elif distro.id() in RPM_DISTROS:
175178
output = run(
176179
[f"xargs", "-a", input_file, "rpm", "-qi"],
177180
stderr=PIPE,

doc/MANUAL.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ The output will look like following:
335335

336336
### -L PACKAGE_LIST, --package-list PACKAGE_LIST
337337

338-
This option runs a CVE scan on installed packages listed in a package list. It takes a python package list (requirements.txt) or a package list of packages of an Ubuntu system as an input for the scan. This option is much faster and detects more CVEs than the default method of scanning binaries.
338+
This option runs a CVE scan on installed packages listed in a package list. It takes a python package list (requirements.txt) or a package list of packages of systems that has rpm or dpkg package manager as an input for the scan. This option is much faster and detects more CVEs than the default method of scanning binaries.
339339

340340
An example of the package list for Linux systems:
341341

@@ -349,8 +349,8 @@ python3
349349

350350
> Note: The packages in the package list should be installed in the system before the scan. Run
351351
- `pip install -r requirements.txt` to install python packages
352-
- `sudo apt-get install $(cat package-list)` for packages in an Ubuntu system
353-
- `sudo yum install $(cat package-list)`for packages in a CentOS system
352+
- `sudo apt-get install $(cat package-list)` for packages in a Debian based system
353+
- `sudo yum install $(cat package-list)`for packages in a CentOS/Fedora system
354354

355355
> Note: Don't use invalid package names in the package list, as it will throw errors.
356356
@@ -359,9 +359,9 @@ You can test it using our [test package list](https://github.com/intel/cve-bin-t
359359
```console
360360
cve-bin-tool -L test/txt/test_ubuntu_list.txt
361361
```
362-
You can get a package list of all installed packages in
363-
- an Ubuntu system by running `dpkg-query -W -f '${binary:Package}\n' > pkg-list`
364-
- a CentOS system by running `rpm -qa --queryformat '%{NAME}\n' > pkg-list`
362+
You can get a package list of all installed packages in
363+
- a system using dpkg package mananger by running `dpkg-query -W -f '${binary:Package}\n' > pkg-list`
364+
- a system using rpm package mananger by running `rpm -qa --queryformat '%{NAME}\n' > pkg-list`
365365

366366
in the terminal and provide it as an input by running `cve-bin-tool -L pkg-list` for a full package scan.
367367

0 commit comments

Comments
 (0)