2323# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2424
2525import argparse
26+ import json
2627import pydoc
2728
2829from packageurl import PackageURL
@@ -43,7 +44,7 @@ def get_help():
4344Usage: vulntotal-cli.py [-h] [-p PURL] [-l] [-d validator [validator ...]]
4445 [-e validator [validator ...]]
4546
46- Discription :
47+ Description :
4748 When no -e/-d flag is provided CLI will run the PURL through
4849 all the available validators.
4950
@@ -53,6 +54,7 @@ def get_help():
5354 -p PURL, --purl PURL PackageURL to run through validator/s
5455 -l, --list Lists all the available validators
5556
57+ -r, --raw List of all the raw response from vendor
5658 -e validator [validator ...] Enable these validator/s only
5759 --enable validator [validator ...]
5860
@@ -64,6 +66,7 @@ def get_help():
6466 python vulntotal-cli.py -p 'pkg:pypi/jinja2@2.4.1'
6567 python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:pypi/jinja2@2.4.1'
6668 python vulntotal-cli.py -d osv -p 'pkg:pypi/jinja2@2.4.1'
69+ python vulntotal-cli.py -r -e osv -p 'pkg:pypi/jinja2@2.4.1'
6770"""
6871
6972
@@ -102,6 +105,19 @@ def formatted_row(validator, advisory):
102105 return [validator .upper (), aliases , affected , fixed ]
103106
104107
108+ def get_raw_response (purl , validators ):
109+ if not validators :
110+ print ("No validators available!" )
111+ return
112+
113+ all_raw_responses = {}
114+ for key , validator in validators .items ():
115+ vendor = validator ()
116+ vendor_advisories = vendor .validator_advisory (PackageURL .from_string (purl ))
117+ all_raw_responses [key ] = vendor .raw_dump
118+ print (all_raw_responses )
119+
120+
105121def run_validators (purl , validators ):
106122 if not validators :
107123 print ("No validators available!" )
@@ -116,14 +132,11 @@ def run_validators(purl, validators):
116132 for key , validator in validators .items ():
117133 vendor = validator ()
118134 vendor_advisories = vendor .validator_advisory (PackageURL .from_string (purl ))
119- not_vulnerable_in_vendor_advisory = True
120-
121- for advisory in vendor_advisories :
122- if not_vulnerable_in_vendor_advisory :
123- not_vulnerable_in_vendor_advisory = False
124- table .add_row (formatted_row (key , advisory ))
125135
126- if not_vulnerable_in_vendor_advisory :
136+ if vendor_advisories :
137+ for advisory in vendor_advisories :
138+ table .add_row (formatted_row (key , advisory ))
139+ else :
127140 table .add_row ([key .upper (), "None" , "None" , "None" ])
128141
129142 pydoc .pager (table .draw ())
@@ -138,6 +151,9 @@ def handler():
138151 parser .add_argument (
139152 "-l" , "--list" , action = "store_true" , help = "Lists all the available validators"
140153 )
154+ parser .add_argument (
155+ "-r" , "--raw" , action = "store_true" , help = "List of all the raw response from vendor"
156+ )
141157 parser .add_argument (
142158 "-e" , "--enable" , metavar = "validator" , nargs = "+" , help = "Enable these validator/s only"
143159 )
@@ -157,6 +173,17 @@ def handler():
157173 elif args .list :
158174 list_validators ()
159175
176+ elif args .raw :
177+ if args .purl :
178+ if args .enable :
179+ get_raw_response (args .purl , get_enabled_validator (args .enable ))
180+
181+ elif args .disable :
182+ get_raw_response (args .purl , get_undisabled_validator (args .disable ))
183+
184+ else :
185+ get_raw_response (args .purl , VALIDATORS_REGISTRY )
186+
160187 elif args .purl :
161188 if args .enable :
162189 run_validators (args .purl , get_enabled_validator (args .enable ))
0 commit comments