-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3259 from fnxpt/trivy
Trivy
- Loading branch information
Showing
33 changed files
with
1,911 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: Trivy | ||
category: Datasources | ||
chapter: 4 | ||
order: 6 | ||
--- | ||
|
||
[Trivy](https://www.aquasec.com/products/trivy/) is a tool provided by aquas allowing you to scan for vulnerabilities. | ||
|
||
Dependency-Track integrates with Trivy using its undocumented REST API. | ||
|
||
The Trivy integration is disabled by default. | ||
|
||
### Configuration | ||
|
||
To configure the Trivy integration, navigate to *Analyzers* -> *Trivy* in the administration panel. | ||
|
||
|:---|:----| | ||
| Base URL | Base URL of the Trivy REST API. Defaults to `http://localhost:8081`. | | ||
| API Token | Authentication token for the REST API. | | ||
|
||
![Trivy Configuration](../../images/screenshots/trivy-configuration.png) | ||
|
||
### Run Trivy as Server | ||
|
||
Trivy can be runned as a [server](https://github.com/aquasecurity/trivy/blob/b5874e3ad38e77ac86eedd7a65785b2933f3685f/docs/docs/references/configuration/cli/trivy_server.md) by executing the command `trivy server --listen localhost:8081 --token dummy -d` or by setting it up on a container. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/org/dependencytrack/event/TrivyAnalysisEvent.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Steve Springett. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.event; | ||
|
||
import org.dependencytrack.model.Component; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Defines an event used to start an analysis via Trivy API. | ||
*/ | ||
public class TrivyAnalysisEvent extends VulnerabilityAnalysisEvent { | ||
|
||
public TrivyAnalysisEvent() { } | ||
|
||
public TrivyAnalysisEvent(final Component component) { | ||
super(component); | ||
} | ||
|
||
public TrivyAnalysisEvent(final List<Component> components) { | ||
super(components); | ||
} | ||
|
||
} |
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
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
132 changes: 132 additions & 0 deletions
132
src/main/java/org/dependencytrack/parser/trivy/TrivyParser.java
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Steve Springett. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.parser.trivy; | ||
|
||
import alpine.common.logging.Logger; | ||
import org.dependencytrack.model.Cwe; | ||
import org.dependencytrack.model.Severity; | ||
import org.dependencytrack.model.Vulnerability; | ||
import org.dependencytrack.model.VulnerableSoftware; | ||
import org.dependencytrack.parser.common.resolver.CweResolver; | ||
import org.dependencytrack.parser.trivy.model.CVSS; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import java.math.BigDecimal; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class TrivyParser { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(TrivyParser.class); | ||
|
||
public Vulnerability parse(org.dependencytrack.parser.trivy.model.Vulnerability data, QueryManager qm) { | ||
Vulnerability synchronizedVulnerability = new Vulnerability(); | ||
Vulnerability vulnerability = new Vulnerability(); | ||
List<VulnerableSoftware> vsList = new ArrayList<>(); | ||
|
||
vulnerability.setSource(Vulnerability.Source.resolve(data.getVulnerabilityID())); | ||
|
||
vulnerability.setPatchedVersions(data.getFixedVersion()); | ||
|
||
// get the id of the data record (vulnerability) | ||
vulnerability.setVulnId(data.getVulnerabilityID()); | ||
vulnerability.setTitle(data.getTitle()); | ||
vulnerability.setDescription(data.getDescription()); | ||
vulnerability.setSeverity(parseSeverity(data.getSeverity())); | ||
|
||
try { | ||
vulnerability.setPublished(parseDate(data.getPublishedDate())); | ||
vulnerability.setCreated(vulnerability.getPublished()); | ||
} catch (ParseException ex) { | ||
LOGGER.warn("Unable to parse published date %s".formatted(data.getPublishedDate())); | ||
} | ||
|
||
try { | ||
vulnerability.setUpdated(parseDate(data.getLastModifiedDate())); | ||
} catch (ParseException ex) { | ||
LOGGER.warn("Unable to parse last modified date %s".formatted(data.getLastModifiedDate())); | ||
} | ||
|
||
vulnerability.setReferences(addReferences(data.getReferences())); | ||
|
||
// CWE | ||
for (String id : data.getCweIDS()) { | ||
final Cwe cwe = CweResolver.getInstance().lookup(id); | ||
if (cwe != null) { | ||
vulnerability.addCwe(cwe); | ||
} | ||
} | ||
|
||
vulnerability = setCvssScore(data.getCvss().get(data.getSeveritySource()), vulnerability); | ||
|
||
return vulnerability; | ||
} | ||
|
||
public Date parseDate(String input) throws ParseException { | ||
if (input != null) { | ||
String format = input.length() == 20 ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; | ||
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH); | ||
return formatter.parse(input); | ||
} | ||
return null; | ||
} | ||
|
||
public Severity parseSeverity(String severity) { | ||
|
||
if (severity != null) { | ||
if (severity.equalsIgnoreCase("CRITICAL")) { | ||
return Severity.CRITICAL; | ||
} else if (severity.equalsIgnoreCase("HIGH")) { | ||
return Severity.HIGH; | ||
} else if (severity.equalsIgnoreCase("MEDIUM")) { | ||
return Severity.MEDIUM; | ||
} else if (severity.equalsIgnoreCase("LOW")) { | ||
return Severity.LOW; | ||
} else { | ||
return Severity.UNASSIGNED; | ||
} | ||
} | ||
return Severity.UNASSIGNED; | ||
} | ||
|
||
public Vulnerability setCvssScore(CVSS cvss, Vulnerability vulnerability) { | ||
if (cvss != null) { | ||
vulnerability.setCvssV2Vector(cvss.getV2Vector()); | ||
vulnerability.setCvssV3Vector(cvss.getV3Vector()); | ||
vulnerability.setCvssV2BaseScore(BigDecimal.valueOf(cvss.getV2Score())); | ||
vulnerability.setCvssV3BaseScore(BigDecimal.valueOf(cvss.getV3Score())); | ||
} | ||
|
||
return vulnerability; | ||
} | ||
|
||
public String addReferences(String[] references) { | ||
final StringBuilder sb = new StringBuilder(); | ||
for (String reference : references) { | ||
if (reference != null) { | ||
sb.append("* [").append(reference).append("](").append(reference).append(")\n"); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/org/dependencytrack/parser/trivy/model/Application.java
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) Steve Springett. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.parser.trivy.model; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Application { | ||
private String type; | ||
private ArrayList<Library> libraries; | ||
|
||
public Application(String type) { | ||
this.type = type; | ||
this.libraries = new ArrayList<Library>(); | ||
} | ||
|
||
public String getType() { return type; } | ||
public void setType(String value) { this.type = value; } | ||
|
||
public ArrayList<Library> getLibraries() { return libraries; } | ||
public void setLibraries(ArrayList<Library> value) { this.libraries = value; } | ||
public void addLibrary(Library value) { this.libraries.add(value); } | ||
} |
Oops, something went wrong.