-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Keshav Priyadarshi <[email protected]>
- Loading branch information
1 parent
a123e7c
commit daa8a1c
Showing
1 changed file
with
35 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
# Visit https://github.com/nexB/vulnerablecode/ for support and download. | ||
|
||
import argparse | ||
import json | ||
import pydoc | ||
|
||
from packageurl import PackageURL | ||
|
@@ -43,7 +44,7 @@ def get_help(): | |
Usage: vulntotal-cli.py [-h] [-p PURL] [-l] [-d validator [validator ...]] | ||
[-e validator [validator ...]] | ||
Discription: | ||
Description: | ||
When no -e/-d flag is provided CLI will run the PURL through | ||
all the available validators. | ||
|
@@ -53,6 +54,7 @@ def get_help(): | |
-p PURL, --purl PURL PackageURL to run through validator/s | ||
-l, --list Lists all the available validators | ||
-r, --raw List of all the raw response from vendor | ||
-e validator [validator ...] Enable these validator/s only | ||
--enable validator [validator ...] | ||
|
@@ -64,6 +66,7 @@ def get_help(): | |
python vulntotal-cli.py -p 'pkg:pypi/[email protected]' | ||
python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:pypi/[email protected]' | ||
python vulntotal-cli.py -d osv -p 'pkg:pypi/[email protected]' | ||
python vulntotal-cli.py -r -e osv -p 'pkg:pypi/[email protected]' | ||
""" | ||
|
||
|
||
|
@@ -102,6 +105,19 @@ def formatted_row(validator, advisory): | |
return [validator.upper(), aliases, affected, fixed] | ||
|
||
|
||
def get_raw_response(purl, validators): | ||
if not validators: | ||
print("No validators available!") | ||
return | ||
|
||
all_raw_responses = {} | ||
for key, validator in validators.items(): | ||
vendor = validator() | ||
vendor_advisories = vendor.validator_advisory(PackageURL.from_string(purl)) | ||
all_raw_responses[key] = vendor.raw_dump | ||
print(all_raw_responses) | ||
|
||
|
||
def run_validators(purl, validators): | ||
if not validators: | ||
print("No validators available!") | ||
|
@@ -116,14 +132,11 @@ def run_validators(purl, validators): | |
for key, validator in validators.items(): | ||
vendor = validator() | ||
vendor_advisories = vendor.validator_advisory(PackageURL.from_string(purl)) | ||
not_vulnerable_in_vendor_advisory = True | ||
|
||
for advisory in vendor_advisories: | ||
if not_vulnerable_in_vendor_advisory: | ||
not_vulnerable_in_vendor_advisory = False | ||
table.add_row(formatted_row(key, advisory)) | ||
|
||
if not_vulnerable_in_vendor_advisory: | ||
if vendor_advisories: | ||
for advisory in vendor_advisories: | ||
table.add_row(formatted_row(key, advisory)) | ||
else: | ||
table.add_row([key.upper(), "None", "None", "None"]) | ||
|
||
pydoc.pager(table.draw()) | ||
|
@@ -138,6 +151,9 @@ def handler(): | |
parser.add_argument( | ||
"-l", "--list", action="store_true", help="Lists all the available validators" | ||
) | ||
parser.add_argument( | ||
"-r", "--raw", action="store_true", help="List of all the raw response from vendor" | ||
) | ||
parser.add_argument( | ||
"-e", "--enable", metavar="validator", nargs="+", help="Enable these validator/s only" | ||
) | ||
|
@@ -157,6 +173,17 @@ def handler(): | |
elif args.list: | ||
list_validators() | ||
|
||
elif args.raw: | ||
if args.purl: | ||
if args.enable: | ||
get_raw_response(args.purl, get_enabled_validator(args.enable)) | ||
|
||
elif args.disable: | ||
get_raw_response(args.purl, get_undisabled_validator(args.disable)) | ||
|
||
else: | ||
get_raw_response(args.purl, VALIDATORS_REGISTRY) | ||
|
||
elif args.purl: | ||
if args.enable: | ||
run_validators(args.purl, get_enabled_validator(args.enable)) | ||
|