Skip to content

Commit

Permalink
Merge pull request #222 from future-architect/ignore-cves
Browse files Browse the repository at this point in the history
Support ignore CveIDs in config
  • Loading branch information
kotakanbe authored Oct 17, 2016
2 parents 63f0a27 + 1e2b93d commit fff6047
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 8 deletions.
40 changes: 40 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ host = "172.31.4.82"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6313"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -488,6 +489,7 @@ host = "172.31.4.82"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6314"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -502,6 +504,7 @@ host = "172.31.4.82"
- keyPath: SSH private key path
- cpeNames: see [Usage: Scan vulnerability of non-OS package](https://github.com/future-architect/vuls/blob/master/README.ja.md#usage-scan-vulnerability-of-non-os-package)
- containers: see [Usage: Scan Docker containers](https://github.com/future-architect/vuls/blob/master/README.ja.md#usage-scan-docker-containers)
- ignoreCves: CVE IDs that will not be reported. But output to JSON file.
- optional: JSONレポートに含めたい追加情報
Expand Down Expand Up @@ -782,6 +785,43 @@ $ vuls scan \
-azure-container=vuls
```
## Example: IgnoreCves
Slack, Mail, テキスト出力しないくないCVE IDがある場合は、設定ファイルに定義することでレポートされなくなる。
ただ、JSONファイルには以下のように出力される。
- config.toml
```toml
[default]
ignoreCves = ["CVE-2016-6313"]
[servers.bsd]
host = "192.168.11.11"
user = "kanbe"
ignoreCves = ["CVE-2016-6314"]
```

- bsd.json
```json
[
{
"ServerName": "bsd",
"Family": "FreeBSD",
"Release": "10.3-RELEASE",
"IgnoredCves" : {
"CveDetail" : {
"CVE-2016-6313",
...
},
"CveDetail" : {
"CVE-2016-6314",
...
},
}
}
]
```

## Example: Add optional key-value pairs to JSON

追加情報をJSONに含めることができる。
Expand Down
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ subjectPrefix = "[vuls]"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6313"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -404,6 +405,7 @@ host = "172.31.4.82"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6313"]
#optional = [
# ["key", "value"],
#]
Expand Down Expand Up @@ -476,6 +478,7 @@ You can customize your configuration using this template.
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6313"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -495,6 +498,7 @@ You can customize your configuration using this template.
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2016-6314"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -508,6 +512,7 @@ You can customize your configuration using this template.
- keyPath: SSH private key path
- cpeNames: see [Usage: Scan vulnerability of non-OS package](https://github.com/future-architect/vuls#usage-scan-vulnerability-of-non-os-package)
- containers: see [Usage: Scan Docker containers](https://github.com/future-architect/vuls#usage-scan-docker-containers)
- ignoreCves: CVE IDs that will not be reported. But output to JSON file.
- optional: Add additional information to JSON report.
Vuls supports two types of SSH. One is native go implementation. The other is external SSH command. For details, see [-ssh-external option](https://github.com/future-architect/vuls#-ssh-external-option)
Expand Down Expand Up @@ -780,6 +785,43 @@ $ vuls scan \
-azure-container=vuls
```
## Example: IgnoreCves
Define ignoreCves in config if you don't want to report(slack, mail, text...) specific CVE IDs. But these ignoreCves will be output to JSON file like below.
- config.toml
```toml
[default]
ignoreCves = ["CVE-2016-6313"]
[servers.bsd]
host = "192.168.11.11"
user = "kanbe"
ignoreCves = ["CVE-2016-6314"]
```

- bsd.json
```json
[
{
"ServerName": "bsd",
"Family": "FreeBSD",
"Release": "10.3-RELEASE",
"IgnoredCves" : {
"CveDetail" : {
"CVE-2016-6313",
...
},
"CveDetail" : {
"CVE-2016-6314",
...
},
}
}
]
```


## Example: Add optional key-value pairs to JSON

Optional key-value can be outputted to JSON.
Expand Down Expand Up @@ -1097,4 +1139,3 @@ Please see [CHANGELOG](https://github.com/future-architect/vuls/blob/master/CHAN
# License
Please see [LICENSE](https://github.com/future-architect/vuls/blob/master/LICENSE).
2 changes: 2 additions & 0 deletions commands/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ subjectPrefix = "[vuls]"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2014-6271"]
#optional = [
# ["key", "value"],
#]
Expand All @@ -132,6 +133,7 @@ host = "{{$ip}}"
# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1",
#]
#containers = ["${running}"]
#ignoreCves = ["CVE-2014-0160"]
#optional = [
# ["key", "value"],
#]
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ type ServerInfo struct {
// Container Names or IDs
Containers []string

IgnoreCves []string

// Optional key-value set that will be outputted to JSON
Optional [][]interface{}

Expand Down
15 changes: 14 additions & 1 deletion config/tomlloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) (err error) {

i := 0
for name, v := range conf.Servers {

if 0 < len(v.KeyPassword) {
log.Warn("[Deprecated] KEYPASSWORD IN CONFIG FILE ARE UNSECURE. REMOVE THEM IMMEDIATELY FOR A SECURITY REASONS. THEY WILL BE REMOVED IN A FUTURE RELEASE.")
}
Expand Down Expand Up @@ -108,6 +107,20 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) (err error) {
s.Containers = d.Containers
}

s.IgnoreCves = v.IgnoreCves
for _, cve := range d.IgnoreCves {
found := false
for _, c := range s.IgnoreCves {
if cve == c {
found = true
break
}
}
if !found {
s.IgnoreCves = append(s.IgnoreCves, cve)
}
}

s.Optional = v.Optional
for _, dkv := range d.Optional {
found := false
Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ScanResult struct {
// NWLinks []NWLink
KnownCves []CveInfo
UnknownCves []CveInfo
IgnoredCves []CveInfo

Optional [][]interface{} `gorm:"-"`
}
Expand Down
3 changes: 0 additions & 3 deletions report/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type SlackWriter struct{}
func (w SlackWriter) Write(scanResults []models.ScanResult) error {
conf := config.Conf.Slack
for _, s := range scanResults {

channel := conf.Channel
if channel == "${servername}" {
channel = fmt.Sprintf("#%s", s.ServerName)
Expand Down Expand Up @@ -97,7 +96,6 @@ func (w SlackWriter) Write(scanResults []models.ScanResult) error {
}

func msgText(r models.ScanResult) string {

notifyUsers := ""
if 0 < len(r.KnownCves) || 0 < len(r.UnknownCves) {
notifyUsers = getNotifyUsers(config.Conf.Slack.NotifyUsers)
Expand All @@ -108,7 +106,6 @@ func msgText(r models.ScanResult) string {
}

func toSlackAttachments(scanResult models.ScanResult) (attaches []*attachment) {

cves := scanResult.KnownCves
if !config.Conf.IgnoreUnscoredCves {
cves = append(cves, scanResult.UnknownCves...)
Expand Down
27 changes: 24 additions & 3 deletions scan/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,31 @@ func (l base) isAwsInstanceID(str string) bool {
}

func (l *base) convertToModel() (models.ScanResult, error) {
var scoredCves, unscoredCves models.CveInfos
var scoredCves, unscoredCves, ignoredCves models.CveInfos
for _, p := range l.UnsecurePackages {
// ignoreCves
found := false
for _, icve := range l.getServerInfo().IgnoreCves {
if icve == p.CveDetail.CveID {
ignoredCves = append(ignoredCves, models.CveInfo{
CveDetail: p.CveDetail,
Packages: p.Packs,
DistroAdvisories: p.DistroAdvisories,
})
found = true
break
}
}
if found {
continue
}

// unscoredCves
if p.CveDetail.CvssScore(config.Conf.Lang) <= 0 {
unscoredCves = append(unscoredCves, models.CveInfo{
CveDetail: p.CveDetail,
Packages: p.Packs,
DistroAdvisories: p.DistroAdvisories, // only Amazon Linux
DistroAdvisories: p.DistroAdvisories,
})
continue
}
Expand All @@ -241,10 +259,11 @@ func (l *base) convertToModel() (models.ScanResult, error) {
models.CpeName{Name: cpename})
}

// scoredCves
cve := models.CveInfo{
CveDetail: p.CveDetail,
Packages: p.Packs,
DistroAdvisories: p.DistroAdvisories, // only Amazon Linux
DistroAdvisories: p.DistroAdvisories,
CpeNames: cpenames,
}
scoredCves = append(scoredCves, cve)
Expand All @@ -257,6 +276,7 @@ func (l *base) convertToModel() (models.ScanResult, error) {

sort.Sort(scoredCves)
sort.Sort(unscoredCves)
sort.Sort(ignoredCves)

return models.ScanResult{
ServerName: l.ServerInfo.ServerName,
Expand All @@ -267,6 +287,7 @@ func (l *base) convertToModel() (models.ScanResult, error) {
Platform: l.Platform,
KnownCves: scoredCves,
UnknownCves: unscoredCves,
IgnoredCves: ignoredCves,
Optional: l.ServerInfo.Optional,
}, nil
}
Expand Down

0 comments on commit fff6047

Please sign in to comment.