-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add vulnerability command
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 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
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,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/CompassSecurity/pipeleak/helper" | ||
"github.com/CompassSecurity/pipeleak/nist" | ||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
var ( | ||
gitlabApiToken string | ||
) | ||
|
||
func NewVulnCmd() *cobra.Command { | ||
vulnCmd := &cobra.Command{ | ||
Use: "vuln [no options!]", | ||
Short: "Check if the installed GitLab version is vulnerable", | ||
Run: CheckVulns, | ||
} | ||
vulnCmd.Flags().StringVarP(&gitlabUrl, "gitlab", "g", "", "GitLab instance URL") | ||
err := vulnCmd.MarkFlagRequired("gitlab") | ||
if err != nil { | ||
log.Fatal().Stack().Err(err).Msg("Unable to require gitlab flag") | ||
} | ||
|
||
vulnCmd.Flags().StringVarP(&gitlabApiToken, "token", "t", "", "GitLab API Token") | ||
err = vulnCmd.MarkFlagRequired("token") | ||
if err != nil { | ||
log.Fatal().Msg("Unable to require token flag") | ||
} | ||
vulnCmd.MarkFlagsRequiredTogether("gitlab", "token") | ||
|
||
vulnCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose logging") | ||
return vulnCmd | ||
} | ||
|
||
func CheckVulns(cmd *cobra.Command, args []string) { | ||
if verbose { | ||
zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||
log.Debug().Msg("Verbose log output enabled") | ||
} | ||
|
||
installedVersion := helper.DetermineVersion(gitlabUrl, gitlabApiToken) | ||
log.Info().Str("version", installedVersion.Version).Msg("GitLab") | ||
|
||
log.Info().Str("version", installedVersion.Version).Msg("Fetching CVEs for this version") | ||
vulnsJsonStr, err := nist.FetchVulns(installedVersion.Version) | ||
if err != nil { | ||
log.Fatal().Msg("Unable fetch vulnerabilities from NIST") | ||
} | ||
|
||
result := gjson.Get(vulnsJsonStr, "vulnerabilities") | ||
result.ForEach(func(key, value gjson.Result) bool { | ||
cve := value.Get("cve.id").String() | ||
description := value.Get("cve.descriptions.0.value").String() | ||
log.Info().Str("cve", cve).Str("description", description).Msg("Vulnerable") | ||
return true | ||
}) | ||
|
||
log.Info().Msg("Finished vuln scan") | ||
} |
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,29 @@ | ||
package nist | ||
|
||
import ( | ||
"github.com/CompassSecurity/pipeleak/helper" | ||
"github.com/rs/zerolog/log" | ||
"io" | ||
) | ||
|
||
func FetchVulns(version string) (string, error) { | ||
client := helper.GetNonVerifyingHTTPClient() | ||
res, err := client.Get("https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:a:gitlab:gitlab:" + version + ":*:*:*:*:*:*:*") | ||
if err != nil { | ||
return "{}", err | ||
} | ||
defer res.Body.Close() | ||
|
||
if res.StatusCode == 200 { | ||
resData, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
log.Error().Int("http", res.StatusCode).Msg("unable to read HTTP response body") | ||
return "{}", err | ||
} | ||
|
||
return string(resData), nil | ||
} else { | ||
log.Error().Int("http", res.StatusCode).Msg("failed fetching vulnerabilities") | ||
return "{}", nil | ||
} | ||
} |