2323# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2424
2525import argparse
26+ import json
2627import pydoc
2728
2829from packageurl import PackageURL
@@ -40,30 +41,33 @@ def get_help():
4041 ╚██╔╝ ╚██████╔╝███████╗██║ ╚███║ ██║ ╚█████╔╝ ██║ ██║ ██║███████╗
4142 ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
4243
43- Usage: vulntotal-cli.py [-h] [-p PURL ] [-l ] [-d validator [validator ...]]
44- [-e validator [validator ...]]
44+ Usage: vulntotal-cli.py [-h] [-l ] [-r ] [-d validator [validator ...]]
45+ [-e validator [validator ...]] [-p PURL]
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
5051
5152Optional arguments:
5253 -h, --help Show this help message and exit
53- -p PURL, --purl PURL PackageURL to run through validator/s
5454 -l, --list Lists all the available validators
55+ -r, --raw List of all the raw response from vendor
5556
5657 -e validator [validator ...] Enable these validator/s only
5758 --enable validator [validator ...]
5859
5960 -d validator [validator ...] Disable these validator/s
6061 --disable validator [validator ...]
6162
63+ -p PURL, --purl PURL PackageURL to run through validator/s
64+
6265Examples:
6366 python vulntotal-cli.py --list
6467 python vulntotal-cli.py -p 'pkg:pypi/jinja2@2.4.1'
65- python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:pypi/jinja2@2.4.1'
66- python vulntotal-cli.py -d osv -p 'pkg:pypi/jinja2@2.4.1'
68+ python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:go/github.com/cloudflare/cfrpki@v1.4.1'
69+ python vulntotal-cli.py -d osv -p 'pkg:maven/org.apache.tomcat/tomcat@10.1.0-M8'
70+ python vulntotal-cli.py -r -e osv -p 'pkg:npm/semver-regex@3.1.3'
6771"""
6872
6973
@@ -97,11 +101,24 @@ def list_validators():
97101
98102def formatted_row (validator , advisory ):
99103 aliases = "\n " .join (advisory .aliases )
100- affected = " " .join (advisory .affected_versions )
101- fixed = " " .join (advisory .fixed_versions )
104+ affected = " " .join (advisory .affected_versions )
105+ fixed = " " .join (advisory .fixed_versions )
102106 return [validator .upper (), aliases , affected , fixed ]
103107
104108
109+ def get_raw_response (purl , validators ):
110+ if not validators :
111+ print ("No validators available!" )
112+ return
113+
114+ all_raw_responses = {}
115+ for key , validator in validators .items ():
116+ vendor = validator ()
117+ vendor_advisories = vendor .validator_advisory (PackageURL .from_string (purl ))
118+ all_raw_responses [key ] = vendor .raw_dump
119+ print (all_raw_responses )
120+
121+
105122def run_validators (purl , validators ):
106123 if not validators :
107124 print ("No validators available!" )
@@ -116,14 +133,11 @@ def run_validators(purl, validators):
116133 for key , validator in validators .items ():
117134 vendor = validator ()
118135 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 ))
125136
126- if not_vulnerable_in_vendor_advisory :
137+ if vendor_advisories :
138+ for advisory in vendor_advisories :
139+ table .add_row (formatted_row (key , advisory ))
140+ else :
127141 table .add_row ([key .upper (), "None" , "None" , "None" ])
128142
129143 pydoc .pager (table .draw ())
@@ -138,6 +152,9 @@ def handler():
138152 parser .add_argument (
139153 "-l" , "--list" , action = "store_true" , help = "Lists all the available validators"
140154 )
155+ parser .add_argument (
156+ "-r" , "--raw" , action = "store_true" , help = "List of all the raw response from vendor"
157+ )
141158 parser .add_argument (
142159 "-e" , "--enable" , metavar = "validator" , nargs = "+" , help = "Enable these validator/s only"
143160 )
@@ -157,6 +174,17 @@ def handler():
157174 elif args .list :
158175 list_validators ()
159176
177+ elif args .raw :
178+ if args .purl :
179+ if args .enable :
180+ get_raw_response (args .purl , get_enabled_validator (args .enable ))
181+
182+ elif args .disable :
183+ get_raw_response (args .purl , get_undisabled_validator (args .disable ))
184+
185+ else :
186+ get_raw_response (args .purl , VALIDATORS_REGISTRY )
187+
160188 elif args .purl :
161189 if args .enable :
162190 run_validators (args .purl , get_enabled_validator (args .enable ))
0 commit comments