|
44 | 44 | parser.add_argument("-s", "--save_dt",
|
45 | 45 | action='store_true',
|
46 | 46 | help="If set, the date/time will be saved to a file named '.last_run' in the current directory which can be used later with the -n option to see vulnerabilities published since the last run.")
|
| 47 | +parser.add_argument("-l", "--limit", default=9999, help="Set limit on number of vulnerabilitties to retrieve (default 9999)") |
| 48 | +parser.add_argument("-nd", type=bool, default=False, help="Disables retrieving details for each vulnerability to reduce execution time") |
47 | 49 | args = parser.parse_args()
|
48 | 50 |
|
| 51 | + |
49 | 52 | if args.newer_than:
|
50 | 53 | newer_than = timestring.Date(args.newer_than).date
|
51 | 54 | else:
|
|
66 | 69 | version = hub.get_version_by_name(project, args.version)
|
67 | 70 | version_id = object_id(version)
|
68 | 71 |
|
69 |
| -vulnerable_components_url = hub.get_link(version, "vulnerable-components") + "?limit=9999" |
| 72 | +vulnerablity_limit = "limit?={}".format(args.limit) |
| 73 | + |
| 74 | +vulnerable_components_url = hub.get_link(version, "vulnerable-components") + vulnerablity_limit |
70 | 75 | custom_headers = {'Accept':'application/vnd.blackducksoftware.bill-of-materials-6+json'}
|
71 | 76 | response = hub.execute_get(vulnerable_components_url, custom_headers=custom_headers)
|
72 | 77 | vulnerable_bom_components = response.json().get('items', [])
|
73 | 78 |
|
74 | 79 | bdsa_records = set()
|
75 | 80 | cve_records = set()
|
76 | 81 |
|
77 |
| -for i, vuln in enumerate(vulnerable_bom_components): |
78 |
| - source = vuln['vulnerabilityWithRemediation']['source'] |
79 |
| - vuln_name = vuln['vulnerabilityWithRemediation']['vulnerabilityName'] |
80 | 82 |
|
81 |
| - # Retrieve additional details about the vulnerability |
82 |
| - # |
| 83 | +if args.nodetails==False: |
| 84 | + for i, vuln in enumerate(vulnerable_bom_components): |
| 85 | + source = vuln['vulnerabilityWithRemediation']['source'] |
| 86 | + vuln_name = vuln['vulnerabilityWithRemediation']['vulnerabilityName'] |
83 | 87 |
|
84 |
| - update_guidance_url = vuln['componentVersion'] + "/upgrade-guidance" |
85 |
| - update_guidance_results = hub.execute_get(update_guidance_url).json() |
86 |
| - vuln['update_guidance'] = update_guidance_results |
| 88 | + # Retrieve additional details about the vulnerability |
| 89 | + # |
87 | 90 |
|
88 |
| - logging.debug("Retrieving additional details regarding vuln {}, i={}".format(vuln_name, i)) |
89 |
| - vuln_url = hub.get_apibase() + "/vulnerabilities/{}".format(vuln_name) |
90 |
| - vuln_details_response = hub.execute_get(vuln_url, custom_headers={'Accept': 'application/json'}) |
91 |
| - vuln_details = vuln_details_response.json() |
| 91 | + update_guidance_url = vuln['componentVersion'] + "/upgrade-guidance" |
| 92 | + update_guidance_results = hub.execute_get(update_guidance_url).json() |
| 93 | + vuln['update_guidance'] = update_guidance_results |
92 | 94 |
|
93 |
| - vuln['additional_vuln_info'] = vuln_details |
| 95 | + logging.debug("Retrieving additional details regarding vuln {}, i={}".format(vuln_name, i)) |
| 96 | + vuln_url = hub.get_apibase() + "/vulnerabilities/{}".format(vuln_name) |
| 97 | + vuln_details_response = hub.execute_get(vuln_url, custom_headers={'Accept': 'application/json'}) |
| 98 | + vuln_details = vuln_details_response.json() |
94 | 99 |
|
95 |
| - if source == 'BDSA': |
96 |
| - bdsa_records.add(vuln_name) |
| 100 | + vuln['additional_vuln_info'] = vuln_details |
97 | 101 |
|
98 |
| - # get related vulnerability info, i.e. CVE |
99 |
| - # note: not all BDSA records will have a corresponding CVE record |
100 |
| - cve_url = hub.get_link(vuln_details, "related-vulnerability") |
101 |
| - if cve_url: |
102 |
| - cve_details_response = hub.execute_get(cve_url, custom_headers={'Accept': 'application/json'}) |
103 |
| - cve_details = cve_details_response.json() |
104 |
| - vuln['related_vulnerability'] = cve_details |
105 |
| - cve_records.add(cve_details['name']) |
106 |
| - elif source == "NVD": |
107 |
| - cve_records.add(vuln_name) |
108 |
| - else: |
109 |
| - logging.warning(f"source {source} was not recognized") |
| 102 | + if source == 'BDSA': |
| 103 | + bdsa_records.add(vuln_name) |
| 104 | + |
| 105 | + # get related vulnerability info, i.e. CVE |
| 106 | + # note: not all BDSA records will have a corresponding CVE record |
| 107 | + cve_url = hub.get_link(vuln_details, "related-vulnerability") |
| 108 | + if cve_url: |
| 109 | + cve_details_response = hub.execute_get(cve_url, custom_headers={'Accept': 'application/json'}) |
| 110 | + cve_details = cve_details_response.json() |
| 111 | + vuln['related_vulnerability'] = cve_details |
| 112 | + cve_records.add(cve_details['name']) |
| 113 | + elif source == "NVD": |
| 114 | + cve_records.add(vuln_name) |
| 115 | + else: |
| 116 | + logging.warning(f"source {source} was not recognized") |
110 | 117 |
|
111 | 118 | if vulnerable_bom_components:
|
112 | 119 | vulnerable_bom_components = sorted(
|
|
142 | 149 | 'by_remediation_status': remediation_counts
|
143 | 150 | }
|
144 | 151 |
|
145 |
| - |
146 |
| -everything = { |
147 |
| - 'counts': counts, |
148 |
| - 'vulnerabilities': vulnerable_bom_components, |
149 |
| - 'bdsa_records': list(bdsa_records), |
150 |
| - 'cve_records': list(cve_records), |
151 |
| -} |
| 152 | +if args.nodetails==False: |
| 153 | + everything = { |
| 154 | + 'counts': counts, |
| 155 | + 'vulnerabilities': vulnerable_bom_components, |
| 156 | + 'bdsa_records': list(bdsa_records), |
| 157 | + 'cve_records': list(cve_records), |
| 158 | + } |
| 159 | +else: |
| 160 | + everything = { |
| 161 | + 'counts': counts, |
| 162 | + 'vulnerabilities': vulnerable_bom_components, |
| 163 | + } |
152 | 164 |
|
153 | 165 | print(json.dumps(everything))
|
154 | 166 |
|
0 commit comments