From 44fa2c5800b672b8c85b188505b37a2013517ef1 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Mon, 27 Aug 2018 13:51:09 +0900 Subject: [PATCH] v0.5.0 (no backwards compatibility) (#478) * Change config.toml, Auto-generate UUIDs, change structure of optional field * Detect processes affected by update using yum-ps (#482) Detect processes affected by update using yum-ps * Detect processes needs restart using checkrestart on Debian and Ubuntu. * pass cpename by args when calling FillCveInfo (#513) * fix new db (#502) * Include Version,Revision in JSON * Include hostname in JSON * Update goval-dictionary's commit hash in Gopkg.lock * Remove README.ja.md * update packages (#596) * fix: change ControlPath to .vuls of SSH option (#618) * feat: checkrestart for Ubuntu and Debian (#622) * feat: checkrestart for Ubuntu and Debian * fix: dependencies check logic of configtest * feat: need-restarting on RedHat * refactor: Process.ProcName to Process.Name * feat: detect a systemd service name of need-restarting-process * feat: detect a systemd service name of need-restarting-process on Ubuntu * feat: fill a service name of need-restarting-process, init-system * Support NVD JSON and CVSS3 of JVN (#605) * fix: compile errors * fix: Show CVSS3 on TUI * fix: test cases * fix: Avoid null in JSON * Fix maxCvssScore (#621) * Fix maxCvssScore * Update vulninfos.go * fix(init): remove unnecessary log initialization * refactor(nvd): use only json feed if exists json data. if not, use xml feed * fix(scan): make Confidence slice * feat(CWE): Display CWE name to TUI * feat(cwe): import CWE defs in Japanese * feat(cwe): add OWASP Top 10 ranking to CWE if applicable * feat(scan): add -fast-root mode, implement scan/amazon.go * refactor(const): change const name JVN to Jvn * feat(scan): add -fast-root mode, implement scan/centos.go * refactor(dep): update deps * fix(amazon): deps check * feat(scan): add -fast-root mode, implement scan/rhel.go * feat(scan): add -fast-root mode, implement scan/oracle.go * fix complile err * feat(scan): add -fast-root mode, implement scan/debian.go * fix testcase * fix(amazon): scan using yum * fix(configtest): change error message, status when no scannnable servers * Fix(scan): detect init process logic * fix(tui): display cvss as table format * fix(scan): parse a output of reboot-notifier on CentOS6.9 * fix(tui): don't display score, vector when score is zero * fix(scan): add -offline mode to suse scanner * fix(scan): fix help message * feat(scan): enable to define scan mode for each servers in config.toml #510 * refactor(config): chagne cpeNames to cpeURIs * refactor(config): change dependencyCheckXMLPath to owaspDCXMLPath * fix(config): containers -> containersIncluded, Excluded, containerType * feature(report): enable to define cpeURIs for each contaner * feature(report): enable to specify owasp dc xml path for each container * fix(discover): fix a template displayed at the end of discover * feature(report): add ignorePkgsRegexp #665 * feature(report): enable to define ignoreCves for each container #666 * fix(report): Displayed nothing in TUI detail area when CweID is nil * Gopkg.toml diet * feat(server): support server mode (#678) * feat(server): support server mode * Lock go version * Use the latest kernel release among the installed release when the running kernel release is unknown * Add TestViaHTTP * Set logger to go-cve-dictionary client * Add -to-localfile * Add -to-http option to report * Load -to-http conf from config.toml * Support gost (#676) * feat(gost): Support RedHat API * feat(gost): Support Debian Security Tracker * feat(db): display error msg when SQLite3 is locked at the beginning of reporting. * feat(gost): TUI * Only use RedHat information of installed packages * feat(tui): show mitigation on TUI * feat(gost): support redis backend * fix test case * fix nil pointer when db is nil * fix(gost): detect vulns of src packages for Debian * feat(gost): implement redis backend for gost redhat api * feat(report): display fixState of unfixed pkgs * fix(report): display distincted cweIDs * feat(slack): display gost info * feat(slack): display mitigation * feat(report): display available patch state as fixed/total * fix(tui): display - if source of reference is empty * update deps * fix(report): key in ScanResult JSON be lowerCamelcase. * some keys to lower camel * fix(configtest): dep check logic of yum-plugin-ps * fix(tui): format * feat(report): add -format-list option * fix(report): -format-full-text * fix(report): report -format-full-text * fix(report): display v3 score detected by gost * fix(scan): scan in fast mode if not defined in config.toml * fix(gost): fetch RedHat data for fixed CVEs * feat(report): show number of cves detected in each database * fix(report): show new version as `Unknown` in offline and fast scan mode * fix(report): fix num of upadtable and fixed * fix(report): set `Not fixed yet` if packageStatus is empty * refact(gost): make convertToModel public * fix(test): fix test case * update deps * fix(report): include gost score in MaxCvssScore * [WIP] feat(config): enable to set options in config.toml instead of cmd opt (#690) * feat(config): enable to set options in config.toml instead of cmd opt * fix(config): change Conf.Report.Slack to Conf.Slack * fix(discover): change tempalte * fix(report): fix config.toml auto-generate with -uuid * Add endpoint for health check and change endpoint * refact(cmd): refactor flag set * fix(report): enable to specify opts with cmd arg and env value * fix(scan): enable to parse the release version of amazon linux 2 * add(report) add -to-saas option (#695) * add(report) add -to-saas option * ignore other writer if -to-saas * fix(saas) fix bug * fix(scan): need-restarting needs internet connection * fix(scan,configtest): check scan mode * refactor(scan): change func name * fix(suse): support offline mode, bug fix on AWS, zypper --no-color * fix(tui): fix nil pointer when no vulns in tui * feat(report): enable to define CPE FS format in config.toml * fix(vet): fix warnings of go vet * fix(travis): go version to 1.11 * update deps --- .gitignore | 1 + .travis.yml | 2 +- GNUmakefile | 16 +- Gopkg.lock | 374 +- Gopkg.toml | 97 - README.md | 3 +- cache/bolt.go | 5 +- commands/configtest.go | 93 +- commands/discover.go | 157 +- commands/history.go | 13 +- commands/report.go | 493 +- commands/scan.go | 124 +- commands/server.go | 219 + commands/tui.go | 183 +- config/config.go | 651 ++- config/tomlloader.go | 164 +- config/tomlloader_test.go | 44 + .../owasp-dependency-check/parser/parser.go | 2 +- cwe/en.go | 5145 +++++++++++++++++ cwe/ja.go | 1027 ++++ cwe/owasp.go | 65 + gost/debian.go | 178 + gost/gost.go | 107 + gost/gost_test.go | 129 + gost/redhat.go | 253 + gost/util.go | 201 + main.go | 10 +- models/cvecontents.go | 112 +- models/cvecontents_test.go | 36 +- models/models.go | 2 +- models/packages.go | 102 +- models/scanresults.go | 267 +- models/scanresults_test.go | 466 +- models/utils.go | 140 +- models/vulninfos.go | 379 +- models/vulninfos_test.go | 356 +- oval/alpine.go | 17 +- oval/debian.go | 52 +- oval/oval.go | 54 +- oval/redhat.go | 73 +- oval/redhat_test.go | 2 +- oval/suse.go | 22 +- oval/util.go | 27 +- oval/util_test.go | 168 +- report/azureblob.go | 14 +- report/cve_client.go | 107 +- report/db_client.go | 158 + report/http.go | 62 + report/localfile.go | 12 +- report/report.go | 495 +- report/s3.go | 24 +- report/saas.go | 153 + report/slack.go | 76 +- report/stdout.go | 4 +- report/syslog.go | 7 +- report/syslog_test.go | 15 +- report/tui.go | 222 +- report/util.go | 236 +- report/util_test.go | 40 +- scan/alpine.go | 15 +- scan/amazon.go | 114 + scan/base.go | 81 +- scan/base_test.go | 42 +- scan/centos.go | 120 + scan/debian.go | 328 +- scan/debian_test.go | 136 + scan/executil.go | 2 +- scan/executil_test.go | 90 +- scan/freebsd.go | 16 +- scan/oracle.go | 167 + scan/pseudo.go | 10 +- scan/{redhat.go => redhatbase.go} | 619 +- scan/{redhat_test.go => redhatbase_test.go} | 507 +- scan/rhel.go | 159 + scan/serverapi.go | 137 +- scan/serverapi_test.go | 137 + scan/suse.go | 34 +- scan/unknownDistro.go | 12 +- scan/utils_test.go | 2 +- server/server.go | 106 + util/logutil.go | 10 +- util/util.go | 4 +- 82 files changed, 14019 insertions(+), 2485 deletions(-) create mode 100644 commands/server.go create mode 100644 config/tomlloader_test.go create mode 100644 cwe/en.go create mode 100644 cwe/ja.go create mode 100644 cwe/owasp.go create mode 100644 gost/debian.go create mode 100644 gost/gost.go create mode 100644 gost/gost_test.go create mode 100644 gost/redhat.go create mode 100644 gost/util.go create mode 100644 report/db_client.go create mode 100644 report/http.go create mode 100644 report/saas.go create mode 100644 scan/amazon.go create mode 100644 scan/centos.go create mode 100644 scan/oracle.go rename scan/{redhat.go => redhatbase.go} (65%) rename scan/{redhat_test.go => redhatbase_test.go} (74%) create mode 100644 scan/rhel.go create mode 100644 server/server.go diff --git a/.gitignore b/.gitignore index a4927490..fc852d94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ vuls .vscode *.txt +*.json *.sqlite3* *.db tags diff --git a/.travis.yml b/.travis.yml index a4c572aa..27418584 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - "1.10" + - "1.11" after_success: - test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash diff --git a/GNUmakefile b/GNUmakefile index 106afca1..d200b741 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,18 +18,18 @@ SRCS = $(shell git ls-files '*.go') PKGS = $(shell go list ./...) VERSION := $(shell git describe --tags --abbrev=0) REVISION := $(shell git rev-parse --short HEAD) -LDFLAGS := -X 'main.version=$(VERSION)' \ - -X 'main.revision=$(REVISION)' +LDFLAGS := -X 'github.com/future-architect/vuls/config.Version=$(VERSION)' \ + -X 'github.com/future-architect/vuls/config.Revision=$(REVISION)' -all: dep build test +all: dep build dep: go get -u github.com/golang/dep/... - dep ensure + dep ensure -v depup: go get -u github.com/golang/dep/... - dep ensure -update + dep ensure -update -v build: main.go dep pretest go build -ldflags "$(LDFLAGS)" -o vuls $< @@ -49,13 +49,15 @@ vet: fmt: gofmt -s -w $(SRCS) +mlint: + $(foreach file,$(SRCS),gometalinter $(file) || exit;) + fmtcheck: $(foreach file,$(SRCS),gofmt -s -d $(file);) pretest: lint vet fmtcheck -test: pretest - go install +test: echo $(PKGS) | xargs go test -cover -v || exit; unused: diff --git a/Gopkg.lock b/Gopkg.lock index c3d1e32d..b8cecd8d 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,31 +2,33 @@ [[projects]] - digest = "1:5fa4dde7611b07310d44d104e4fbebb2830cb03a2cf99798433d2f828c7012ca" + digest = "1:46ea9487304f4b3c787f54483ecb13a338d686dcd670db0ab1a112ed0ae2128e" name = "github.com/Azure/azure-sdk-for-go" packages = [ "storage", "version", ] pruneopts = "UT" - revision = "fbe7db0e3f9793ba3e5704efbab84f51436c136e" - version = "v18.0.0" + revision = "4e8cbbfb1aeab140cd0fa97fd16b64ee18c3ca6a" + version = "v19.1.0" [[projects]] - digest = "1:2de18968f9e072e3c6f9588c651a3d72780a0199f721216d4fbb29cc6f9ac201" + digest = "1:327b9226c8ea5f1cd9952ba859bb7c335cab40fd8781c4a790ef259b0c5fbc40" name = "github.com/Azure/go-autorest" packages = [ "autorest", "autorest/adal", "autorest/azure", "autorest/date", + "logger", + "version", ] pruneopts = "UT" - revision = "1f7cd6cfe0adea687ad44a512dfe76140f804318" - version = "v10.12.0" + revision = "39013ecb48eaf6ced3f4e3e1d95515140ce6b3cf" + version = "v10.15.2" [[projects]] - digest = "1:282acb7fe0ca456de4ea5c3174c2691a2bd74008462e966b69094ad0b2c23e6e" + digest = "1:b16fbfbcc20645cb419f78325bb2e85ec729b338e996a228124d68931a6f2a37" name = "github.com/BurntSushi/toml" packages = ["."] pruneopts = "UT" @@ -42,7 +44,7 @@ version = "v9" [[projects]] - digest = "1:9ecbc06b996b582f9530fd872c35ab0aa1e828fe97fa44bd24a5efef443a3852" + digest = "1:4f8b94c4cb403af4e7834e2a6455a25a5209dc61771b0d24a820ae9ae30f3f74" name = "github.com/aws/aws-sdk-go" packages = [ "aws", @@ -64,6 +66,7 @@ "aws/signer/v4", "internal/sdkio", "internal/sdkrand", + "internal/sdkuri", "internal/shareddefaults", "private/protocol", "private/protocol/eventstream", @@ -77,8 +80,8 @@ "service/sts", ] pruneopts = "UT" - revision = "66e86be40287fdef6990768b65f713f4bce11deb" - version = "v1.14.23" + revision = "4324bc9d8865bdb3e6aa86ec7772ca1272d2750e" + version = "v1.15.21" [[projects]] digest = "1:0f98f59e9a2f4070d66f0c9c39561f68fcd1dc837b22a852d28d0003aebd1b1e" @@ -97,12 +100,12 @@ version = "v2.0.0" [[projects]] - branch = "master" - digest = "1:d8cd4f14785b5ae65100524a29ebba8b9dfc5401020fe7504f80b438bb8e8e0d" + digest = "1:e04c00d619875ce5fa67180891984a9b1fadcc031af36bcd7a3509cbdad1df15" name = "github.com/cheggaaa/pb" packages = ["."] pruneopts = "UT" - revision = "2af8bbdea9e99e83b3ac400d8f6b6d1b8cbbf338" + revision = "c112833d014c77e8bde723fd0158e3156951639f" + version = "v2.0.6" [[projects]] digest = "1:76dc72490af7174349349838f2fe118996381b31ea83243812a97e5a0fd5ed55" @@ -113,15 +116,31 @@ version = "v3.2.0" [[projects]] - digest = "1:fb46255681497314debedde38b64be32a75bae50bad107586c22f1662bf2d352" + digest = "1:865079840386857c809b72ce300be7580cb50d3d3129ce11bf9aa6ca2bc1934a" + name = "github.com/fatih/color" + packages = ["."] + pruneopts = "UT" + revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4" + version = "v1.7.0" + +[[projects]] + digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd" + name = "github.com/fsnotify/fsnotify" + packages = ["."] + pruneopts = "UT" + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" + +[[projects]] + digest = "1:5abd6a22805b1919f6a6bca0ae58b13cef1f3412812f38569978f43ef02743d4" name = "github.com/go-ini/ini" packages = ["."] pruneopts = "UT" - revision = "06f5f3d67269ccec1fe5fe4134ba6e982984f7f5" - version = "v1.37.0" + revision = "5cf292cae48347c2490ac1a58fe36735fb78df7e" + version = "v1.38.2" [[projects]] - digest = "1:f0e9573388aa6e99341cbea024d15775f8209896f9f7826cd92a3044f1f8ea39" + digest = "1:ad9585b1b4361cbe8e7d8cc31af82ef5f597b9243909daa16f2c225b8af68c46" name = "github.com/go-redis/redis" packages = [ ".", @@ -134,8 +153,8 @@ "internal/util", ] pruneopts = "UT" - revision = "83fb42932f6145ce52df09860384a4653d2d332a" - version = "v6.12.0" + revision = "1614e579ed966441b8e0c3ccea1dd0fbbd93a6ae" + version = "v6.14.0" [[projects]] digest = "1:adea5a94903eb4384abef30f3d878dc9ff6b6b5b0722da25b82e5169216dfb61" @@ -146,12 +165,12 @@ version = "v1.4.0" [[projects]] - digest = "1:c4a2528ccbcabf90f9f3c464a5fc9e302d592861bbfd0b7135a7de8a943d0406" + digest = "1:586ea76dbd0374d6fb649a91d70d652b7fe0ccffb8910a77468e7702e7901f3d" name = "github.com/go-stack/stack" packages = ["."] pruneopts = "UT" - revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc" - version = "v1.7.0" + revision = "2fee6af1a9795aafbe0253a0cfbdf668e1fb8a9a" + version = "v1.8.0" [[projects]] branch = "master" @@ -162,16 +181,16 @@ revision = "5bae204cdfb2d92dcc333d56014bae6a2f6c58b1" [[projects]] - digest = "1:43dd08a10854b2056e615d1b1d22ac94559d822e1f8b6fcc92c1a1057e85188e" + digest = "1:cee8e8ac80df6373e7daa11baf1f98c1b6f7242c49ccae7e1ec34a971dc408d9" name = "github.com/gorilla/websocket" packages = ["."] pruneopts = "UT" - revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b" - version = "v1.2.0" + revision = "3ff3320c2a1756a3691521efc290b4701575147c" + version = "v1.3.0" [[projects]] branch = "master" - digest = "1:cfff48546cb55d9bfcb60078c1bb27b0cb8fbf403d8d481d7244a920359c8d7b" + digest = "1:4e08dc2383a46b3107f0b34ca338c4459e8fc8ee90e46a60e728aa8a2b21d558" name = "github.com/gosuri/uitable" packages = [ ".", @@ -181,6 +200,41 @@ pruneopts = "UT" revision = "36ee7e946282a3fb1cfecd476ddc9b35d8847e42" +[[projects]] + digest = "1:77395dd3847dac9c45118c668f5dab85aedf0163dc3b38aea6578c5cf0d502f9" + name = "github.com/hashicorp/go-version" + packages = ["."] + pruneopts = "UT" + revision = "b5a281d3160aa11950a6182bd9a9dc2cb1e02d50" + version = "v1.0.0" + +[[projects]] + digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" + name = "github.com/hashicorp/hcl" + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/printer", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token", + ] + pruneopts = "UT" + revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241" + version = "v1.0.0" + +[[projects]] + branch = "master" + digest = "1:0f8b63af5601a93b6b6a63a420c857819e98a252369262d8faf66f3566ba294e" + name = "github.com/hashicorp/uuid" + packages = ["."] + pruneopts = "UT" + revision = "ebb0a03e909c9c642a36d2527729104324c44fdb" + [[projects]] branch = "master" digest = "1:0778dc7fce1b4669a8bfa7ae506ec1f595b6ab0f8989c1c0d22a8ca1144e9972" @@ -190,15 +244,15 @@ revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8" [[projects]] - digest = "1:dacb152d24b21683403e82e4e397e973cdc218befff03b0eba8f7fbffcef325c" + digest = "1:e96640e5b9ce93e2d7ee18f48048483080fd23e72e3c38bc17e9c8b77062031a" name = "github.com/inconshreveable/log15" packages = ["."] pruneopts = "UT" - revision = "0decfc6c20d9ca0ad143b0e89dcaa20f810b4fb3" - version = "v2.13" + revision = "67afb5ed74ec82fd7ac8f49d27c509ac6f991970" + version = "v2.14" [[projects]] - digest = "1:2e8f5374b87a5afd6529a07b4bcfffe5f44ddf005c8eb581ac2863875ece8bae" + digest = "1:8fe19266ce82209076d4a81007ff93f40dd349faca4a917aea59d33956bbd4fd" name = "github.com/jinzhu/gorm" packages = [ ".", @@ -241,6 +295,18 @@ revision = "027a6d1765d673d337e687394dbe780dd64e2a1e" version = "v2.3.0" +[[projects]] + branch = "master" + digest = "1:bdf08c9b41c029c60ba5dc99443a3ce74eedad842cf2adf9c255513f432422e2" + name = "github.com/knqyf263/go-cpe" + packages = [ + "common", + "matching", + "naming", + ] + pruneopts = "UT" + revision = "659663f6eca2ff32258e282557e7808115ea498a" + [[projects]] branch = "master" digest = "1:a9955a589c7f6f28bd5a5f69da3f1e2cc857c23c7605c5fa7b605f065ba8f3fe" @@ -258,20 +324,30 @@ revision = "74609b86c936dff800c69ec89fcf4bc52d5f13a4" [[projects]] - branch = "master" - digest = "1:b6262669b4826e969fdba4f78d953c1008553e0f69a9ad3f1b2155db4108775a" + digest = "1:7f4a6b4726da539e615256d19381f7c7326255f80ec19cdbeedcc4d9d57e1831" + name = "github.com/knqyf263/gost" + packages = [ + "config", + "db", + "models", + "util", + ] + pruneopts = "UT" + revision = "e926a00c01bead2152ea43026159ec5cee7ca998" + version = "v0.1.0" + +[[projects]] + digest = "1:a0936d2be9f1dfa483fb8c2251453a9202dca2a374b1e42c7d75036a87d1c69d" name = "github.com/kotakanbe/go-cve-dictionary" packages = [ "config", "db", - "jvn", "log", "models", - "nvd", - "util", ] pruneopts = "UT" - revision = "4ee71e8b928d387bdedfd8f1a0c394bbd84f273e" + revision = "01c566055f7231f55f8551a2ae69569e0a4b9641" + version = "v0.2.0" [[projects]] digest = "1:54d3c90db1164399906830313a6fce7770917d7e4a12da8f2d8693d18ff5ef27" @@ -282,8 +358,7 @@ version = "v0.1.0" [[projects]] - branch = "master" - digest = "1:ede6d917a203511d006d81c0f491687df3e3ad81a546215831cefa2f39373ba4" + digest = "1:564a03e039dfed4121709e3d76c05c08a9d4291335ca682b5065ae46285a688a" name = "github.com/kotakanbe/goval-dictionary" packages = [ "config", @@ -292,7 +367,8 @@ "models", ] pruneopts = "UT" - revision = "f3255b2e6a0a38b88eaa25b5696d7e73868e46dc" + revision = "818624daf2658cc177ea93100ff20c5caed064b6" + version = "v0.1.0" [[projects]] branch = "master" @@ -303,8 +379,18 @@ revision = "928f7356cb964637e2489a6ef37eee55181676c5" [[projects]] - branch = "master" - digest = "1:defb20f3cbe2ee567752a32f4f5a41ed22d648654545147fb5c94e28beec3fca" + digest = "1:faee5b9f53eb1ae4eb04708c040c8c4dd685ce46509671e57a08520a15c54368" + name = "github.com/labstack/gommon" + packages = [ + "color", + "log", + ] + pruneopts = "UT" + revision = "d6898124de917583f5ff5592ef931d1dfe0ddc05" + version = "0.2.6" + +[[projects]] + digest = "1:b18ffc558326ebaed3b4a175617f1e12ed4e3f53d6ebfe5ba372a3de16d22278" name = "github.com/lib/pq" packages = [ ".", @@ -312,7 +398,16 @@ "oid", ] pruneopts = "UT" - revision = "90697d60dd844d5ef6ff15135d0203f65d2f53b8" + revision = "4ded0e9383f75c197b3a2aaa6d590ac52df6fd79" + version = "v1.0.0" + +[[projects]] + digest = "1:c568d7727aa262c32bdf8a3f7db83614f7af0ed661474b24588de635c20024c7" + name = "github.com/magiconair/properties" + packages = ["."] + pruneopts = "UT" + revision = "c2353362d570a7bfa228149c62842019201cfb71" + version = "v1.8.0" [[projects]] digest = "1:4e878df5f4e9fd625bf9c9aac77ef7cbfa4a74c01265505527c23470c0e40300" @@ -339,12 +434,12 @@ version = "v0.0.3" [[projects]] - digest = "1:e2d1d410fb367567c2b53ed9e2d719d3c1f0891397bb2fa49afd747cfbf1e8e4" + digest = "1:cdb899c199f907ac9fb50495ec71212c95cb5b0e0a8ee0800da0238036091033" name = "github.com/mattn/go-runewidth" packages = ["."] pruneopts = "UT" - revision = "9e777a8366cce605130a531d2cd6363d07ad7317" - version = "v0.0.2" + revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb" + version = "v0.0.3" [[projects]] digest = "1:3cafc6a5a1b8269605d9df4c6956d43d8011fc57f266ca6b9d04da6c09dee548" @@ -363,12 +458,20 @@ revision = "9520e82c474b0a04dd04f8a40959027271bab992" [[projects]] - branch = "master" - digest = "1:8eb17c2ec4df79193ae65b621cd1c0c4697db3bc317fe6afdc76d7f2746abd05" + digest = "1:78bbb1ba5b7c3f2ed0ea1eab57bdd3859aec7e177811563edc41198a760b06af" name = "github.com/mitchellh/go-homedir" packages = ["."] pruneopts = "UT" - revision = "3864e76763d94a6df2f9960b16a20a33da9f9a66" + revision = "ae18d6b8b3205b561c79e8e5f69bff09736185f4" + version = "v1.0.0" + +[[projects]] + digest = "1:645110e089152bd0f4a011a2648fbb0e4df5977be73ca605781157ac297f50c4" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + pruneopts = "UT" + revision = "fa473d140ef3c6adf42d6b391fe76707f1f243c8" + version = "v1.0.0" [[projects]] branch = "master" @@ -379,20 +482,28 @@ revision = "9ac6cf4d929b2fa8fd2d2e6dec5bb0feb4f4911d" [[projects]] - digest = "1:20de7c621165002b38aa0378d26e4ad0470cf2c8ecc4934f7df50d19d6c0dab0" + digest = "1:ace662a36243b5cdc2f71e654175dc192f903fafbf3411a95bc910c1cad53ce7" name = "github.com/nlopes/slack" packages = ["."] pruneopts = "UT" - revision = "8ab4d0b364ef1e9af5d102531da20d5ec902b6c4" - version = "v0.2.0" + revision = "0db1d5eae1116bf7c8ed96c6749acfbf4daaec3e" + version = "v0.3.0" [[projects]] branch = "master" - digest = "1:c9b6e36dbd23f8403a04493376916ca5dad8c01b2da5ae0a05e6a468eb0b6f24" + digest = "1:f335d800550786b6f51ddaedb9d1107a7a72f4a2195e5b039dd7c0e103e119bc" name = "github.com/nsf/termbox-go" packages = ["."] pruneopts = "UT" - revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3" + revision = "b66b20ab708e289ff1eb3e218478302e6aec28ce" + +[[projects]] + branch = "master" + digest = "1:4daa045e1e1f3e23f4b07db6880cdf9f259dab65312dfe244a878e6070faaf77" + name = "github.com/olekukonko/tablewriter" + packages = ["."] + pruneopts = "UT" + revision = "d4647c9c7a84d847478d890b816b7d8b62b0b279" [[projects]] digest = "1:d776f3e95774a8719f2e57fabbbb33103035fe072dcf6f1864f33abd17b753e5" @@ -402,6 +513,14 @@ revision = "a578a48e8d6ca8b01a3b18314c43c6716bb5f5a3" version = "v0.2.15" +[[projects]] + digest = "1:95741de3af260a92cc5c7f3f3061e85273f5a81b5db20d4bd68da74bd521675e" + name = "github.com/pelletier/go-toml" + packages = ["."] + pruneopts = "UT" + revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194" + version = "v1.2.0" + [[projects]] digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" name = "github.com/pkg/errors" @@ -428,11 +547,70 @@ [[projects]] branch = "master" - digest = "1:04330644a1b03ccdf9b31b2f98a0978e2697d967892c07c426f58676209428f6" + digest = "1:61ada1b10eccab5329199eaad8fc94048ed689969130010f592a6cc15f9afe39" name = "github.com/sirupsen/logrus" packages = ["."] pruneopts = "UT" - revision = "e54a77765aca7bbdd8e56c1c54f60579968b2dc9" + revision = "49fbef4694fb220643e975c02c9547a1cda57c26" + +[[projects]] + digest = "1:bd1ae00087d17c5a748660b8e89e1043e1e5479d0fea743352cda2f8dd8c4f84" + name = "github.com/spf13/afero" + packages = [ + ".", + "mem", + ] + pruneopts = "UT" + revision = "787d034dfe70e44075ccc060d346146ef53270ad" + version = "v1.1.1" + +[[projects]] + digest = "1:516e71bed754268937f57d4ecb190e01958452336fa73dbac880894164e91c1f" + name = "github.com/spf13/cast" + packages = ["."] + pruneopts = "UT" + revision = "8965335b8c7107321228e3e3702cab9832751bac" + version = "v1.2.0" + +[[projects]] + branch = "master" + digest = "1:8a020f916b23ff574845789daee6818daf8d25a4852419aae3f0b12378ba432a" + name = "github.com/spf13/jwalterweatherman" + packages = ["."] + pruneopts = "UT" + revision = "14d3d4c518341bea657dd8a226f5121c0ff8c9f2" + +[[projects]] + digest = "1:dab83a1bbc7ad3d7a6ba1a1cc1760f25ac38cdf7d96a5cdd55cd915a4f5ceaf9" + name = "github.com/spf13/pflag" + packages = ["."] + pruneopts = "UT" + revision = "9a97c102cda95a86cec2345a6f09f55a939babf5" + version = "v1.0.2" + +[[projects]] + digest = "1:4fc8a61287ccfb4286e1ca5ad2ce3b0b301d746053bf44ac38cf34e40ae10372" + name = "github.com/spf13/viper" + packages = ["."] + pruneopts = "UT" + revision = "907c19d40d9a6c9bb55f040ff4ae45271a4754b9" + version = "v1.1.0" + +[[projects]] + branch = "master" + digest = "1:c468422f334a6b46a19448ad59aaffdfc0a36b08fdcc1c749a0b29b6453d7e59" + name = "github.com/valyala/bytebufferpool" + packages = ["."] + pruneopts = "UT" + revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7" + +[[projects]] + branch = "master" + digest = "1:268b8bce0064e8c057d7b913605459f9a26dcab864c0886a56d196540fbf003f" + name = "github.com/valyala/fasttemplate" + packages = ["."] + pruneopts = "UT" + revision = "dcecefd839c4193db0d35b88ec65b4c12d360ab0" [[projects]] branch = "master" @@ -444,7 +622,7 @@ [[projects]] branch = "master" - digest = "1:aa95bbd7d9184ef9595b69cbd51b2a96f15627ae9d7d4f762c81860f7824dba6" + digest = "1:6019f7d49498f02cd589d41db388e11470de1f218a0a534c52353788684d8cd9" name = "golang.org/x/crypto" packages = [ "curve25519", @@ -458,11 +636,11 @@ "ssh/terminal", ] pruneopts = "UT" - revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602" + revision = "614d502a4dac94afa3a6ce146bd1736da82514c6" [[projects]] branch = "master" - digest = "1:79d16bf6031c953123613b78dffd6590ef0927cc4b02f5f2ec8b42e8d44c0508" + digest = "1:357e8a9010dc590929a02bc5602c058acea216e4c46089755e618a5a59789604" name = "golang.org/x/net" packages = [ "context", @@ -470,21 +648,21 @@ "publicsuffix", ] pruneopts = "UT" - revision = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f" + revision = "8a410e7b638dca158bf9e766925842f6651ff828" [[projects]] branch = "master" - digest = "1:72d6244a51be9611f08994aca19677fcc31676b3e7b742c37e129e6ece4ad8fc" + digest = "1:0dafafed83f125cdc945a014b2dec15e5b5d8cd2d77a2d1e3763120b08ab381b" name = "golang.org/x/sys" packages = [ "unix", "windows", ] pruneopts = "UT" - revision = "1b2967e3c290b7c545b3db0deeda16e9be4f98a2" + revision = "4910a1d54f876d7b22162a85f4d066d3ee649450" [[projects]] - digest = "1:7509ba4347d1f8de6ae9be8818b0cd1abc3deeffe28aeaf4be6d4b6b5178d9ca" + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -514,6 +692,70 @@ revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" version = "v1.1.0" +[[projects]] + digest = "1:e626376fab8608a972d47e91b3c1bbbddaecaf1d42b82be6dcc52d10a7557893" + name = "gopkg.in/VividCortex/ewma.v1" + packages = ["."] + pruneopts = "UT" + revision = "b24eb346a94c3ba12c1da1e564dbac1b498a77ce" + version = "v1.1.1" + +[[projects]] + digest = "1:d8cd4f14785b5ae65100524a29ebba8b9dfc5401020fe7504f80b438bb8e8e0d" + name = "gopkg.in/cheggaaa/pb.v1" + packages = ["."] + pruneopts = "UT" + revision = "2af8bbdea9e99e83b3ac400d8f6b6d1b8cbbf338" + version = "v1.0.25" + +[[projects]] + digest = "1:256938e7d43c73bd5e7bb97dd281d1ebe294b2928403ee1fbec96249915d1150" + name = "gopkg.in/cheggaaa/pb.v2" + packages = ["termutil"] + pruneopts = "UT" + revision = "c112833d014c77e8bde723fd0158e3156951639f" + version = "v2.0.6" + +[[projects]] + digest = "1:865079840386857c809b72ce300be7580cb50d3d3129ce11bf9aa6ca2bc1934a" + name = "gopkg.in/fatih/color.v1" + packages = ["."] + pruneopts = "UT" + revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4" + version = "v1.7.0" + +[[projects]] + digest = "1:c658e84ad3916da105a761660dcaeb01e63416c8ec7bc62256a9b411a05fcd67" + name = "gopkg.in/mattn/go-colorable.v0" + packages = ["."] + pruneopts = "UT" + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + digest = "1:d4d17353dbd05cb52a2a52b7fe1771883b682806f68db442b436294926bbfafb" + name = "gopkg.in/mattn/go-isatty.v0" + packages = ["."] + pruneopts = "UT" + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + digest = "1:cdb899c199f907ac9fb50495ec71212c95cb5b0e0a8ee0800da0238036091033" + name = "gopkg.in/mattn/go-runewidth.v0" + packages = ["."] + pruneopts = "UT" + revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb" + version = "v0.0.3" + +[[projects]] + digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "UT" + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + version = "v2.2.1" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 @@ -527,17 +769,22 @@ "github.com/aws/aws-sdk-go/aws/ec2metadata", "github.com/aws/aws-sdk-go/aws/session", "github.com/aws/aws-sdk-go/service/s3", + "github.com/aws/aws-sdk-go/service/sts", "github.com/boltdb/bolt", "github.com/cenkalti/backoff", "github.com/google/subcommands", "github.com/gosuri/uitable", + "github.com/hashicorp/uuid", "github.com/howeyc/gopass", "github.com/jroimartin/gocui", "github.com/k0kubun/pp", + "github.com/knqyf263/go-cpe/naming", "github.com/knqyf263/go-deb-version", "github.com/knqyf263/go-rpm-version", - "github.com/kotakanbe/go-cve-dictionary/config", + "github.com/knqyf263/gost/db", + "github.com/knqyf263/gost/models", "github.com/kotakanbe/go-cve-dictionary/db", + "github.com/kotakanbe/go-cve-dictionary/log", "github.com/kotakanbe/go-cve-dictionary/models", "github.com/kotakanbe/go-pingscanner", "github.com/kotakanbe/goval-dictionary/db", @@ -545,6 +792,7 @@ "github.com/kotakanbe/logrus-prefixed-formatter", "github.com/mitchellh/go-homedir", "github.com/nlopes/slack", + "github.com/olekukonko/tablewriter", "github.com/parnurzeal/gorequest", "github.com/pkg/errors", "github.com/rifflock/lfshook", diff --git a/Gopkg.toml b/Gopkg.toml index e16cb9cb..2765dc95 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -24,103 +24,6 @@ # go-tests = true # unused-packages = true - -[[constraint]] - name = "github.com/Azure/azure-sdk-for-go" - version = "18.0.0" - -[[constraint]] - name = "github.com/BurntSushi/toml" - version = "0.3.0" - -[[constraint]] - name = "github.com/asaskevich/govalidator" - version = "9.0.0" - -[[constraint]] - name = "github.com/aws/aws-sdk-go" - version = "1.14.23" - -[[constraint]] - name = "github.com/boltdb/bolt" - version = "1.3.1" - -[[constraint]] - name = "github.com/cenkalti/backoff" - version = "2.0.0" - -[[constraint]] - branch = "master" - name = "github.com/google/subcommands" - -[[constraint]] - branch = "master" - name = "github.com/gosuri/uitable" - -[[constraint]] - branch = "master" - name = "github.com/howeyc/gopass" - -[[constraint]] - name = "github.com/jroimartin/gocui" - version = "0.3.0" - -[[constraint]] - name = "github.com/k0kubun/pp" - version = "2.3.0" - -[[constraint]] - branch = "master" - name = "github.com/knqyf263/go-deb-version" - -[[constraint]] - branch = "master" - name = "github.com/knqyf263/go-rpm-version" - -[[constraint]] - name = "github.com/kotakanbe/go-cve-dictionary" - branch = "master" - -[[constraint]] - name = "github.com/kotakanbe/go-pingscanner" - version = "0.1.0" - -[[constraint]] - branch = "master" - name = "github.com/kotakanbe/goval-dictionary" - -[[constraint]] - branch = "master" - name = "github.com/kotakanbe/logrus-prefixed-formatter" - -[[constraint]] - branch = "master" - name = "github.com/mitchellh/go-homedir" - -[[constraint]] - name = "github.com/nlopes/slack" - version = "0.2.0" - -[[constraint]] - name = "github.com/parnurzeal/gorequest" - version = "0.2.15" - -[[constraint]] - name = "github.com/pkg/errors" - version = "0.8.0" - -[[constraint]] - name = "github.com/rifflock/lfshook" - version = "2.3.0" - -[[constraint]] - branch = "master" - name = "github.com/sirupsen/logrus" - -[[constraint]] - branch = "master" - name = "golang.org/x/crypto" - [prune] go-tests = true unused-packages = true diff --git a/README.md b/README.md index 57770d1a..5e2f062c 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,11 @@ Vuls is a tool created to solve the problems listed above. It has the following - Fast scan and Deep scan - Fast Scan - Scan without root privilege - - Scan with No internet access. (RedHat, CentOS, OracleLinux, Ubuntu, Debian) + - Scan with No internet access. (RedHat, CentOS, OracleLinux, Ubuntu and Debian) - Almost no load on the scan target server - Deep Scan - Scan with root privilege + - Detect processes affected by update using yum-ps (RedHat, CentOS, OracleLinux and Amazon Linux) - Parses the Changelog Changelog has a history of version changes. When a security issue is fixed, the relevant CVE ID is listed. By parsing the changelog and analysing the updates between the installed version of software on the server and the newest version of that software diff --git a/cache/bolt.go b/cache/bolt.go index fa44a7d2..bb8fcf91 100644 --- a/cache/bolt.go +++ b/cache/bolt.go @@ -183,9 +183,6 @@ func (b Bolt) PutChangelog(servername, packName, changelog string) error { if bkt == nil { return fmt.Errorf("Failed to get Bucket: %s", servername) } - if err := bkt.Put([]byte(packName), []byte(changelog)); err != nil { - return err - } - return nil + return bkt.Put([]byte(packName), []byte(changelog)) }) } diff --git a/commands/configtest.go b/commands/configtest.go index 80685602..dfe94b2a 100644 --- a/commands/configtest.go +++ b/commands/configtest.go @@ -33,20 +33,8 @@ import ( // ConfigtestCmd is Subcommand type ConfigtestCmd struct { configPath string - logDir string askKeyPassword bool - containersOnly bool - sshNative bool - sshConfig bool - httpProxy string timeoutSec int - - fast bool - offline bool - deep bool - - debug bool - vvv bool } // Name return subcommand name @@ -59,9 +47,6 @@ func (*ConfigtestCmd) Synopsis() string { return "Test configuration" } func (*ConfigtestCmd) Usage() string { return `configtest: configtest - [-fast] - [-offline] - [-deep] [-config=/path/to/config.toml] [-log-dir=/path/to/log] [-ask-key-password] @@ -83,66 +68,33 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") defaultLogDir := util.GetDefaultLogDir() - f.StringVar(&p.logDir, "log-dir", defaultLogDir, "/path/to/log") - - f.BoolVar(&p.debug, "debug", false, "debug mode") + f.StringVar(&c.Conf.LogDir, "log-dir", defaultLogDir, "/path/to/log") + f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode") f.IntVar(&p.timeoutSec, "timeout", 5*60, "Timeout(Sec)") - f.BoolVar( - &p.askKeyPassword, - "ask-key-password", - false, + f.BoolVar(&p.askKeyPassword, "ask-key-password", false, "Ask ssh privatekey password before scanning", ) - f.BoolVar( - &p.fast, - "fast", - false, - "Config test for online fast scan mode") + f.StringVar(&c.Conf.HTTPProxy, "http-proxy", "", + "http://proxy-url:port (default: empty)") - f.BoolVar( - &p.offline, - "offline", - false, - "Config test for offline scan mode") - - f.BoolVar(&p.deep, "deep", false, "Config test for deep scan mode") - - f.StringVar( - &p.httpProxy, - "http-proxy", - "", - "http://proxy-url:port (default: empty)", - ) - - f.BoolVar( - &p.sshNative, - "ssh-native-insecure", - false, + f.BoolVar(&c.Conf.SSHNative, "ssh-native-insecure", false, "Use Native Go implementation of SSH. Default: Use the external command") - f.BoolVar( - &p.sshConfig, - "ssh-config", - false, + f.BoolVar(&c.Conf.SSHConfig, "ssh-config", false, "Use SSH options specified in ssh_config preferentially") - f.BoolVar( - &p.containersOnly, - "containers-only", - false, + f.BoolVar(&c.Conf.ContainersOnly, "containers-only", false, "Test containers only. Default: Test both of hosts and containers") - f.BoolVar(&p.vvv, "vvv", false, "ssh -vvv") + f.BoolVar(&c.Conf.Vvv, "vvv", false, "ssh -vvv") } // Execute execute func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { // Setup Logger - c.Conf.Debug = p.debug - c.Conf.LogDir = p.logDir util.Log = util.NewCustomLogger(c.ServerInfo{}) if err := mkdirDotVuls(); err != nil { @@ -167,19 +119,6 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa util.Log.Errorf("Please check README: https://github.com/future-architect/vuls#configuration") return subcommands.ExitUsageError } - c.Conf.SSHNative = p.sshNative - c.Conf.SSHConfig = p.sshConfig - - c.Conf.HTTPProxy = p.httpProxy - c.Conf.ContainersOnly = p.containersOnly - - c.Conf.Fast = p.fast - c.Conf.Offline = p.offline - c.Conf.Deep = p.deep - if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) { - c.Conf.Fast = true - } - c.Conf.Vvv = p.vvv var servernames []string if 0 < len(f.Args()) { @@ -216,12 +155,22 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa return subcommands.ExitFailure } + util.Log.Info("Checking Scan Modes...") + if err := scan.CheckScanModes(); err != nil { + util.Log.Errorf("Fix config.toml: %s", err) + return subcommands.ExitFailure + } + util.Log.Info("Checking dependencies...") scan.CheckDependencies(p.timeoutSec) util.Log.Info("Checking sudo settings...") scan.CheckIfSudoNoPasswd(p.timeoutSec) - scan.PrintSSHableServerNames() - return subcommands.ExitSuccess + util.Log.Info("It can be scanned with fast scan mode even if warn or err messages are displayed due to lack of dependent packages or sudo settings in fast-root or deep scan mode") + + if scan.PrintSSHableServerNames() { + return subcommands.ExitSuccess + } + return subcommands.ExitFailure } diff --git a/commands/discover.go b/commands/discover.go index f17afbcd..f87210d4 100644 --- a/commands/discover.go +++ b/commands/discover.go @@ -90,61 +90,130 @@ func (p *DiscoverCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface // Output the template of config.toml func printConfigToml(ips []string) (err error) { const tomlTemplate = ` -[slack] -hookURL = "https://hooks.slack.com/services/abc123/defghijklmnopqrstuvwxyz" -#legacyToken = "xoxp-11111111111-222222222222-3333333333" -channel = "#channel-name" -#channel = "${servername}" -iconEmoji = ":ghost:" -authUser = "username" -notifyUsers = ["@username"] -[email] -smtpAddr = "smtp.example.com" -smtpPort = "587" -user = "username" -password = "password" -from = "from@example.com" -to = ["to@example.com"] -cc = ["cc@example.com"] -subjectPrefix = "[vuls]" +# TODO Doc Link +[cveDict] +type = "sqlite3" +sqlite3Path = "/path/to/cve.sqlite3" +#url = "" +# TODO Doc Link +[ovalDict] +type = "sqlite3" +sqlite3Path = "/path/to/oval.sqlite3" +#url = "" + +# TODO Doc Link +[gost] +type = "sqlite3" +sqlite3Path = "/path/to/gost.sqlite3" +#url = "" + +# https://vuls.io/docs/en/usage-settings.html#slack-section +#[slack] +#hookURL = "https://hooks.slack.com/services/abc123/defghijklmnopqrstuvwxyz" +##legacyToken = "xoxp-11111111111-222222222222-3333333333" +#channel = "#channel-name" +##channel = "${servername}" +#iconEmoji = ":ghost:" +#authUser = "username" +#notifyUsers = ["@username"] + +# https://vuls.io/docs/en/usage-settings.html#email-section +#[email] +#smtpAddr = "smtp.example.com" +#smtpPort = "587" +#user = "username" +#password = "password" +#from = "from@example.com" +#to = ["to@example.com"] +#cc = ["cc@example.com"] +#subjectPrefix = "[vuls]" + +# https://vuls.io/docs/en/usage-settings.html#http-section +#[http] +#url = "http://localhost:11234" + +# https://vuls.io/docs/en/usage-settings.html#syslog-section +#[syslog] +#protocol = "tcp" +#host = "localhost" +#port = "514" +#tag = "vuls" +#facility = "local0" +#severity = "alert" +#verbose = false + +# https://vuls.io/docs/en/usage-report.html#example-put-results-in-s3-bucket +#[aws] +#profile = "default" +#region = "ap-northeast-1" +#s3Bucket = "vuls" +#s3ResultsDir = "/path/to/result" +#s3ServerSideEncryption = "AES256" + +# https://vuls.io/docs/en/usage-report.html#example-put-results-in-azure-blob-storage +#[azure] +#accountName = "default" +#accountKey = "xxxxxxxxxxxxxx" +#containerName = "vuls" + +# https://vuls.io/docs/en/usage-settings.html#stride-section +#[stride] +#hookURL = "xxxxxxxxxxxxxxx" +#authToken = "xxxxxxxxxxxxxx" + +# https://vuls.io/docs/en/usage-settings.html#hipchat-section +#[hipchat] +#room = "vuls" +#authToken = "xxxxxxxxxxxxxx" + +# https://vuls.io/docs/en/usage-settings.html#chatwork-section +#[chatwork] +#room = "xxxxxxxxxxx" +#apiToken = "xxxxxxxxxxxxxxxxxx" + +# https://vuls.io/docs/en/usage-settings.html#default-section [default] -#port = "22" -#user = "username" -#keyPath = "/home/username/.ssh/id_rsa" +#port = "22" +#user = "username" +#keyPath = "/home/username/.ssh/id_rsa" +#scanMode = ["fast", "fast-root", "deep", "offline"] #cpeNames = [ # "cpe:/a:rubyonrails:ruby_on_rails:4.2.1", #] -#dependencyCheckXMLPath = "/tmp/dependency-check-report.xml" -#ignoreCves = ["CVE-2014-6271"] -#optional = [ -# ["key", "value"], -#] -#containers = ["${running}"] - +#owaspDCXMLPath = "/tmp/dependency-check-report.xml" +#ignoreCves = ["CVE-2014-6271"] +#containerType = "docker" #or "lxd" or "lxc" default: docker +#containersIncluded = ["${running}"] +#containersExcluded = ["container_name_a"] +# https://vuls.io/docs/en/usage-settings.html#servers-section [servers] {{- $names:= .Names}} {{range $i, $ip := .IPs}} [servers.{{index $names $i}}] -host = "{{$ip}}" -#port = "22" -#user = "root" -#keyPath = "/home/username/.ssh/id_rsa" -#type = "pseudo" -#cpeNames = [ -# "cpe:/a:rubyonrails:ruby_on_rails:4.2.1", -#] -#dependencyCheckXMLPath = "/tmp/dependency-check-report.xml" -#ignoreCves = ["CVE-2014-0160"] -#optional = [ -# ["key", "value"], -#] -#[servers.{{index $names $i}}.containers] -#type = "docker" #or "lxd" default: docker -#includes = ["${running}"] -#excludes = ["container_name_a", "4aa37a8b63b9"] +host = "{{$ip}}" +#port = "22" +#user = "root" +#keyPath = "/home/username/.ssh/id_rsa" +#scanMode = ["fast", "fast-root", "deep", "offline"] +#type = "pseudo" +#memo = "DB Server" +#cpeNames = [ "cpe:/a:rubyonrails:ruby_on_rails:4.2.1" ] +#owaspDCXMLPath = "/path/to/dependency-check-report.xml" +#ignoreCves = ["CVE-2014-0160"] +#containerType = "docker" #or "lxd" or "lxc" default: docker +#containersIncluded = ["${running}"] +#containersExcluded = ["container_name_a"] + +#[servers.{{index $names $i}}.containers.container_name_a] +#cpeNames = [ "cpe:/a:rubyonrails:ruby_on_rails:4.2.1" ] +#owaspDCXMLPath = "/path/to/dependency-check-report.xml" +#ignoreCves = ["CVE-2014-0160"] + +#[servers.{{index $names $i}}.optional] +#key = "value1" {{end}} diff --git a/commands/history.go b/commands/history.go index fad48c9c..163e04f0 100644 --- a/commands/history.go +++ b/commands/history.go @@ -32,11 +32,7 @@ import ( ) // HistoryCmd is Subcommand of list scanned results -type HistoryCmd struct { - debug bool - debugSQL bool - resultsDir string -} +type HistoryCmd struct{} // Name return subcommand name func (*HistoryCmd) Name() string { return "history" } @@ -56,19 +52,16 @@ func (*HistoryCmd) Usage() string { // SetFlags set flag func (p *HistoryCmd) SetFlags(f *flag.FlagSet) { - f.BoolVar(&p.debugSQL, "debug-sql", false, "SQL debug mode") + f.BoolVar(&c.Conf.DebugSQL, "debug-sql", false, "SQL debug mode") wd, _ := os.Getwd() defaultResultsDir := filepath.Join(wd, "results") - f.StringVar(&p.resultsDir, "results-dir", defaultResultsDir, "/path/to/results") + f.StringVar(&c.Conf.ResultsDir, "results-dir", defaultResultsDir, "/path/to/results") } // Execute execute func (p *HistoryCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { - c.Conf.DebugSQL = p.debugSQL - c.Conf.ResultsDir = p.resultsDir - dirs, err := report.ListValidJSONDirs() if err != nil { return subcommands.ExitFailure diff --git a/commands/report.go b/commands/report.go index 09723472..7f90205a 100644 --- a/commands/report.go +++ b/commands/report.go @@ -20,73 +20,27 @@ package commands import ( "context" "flag" - "fmt" "os" "path/filepath" c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/gost" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/oval" "github.com/future-architect/vuls/report" "github.com/future-architect/vuls/util" "github.com/google/subcommands" + "github.com/k0kubun/pp" + cvelog "github.com/kotakanbe/go-cve-dictionary/log" ) // ReportCmd is subcommand for reporting type ReportCmd struct { - lang string - debug bool - debugSQL bool configPath string - resultsDir string - logDir string - refreshCve bool - - cvssScoreOver float64 - ignoreUnscoredCves bool - ignoreUnfixed bool - - httpProxy string - - cveDBType string - cveDBPath string - cveDBURL string - - ovalDBType string - ovalDBPath string - ovalDBURL string - - toSlack bool - toStride bool - toHipChat bool - toChatWork bool - toEMail bool - toSyslog bool - toLocalFile bool - toS3 bool - toAzureBlob bool - - formatJSON bool - formatXML bool - formatOneEMail bool - formatOneLineText bool - formatShortText bool - formatFullText bool - - gzip bool - - awsProfile string - awsRegion string - awsS3Bucket string - awsS3ResultsDir string - awsS3ServerSideEncryption string - - azureAccount string - azureKey string - azureContainer string - - pipe bool - diff bool + cvelDict c.GoCveDictConf + ovalDict c.GovalDictConf + gostConf c.GostConf + httpConf c.HTTPConf } // Name return subcommand name @@ -104,17 +58,12 @@ func (*ReportCmd) Usage() string { [-results-dir=/path/to/results] [-log-dir=/path/to/log] [-refresh-cve] - [-cvedb-type=sqlite3|mysql|postgres] - [-cvedb-path=/path/to/cve.sqlite3] - [-cvedb-url=http://127.0.0.1:1323 or DB connection string] - [-ovaldb-type=sqlite3|mysql] - [-ovaldb-path=/path/to/oval.sqlite3] - [-ovaldb-url=http://127.0.0.1:1324 or DB connection string] [-cvss-over=7] [-diff] [-ignore-unscored-cves] [-ignore-unfixed] [-to-email] + [-to-http] [-to-slack] [-to-stride] [-to-hipchat] @@ -122,25 +71,29 @@ func (*ReportCmd) Usage() string { [-to-localfile] [-to-s3] [-to-azure-blob] + [-to-saas] [-format-json] [-format-xml] [-format-one-email] [-format-one-line-text] - [-format-short-text] + [-format-list] [-format-full-text] [-gzip] - [-aws-profile=default] - [-aws-region=us-west-2] - [-aws-s3-bucket=bucket_name] - [-aws-s3-results-dir=/bucket/path/to/results] - [-aws-s3-server-side-encryption=AES256] - [-azure-account=account] - [-azure-key=key] - [-azure-container=container] + [-uuid] [-http-proxy=http://192.168.0.1:8080] [-debug] [-debug-sql] [-pipe] + [-cvedb-type=sqlite3|mysql|postgres|redis] + [-cvedb-path=/path/to/cve.sqlite3] + [-cvedb-url=http://127.0.0.1:1323 or DB connection string] + [-ovaldb-type=sqlite3|mysql|redis] + [-ovaldb-path=/path/to/oval.sqlite3] + [-ovaldb-url=http://127.0.0.1:1324 or DB connection string] + [-gostdb-type=sqlite3|mysql|redis] + [-gostdb-path=/path/to/gost.sqlite3] + [-gostdb-url=http://127.0.0.1:1325 or DB connection string] + [-http="http://vuls-report-server"] [RFC3339 datetime format under results dir] ` @@ -148,218 +101,110 @@ func (*ReportCmd) Usage() string { // SetFlags set flag func (p *ReportCmd) SetFlags(f *flag.FlagSet) { - f.StringVar(&p.lang, "lang", "en", "[en|ja]") - f.BoolVar(&p.debug, "debug", false, "debug mode") - f.BoolVar(&p.debugSQL, "debug-sql", false, "SQL debug mode") + f.StringVar(&c.Conf.Lang, "lang", "en", "[en|ja]") + f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode") + f.BoolVar(&c.Conf.DebugSQL, "debug-sql", false, "SQL debug mode") wd, _ := os.Getwd() - defaultConfPath := filepath.Join(wd, "config.toml") f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") defaultResultsDir := filepath.Join(wd, "results") - f.StringVar(&p.resultsDir, "results-dir", defaultResultsDir, "/path/to/results") + f.StringVar(&c.Conf.ResultsDir, "results-dir", defaultResultsDir, "/path/to/results") defaultLogDir := util.GetDefaultLogDir() - f.StringVar(&p.logDir, "log-dir", defaultLogDir, "/path/to/log") + f.StringVar(&c.Conf.LogDir, "log-dir", defaultLogDir, "/path/to/log") - f.BoolVar( - &p.refreshCve, - "refresh-cve", - false, + f.BoolVar(&c.Conf.RefreshCve, "refresh-cve", false, "Refresh CVE information in JSON file under results dir") - f.StringVar( - &p.cveDBType, - "cvedb-type", - "sqlite3", - "DB type for fetching CVE dictionary (sqlite3, mysql or postgres)") - - defaultCveDBPath := filepath.Join(wd, "cve.sqlite3") - f.StringVar( - &p.cveDBPath, - "cvedb-path", - defaultCveDBPath, - "/path/to/sqlite3 (For get cve detail from cve.sqlite3)") - - f.StringVar( - &p.cveDBURL, - "cvedb-url", - "", - "http://cve-dictionary.com:1323 or mysql connection string") - - f.StringVar( - &p.ovalDBType, - "ovaldb-type", - "sqlite3", - "DB type for fetching OVAL dictionary (sqlite3 or mysql)") - - defaultOvalDBPath := filepath.Join(wd, "oval.sqlite3") - f.StringVar( - &p.ovalDBPath, - "ovaldb-path", - defaultOvalDBPath, - "/path/to/sqlite3 (For get oval detail from oval.sqlite3)") - - f.StringVar( - &p.ovalDBURL, - "ovaldb-url", - "", - "http://goval-dictionary.com:1324 or mysql connection string") - - f.Float64Var( - &p.cvssScoreOver, - "cvss-over", - 0, + f.Float64Var(&c.Conf.CvssScoreOver, "cvss-over", 0, "-cvss-over=6.5 means reporting CVSS Score 6.5 and over (default: 0 (means report all))") - f.BoolVar(&p.diff, - "diff", - false, - fmt.Sprintf("Difference between previous result and current result ")) + f.BoolVar(&c.Conf.Diff, "diff", false, + "Difference between previous result and current result ") - f.BoolVar( - &p.ignoreUnscoredCves, - "ignore-unscored-cves", - false, + f.BoolVar(&c.Conf.IgnoreUnscoredCves, "ignore-unscored-cves", false, "Don't report the unscored CVEs") f.BoolVar( - &p.ignoreUnfixed, - "ignore-unfixed", - false, + &c.Conf.IgnoreUnfixed, "ignore-unfixed", false, "Don't report the unfixed CVEs") f.StringVar( - &p.httpProxy, - "http-proxy", - "", + &c.Conf.HTTPProxy, "http-proxy", "", "http://proxy-url:port (default: empty)") - f.BoolVar(&p.formatJSON, - "format-json", - false, - fmt.Sprintf("JSON format")) - - f.BoolVar(&p.formatXML, - "format-xml", - false, - fmt.Sprintf("XML format")) - - f.BoolVar(&p.formatOneEMail, - "format-one-email", - false, + f.BoolVar(&c.Conf.FormatJSON, "format-json", false, "JSON format") + f.BoolVar(&c.Conf.FormatXML, "format-xml", false, "XML format") + f.BoolVar(&c.Conf.FormatOneEMail, "format-one-email", false, "Send all the host report via only one EMail (Specify with -to-email)") + f.BoolVar(&c.Conf.FormatOneLineText, "format-one-line-text", false, + "One line summary in plain text") + f.BoolVar(&c.Conf.FormatList, "format-list", false, "Display as list format") + f.BoolVar(&c.Conf.FormatFullText, "format-full-text", false, + "Detail report in plain text") - f.BoolVar(&p.formatOneLineText, - "format-one-line-text", - false, - fmt.Sprintf("One line summary in plain text")) - - f.BoolVar(&p.formatShortText, - "format-short-text", - false, - fmt.Sprintf("Summary in plain text")) - - f.BoolVar(&p.formatFullText, - "format-full-text", - false, - fmt.Sprintf("Detail report in plain text")) - - f.BoolVar(&p.gzip, "gzip", false, "gzip compression") - - f.BoolVar(&p.toSlack, "to-slack", false, "Send report via Slack") - f.BoolVar(&p.toStride, "to-stride", false, "Send report via Stride") - f.BoolVar(&p.toHipChat, "to-hipchat", false, "Send report via hipchat") - f.BoolVar(&p.toChatWork, "to-chatwork", false, "Send report via chatwork") - f.BoolVar(&p.toEMail, "to-email", false, "Send report via Email") - f.BoolVar(&p.toSyslog, "to-syslog", false, "Send report via Syslog") - f.BoolVar(&p.toLocalFile, - "to-localfile", - false, - fmt.Sprintf("Write report to localfile")) - - f.BoolVar(&p.toS3, - "to-s3", - false, + f.BoolVar(&c.Conf.ToSlack, "to-slack", false, "Send report via Slack") + f.BoolVar(&c.Conf.ToStride, "to-stride", false, "Send report via Stride") + f.BoolVar(&c.Conf.ToHipChat, "to-hipchat", false, "Send report via hipchat") + f.BoolVar(&c.Conf.ToChatWork, "to-chatwork", false, "Send report via chatwork") + f.BoolVar(&c.Conf.ToEmail, "to-email", false, "Send report via Email") + f.BoolVar(&c.Conf.ToSyslog, "to-syslog", false, "Send report via Syslog") + f.BoolVar(&c.Conf.ToLocalFile, "to-localfile", false, "Write report to localfile") + f.BoolVar(&c.Conf.ToS3, "to-s3", false, "Write report to S3 (bucket/yyyyMMdd_HHmm/servername.json/xml/txt)") - f.StringVar(&p.awsProfile, "aws-profile", "default", "AWS profile to use") - f.StringVar(&p.awsRegion, "aws-region", "us-east-1", "AWS region to use") - f.StringVar(&p.awsS3Bucket, "aws-s3-bucket", "", "S3 bucket name") - f.StringVar(&p.awsS3ResultsDir, "aws-s3-results-dir", "", "/bucket/path/to/results") - f.StringVar(&p.awsS3ServerSideEncryption, "aws-s3-server-side-encryption", "", "The Server-side encryption algorithm used when storing the reports in S3 (e.g., AES256, aws:kms).") - - f.BoolVar(&p.toAzureBlob, - "to-azure-blob", - false, + f.BoolVar(&c.Conf.ToHTTP, "to-http", false, "Send report via HTTP POST") + f.BoolVar(&c.Conf.ToAzureBlob, "to-azure-blob", false, "Write report to Azure Storage blob (container/yyyyMMdd_HHmm/servername.json/xml/txt)") - f.StringVar(&p.azureAccount, - "azure-account", - "", - "Azure account name to use. AZURE_STORAGE_ACCOUNT environment variable is used if not specified") - f.StringVar(&p.azureKey, - "azure-key", - "", - "Azure account key to use. AZURE_STORAGE_ACCESS_KEY environment variable is used if not specified") - f.StringVar(&p.azureContainer, "azure-container", "", "Azure storage container name") + f.BoolVar(&c.Conf.ToSaas, "to-saas", false, + "Upload report to Future Vuls(https://vuls.biz/) before report") + + f.BoolVar(&c.Conf.GZIP, "gzip", false, "gzip compression") + f.BoolVar(&c.Conf.UUID, "uuid", false, + "Auto generate of scan target servers and then write to config.toml and scan result") + f.BoolVar(&c.Conf.Pipe, "pipe", false, "Use args passed via PIPE") + + f.StringVar(&p.cvelDict.Type, "cvedb-type", "sqlite3", + "DB type of go-cve-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.cvelDict.SQLite3Path, "cvedb-sqlite3-path", "", "/path/to/sqlite3") + f.StringVar(&p.cvelDict.URL, "cvedb-url", "", + "http://go-cve-dictionary.com:1323 or DB connection string") + + f.StringVar(&p.ovalDict.Type, "ovaldb-type", "", + "DB type of goval-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.ovalDict.SQLite3Path, "ovaldb-sqlite3-path", "", "/path/to/sqlite3") + f.StringVar(&p.ovalDict.URL, "ovaldb-url", "", + "http://goval-dictionary.com:1324 or DB connection string") + + f.StringVar(&p.gostConf.Type, "gostdb-type", "", + "DB type of gost (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.gostConf.SQLite3Path, "gostdb-sqlite3-path", "", "/path/to/sqlite3") + f.StringVar(&p.gostConf.URL, "gostdb-url", "", + "http://gost.com:1325 or DB connection string") + + f.StringVar(&p.httpConf.URL, "http", "", "-to-http http://vuls-report") - f.BoolVar( - &p.pipe, - "pipe", - false, - "Use args passed via PIPE") } // Execute execute func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { - c.Conf.Debug = p.debug - c.Conf.DebugSQL = p.debugSQL - c.Conf.LogDir = p.logDir util.Log = util.NewCustomLogger(c.ServerInfo{}) + cvelog.SetLogger(c.Conf.LogDir, false, c.Conf.Debug, false) if err := c.Load(p.configPath, ""); err != nil { util.Log.Errorf("Error loading %s, %s", p.configPath, err) return subcommands.ExitUsageError } - c.Conf.Lang = p.lang - c.Conf.ResultsDir = p.resultsDir - c.Conf.RefreshCve = p.refreshCve - c.Conf.CveDBType = p.cveDBType - c.Conf.CveDBPath = p.cveDBPath - c.Conf.CveDBURL = p.cveDBURL - c.Conf.OvalDBType = p.ovalDBType - c.Conf.OvalDBPath = p.ovalDBPath - c.Conf.OvalDBURL = p.ovalDBURL - c.Conf.CvssScoreOver = p.cvssScoreOver - c.Conf.IgnoreUnscoredCves = p.ignoreUnscoredCves - c.Conf.IgnoreUnfixed = p.ignoreUnfixed - c.Conf.HTTPProxy = p.httpProxy - - c.Conf.ToSlack = p.toSlack - c.Conf.ToStride = p.toStride - c.Conf.ToHipChat = p.toHipChat - c.Conf.ToChatWork = p.toChatWork - c.Conf.ToEmail = p.toEMail - c.Conf.ToSyslog = p.toSyslog - c.Conf.ToLocalFile = p.toLocalFile - c.Conf.ToS3 = p.toS3 - c.Conf.ToAzureBlob = p.toAzureBlob - - c.Conf.FormatXML = p.formatXML - c.Conf.FormatJSON = p.formatJSON - c.Conf.FormatOneEMail = p.formatOneEMail - c.Conf.FormatOneLineText = p.formatOneLineText - c.Conf.FormatShortText = p.formatShortText - c.Conf.FormatFullText = p.formatFullText - - c.Conf.GZIP = p.gzip - c.Conf.Diff = p.diff - c.Conf.Pipe = p.pipe + c.Conf.CveDict.Overwrite(p.cvelDict) + c.Conf.OvalDict.Overwrite(p.ovalDict) + c.Conf.Gost.Overwrite(p.gostConf) + c.Conf.HTTP.Overwrite(p.httpConf) var dir string var err error - if p.diff { + if c.Conf.Diff { dir, err = report.JSONDir([]string{}) } else { dir, err = report.JSONDir(f.Args()) @@ -374,107 +219,87 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{} report.StdoutWriter{}, } - if p.toSlack { + if c.Conf.ToSlack { reports = append(reports, report.SlackWriter{}) } - if p.toStride { + if c.Conf.ToStride { reports = append(reports, report.StrideWriter{}) } - if p.toHipChat { + if c.Conf.ToHipChat { reports = append(reports, report.HipChatWriter{}) } - if p.toChatWork { + if c.Conf.ToChatWork { reports = append(reports, report.ChatWorkWriter{}) } - if p.toEMail { + if c.Conf.ToEmail { reports = append(reports, report.EMailWriter{}) } - if p.toSyslog { + if c.Conf.ToSyslog { reports = append(reports, report.SyslogWriter{}) } - if p.toLocalFile { + if c.Conf.ToHTTP { + reports = append(reports, report.HTTPRequestWriter{}) + } + + if c.Conf.ToLocalFile { reports = append(reports, report.LocalFileWriter{ CurrentDir: dir, }) } - if p.toS3 { - c.Conf.AwsRegion = p.awsRegion - c.Conf.AwsProfile = p.awsProfile - c.Conf.S3Bucket = p.awsS3Bucket - c.Conf.S3ResultsDir = p.awsS3ResultsDir - c.Conf.S3ServerSideEncryption = p.awsS3ServerSideEncryption + if c.Conf.ToS3 { if err := report.CheckIfBucketExists(); err != nil { - util.Log.Errorf("Check if there is a bucket beforehand: %s, err: %s", c.Conf.S3Bucket, err) + util.Log.Errorf("Check if there is a bucket beforehand: %s, err: %s", + c.Conf.AWS.S3Bucket, err) return subcommands.ExitUsageError } reports = append(reports, report.S3Writer{}) } - if p.toAzureBlob { - c.Conf.AzureAccount = p.azureAccount - if len(c.Conf.AzureAccount) == 0 { - c.Conf.AzureAccount = os.Getenv("AZURE_STORAGE_ACCOUNT") + if c.Conf.ToAzureBlob { + if len(c.Conf.Azure.AccountName) == 0 { + c.Conf.Azure.AccountName = os.Getenv("AZURE_STORAGE_ACCOUNT") } - c.Conf.AzureKey = p.azureKey - if len(c.Conf.AzureKey) == 0 { - c.Conf.AzureKey = os.Getenv("AZURE_STORAGE_ACCESS_KEY") + if len(c.Conf.Azure.AccountKey) == 0 { + c.Conf.Azure.AccountKey = os.Getenv("AZURE_STORAGE_ACCESS_KEY") } - c.Conf.AzureContainer = p.azureContainer - if len(c.Conf.AzureContainer) == 0 { + if len(c.Conf.Azure.ContainerName) == 0 { util.Log.Error("Azure storage container name is required with -azure-container option") return subcommands.ExitUsageError } if err := report.CheckIfAzureContainerExists(); err != nil { - util.Log.Errorf("Check if there is a container beforehand: %s, err: %s", c.Conf.AzureContainer, err) + util.Log.Errorf("Check if there is a container beforehand: %s, err: %s", + c.Conf.Azure.ContainerName, err) return subcommands.ExitUsageError } reports = append(reports, report.AzureBlobWriter{}) } - if !(p.formatJSON || p.formatOneLineText || - p.formatShortText || p.formatFullText || p.formatXML) { - c.Conf.FormatShortText = true + if c.Conf.ToSaas { + if !c.Conf.UUID { + util.Log.Errorf("If you use the -to-saas option, you need to enable the uuid option") + return subcommands.ExitUsageError + } + reports = append(reports, report.SaasWriter{}) + } + + if !(c.Conf.FormatJSON || c.Conf.FormatOneLineText || + c.Conf.FormatList || c.Conf.FormatFullText || c.Conf.FormatXML) { + c.Conf.FormatList = true } util.Log.Info("Validating config...") if !c.Conf.ValidateOnReport() { return subcommands.ExitUsageError } - if err := report.CveClient.CheckHealth(); err != nil { - util.Log.Errorf("CVE HTTP server is not running. err: %s", err) - util.Log.Errorf("Run go-cve-dictionary as server mode before reporting or run with -cvedb-path option") - return subcommands.ExitFailure - } - if c.Conf.CveDBURL != "" { - util.Log.Infof("cve-dictionary: %s", c.Conf.CveDBURL) - } else { - if c.Conf.CveDBType == "sqlite3" { - util.Log.Infof("cve-dictionary: %s", c.Conf.CveDBPath) - } - } - - if c.Conf.OvalDBURL != "" { - util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDBURL) - err := oval.Base{}.CheckHTTPHealth() - if err != nil { - util.Log.Errorf("OVAL HTTP server is not running. err: %s", err) - util.Log.Errorf("Run goval-dictionary as server mode before reporting or run with -ovaldb-path option") - return subcommands.ExitFailure - } - } else { - if c.Conf.OvalDBType == "sqlite3" { - util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDBPath) - } - } var loaded models.ScanResults if loaded, err = report.LoadScanResults(dir); err != nil { @@ -493,9 +318,86 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{} } } - if res, err = report.FillCveInfos(res, dir); err != nil { - util.Log.Error(err) - return subcommands.ExitFailure + for _, r := range res { + util.Log.Debugf("%s: %s", + r.ServerInfo(), + pp.Sprintf("%s", c.Conf.Servers[r.ServerName])) + } + + if c.Conf.UUID { + // Ensure UUIDs of scan target servers in config.toml + if err := report.EnsureUUIDs(p.configPath, res); err != nil { + util.Log.Errorf("Failed to ensure UUIDs: %s", err) + return subcommands.ExitFailure + } + } + + if !c.Conf.ToSaas { + util.Log.Info("Validating db config...") + if !c.Conf.ValidateOnReportDB() { + return subcommands.ExitUsageError + } + + if err := report.CveClient.CheckHealth(); err != nil { + util.Log.Errorf("CVE HTTP server is not running. err: %s", err) + util.Log.Errorf("Run go-cve-dictionary as server mode before reporting or run with -cvedb-path option instead of -cvedb-url") + return subcommands.ExitFailure + } + if c.Conf.CveDict.URL != "" { + util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.URL) + } else { + if c.Conf.CveDict.Type == "sqlite3" { + util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.SQLite3Path) + } + } + + if c.Conf.OvalDict.URL != "" { + util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.URL) + err := oval.Base{}.CheckHTTPHealth() + if err != nil { + util.Log.Errorf("OVAL HTTP server is not running. err: %s", err) + util.Log.Errorf("Run goval-dictionary as server mode before reporting or run with -ovaldb-path option instead of -ovaldb-url") + return subcommands.ExitFailure + } + } else { + if c.Conf.OvalDict.Type == "sqlite3" { + util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.SQLite3Path) + } + } + + if c.Conf.Gost.URL != "" { + util.Log.Infof("gost: %s", c.Conf.Gost.URL) + err := gost.Base{}.CheckHTTPHealth() + if err != nil { + util.Log.Errorf("gost HTTP server is not running. err: %s", err) + util.Log.Errorf("Run gost as server mode before reporting or run with -gostdb-path option instead of -gostdb-url") + return subcommands.ExitFailure + } + } else { + if c.Conf.Gost.Type == "sqlite3" { + util.Log.Infof("gost: %s", c.Conf.Gost.SQLite3Path) + } + } + dbclient, locked, err := report.NewDBClient(report.DBClientConf{ + CveDictCnf: c.Conf.CveDict, + OvalDictCnf: c.Conf.OvalDict, + GostCnf: c.Conf.Gost, + DebugSQL: c.Conf.DebugSQL, + }) + if locked { + util.Log.Errorf("SQLite3 is locked. Close other DB connections and try again: %s", err) + return subcommands.ExitFailure + } + if err != nil { + util.Log.Errorf("Failed to init DB Clients: %s", err) + return subcommands.ExitFailure + } + defer dbclient.CloseDB() + + if res, err = report.FillCveInfos(*dbclient, res, dir); err != nil { + util.Log.Error(err) + return subcommands.ExitFailure + } } for _, w := range reports { @@ -504,5 +406,6 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{} return subcommands.ExitFailure } } + return subcommands.ExitSuccess } diff --git a/commands/scan.go b/commands/scan.go index fba8af26..b037a555 100644 --- a/commands/scan.go +++ b/commands/scan.go @@ -35,22 +35,8 @@ import ( // ScanCmd is Subcommand of host discovery mode type ScanCmd struct { - debug bool configPath string - resultsDir string - logDir string - cacheDBPath string - httpProxy string askKeyPassword bool - containersOnly bool - fast bool - offline bool - deep bool - skipBroken bool - sshNative bool - sshConfig bool - pipe bool - vvv bool timeoutSec int scanTimeoutSec int } @@ -65,9 +51,6 @@ func (*ScanCmd) Synopsis() string { return "Scan vulnerabilities" } func (*ScanCmd) Usage() string { return `scan: scan - [-fast] - [-offline] - [-deep] [-config=/path/to/config.toml] [-results-dir=/path/to/results] [-log-dir=/path/to/log] @@ -90,101 +73,49 @@ func (*ScanCmd) Usage() string { // SetFlags set flag func (p *ScanCmd) SetFlags(f *flag.FlagSet) { - f.BoolVar(&p.debug, "debug", false, "debug mode") + f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode") wd, _ := os.Getwd() - defaultConfPath := filepath.Join(wd, "config.toml") f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") defaultResultsDir := filepath.Join(wd, "results") - f.StringVar(&p.resultsDir, "results-dir", defaultResultsDir, "/path/to/results") + f.StringVar(&c.Conf.ResultsDir, "results-dir", defaultResultsDir, "/path/to/results") defaultLogDir := util.GetDefaultLogDir() - f.StringVar(&p.logDir, "log-dir", defaultLogDir, "/path/to/log") + f.StringVar(&c.Conf.LogDir, "log-dir", defaultLogDir, "/path/to/log") defaultCacheDBPath := filepath.Join(wd, "cache.db") - f.StringVar( - &p.cacheDBPath, - "cachedb-path", - defaultCacheDBPath, + f.StringVar(&c.Conf.CacheDBPath, "cachedb-path", defaultCacheDBPath, "/path/to/cache.db (local cache of changelog for Ubuntu/Debian)") - f.BoolVar( - &p.sshNative, - "ssh-native-insecure", - false, + f.BoolVar(&c.Conf.SSHNative, "ssh-native-insecure", false, "Use Native Go implementation of SSH. Default: Use the external command") - f.BoolVar( - &p.sshConfig, - "ssh-config", - false, + f.BoolVar(&c.Conf.SSHConfig, "ssh-config", false, "Use SSH options specified in ssh_config preferentially") - f.BoolVar( - &p.containersOnly, - "containers-only", - false, + f.BoolVar(&c.Conf.ContainersOnly, "containers-only", false, "Scan containers only. Default: Scan both of hosts and containers") - f.BoolVar( - &p.skipBroken, - "skip-broken", - false, + f.BoolVar(&c.Conf.SkipBroken, "skip-broken", false, "[For CentOS] yum update changelog with --skip-broken option") - f.StringVar( - &p.httpProxy, - "http-proxy", - "", - "http://proxy-url:port (default: empty)", - ) + f.StringVar(&c.Conf.HTTPProxy, "http-proxy", "", + "http://proxy-url:port (default: empty)") - f.BoolVar( - &p.askKeyPassword, - "ask-key-password", - false, + f.BoolVar(&p.askKeyPassword, "ask-key-password", false, "Ask ssh privatekey password before scanning", ) - f.BoolVar( - &p.fast, - "fast", - false, - "Online fast scan mode.") + f.BoolVar(&c.Conf.Pipe, "pipe", false, "Use stdin via PIPE") + f.BoolVar(&c.Conf.Vvv, "vvv", false, "ssh -vvv") - f.BoolVar( - &p.offline, - "offline", - false, - "Offline scan mode. Unable to get updatable packages information.") - - f.BoolVar( - &p.deep, - "deep", - false, - "Deep scan mode. Scan accuracy improves and scanned information becomes richer. Since analysis of changelog, issue commands requiring sudo, but it may be slower and high load on the target server") - - f.BoolVar( - &p.pipe, - "pipe", - false, - "Use stdin via PIPE") - - f.BoolVar(&p.vvv, "vvv", false, "ssh -vvv") - - f.IntVar( - &p.timeoutSec, - "timeout", - 5*60, + f.IntVar(&p.timeoutSec, "timeout", 5*60, "Number of seconds for processing other than scan", ) - f.IntVar( - &p.scanTimeoutSec, - "timeout-scan", - 120*60, + f.IntVar(&p.scanTimeoutSec, "timeout-scan", 120*60, "Number of seconds for scanning vulnerabilities for all servers", ) } @@ -192,8 +123,6 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) { // Execute execute func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { // Setup Logger - c.Conf.Debug = p.debug - c.Conf.LogDir = p.logDir util.Log = util.NewCustomLogger(c.ServerInfo{}) if err := mkdirDotVuls(); err != nil { @@ -222,8 +151,6 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) util.Log.Info("Start scanning") util.Log.Infof("config: %s", p.configPath) - c.Conf.Pipe = p.pipe - c.Conf.Vvv = p.vvv var servernames []string if 0 < len(f.Args()) { servernames = f.Args() @@ -259,21 +186,6 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) } util.Log.Debugf("%s", pp.Sprintf("%v", target)) - c.Conf.ResultsDir = p.resultsDir - c.Conf.CacheDBPath = p.cacheDBPath - c.Conf.SSHNative = p.sshNative - c.Conf.SSHConfig = p.sshConfig - c.Conf.HTTPProxy = p.httpProxy - c.Conf.ContainersOnly = p.containersOnly - c.Conf.SkipBroken = p.skipBroken - - c.Conf.Fast = p.fast - c.Conf.Offline = p.offline - c.Conf.Deep = p.deep - if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) { - c.Conf.Fast = true - } - util.Log.Info("Validating config...") if !c.Conf.ValidateOnScan() { return subcommands.ExitUsageError @@ -285,6 +197,12 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) return subcommands.ExitFailure } + util.Log.Info("Checking Scan Modes... ") + if err := scan.CheckScanModes(); err != nil { + util.Log.Errorf("Fix config.toml: %s", err) + return subcommands.ExitFailure + } + util.Log.Info("Detecting Platforms... ") scan.DetectPlatforms(p.timeoutSec) diff --git a/commands/server.go b/commands/server.go new file mode 100644 index 00000000..b65dcf2f --- /dev/null +++ b/commands/server.go @@ -0,0 +1,219 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package commands + +import ( + "context" + "flag" + "fmt" + "net/http" + "os" + "path/filepath" + + // "github.com/future-architect/vuls/Server" + + c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/oval" + "github.com/future-architect/vuls/report" + "github.com/future-architect/vuls/server" + "github.com/future-architect/vuls/util" + "github.com/google/subcommands" + cvelog "github.com/kotakanbe/go-cve-dictionary/log" +) + +// ServerCmd is subcommand for server +type ServerCmd struct { + configPath string + listen string + cvelDict c.GoCveDictConf + ovalDict c.GovalDictConf + gostConf c.GostConf +} + +// Name return subcommand name +func (*ServerCmd) Name() string { return "server" } + +// Synopsis return synopsis +func (*ServerCmd) Synopsis() string { return "Server" } + +// Usage return usage +func (*ServerCmd) Usage() string { + return `Server: + Server + [-lang=en|ja] + [-config=/path/to/config.toml] + [-log-dir=/path/to/log] + [-cvss-over=7] + [-diff] + [-ignore-unscored-cves] + [-ignore-unfixed] + [-to-email] + [-to-slack] + [-to-stride] + [-to-hipchat] + [-to-chatwork] + [-to-localfile] + [-to-s3] + [-to-azure-blob] + [-format-json] + [-format-xml] + [-format-one-email] + [-format-one-line-text] + [-format-list] + [-format-full-text] + [-http-proxy=http://192.168.0.1:8080] + [-debug] + [-debug-sql] + [-listen=localhost:5515] + [-cvedb-type=sqlite3|mysql|postgres|redis] + [-cvedb-path=/path/to/cve.sqlite3] + [-cvedb-url=http://127.0.0.1:1323 or DB connection string] + [-ovaldb-type=sqlite3|mysql|redis] + [-ovaldb-path=/path/to/oval.sqlite3] + [-ovaldb-url=http://127.0.0.1:1324 or DB connection string] + [-gostdb-type=sqlite3|mysql|redis] + [-gostdb-path=/path/to/gost.sqlite3] + [-gostdb-url=http://127.0.0.1:1325 or DB connection string] + + [RFC3339 datetime format under results dir] +` +} + +// SetFlags set flag +func (p *ServerCmd) SetFlags(f *flag.FlagSet) { + f.StringVar(&c.Conf.Lang, "lang", "en", "[en|ja]") + f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode") + f.BoolVar(&c.Conf.DebugSQL, "debug-sql", false, "SQL debug mode") + + wd, _ := os.Getwd() + defaultConfPath := filepath.Join(wd, "config.toml") + f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") + + defaultResultsDir := filepath.Join(wd, "results") + f.StringVar(&c.Conf.ResultsDir, "results-dir", defaultResultsDir, "/path/to/results") + + defaultLogDir := util.GetDefaultLogDir() + f.StringVar(&c.Conf.LogDir, "log-dir", defaultLogDir, "/path/to/log") + + f.Float64Var(&c.Conf.CvssScoreOver, "cvss-over", 0, + "-cvss-over=6.5 means Servering CVSS Score 6.5 and over (default: 0 (means Server all))") + + f.BoolVar(&c.Conf.IgnoreUnscoredCves, "ignore-unscored-cves", false, + "Don't Server the unscored CVEs") + + f.BoolVar(&c.Conf.IgnoreUnfixed, "ignore-unfixed", false, + "Don't Server the unfixed CVEs") + + f.StringVar(&c.Conf.HTTPProxy, "http-proxy", "", + "http://proxy-url:port (default: empty)") + + f.BoolVar(&c.Conf.FormatJSON, "format-json", false, "JSON format") + + f.BoolVar(&c.Conf.ToLocalFile, "to-localfile", false, "Write report to localfile") + f.StringVar(&p.listen, "listen", "localhost:5515", + "host:port (default: localhost:5515)") + + f.StringVar(&p.cvelDict.Type, "cvedb-type", "sqlite3", + "DB type of go-cve-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.cvelDict.SQLite3Path, "cvedb-path", "", "/path/to/sqlite3") + f.StringVar(&p.cvelDict.URL, "cvedb-url", "", + "http://go-cve-dictionary.com:1323 or DB connection string") + + f.StringVar(&p.ovalDict.Type, "ovaldb-type", "", + "DB type of goval-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.ovalDict.SQLite3Path, "ovaldb-path", "", "/path/to/sqlite3") + f.StringVar(&p.ovalDict.URL, "ovaldb-url", "", + "http://goval-dictionary.com:1324 or DB connection string") + + f.StringVar(&p.gostConf.Type, "gostdb-type", "", + "DB type of gost (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.gostConf.SQLite3Path, "gostdb-path", "", "/path/to/sqlite3") + f.StringVar(&p.gostConf.URL, "gostdb-url", "", + "http://gost.com:1325 or DB connection string") +} + +// Execute execute +func (p *ServerCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + util.Log = util.NewCustomLogger(c.ServerInfo{}) + cvelog.SetLogger(c.Conf.LogDir, false, c.Conf.Debug, false) + + c.Conf.CveDict.Overwrite(p.cvelDict) + c.Conf.OvalDict.Overwrite(p.ovalDict) + c.Conf.Gost.Overwrite(p.gostConf) + + util.Log.Info("Validating config...") + if !c.Conf.ValidateOnReport() { + return subcommands.ExitUsageError + } + + if err := report.CveClient.CheckHealth(); err != nil { + util.Log.Errorf("CVE HTTP server is not running. err: %s", err) + util.Log.Errorf("Run go-cve-dictionary as server mode before Servering or run with -cvedb-path option") + return subcommands.ExitFailure + } + if c.Conf.CveDict.URL != "" { + util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.URL) + } else { + if c.Conf.CveDict.Type == "sqlite3" { + util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.SQLite3Path) + } + } + + if c.Conf.OvalDict.URL != "" { + util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.URL) + err := oval.Base{}.CheckHTTPHealth() + if err != nil { + util.Log.Errorf("OVAL HTTP server is not running. err: %s", err) + util.Log.Errorf("Run goval-dictionary as server mode before Servering or run with -ovaldb-path option") + return subcommands.ExitFailure + } + } else { + if c.Conf.OvalDict.Type == "sqlite3" { + util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.SQLite3Path) + } + } + + dbclient, locked, err := report.NewDBClient(report.DBClientConf{ + CveDictCnf: c.Conf.CveDict, + OvalDictCnf: c.Conf.OvalDict, + GostCnf: c.Conf.Gost, + DebugSQL: c.Conf.DebugSQL, + }) + if locked { + util.Log.Errorf("SQLite3 is locked. Close other DB connections and try again: %s", err) + return subcommands.ExitFailure + } + + if err != nil { + util.Log.Errorf("Failed to init DB Clients: %s", err) + return subcommands.ExitFailure + } + + defer dbclient.CloseDB() + + http.Handle("/vuls", server.VulsHandler{DBclient: *dbclient}) + http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "ok") + }) + util.Log.Infof("Listening on %s", p.listen) + if err := http.ListenAndServe(p.listen, nil); err != nil { + util.Log.Errorf("Failed to start server: %s", err) + return subcommands.ExitFailure + } + return subcommands.ExitSuccess +} diff --git a/commands/tui.go b/commands/tui.go index a7f1f37e..81a3fd8a 100644 --- a/commands/tui.go +++ b/commands/tui.go @@ -20,7 +20,6 @@ package commands import ( "context" "flag" - "fmt" "os" "path/filepath" @@ -29,33 +28,15 @@ import ( "github.com/future-architect/vuls/report" "github.com/future-architect/vuls/util" "github.com/google/subcommands" + cvelog "github.com/kotakanbe/go-cve-dictionary/log" ) // TuiCmd is Subcommand of host discovery mode type TuiCmd struct { - lang string - debugSQL bool - debug bool configPath string - logDir string - - resultsDir string - refreshCve bool - - cvedbtype string - cvedbpath string - cveDictionaryURL string - - ovalDBType string - ovalDBPath string - ovalDBURL string - - cvssScoreOver float64 - ignoreUnscoredCves bool - ignoreUnfixed bool - - pipe bool - diff bool + cvelDict c.GoCveDictConf + ovalDict c.GovalDictConf + gostConf c.GostConf } // Name return subcommand name @@ -70,12 +51,6 @@ func (*TuiCmd) Usage() string { tui [-refresh-cve] [-config=/path/to/config.toml] - [-cvedb-type=sqlite3|mysql|postgres] - [-cvedb-path=/path/to/cve.sqlite3] - [-cvedb-url=http://127.0.0.1:1323 or DB connection string] - [-ovaldb-type=sqlite3|mysql] - [-ovaldb-path=/path/to/oval.sqlite3] - [-ovaldb-url=http://127.0.0.1:1324 or DB connection string] [-cvss-over=7] [-diff] [-ignore-unscored-cves] @@ -85,6 +60,15 @@ func (*TuiCmd) Usage() string { [-debug] [-debug-sql] [-pipe] + [-cvedb-type=sqlite3|mysql|postgres|redis] + [-cvedb-path=/path/to/cve.sqlite3] + [-cvedb-url=http://127.0.0.1:1323 or DB connection string] + [-ovaldb-type=sqlite3|mysql|redis] + [-ovaldb-path=/path/to/oval.sqlite3] + [-ovaldb-url=http://127.0.0.1:1324 or DB connection string] + [-gostdb-type=sqlite3|mysql|redis] + [-gostdb-path=/path/to/gost.sqlite3] + [-gostdb-url=http://127.0.0.1:1325 or DB connection string] ` } @@ -92,91 +76,54 @@ func (*TuiCmd) Usage() string { // SetFlags set flag func (p *TuiCmd) SetFlags(f *flag.FlagSet) { // f.StringVar(&p.lang, "lang", "en", "[en|ja]") - f.BoolVar(&p.debugSQL, "debug-sql", false, "debug SQL") - f.BoolVar(&p.debug, "debug", false, "debug mode") + f.BoolVar(&c.Conf.DebugSQL, "debug-sql", false, "debug SQL") + f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode") defaultLogDir := util.GetDefaultLogDir() - f.StringVar(&p.logDir, "log-dir", defaultLogDir, "/path/to/log") + f.StringVar(&c.Conf.LogDir, "log-dir", defaultLogDir, "/path/to/log") wd, _ := os.Getwd() defaultResultsDir := filepath.Join(wd, "results") - f.StringVar(&p.resultsDir, "results-dir", defaultResultsDir, "/path/to/results") + f.StringVar(&c.Conf.ResultsDir, "results-dir", defaultResultsDir, "/path/to/results") defaultConfPath := filepath.Join(wd, "config.toml") f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml") - f.BoolVar( - &p.refreshCve, - "refresh-cve", - false, + f.BoolVar(&c.Conf.RefreshCve, "refresh-cve", false, "Refresh CVE information in JSON file under results dir") - f.StringVar( - &p.cvedbtype, - "cvedb-type", - "sqlite3", - "DB type for fetching CVE dictionary (sqlite3, mysql or postgres)") - - defaultCveDBPath := filepath.Join(wd, "cve.sqlite3") - f.StringVar( - &p.cvedbpath, - "cvedb-path", - defaultCveDBPath, - "/path/to/sqlite3 (For get cve detail from cve.sqlite3)") - - f.StringVar( - &p.cveDictionaryURL, - "cvedb-url", - "", - "http://cve-dictionary.example.com:1323 or mysql connection string") - - f.StringVar( - &p.ovalDBType, - "ovaldb-type", - "sqlite3", - "DB type for fetching OVAL dictionary (sqlite3 or mysql)") - - defaultOvalDBPath := filepath.Join(wd, "oval.sqlite3") - f.StringVar( - &p.ovalDBPath, - "ovaldb-path", - defaultOvalDBPath, - "/path/to/sqlite3 (For get oval detail from oval.sqlite3)") - - f.StringVar( - &p.ovalDBURL, - "ovaldb-url", - "", - "http://goval-dictionary.example.com:1324 or mysql connection string") - - f.Float64Var( - &p.cvssScoreOver, - "cvss-over", - 0, + f.Float64Var(&c.Conf.CvssScoreOver, "cvss-over", 0, "-cvss-over=6.5 means reporting CVSS Score 6.5 and over (default: 0 (means report all))") - f.BoolVar(&p.diff, - "diff", - false, - fmt.Sprintf("Difference between previous result and current result ")) + f.BoolVar(&c.Conf.Diff, "diff", false, + "Difference between previous result and current result ") f.BoolVar( - &p.ignoreUnscoredCves, - "ignore-unscored-cves", - false, + &c.Conf.IgnoreUnscoredCves, "ignore-unscored-cves", false, "Don't report the unscored CVEs") - f.BoolVar( - &p.ignoreUnfixed, - "ignore-unfixed", - false, + f.BoolVar(&c.Conf.IgnoreUnfixed, "ignore-unfixed", false, "Don't report the unfixed CVEs") - f.BoolVar( - &p.pipe, - "pipe", - false, - "Use stdin via PIPE") + f.BoolVar(&c.Conf.Pipe, "pipe", false, "Use stdin via PIPE") + + f.StringVar(&p.cvelDict.Type, "cvedb-type", "sqlite3", + "DB type of go-cve-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.cvelDict.SQLite3Path, "cvedb-path", "", "/path/to/sqlite3") + f.StringVar(&p.cvelDict.URL, "cvedb-url", "", + "http://go-cve-dictionary.com:1323 or DB connection string") + + f.StringVar(&p.ovalDict.Type, "ovaldb-type", "", + "DB type of goval-dictionary (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.ovalDict.SQLite3Path, "ovaldb-path", "", "/path/to/sqlite3") + f.StringVar(&p.ovalDict.URL, "ovaldb-url", "", + "http://goval-dictionary.com:1324 or DB connection string") + + f.StringVar(&p.gostConf.Type, "gostdb-type", "", + "DB type of gost (sqlite3, mysql, postgres or redis)") + f.StringVar(&p.gostConf.SQLite3Path, "gostdb-path", "", "/path/to/sqlite3") + f.StringVar(&p.gostConf.URL, "gostdb-url", "", + "http://gost.com:1325 or DB connection string") } // Execute execute @@ -184,40 +131,26 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s c.Conf.Lang = "en" // Setup Logger - c.Conf.Debug = p.debug - c.Conf.DebugSQL = p.debugSQL - c.Conf.LogDir = p.logDir util.Log = util.NewCustomLogger(c.ServerInfo{}) - log := util.Log + cvelog.SetLogger(c.Conf.LogDir, false, c.Conf.Debug, false) if err := c.Load(p.configPath, ""); err != nil { util.Log.Errorf("Error loading %s, %s", p.configPath, err) return subcommands.ExitUsageError } - c.Conf.ResultsDir = p.resultsDir - c.Conf.CveDBType = p.cvedbtype - c.Conf.CveDBPath = p.cvedbpath - c.Conf.CveDBURL = p.cveDictionaryURL - c.Conf.OvalDBType = p.ovalDBType - c.Conf.OvalDBPath = p.ovalDBPath - c.Conf.OvalDBURL = p.ovalDBURL - c.Conf.CvssScoreOver = p.cvssScoreOver - c.Conf.IgnoreUnscoredCves = p.ignoreUnscoredCves - c.Conf.IgnoreUnfixed = p.ignoreUnfixed - c.Conf.RefreshCve = p.refreshCve + c.Conf.CveDict.Overwrite(p.cvelDict) + c.Conf.OvalDict.Overwrite(p.ovalDict) + c.Conf.Gost.Overwrite(p.gostConf) - log.Info("Validating config...") + util.Log.Info("Validating config...") if !c.Conf.ValidateOnTui() { return subcommands.ExitUsageError } - c.Conf.Pipe = p.pipe - c.Conf.Diff = p.diff - var dir string var err error - if p.diff { + if c.Conf.Diff { dir, err = report.JSONDir([]string{}) } else { dir, err = report.JSONDir(f.Args()) @@ -233,7 +166,25 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s } util.Log.Infof("Loaded: %s", dir) - if res, err = report.FillCveInfos(res, dir); err != nil { + dbclient, locked, err := report.NewDBClient(report.DBClientConf{ + CveDictCnf: c.Conf.CveDict, + OvalDictCnf: c.Conf.OvalDict, + GostCnf: c.Conf.Gost, + DebugSQL: c.Conf.DebugSQL, + }) + if locked { + util.Log.Errorf("SQLite3 is locked. Close other DB connections and try again: %s", err) + return subcommands.ExitFailure + } + + if err != nil { + util.Log.Errorf("Failed to init DB Clients: %s", err) + return subcommands.ExitFailure + } + + defer dbclient.CloseDB() + + if res, err = report.FillCveInfos(*dbclient, res, dir); err != nil { util.Log.Error(err) return subcommands.ExitFailure } diff --git a/config/config.go b/config/config.go index 754c4d49..b3b3f335 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ import ( "fmt" "log/syslog" "os" + "path/filepath" "runtime" "strconv" "strings" @@ -30,6 +31,12 @@ import ( log "github.com/sirupsen/logrus" ) +// Version of Vuls +var Version = "0.5.0" + +// Revision of Git +var Revision string + // Conf has Configuration var Conf Config @@ -90,80 +97,62 @@ const ( //Config is struct of Configuration type Config struct { - Debug bool - DebugSQL bool - Lang string + Debug bool `json:"debug"` + DebugSQL bool `json:"debugSQL"` + Lang string `json:"lang"` + HTTPProxy string `valid:"url" json:"httpProxy"` + LogDir string `json:"logDir"` + ResultsDir string `json:"resultsDir"` + Pipe bool `json:"pipe"` - EMail SMTPConf - Slack SlackConf - Stride StrideConf - HipChat HipChatConf - ChatWork ChatWorkConf - Syslog SyslogConf - Default ServerInfo - Servers map[string]ServerInfo + Default ServerInfo `json:"default"` + Servers map[string]ServerInfo `json:"servers"` + CvssScoreOver float64 `json:"cvssScoreOver"` + IgnoreUnscoredCves bool `json:"ignoreUnscoredCves"` + IgnoreUnfixed bool `json:"ignoreUnfixed"` + SSHNative bool `json:"sshNative"` + SSHConfig bool `json:"sshConfig"` + ContainersOnly bool `json:"containersOnly"` + SkipBroken bool `json:"skipBroken"` + CacheDBPath string `json:"cacheDBPath"` + Vvv bool `json:"vvv"` + UUID bool `json:"uuid"` - CvssScoreOver float64 - IgnoreUnscoredCves bool - IgnoreUnfixed bool + CveDict GoCveDictConf `json:"cveDict"` + OvalDict GovalDictConf `json:"ovalDict"` + Gost GostConf `json:"gost"` - SSHNative bool - SSHConfig bool + Slack SlackConf `json:"-"` + EMail SMTPConf `json:"-"` + HTTP HTTPConf `json:"-"` + Syslog SyslogConf `json:"-"` + AWS AWS `json:"-"` + Azure Azure `json:"-"` + Stride StrideConf `json:"-"` + HipChat HipChatConf `json:"-"` + ChatWork ChatWorkConf `json:"-"` + Saas SaasConf `json:"-"` - ContainersOnly bool - Fast bool - Offline bool - Deep bool - SkipBroken bool - - HTTPProxy string `valid:"url"` - LogDir string - ResultsDir string - - CveDBType string - CveDBPath string - CveDBURL string - - OvalDBType string - OvalDBPath string - OvalDBURL string - - CacheDBPath string - - RefreshCve bool - - ToSlack bool - ToStride bool - ToHipChat bool - ToChatWork bool - ToEmail bool - ToSyslog bool - ToLocalFile bool - ToS3 bool - ToAzureBlob bool - - FormatXML bool - FormatJSON bool - FormatOneEMail bool - FormatOneLineText bool - FormatShortText bool - FormatFullText bool - - GZIP bool - - AwsProfile string - AwsRegion string - S3Bucket string - S3ResultsDir string - S3ServerSideEncryption string - - AzureAccount string - AzureKey string `json:"-"` - AzureContainer string - - Pipe bool - Vvv bool - Diff bool + RefreshCve bool `json:"refreshCve"` + ToSlack bool `json:"toSlack"` + ToStride bool `json:"toStride"` + ToHipChat bool `json:"toHipChat"` + ToChatWork bool `json:"toChatWork"` + ToEmail bool `json:"toEmail"` + ToSyslog bool `json:"toSyslog"` + ToLocalFile bool `json:"toLocalFile"` + ToS3 bool `json:"toS3"` + ToAzureBlob bool `json:"toAzureBlob"` + ToSaas bool `json:"toSaas"` + ToHTTP bool `json:"toHTTP"` + FormatXML bool `json:"formatXML"` + FormatJSON bool `json:"formatJSON"` + FormatOneEMail bool `json:"formatOneEMail"` + FormatOneLineText bool `json:"formatOneLineText"` + FormatList bool `json:"formatList"` + FormatFullText bool `json:"formatFullText"` + GZIP bool `json:"gzip"` + Diff bool `json:"diff"` } // ValidateOnConfigtest validates @@ -186,11 +175,6 @@ func (c Config) ValidateOnConfigtest() bool { return len(errs) == 0 } -// ValidateOnPrepare validates configuration -func (c Config) ValidateOnPrepare() bool { - return c.ValidateOnConfigtest() -} - // ValidateOnScan validates configuration func (c Config) ValidateOnScan() bool { errs := []error{} @@ -216,20 +200,11 @@ func (c Config) ValidateOnScan() bool { if len(c.CacheDBPath) != 0 { if ok, _ := valid.IsFilePath(c.CacheDBPath); !ok { errs = append(errs, fmt.Errorf( - "Cache DB path must be a *Absolute* file path. -cache-dbpath: %s", c.CacheDBPath)) + "Cache DB path must be a *Absolute* file path. -cache-dbpath: %s", + c.CacheDBPath)) } } - numTrue := 0 - for _, b := range []bool{c.Fast, c.Offline, c.Deep} { - if b { - numTrue++ - } - } - if numTrue != 1 { - errs = append(errs, fmt.Errorf("Specify only one of -fast, -fast-offline, -deep")) - } - _, err := valid.ValidateStruct(c) if err != nil { errs = append(errs, err) @@ -242,6 +217,30 @@ func (c Config) ValidateOnScan() bool { return len(errs) == 0 } +// ValidateOnReportDB validates configuration +func (c Config) ValidateOnReportDB() bool { + errs := []error{} + + if err := validateDB("cvedb", c.CveDict.Type, c.CveDict.SQLite3Path, c.CveDict.URL); err != nil { + errs = append(errs, err) + } + if c.CveDict.Type == "sqlite3" { + if _, err := os.Stat(c.CveDict.SQLite3Path); os.IsNotExist(err) { + errs = append(errs, fmt.Errorf("SQLite3 DB path (%s) is not exist: %s", "cvedb", c.CveDict.SQLite3Path)) + } + } + + if err := validateDB("ovaldb", c.OvalDict.Type, c.OvalDict.SQLite3Path, c.OvalDict.URL); err != nil { + errs = append(errs, err) + } + + for _, err := range errs { + log.Error(err) + } + + return len(errs) == 0 +} + // ValidateOnReport validates configuration func (c Config) ValidateOnReport() bool { errs := []error{} @@ -253,19 +252,6 @@ func (c Config) ValidateOnReport() bool { } } - if err := validateDB("cvedb", c.CveDBType, c.CveDBPath, c.CveDBURL); err != nil { - errs = append(errs, err) - } - if c.CveDBType == "sqlite3" { - if _, err := os.Stat(c.CveDBPath); os.IsNotExist(err) { - errs = append(errs, fmt.Errorf("SQLite3 DB path (%s) is not exist: %s", "cvedb", c.CveDBPath)) - } - } - - if err := validateDB("ovaldb", c.OvalDBType, c.OvalDBPath, c.OvalDBURL); err != nil { - errs = append(errs, err) - } - _, err := valid.ValidateStruct(c) if err != nil { errs = append(errs, err) @@ -291,10 +277,18 @@ func (c Config) ValidateOnReport() bool { errs = append(errs, strideerrs...) } + if saaserrs := c.Saas.Validate(); 0 < len(saaserrs) { + errs = append(errs, saaserrs...) + } + if syslogerrs := c.Syslog.Validate(); 0 < len(syslogerrs) { errs = append(errs, syslogerrs...) } + if httperrs := c.HTTP.Validate(); 0 < len(httperrs) { + errs = append(errs, httperrs...) + } + for _, err := range errs { log.Error(err) } @@ -313,12 +307,12 @@ func (c Config) ValidateOnTui() bool { } } - if err := validateDB("cvedb", c.CveDBType, c.CveDBPath, c.CveDBURL); err != nil { + if err := validateDB("cvedb", c.CveDict.Type, c.CveDict.SQLite3Path, c.CveDict.URL); err != nil { errs = append(errs, err) } - if c.CveDBType == "sqlite3" { - if _, err := os.Stat(c.CveDBPath); os.IsNotExist(err) { - errs = append(errs, fmt.Errorf("SQLite3 DB path (%s) is not exist: %s", "cvedb", c.CveDBPath)) + if c.CveDict.Type == "sqlite3" { + if _, err := os.Stat(c.CveDict.SQLite3Path); os.IsNotExist(err) { + errs = append(errs, fmt.Errorf("SQLite3 DB path (%s) is not exist: %s", "cvedb", c.CveDict.SQLite3Path)) } } @@ -371,15 +365,14 @@ func validateDB(dictionaryDBName, dbType, dbPath, dbURL string) error { // SMTPConf is smtp config type SMTPConf struct { - SMTPAddr string - SMTPPort string `valid:"port"` - - User string - Password string `json:"-"` - From string - To []string - Cc []string - SubjectPrefix string + SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"` + SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"` + User string `toml:"user,omitempty" json:"-"` + Password string `toml:"password,omitempty" json:"-"` + From string `toml:"from,omitempty" json:"-"` + To []string `toml:"to,omitempty" json:"-"` + Cc []string `toml:"cc,omitempty" json:"-"` + SubjectPrefix string `toml:"subjectPrefix,omitempty" json:"-"` } func checkEmails(emails []string) (errs []error) { @@ -399,7 +392,6 @@ func (c *SMTPConf) Validate() (errs []error) { if !Conf.ToEmail { return } - // Check Emails fromat emails := []string{} emails = append(emails, c.From) @@ -432,8 +424,8 @@ func (c *SMTPConf) Validate() (errs []error) { // StrideConf is stride config type StrideConf struct { - HookURL string `json:"hook_url"` - AuthToken string `json:"AuthToken"` + HookURL string `json:"-"` + AuthToken string `json:"-"` } // Validate validates configuration @@ -459,14 +451,13 @@ func (c *StrideConf) Validate() (errs []error) { // SlackConf is slack config type SlackConf struct { - HookURL string `valid:"url" json:"-"` - LegacyToken string `json:"token" toml:"legacyToken,omitempty"` - Channel string `json:"channel"` - IconEmoji string `json:"icon_emoji"` - AuthUser string `json:"username"` - - NotifyUsers []string - Text string `json:"text"` + HookURL string `valid:"url" json:"-" toml:"hookURL,omitempty"` + LegacyToken string `json:"-" toml:"legacyToken,omitempty"` + Channel string `json:"-" toml:"channel,omitempty"` + IconEmoji string `json:"-" toml:"iconEmoji,omitempty"` + AuthUser string `json:"-" toml:"authUser,omitempty"` + NotifyUsers []string `toml:"notifyUsers,omitempty" json:"-"` + Text string `json:"-"` } // Validate validates configuration @@ -503,8 +494,8 @@ func (c *SlackConf) Validate() (errs []error) { // HipChatConf is HipChat config type HipChatConf struct { - AuthToken string `json:"AuthToken"` - Room string `json:"Room"` + AuthToken string `json:"-"` + Room string `json:"-"` } // Validate validates configuration @@ -529,8 +520,8 @@ func (c *HipChatConf) Validate() (errs []error) { // ChatWorkConf is ChatWork config type ChatWorkConf struct { - APIToken string `json:"ApiToken"` - Room string `json:"Room"` + APIToken string `json:"-"` + Room string `json:"-"` } // Validate validates configuration @@ -553,16 +544,47 @@ func (c *ChatWorkConf) Validate() (errs []error) { return } +// SaasConf is stride config +type SaasConf struct { + GroupID int `json:"-"` + Token string `json:"-"` + URL string `json:"-"` +} + +// Validate validates configuration +func (c *SaasConf) Validate() (errs []error) { + if !Conf.ToSaas { + return + } + + if c.GroupID == 0 { + errs = append(errs, fmt.Errorf("saas.GroupID must not be empty")) + } + + if len(c.Token) == 0 { + errs = append(errs, fmt.Errorf("saas.Token must not be empty")) + } + + if len(c.URL) == 0 { + errs = append(errs, fmt.Errorf("saas.URL must not be empty")) + } + + _, err := valid.ValidateStruct(c) + if err != nil { + errs = append(errs, err) + } + return +} + // SyslogConf is syslog config type SyslogConf struct { - Protocol string - Host string `valid:"host"` - Port string `valid:"port"` - Severity string - Facility string - Tag string - - Verbose bool + Protocol string `json:"-"` + Host string `valid:"host" json:"-"` + Port string `valid:"port" json:"-"` + Severity string `json:"-"` + Facility string `json:"-"` + Tag string `json:"-"` + Verbose bool `json:"-"` } // Validate validates configuration @@ -674,42 +696,342 @@ func (c *SyslogConf) GetFacility() (syslog.Priority, error) { } } -// ServerInfo has SSH Info, additional CPE packages to scan. -type ServerInfo struct { - ServerName string - User string - Host string - Port string - KeyPath string - KeyPassword string `json:"-"` +// HTTPConf is HTTP config +type HTTPConf struct { + URL string `valid:"url" json:"-"` +} - CpeNames []string - DependencyCheckXMLPath string +// Validate validates configuration +func (c *HTTPConf) Validate() (errs []error) { + if !Conf.ToHTTP { + return nil + } - // Container Names or IDs - Containers Containers + if _, err := valid.ValidateStruct(c); err != nil { + errs = append(errs, err) + } + return errs +} - IgnoreCves []string +const httpKey = "VULS_HTTP_URL" - // Optional key-value set that will be outputted to JSON - Optional [][]interface{} +// Overwrite set options with the following priority. +// 1. Command line option +// 2. Environment variable +// 3. config.toml +func (c *HTTPConf) Overwrite(cmdOpt HTTPConf) { + if os.Getenv(httpKey) != "" { + c.URL = os.Getenv(httpKey) + } + if cmdOpt.URL != "" { + c.URL = cmdOpt.URL + } +} - // For CentOS, RHEL, Amazon - Enablerepo []string - - // "pseudo" or "" +// GoCveDictConf is go-cve-dictionary config +type GoCveDictConf struct { + // DB type of CVE dictionary (sqlite3, mysql, postgres or redis) Type string - // used internal - LogMsgAnsiColor string // DebugLog Color - Container Container - Distro Distro + // http://cve-dictionary.com:1323 or DB connection string + URL string `valid:"url" json:"-"` - // IP addresses - IPv4Addrs []string - IPv6Addrs []string + // /path/to/cve.sqlite3 + SQLite3Path string `json:"-"` } +func (cnf *GoCveDictConf) setDefault() { + if cnf.Type == "" { + cnf.Type = "sqlite3" + } + if cnf.URL == "" && cnf.SQLite3Path == "" { + wd, _ := os.Getwd() + cnf.SQLite3Path = filepath.Join(wd, "cve.sqlite3") + } +} + +const cveDBType = "CVEDB_TYPE" +const cveDBURL = "CVEDB_URL" +const cveDBPATH = "CVEDB_SQLITE3_PATH" + +// Overwrite set options with the following priority. +// 1. Command line option +// 2. Environment variable +// 3. config.toml +func (cnf *GoCveDictConf) Overwrite(cmdOpt GoCveDictConf) { + if os.Getenv(cveDBType) != "" { + cnf.Type = os.Getenv(cveDBType) + } + if os.Getenv(cveDBURL) != "" { + cnf.URL = os.Getenv(cveDBURL) + } + if os.Getenv(cveDBPATH) != "" { + cnf.SQLite3Path = os.Getenv(cveDBPATH) + } + + if cmdOpt.Type != "" { + cnf.Type = cmdOpt.Type + } + if cmdOpt.URL != "" { + cnf.URL = cmdOpt.URL + } + if cmdOpt.SQLite3Path != "" { + cnf.SQLite3Path = cmdOpt.SQLite3Path + } + cnf.setDefault() +} + +// GovalDictConf is goval-dictionary config +type GovalDictConf struct { + + // DB type of OVAL dictionary (sqlite3, mysql, postgres or redis) + Type string + + // http://goval-dictionary.com:1324 or DB connection string + URL string `valid:"url" json:"-"` + + // /path/to/oval.sqlite3 + SQLite3Path string `json:"-"` +} + +func (cnf *GovalDictConf) setDefault() { + if cnf.Type == "" { + cnf.Type = "sqlite3" + } + if cnf.URL == "" && cnf.SQLite3Path == "" { + wd, _ := os.Getwd() + cnf.SQLite3Path = filepath.Join(wd, "oval.sqlite3") + } +} + +const govalType = "OVALDB_TYPE" +const govalURL = "OVALDB_URL" +const govalPATH = "OVALDB_SQLITE3_PATH" + +// Overwrite set options with the following priority. +// 1. Command line option +// 2. Environment variable +// 3. config.toml +func (cnf *GovalDictConf) Overwrite(cmdOpt GovalDictConf) { + if os.Getenv(govalType) != "" { + cnf.Type = os.Getenv(govalType) + } + if os.Getenv(govalURL) != "" { + cnf.URL = os.Getenv(govalURL) + } + if os.Getenv(govalPATH) != "" { + cnf.SQLite3Path = os.Getenv(govalPATH) + } + + if cmdOpt.Type != "" { + cnf.Type = cmdOpt.Type + } + if cmdOpt.URL != "" { + cnf.URL = cmdOpt.URL + } + if cmdOpt.SQLite3Path != "" { + cnf.SQLite3Path = cmdOpt.SQLite3Path + } + cnf.setDefault() +} + +// GostConf is gost config +type GostConf struct { + // DB type for gost dictionary (sqlite3, mysql, postgres or redis) + Type string + + // http://gost-dictionary.com:1324 or DB connection string + URL string `valid:"url" json:"-"` + + // /path/to/gost.sqlite3 + SQLite3Path string `json:"-"` +} + +func (cnf *GostConf) setDefault() { + if cnf.Type == "" { + cnf.Type = "sqlite3" + } + if cnf.URL == "" && cnf.SQLite3Path == "" { + wd, _ := os.Getwd() + cnf.SQLite3Path = filepath.Join(wd, "gost.sqlite3") + } +} + +const gostDBType = "GOSTDB_TYPE" +const gostDBURL = "GOSTDB_URL" +const gostDBPATH = "GOSTDB_SQLITE3_PATH" + +// Overwrite set options with the following priority. +// 1. Command line option +// 2. Environment variable +// 3. config.toml +func (cnf *GostConf) Overwrite(cmdOpt GostConf) { + if os.Getenv(gostDBType) != "" { + cnf.Type = os.Getenv(gostDBType) + } + if os.Getenv(gostDBURL) != "" { + cnf.URL = os.Getenv(gostDBURL) + } + if os.Getenv(gostDBPATH) != "" { + cnf.SQLite3Path = os.Getenv(gostDBPATH) + } + + if cmdOpt.Type != "" { + cnf.Type = cmdOpt.Type + } + if cmdOpt.URL != "" { + cnf.URL = cmdOpt.URL + } + if cmdOpt.SQLite3Path != "" { + cnf.SQLite3Path = cmdOpt.SQLite3Path + } + cnf.setDefault() +} + +// AWS is aws config +type AWS struct { + // AWS profile to use + Profile string `json:"profile"` + + // AWS region to use + Region string `json:"region"` + + // S3 bucket name + S3Bucket string `json:"s3Bucket"` + + // /bucket/path/to/results + S3ResultsDir string `json:"s3ResultsDir"` + + // The Server-side encryption algorithm used when storing the reports in S3 (e.g., AES256, aws:kms). + S3ServerSideEncryption string `json:"s3ServerSideEncryption"` +} + +// Azure is azure config +type Azure struct { + // Azure account name to use. AZURE_STORAGE_ACCOUNT environment variable is used if not specified + AccountName string `json:"accountName"` + + // Azure account key to use. AZURE_STORAGE_ACCESS_KEY environment variable is used if not specified + AccountKey string `json:"-"` + + // Azure storage container name + ContainerName string `json:"containerName"` +} + +// ServerInfo has SSH Info, additional CPE packages to scan. +type ServerInfo struct { + ServerName string `toml:"-" json:"serverName"` + User string `toml:"user,omitempty" json:"user"` + Host string `toml:"host,omitempty" json:"host"` + Port string `toml:"port,omitempty" json:"port"` + KeyPath string `toml:"keyPath,omitempty" json:"keyPath"` + KeyPassword string `json:"-" toml:"-"` + CpeNames []string `toml:"cpeNames,omitempty" json:"cpeNames,omitempty"` + ScanMode []string `toml:"scanMode,omitempty" json:"scanMode,omitempty"` + DependencyCheckXMLPath string `toml:"dependencyCheckXMLPath,omitempty" json:"-"` // TODO Deprecated remove in near future + OwaspDCXMLPath string `toml:"owaspDCXMLPath,omitempty" json:"owaspDCXMLPath"` + ContainersIncluded []string `toml:"containersIncluded,omitempty" json:"containersIncluded,omitempty"` + ContainersExcluded []string `toml:"containersExcluded,omitempty" json:"containersExcluded,omitempty"` + ContainerType string `toml:"containerType,omitempty" json:"containerType,omitempty"` + Containers map[string]ContainerSetting `toml:"containers" json:"containers,omitempty"` + IgnoreCves []string `toml:"ignoreCves,omitempty" json:"ignoreCves,omitempty"` + IgnorePkgsRegexp []string `toml:"ignorePkgsRegexp,omitempty" json:"ignorePkgsRegexp,omitempty"` + UUIDs map[string]string `toml:"uuids,omitempty" json:"uuids,omitempty"` + Memo string `toml:"memo,omitempty" json:"memo"` + Enablerepo []string `toml:"enablerepo,omitempty" json:"enablerepo,omitempty"` // For CentOS, RHEL, Amazon + Optional map[string]interface{} `toml:"optional,omitempty" json:"optional,omitempty"` // Optional key-value set that will be outputted to JSON + Type string `toml:"type,omitempty" json:"type"` // "pseudo" or "" + IPv4Addrs []string `toml:"-" json:"ipv4Addrs,omitempty"` + IPv6Addrs []string `toml:"-" json:"ipv6Addrs,omitempty"` + + // used internal + LogMsgAnsiColor string `toml:"-" json:"-"` // DebugLog Color + Container Container `toml:"-" json:"-"` + Distro Distro `toml:"-" json:"-"` + Mode ScanMode `toml:"-" json:"-"` +} + +// ContainerSetting is used for loading container setting in config.toml +type ContainerSetting struct { + Cpes []string `json:"cpes,omitempty"` + OwaspDCXMLPath string `json:"owaspDCXMLPath"` + IgnorePkgsRegexp []string `json:"ignorePkgsRegexp,omitempty"` + IgnoreCves []string `json:"ignoreCves,omitempty"` +} + +// ScanMode has a type of scan mode. fast, fast-root, deep and offline +type ScanMode struct { + flag byte +} + +// Set mode +func (s *ScanMode) Set(f byte) { + s.flag |= f +} + +// IsFast return whether scan mode is fast +func (s ScanMode) IsFast() bool { + return s.flag&Fast == Fast +} + +// IsFastRoot return whether scan mode is fastroot +func (s ScanMode) IsFastRoot() bool { + return s.flag&FastRoot == FastRoot +} + +// IsDeep return whether scan mode is deep +func (s ScanMode) IsDeep() bool { + return s.flag&Deep == Deep +} + +// IsOffline return whether scan mode is offline +func (s ScanMode) IsOffline() bool { + return s.flag&Offline == Offline +} + +func (s ScanMode) validate() error { + numTrue := 0 + for _, b := range []bool{s.IsFast(), s.IsFastRoot(), s.IsDeep()} { + if b { + numTrue++ + } + } + if numTrue == 0 { + s.Set(Fast) + } else if s.IsDeep() && s.IsOffline() { + return fmt.Errorf("Don't specify both of -deep and offline") + } else if numTrue != 1 { + return fmt.Errorf("Specify only one of -fast, -fast-root or -deep") + } + return nil +} + +func (s ScanMode) String() string { + ss := "" + if s.IsFast() { + ss = "fast" + } else if s.IsFastRoot() { + ss = "fast-root" + } else if s.IsDeep() { + ss = "deep" + } + if s.IsOffline() { + ss += " offline" + } + return ss + " mode" +} + +const ( + // Fast is fast scan mode + Fast = byte(1 << iota) + // FastRoot is fast-root scan mode + FastRoot + // Deep is deep scan mode + Deep + // Offline is offline scan mode + Offline +) + // GetServerName returns ServerName if this serverInfo is about host. // If this serverInfo is abount a container, returns containerID@ServerName func (s ServerInfo) GetServerName() string { @@ -757,13 +1079,6 @@ func (s *ServerInfo) SetContainer(d Container) { s.Container = d } -// Containers has Containers information. -type Containers struct { - Type string - Includes []string - Excludes []string -} - // Container has Container information. type Container struct { ContainerID string diff --git a/config/tomlloader.go b/config/tomlloader.go index a4f21adf..14af90e8 100644 --- a/config/tomlloader.go +++ b/config/tomlloader.go @@ -20,10 +20,11 @@ package config import ( "fmt" "os" + "regexp" + "strings" "github.com/BurntSushi/toml" - "github.com/future-architect/vuls/contrib/owasp-dependency-check/parser" - log "github.com/sirupsen/logrus" + "github.com/knqyf263/go-cpe/naming" ) // TOMLLoader loads config @@ -32,22 +33,24 @@ type TOMLLoader struct { // Load load the configuration TOML file specified by path arg. func (c TOMLLoader) Load(pathToToml, keyPass string) error { - if Conf.Debug { - log.SetLevel(log.DebugLevel) - } - var conf Config if _, err := toml.DecodeFile(pathToToml, &conf); err != nil { - log.Error("Load config failed", err) return err } - Conf.EMail = conf.EMail Conf.Slack = conf.Slack Conf.Stride = conf.Stride Conf.HipChat = conf.HipChat Conf.ChatWork = conf.ChatWork + Conf.Saas = conf.Saas Conf.Syslog = conf.Syslog + Conf.HTTP = conf.HTTP + Conf.AWS = conf.AWS + Conf.Azure = conf.Azure + + Conf.CveDict = conf.CveDict + Conf.OvalDict = conf.OvalDict + Conf.Gost = conf.Gost d := conf.Default Conf.Default = d @@ -58,17 +61,16 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { } i := 0 - for name, v := range conf.Servers { + for serverName, 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.") + return fmt.Errorf("[Deprecated] KEYPASSWORD IN CONFIG FILE ARE UNSECURE. REMOVE THEM IMMEDIATELY FOR A SECURITY REASONS. THEY WILL BE REMOVED IN A FUTURE RELEASE: %s", serverName) } - s := ServerInfo{ServerName: name} - + s := ServerInfo{ServerName: serverName} if v.Type != ServerTypePseudo { s.Host = v.Host if len(s.Host) == 0 { - return fmt.Errorf("%s is invalid. host is empty", name) + return fmt.Errorf("%s is invalid. host is empty", serverName) } switch { @@ -87,7 +89,7 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { s.User = d.User default: if s.Port != "local" { - return fmt.Errorf("%s is invalid. User is empty", name) + return fmt.Errorf("%s is invalid. User is empty", serverName) } } @@ -98,7 +100,7 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { if s.KeyPath != "" { if _, err := os.Stat(s.KeyPath); err != nil { return fmt.Errorf( - "%s is invalid. keypath: %s not exists", name, s.KeyPath) + "%s is invalid. keypath: %s not exists", serverName, s.KeyPath) } } @@ -109,31 +111,77 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { } } + s.ScanMode = v.ScanMode + if len(s.ScanMode) == 0 { + s.ScanMode = d.ScanMode + if len(s.ScanMode) == 0 { + s.ScanMode = []string{"fast"} + } + } + for _, m := range s.ScanMode { + switch m { + case "fast": + s.Mode.Set(Fast) + case "fast-root": + s.Mode.Set(FastRoot) + case "deep": + s.Mode.Set(Deep) + case "offline": + s.Mode.Set(Offline) + default: + return fmt.Errorf("scanMode: %s of %s is invalie. Specify -fast, -fast-root, -deep or offline", m, serverName) + } + } + if err := s.Mode.validate(); err != nil { + return fmt.Errorf("%s in %s", err, serverName) + } + s.CpeNames = v.CpeNames if len(s.CpeNames) == 0 { s.CpeNames = d.CpeNames } - s.DependencyCheckXMLPath = v.DependencyCheckXMLPath - if len(s.DependencyCheckXMLPath) == 0 { - s.DependencyCheckXMLPath = d.DependencyCheckXMLPath + for i, n := range s.CpeNames { + uri, err := toCpeURI(n) + if err != nil { + return fmt.Errorf("Failed to parse CPENames %s in %s: %s", n, serverName, err) + } + s.CpeNames[i] = uri } - // Load CPEs from OWASP Dependency Check XML - if len(s.DependencyCheckXMLPath) != 0 { - cpes, err := parser.Parse(s.DependencyCheckXMLPath) - if err != nil { - return fmt.Errorf( - "Failed to read OWASP Dependency Check XML: %s", err) - } - log.Debugf("Loaded from OWASP Dependency Check XML: %s", - s.ServerName) - s.CpeNames = append(s.CpeNames, cpes...) + s.ContainersIncluded = v.ContainersIncluded + if len(s.ContainersIncluded) == 0 { + s.ContainersIncluded = d.ContainersIncluded + } + + s.ContainersExcluded = v.ContainersExcluded + if len(s.ContainersExcluded) == 0 { + s.ContainersExcluded = d.ContainersExcluded + } + + s.ContainerType = v.ContainerType + if len(s.ContainerType) == 0 { + s.ContainerType = d.ContainerType } s.Containers = v.Containers - if len(s.Containers.Includes) == 0 { - s.Containers = d.Containers + for contName, cont := range s.Containers { + cont.IgnoreCves = append(cont.IgnoreCves, d.IgnoreCves...) + s.Containers[contName] = cont + } + + if len(v.DependencyCheckXMLPath) != 0 || len(d.DependencyCheckXMLPath) != 0 { + return fmt.Errorf("[DEPRECATED] dependencyCheckXMLPath IS DEPRECATED. USE owaspDCXMLPath INSTEAD: %s", serverName) + } + + s.OwaspDCXMLPath = v.OwaspDCXMLPath + if len(s.OwaspDCXMLPath) == 0 { + s.OwaspDCXMLPath = d.OwaspDCXMLPath + } + + s.Memo = v.Memo + if s.Memo == "" { + s.Memo = d.Memo } s.IgnoreCves = v.IgnoreCves @@ -150,19 +198,43 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { } } - s.Optional = v.Optional - for _, dkv := range d.Optional { + s.IgnorePkgsRegexp = v.IgnorePkgsRegexp + for _, pkg := range d.IgnorePkgsRegexp { found := false - for _, kv := range s.Optional { - if dkv[0] == kv[0] { + for _, p := range s.IgnorePkgsRegexp { + if pkg == p { found = true break } } if !found { - s.Optional = append(s.Optional, dkv) + s.IgnorePkgsRegexp = append(s.IgnorePkgsRegexp, pkg) } } + for _, reg := range s.IgnorePkgsRegexp { + _, err := regexp.Compile(reg) + if err != nil { + return fmt.Errorf("Faild to parse %s in %s. err: %s", reg, serverName, err) + } + } + for contName, cont := range s.Containers { + for _, reg := range cont.IgnorePkgsRegexp { + _, err := regexp.Compile(reg) + if err != nil { + return fmt.Errorf("Faild to parse %s in %s@%s. err: %s", + reg, contName, serverName, err) + } + } + } + + opt := map[string]interface{}{} + for k, v := range d.Optional { + opt[k] = v + } + for k, v := range v.Optional { + opt[k] = v + } + s.Optional = opt s.Enablerepo = v.Enablerepo if len(s.Enablerepo) == 0 { @@ -176,18 +248,36 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { default: return fmt.Errorf( "For now, enablerepo have to be base or updates: %s, servername: %s", - s.Enablerepo, name) + s.Enablerepo, serverName) } } } + s.UUIDs = v.UUIDs s.Type = v.Type s.LogMsgAnsiColor = Colors[i%len(Colors)] i++ - servers[name] = s + servers[serverName] = s } Conf.Servers = servers return nil } + +func toCpeURI(cpename string) (string, error) { + if strings.HasPrefix(cpename, "cpe:2.3:") { + wfn, err := naming.UnbindFS(cpename) + if err != nil { + return "", err + } + return naming.BindToURI(wfn), nil + } else if strings.HasPrefix(cpename, "cpe:/") { + wfn, err := naming.UnbindURI(cpename) + if err != nil { + return "", err + } + return naming.BindToURI(wfn), nil + } + return "", fmt.Errorf("Unknow CPE format: %s", cpename) +} diff --git a/config/tomlloader_test.go b/config/tomlloader_test.go new file mode 100644 index 00000000..4a18ad80 --- /dev/null +++ b/config/tomlloader_test.go @@ -0,0 +1,44 @@ +package config + +import ( + "testing" +) + +func TestToCpeURI(t *testing.T) { + var tests = []struct { + in string + expected string + err bool + }{ + { + in: "", + expected: "", + err: true, + }, + { + in: "cpe:/a:microsoft:internet_explorer:10", + expected: "cpe:/a:microsoft:internet_explorer:10", + err: false, + }, + { + in: "cpe:2.3:a:microsoft:internet_explorer:10:*:*:*:*:*:*:*", + expected: "cpe:/a:microsoft:internet_explorer:10", + err: false, + }, + } + + for i, tt := range tests { + actual, err := toCpeURI(tt.in) + if err != nil && !tt.err { + t.Errorf("[%d] unexpected error occurred, in: %s act: %s, exp: %s", + i, tt.in, actual, tt.expected) + } else if err == nil && tt.err { + t.Errorf("[%d] expected error is not occurred, in: %s act: %s, exp: %s", + i, tt.in, actual, tt.expected) + } + if actual != tt.expected { + t.Errorf("[%d] in: %s, actual: %s, expected: %s", + i, tt.in, actual, tt.expected) + } + } +} diff --git a/contrib/owasp-dependency-check/parser/parser.go b/contrib/owasp-dependency-check/parser/parser.go index bf585b98..a729723b 100644 --- a/contrib/owasp-dependency-check/parser/parser.go +++ b/contrib/owasp-dependency-check/parser/parser.go @@ -32,7 +32,7 @@ func appendIfMissing(slice []string, str string) []string { return append(slice, str) } -// Parse parses XML and collect list of cpe +// Parse parses OWASP dependency check XML and collect list of cpe func Parse(path string) ([]string, error) { file, err := os.Open(path) if err != nil { diff --git a/cwe/en.go b/cwe/en.go new file mode 100644 index 00000000..215e2b62 --- /dev/null +++ b/cwe/en.go @@ -0,0 +1,5145 @@ +package cwe + +// Cwe has CWE information +type Cwe struct { + CweID string `json:"cweID"` + Name string `json:"name"` + Description string `json:"description"` + ExtendedDescription string `json:"extendedDescription"` + Lang string `json:"-"` +} + +// CweDictEn is the Cwe dictionary +var CweDictEn = map[string]Cwe{ + "1004": { + CweID: "1004", + Name: "Sensitive Cookie Without 'HttpOnly' Flag", + Description: "The software uses a cookie to store sensitive information, but the cookie is not marked with the HttpOnly flag.", + ExtendedDescription: "The HttpOnly flag directs compatible browsers to prevent client-side script from accessing cookies. Including the HttpOnly flag in the Set-Cookie HTTP response header helps mitigate the risk associated with Cross-Site Scripting (XSS) where an attacker's script code might attempt to read the contents of a cookie and exfiltrate information obtained. When set, browsers that support the flag will not reveal the contents of the cookie to a third party via client-side script executed via XSS.", + Lang: "en", + }, + "1007": { + CweID: "1007", + Name: "Insufficient Visual Distinction of Homoglyphs Presented to User", + Description: "The software displays information or identifiers to a user, but the display mechanism does not make it easy for the user to distinguish between visually similar or identical glyphs (homoglyphs), which may cause the user to misinterpret a glyph and perform an unintended, insecure action.", + ExtendedDescription: "", + Lang: "en", + }, + "102": { + CweID: "102", + Name: "Struts: Duplicate Validation Forms", + Description: "The application uses multiple validation forms with the same name, which might cause the Struts Validator to validate a form that the programmer does not expect.", + ExtendedDescription: "If two validation forms have the same name, the Struts Validator arbitrarily chooses one of the forms to use for input validation and discards the other. This decision might not correspond to the programmer's expectations, possibly leading to resultant weaknesses. Moreover, it indicates that the validation logic is not up-to-date, and can indicate that other, more subtle validation errors are present.", + Lang: "en", + }, + "1021": { + CweID: "1021", + Name: "Improper Restriction of Rendered UI Layers or Frames", + Description: "The web application does not restrict or incorrectly restricts frame objects or UI layers that belong to another application or domain, which can lead to user confusion about which interface the user is interacting with.", + ExtendedDescription: "A web application is expected to place restrictions on whether it is allowed to be rendered within frames, iframes, objects, embed or applet elements. Without the restrictions, users can be tricked into interacting with the application when they were not intending to.", + Lang: "en", + }, + "1022": { + CweID: "1022", + Name: "Improper Restriction of Cross-Origin Permission to window.opener.location", + Description: "The web application does not restrict or incorrectly restricts modification of its window opener object's location property by an external application from a different origin.", + ExtendedDescription: "By default, many browsers that open a link to an external application with a target specified as a new window/tab provide cross-origin access to the location property via a window.opener object. This enables the external application to choose a location to redirect the calling web application, e.g. for a phishing attack.", + Lang: "en", + }, + "1023": { + CweID: "1023", + Name: "Incomplete Comparison with Missing Factors", + Description: "The software performs a comparison between entities that must consider multiple factors or characteristics of each entity, but the comparison does not include one or more of these factors. This can lead to resultant weaknesses, e.g. by operating on the wrong object.", + ExtendedDescription: "", + Lang: "en", + }, + "1024": { + CweID: "1024", + Name: "Comparison of Incompatible Types", + Description: "The software performs a comparison between two entities, but the entities are of different, incompatible types that cannot be guaranteed to provide correct results when they are directly compared.", + ExtendedDescription: "In languages that are strictly typed but support casting/conversion, such as C or C++, the programmer might assume that casting one entity to the same type as another entity will ensure that the comparison will be performed correctly, but this cannot be guaranteed. In languages that are not strictly typed, such as PHP or JavaScript, there may be implicit casting/conversion to a type that the programmer is unaware of, causing unexpected results; for example, the string '123' might be converted to a number type. See examples.", + Lang: "en", + }, + "1025": { + CweID: "1025", + Name: "Comparison Using Wrong Factors", + Description: "The software performs a comparison between two entities, but the comparison examines the wrong factors or characteristics of the entities, which can lead to incorrect results and resultant weaknesses.", + ExtendedDescription: "A common example of this weakness occurs when the code inadvertently extracts the reference to an object, instead of its relevant contents.", + Lang: "en", + }, + "103": { + CweID: "103", + Name: "Struts: Incomplete validate() Method Definition", + Description: "The application has a validator form that either does not define a validate() method, or defines a validate() method but does not call super.validate().", + ExtendedDescription: "If you do not call super.validate(), the Validation Framework cannot check the contents of the form against a validation form. In other words, the validation framework will be disabled for the given form.", + Lang: "en", + }, + "104": { + CweID: "104", + Name: "Struts: Form Bean Does Not Extend Validation Class", + Description: "If a form bean does not extend an ActionForm subclass of the Validator framework, it can expose the application to other weaknesses related to insufficient input validation.", + ExtendedDescription: "", + Lang: "en", + }, + "105": { + CweID: "105", + Name: "Struts: Form Field Without Validator", + Description: "The application has a form field that is not validated by a corresponding validation form, which can introduce other weaknesses related to insufficient input validation.", + ExtendedDescription: "Omitting validation for even a single input field may give attackers the leeway they need to compromise the application. Although J2EE applications are not generally susceptible to memory corruption attacks, if a J2EE application interfaces with native code that does not perform array bounds checking, an attacker may be able to use an input validation mistake in the J2EE application to launch a buffer overflow attack.", + Lang: "en", + }, + "106": { + CweID: "106", + Name: "Struts: Plug-in Framework not in Use", + Description: "When an application does not use an input validation framework such as the Struts Validator, there is a greater risk of introducing weaknesses related to insufficient input validation.", + ExtendedDescription: "", + Lang: "en", + }, + "107": { + CweID: "107", + Name: "Struts: Unused Validation Form", + Description: "An unused validation form indicates that validation logic is not up-to-date.", + ExtendedDescription: "It is easy for developers to forget to update validation logic when they remove or rename action form mappings. One indication that validation logic is not being properly maintained is the presence of an unused validation form.", + Lang: "en", + }, + "108": { + CweID: "108", + Name: "Struts: Unvalidated Action Form", + Description: "Every Action Form must have a corresponding validation form.", + ExtendedDescription: "If a Struts Action Form Mapping specifies a form, it must have a validation form defined under the Struts Validator.", + Lang: "en", + }, + "109": { + CweID: "109", + Name: "Struts: Validator Turned Off", + Description: "Automatic filtering via a Struts bean has been turned off, which disables the Struts Validator and custom validation logic. This exposes the application to other weaknesses related to insufficient input validation.", + ExtendedDescription: "", + Lang: "en", + }, + "11": { + CweID: "11", + Name: "ASP.NET Misconfiguration: Creating Debug Binary", + Description: "Debugging messages help attackers learn about the system and plan a form of attack.", + ExtendedDescription: "ASP .NET applications can be configured to produce debug binaries. These binaries give detailed debugging messages and should not be used in production environments. Debug binaries are meant to be used in a development or testing environment and can pose a security risk if they are deployed to production.", + Lang: "en", + }, + "110": { + CweID: "110", + Name: "Struts: Validator Without Form Field", + Description: "Validation fields that do not appear in forms they are associated with indicate that the validation logic is out of date.", + ExtendedDescription: "", + Lang: "en", + }, + "111": { + CweID: "111", + Name: "Direct Use of Unsafe JNI", + Description: "When a Java application uses the Java Native Interface (JNI) to call code written in another programming language, it can expose the application to weaknesses in that code, even if those weaknesses cannot occur in Java.", + ExtendedDescription: "Many safety features that programmers may take for granted simply do not apply for native code, so you must carefully review all such code for potential problems. The languages used to implement native code may be more susceptible to buffer overflows and other attacks. Native code is unprotected by the security features enforced by the runtime environment, such as strong typing and array bounds checking.", + Lang: "en", + }, + "112": { + CweID: "112", + Name: "Missing XML Validation", + Description: "The software accepts XML from an untrusted source but does not validate the XML against the proper schema.", + ExtendedDescription: "Most successful attacks begin with a violation of the programmer's assumptions. By accepting an XML document without validating it against a DTD or XML schema, the programmer leaves a door open for attackers to provide unexpected, unreasonable, or malicious input.", + Lang: "en", + }, + "113": { + CweID: "113", + Name: "Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting')", + Description: "The software receives data from an upstream component, but does not neutralize or incorrectly neutralizes CR and LF characters before the data is included in outgoing HTTP headers.", + ExtendedDescription: "", + Lang: "en", + }, + "114": { + CweID: "114", + Name: "Process Control", + Description: "Executing commands or loading libraries from an untrusted source or in an untrusted environment can cause an application to execute malicious commands (and payloads) on behalf of an attacker.", + ExtendedDescription: "Process control vulnerabilities take two forms: 1. An attacker can change the command that the program executes: the attacker explicitly controls what the command is. 2. An attacker can change the environment in which the command executes: the attacker implicitly controls what the command means. Process control vulnerabilities of the first type occur when either data enters the application from an untrusted source and the data is used as part of a string representing a command that is executed by the application. By executing the command, the application gives an attacker a privilege or capability that the attacker would not otherwise have.", + Lang: "en", + }, + "115": { + CweID: "115", + Name: "Misinterpretation of Input", + Description: "The software misinterprets an input, whether from an attacker or another product, in a security-relevant fashion.", + ExtendedDescription: "", + Lang: "en", + }, + "116": { + CweID: "116", + Name: "Improper Encoding or Escaping of Output", + Description: "The software prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.", + ExtendedDescription: "", + Lang: "en", + }, + "117": { + CweID: "117", + Name: "Improper Output Neutralization for Logs", + Description: "The software does not neutralize or incorrectly neutralizes output that is written to logs.", + ExtendedDescription: "", + Lang: "en", + }, + "118": { + CweID: "118", + Name: "Incorrect Access of Indexable Resource ('Range Error')", + Description: "The software does not restrict or incorrectly restricts operations within the boundaries of a resource that is accessed using an index or pointer, such as memory or files.", + ExtendedDescription: "", + Lang: "en", + }, + "119": { + CweID: "119", + Name: "Improper Restriction of Operations within the Bounds of a Memory Buffer", + Description: "The software performs operations on a memory buffer, but it can read from or write to a memory location that is outside of the intended boundary of the buffer.", + ExtendedDescription: "", + Lang: "en", + }, + "12": { + CweID: "12", + Name: "ASP.NET Misconfiguration: Missing Custom Error Page", + Description: "An ASP .NET application must enable custom error pages in order to prevent attackers from mining information from the framework's built-in responses.", + ExtendedDescription: "", + Lang: "en", + }, + "120": { + CweID: "120", + Name: "Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')", + Description: "The program copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.", + ExtendedDescription: "A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the 'classic' case in which the program copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.", + Lang: "en", + }, + "121": { + CweID: "121", + Name: "Stack-based Buffer Overflow", + Description: "A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).", + ExtendedDescription: "", + Lang: "en", + }, + "122": { + CweID: "122", + Name: "Heap-based Buffer Overflow", + Description: "A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().", + ExtendedDescription: "", + Lang: "en", + }, + "123": { + CweID: "123", + Name: "Write-what-where Condition", + Description: "Any condition where the attacker has the ability to write an arbitrary value to an arbitrary location, often as the result of a buffer overflow.", + ExtendedDescription: "", + Lang: "en", + }, + "124": { + CweID: "124", + Name: "Buffer Underwrite ('Buffer Underflow')", + Description: "The software writes to a buffer using an index or pointer that references a memory location prior to the beginning of the buffer.", + ExtendedDescription: "This typically occurs when a pointer or its index is decremented to a position before the buffer, when pointer arithmetic results in a position before the beginning of the valid memory location, or when a negative index is used.", + Lang: "en", + }, + "125": { + CweID: "125", + Name: "Out-of-bounds Read", + Description: "The software reads data past the end, or before the beginning, of the intended buffer.", + ExtendedDescription: "This typically occurs when the pointer or its index is incremented or decremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in corruption of sensitive information, a crash, or code execution among other things.", + Lang: "en", + }, + "126": { + CweID: "126", + Name: "Buffer Over-read", + Description: "The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations after the targeted buffer.", + ExtendedDescription: "This typically occurs when the pointer or its index is incremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in exposure of sensitive information or possibly a crash.", + Lang: "en", + }, + "127": { + CweID: "127", + Name: "Buffer Under-read", + Description: "The software reads from a buffer using buffer access mechanisms such as indexes or pointers that reference memory locations prior to the targeted buffer.", + ExtendedDescription: "This typically occurs when the pointer or its index is decremented to a position before the buffer, when pointer arithmetic results in a position before the beginning of the valid memory location, or when a negative index is used. This may result in exposure of sensitive information or possibly a crash.", + Lang: "en", + }, + "128": { + CweID: "128", + Name: "Wrap-around Error", + Description: "Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore 'wraps around' to a very small, negative, or undefined value.", + ExtendedDescription: "", + Lang: "en", + }, + "129": { + CweID: "129", + Name: "Improper Validation of Array Index", + Description: "The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array.", + ExtendedDescription: "", + Lang: "en", + }, + "13": { + CweID: "13", + Name: "ASP.NET Misconfiguration: Password in Configuration File", + Description: "Storing a plaintext password in a configuration file allows anyone who can read the file access to the password-protected resource making them an easy target for attackers.", + ExtendedDescription: "", + Lang: "en", + }, + "130": { + CweID: "130", + Name: "Improper Handling of Length Parameter Inconsistency", + Description: "The software parses a formatted message or structure, but it does not handle or incorrectly handles a length field that is inconsistent with the actual length of the associated data.", + ExtendedDescription: "If an attacker can manipulate the length parameter associated with an input such that it is inconsistent with the actual length of the input, this can be leveraged to cause the target application to behave in unexpected, and possibly, malicious ways. One of the possible motives for doing so is to pass in arbitrarily large input to the application. Another possible motivation is the modification of application state by including invalid data for subsequent properties of the application. Such weaknesses commonly lead to attacks such as buffer overflows and execution of arbitrary code.", + Lang: "en", + }, + "131": { + CweID: "131", + Name: "Incorrect Calculation of Buffer Size", + Description: "The software does not correctly calculate the size to be used when allocating a buffer, which could lead to a buffer overflow.", + ExtendedDescription: "", + Lang: "en", + }, + "132": { + CweID: "132", + Name: "DEPRECATED (Duplicate): Miscalculated Null Termination", + Description: "This entry has been deprecated because it was a duplicate of CWE-170. All content has been transferred to CWE-170.", + ExtendedDescription: "", + Lang: "en", + }, + "134": { + CweID: "134", + Name: "Use of Externally-Controlled Format String", + Description: "The software uses a function that accepts a format string as an argument, but the format string originates from an external source.", + ExtendedDescription: "", + Lang: "en", + }, + "135": { + CweID: "135", + Name: "Incorrect Calculation of Multi-Byte String Length", + Description: "The software does not correctly calculate the length of strings that can contain wide or multi-byte characters.", + ExtendedDescription: "", + Lang: "en", + }, + "138": { + CweID: "138", + Name: "Improper Neutralization of Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as control elements or syntactic markers when they are sent to a downstream component.", + ExtendedDescription: "Most languages and protocols have their own special elements such as characters and reserved words. These special elements can carry control implications. If software does not prevent external control or influence over the inclusion of such special elements, the control flow of the program may be altered from what was intended. For example, both Unix and Windows interpret the symbol < ('less than') as meaning 'read input from a file'.", + Lang: "en", + }, + "14": { + CweID: "14", + Name: "Compiler Removal of Code to Clear Buffers", + Description: "Sensitive memory is cleared according to the source code, but compiler optimizations leave the memory untouched when it is not read from again, aka 'dead store removal.'", + ExtendedDescription: "", + Lang: "en", + }, + "140": { + CweID: "140", + Name: "Improper Neutralization of Delimiters", + Description: "The software does not neutralize or incorrectly neutralizes delimiters.", + ExtendedDescription: "", + Lang: "en", + }, + "141": { + CweID: "141", + Name: "Improper Neutralization of Parameter/Argument Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as parameter or argument delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "142": { + CweID: "142", + Name: "Improper Neutralization of Value Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as value delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "143": { + CweID: "143", + Name: "Improper Neutralization of Record Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as record delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "144": { + CweID: "144", + Name: "Improper Neutralization of Line Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as line delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "145": { + CweID: "145", + Name: "Improper Neutralization of Section Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as section delimiters when they are sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "146": { + CweID: "146", + Name: "Improper Neutralization of Expression/Command Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as expression or command delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "147": { + CweID: "147", + Name: "Improper Neutralization of Input Terminators", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as input terminators when they are sent to a downstream component.", + ExtendedDescription: "For example, a '.' in SMTP signifies the end of mail message data, whereas a null character can be used for the end of a string.", + Lang: "en", + }, + "148": { + CweID: "148", + Name: "Improper Neutralization of Input Leaders", + Description: "The application does not properly handle when a leading character or sequence ('leader') is missing or malformed, or if multiple leaders are used when only one should be allowed.", + ExtendedDescription: "", + Lang: "en", + }, + "149": { + CweID: "149", + Name: "Improper Neutralization of Quoting Syntax", + Description: "Quotes injected into an application can be used to compromise a system. As data are parsed, an injected/absent/duplicate/malformed use of quotes may cause the process to take unexpected actions.", + ExtendedDescription: "", + Lang: "en", + }, + "15": { + CweID: "15", + Name: "External Control of System or Configuration Setting", + Description: "One or more system settings or configuration elements can be externally controlled by a user.", + ExtendedDescription: "Allowing external control of system settings can disrupt service or cause an application to behave in unexpected, and potentially malicious ways.", + Lang: "en", + }, + "150": { + CweID: "150", + Name: "Improper Neutralization of Escape, Meta, or Control Sequences", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected/absent/malformed delimiter may cause the process to take unexpected actions.", + Lang: "en", + }, + "151": { + CweID: "151", + Name: "Improper Neutralization of Comment Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as comment delimiters when they are sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "152": { + CweID: "152", + Name: "Improper Neutralization of Macro Symbols", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as macro symbols when they are sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "153": { + CweID: "153", + Name: "Improper Neutralization of Substitution Characters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as substitution characters when they are sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "154": { + CweID: "154", + Name: "Improper Neutralization of Variable Name Delimiters", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as variable name delimiters when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected delimiter may cause the process to take unexpected actions that result in an attack. Example: '$' for an environment variable.", + Lang: "en", + }, + "155": { + CweID: "155", + Name: "Improper Neutralization of Wildcards or Matching Symbols", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as wildcards or matching symbols when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected element may cause the process to take unexpected actions.", + Lang: "en", + }, + "156": { + CweID: "156", + Name: "Improper Neutralization of Whitespace", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as whitespace when they are sent to a downstream component.", + ExtendedDescription: "This can include space, tab, etc.", + Lang: "en", + }, + "157": { + CweID: "157", + Name: "Failure to Sanitize Paired Delimiters", + Description: "The software does not properly handle the characters that are used to mark the beginning and ending of a group of entities, such as parentheses, brackets, and braces.", + ExtendedDescription: "", + Lang: "en", + }, + "158": { + CweID: "158", + Name: "Improper Neutralization of Null Byte or NUL Character", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes NUL characters or null bytes when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, an injected NUL character or null byte may cause the software to believe the input is terminated earlier than it actually is, or otherwise cause the input to be misinterpreted. This could then be used to inject potentially dangerous input that occurs after the null byte or otherwise bypass validation routines and other protection mechanisms.", + Lang: "en", + }, + "159": { + CweID: "159", + Name: "Failure to Sanitize Special Element", + Description: "Weaknesses in this attack-focused category do not properly filter and interpret special elements in user-controlled input which could cause adverse effect on the software behavior and integrity.", + ExtendedDescription: "", + Lang: "en", + }, + "160": { + CweID: "160", + Name: "Improper Neutralization of Leading Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes leading special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled leading special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "161": { + CweID: "161", + Name: "Improper Neutralization of Multiple Leading Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes multiple leading special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled multiple leading special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "162": { + CweID: "162", + Name: "Improper Neutralization of Trailing Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes trailing special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled trailing special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "163": { + CweID: "163", + Name: "Improper Neutralization of Multiple Trailing Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes multiple trailing special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled multiple trailing special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "164": { + CweID: "164", + Name: "Improper Neutralization of Internal Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes internal special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled internal special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "165": { + CweID: "165", + Name: "Improper Neutralization of Multiple Internal Special Elements", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes multiple internal special elements that could be interpreted in unexpected ways when they are sent to a downstream component.", + ExtendedDescription: "As data is parsed, improperly handled multiple internal special elements may cause the process to take unexpected actions that result in an attack.", + Lang: "en", + }, + "166": { + CweID: "166", + Name: "Improper Handling of Missing Special Element", + Description: "The software receives input from an upstream component, but it does not handle or incorrectly handles when an expected special element is missing.", + ExtendedDescription: "", + Lang: "en", + }, + "167": { + CweID: "167", + Name: "Improper Handling of Additional Special Element", + Description: "The software receives input from an upstream component, but it does not handle or incorrectly handles when an additional unexpected special element is missing.", + ExtendedDescription: "", + Lang: "en", + }, + "168": { + CweID: "168", + Name: "Improper Handling of Inconsistent Special Elements", + Description: "The software does not handle when an inconsistency exists between two or more special characters or reserved words.", + ExtendedDescription: "An example of this problem would be if paired characters appear in the wrong order, or if the special characters are not properly nested.", + Lang: "en", + }, + "170": { + CweID: "170", + Name: "Improper Null Termination", + Description: "The software does not terminate or incorrectly terminates a string or array with a null character or equivalent terminator.", + ExtendedDescription: "Null termination errors frequently occur in two different ways. An off-by-one error could cause a null to be written out of bounds, leading to an overflow. Or, a program could use a strncpy() function call incorrectly, which prevents a null terminator from being added at all. Other scenarios are possible.", + Lang: "en", + }, + "172": { + CweID: "172", + Name: "Encoding Error", + Description: "The software does not properly encode or decode the data, resulting in unexpected values.", + ExtendedDescription: "", + Lang: "en", + }, + "173": { + CweID: "173", + Name: "Improper Handling of Alternate Encoding", + Description: "The software does not properly handle when an input uses an alternate encoding that is valid for the control sphere to which the input is being sent.", + ExtendedDescription: "", + Lang: "en", + }, + "174": { + CweID: "174", + Name: "Double Decoding of the Same Data", + Description: "The software decodes the same input twice, which can limit the effectiveness of any protection mechanism that occurs in between the decoding operations.", + ExtendedDescription: "", + Lang: "en", + }, + "175": { + CweID: "175", + Name: "Improper Handling of Mixed Encoding", + Description: "The software does not properly handle when the same input uses several different (mixed) encodings.", + ExtendedDescription: "", + Lang: "en", + }, + "176": { + CweID: "176", + Name: "Improper Handling of Unicode Encoding", + Description: "The software does not properly handle when an input contains Unicode encoding.", + ExtendedDescription: "", + Lang: "en", + }, + "177": { + CweID: "177", + Name: "Improper Handling of URL Encoding (Hex Encoding)", + Description: "The software does not properly handle when all or part of an input has been URL encoded.", + ExtendedDescription: "", + Lang: "en", + }, + "178": { + CweID: "178", + Name: "Improper Handling of Case Sensitivity", + Description: "The software does not properly account for differences in case sensitivity when accessing or determining the properties of a resource, leading to inconsistent results.", + ExtendedDescription: "", + Lang: "en", + }, + "179": { + CweID: "179", + Name: "Incorrect Behavior Order: Early Validation", + Description: "The software validates input before applying protection mechanisms that modify the input, which could allow an attacker to bypass the validation via dangerous inputs that only arise after the modification.", + ExtendedDescription: "Software needs to validate data at the proper time, after data has been canonicalized and cleansed. Early validation is susceptible to various manipulations that result in dangerous inputs that are produced by canonicalization and cleansing.", + Lang: "en", + }, + "180": { + CweID: "180", + Name: "Incorrect Behavior Order: Validate Before Canonicalize", + Description: "The software validates input before it is canonicalized, which prevents the software from detecting data that becomes invalid after the canonicalization step.", + ExtendedDescription: "This can be used by an attacker to bypass the validation and launch attacks that expose weaknesses that would otherwise be prevented, such as injection.", + Lang: "en", + }, + "181": { + CweID: "181", + Name: "Incorrect Behavior Order: Validate Before Filter", + Description: "The software validates data before it has been filtered, which prevents the software from detecting data that becomes invalid after the filtering step.", + ExtendedDescription: "This can be used by an attacker to bypass the validation and launch attacks that expose weaknesses that would otherwise be prevented, such as injection.", + Lang: "en", + }, + "182": { + CweID: "182", + Name: "Collapse of Data into Unsafe Value", + Description: "The software filters data in a way that causes it to be reduced or 'collapsed' into an unsafe value that violates an expected security property.", + ExtendedDescription: "", + Lang: "en", + }, + "183": { + CweID: "183", + Name: "Permissive Whitelist", + Description: "An application uses a 'whitelist' of acceptable values, but the whitelist includes at least one unsafe value, leading to resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "184": { + CweID: "184", + Name: "Incomplete Blacklist", + Description: "An application uses a 'blacklist' of prohibited values, but the blacklist is incomplete.", + ExtendedDescription: "If an incomplete blacklist is used as a security mechanism, then the software may allow unintended values to pass into the application logic.", + Lang: "en", + }, + "185": { + CweID: "185", + Name: "Incorrect Regular Expression", + Description: "The software specifies a regular expression in a way that causes data to be improperly matched or compared.", + ExtendedDescription: "When the regular expression is used in protection mechanisms such as filtering or validation, this may allow an attacker to bypass the intended restrictions on the incoming data.", + Lang: "en", + }, + "186": { + CweID: "186", + Name: "Overly Restrictive Regular Expression", + Description: "A regular expression is overly restrictive, which prevents dangerous values from being detected.", + ExtendedDescription: "", + Lang: "en", + }, + "187": { + CweID: "187", + Name: "Partial Comparison", + Description: "The software performs a comparison that only examines a portion of a factor before determining whether there is a match, such as a substring, leading to resultant weaknesses.", + ExtendedDescription: "For example, an attacker might succeed in authentication by providing a small password that matches the associated portion of the larger, correct password.", + Lang: "en", + }, + "188": { + CweID: "188", + Name: "Reliance on Data/Memory Layout", + Description: "The software makes invalid assumptions about how protocol data or memory is organized at a lower level, resulting in unintended program behavior.", + ExtendedDescription: "", + Lang: "en", + }, + "190": { + CweID: "190", + Name: "Integer Overflow or Wraparound", + Description: "The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.", + ExtendedDescription: "An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.", + Lang: "en", + }, + "191": { + CweID: "191", + Name: "Integer Underflow (Wrap or Wraparound)", + Description: "The product subtracts one value from another, such that the result is less than the minimum allowable integer value, which produces a value that is not equal to the correct result.", + ExtendedDescription: "This can happen in signed and unsigned cases.", + Lang: "en", + }, + "192": { + CweID: "192", + Name: "Integer Coercion Error", + Description: "Integer coercion refers to a set of flaws pertaining to the type casting, extension, or truncation of primitive data types.", + ExtendedDescription: "Several flaws fall under the category of integer coercion errors. For the most part, these errors in and of themselves result only in availability and data integrity issues. However, in some circumstances, they may result in other, more complicated security related flaws, such as buffer overflow conditions.", + Lang: "en", + }, + "193": { + CweID: "193", + Name: "Off-by-one Error", + Description: "A product calculates or uses an incorrect maximum or minimum value that is 1 more, or 1 less, than the correct value.", + ExtendedDescription: "", + Lang: "en", + }, + "194": { + CweID: "194", + Name: "Unexpected Sign Extension", + Description: "The software performs an operation on a number that causes it to be sign extended when it is transformed into a larger data type. When the original number is negative, this can produce unexpected values that lead to resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "195": { + CweID: "195", + Name: "Signed to Unsigned Conversion Error", + Description: "The software uses a signed primitive and performs a cast to an unsigned primitive, which can produce an unexpected value if the value of the signed primitive can not be represented using an unsigned primitive.", + ExtendedDescription: "", + Lang: "en", + }, + "196": { + CweID: "196", + Name: "Unsigned to Signed Conversion Error", + Description: "The software uses an unsigned primitive and performs a cast to a signed primitive, which can produce an unexpected value if the value of the unsigned primitive can not be represented using a signed primitive.", + ExtendedDescription: "Although less frequent an issue than signed-to-unsigned conversion, unsigned-to-signed conversion can be the perfect precursor to dangerous buffer underwrite conditions that allow attackers to move down the stack where they otherwise might not have access in a normal buffer overflow condition. Buffer underwrites occur frequently when large unsigned values are cast to signed values, and then used as indexes into a buffer or for pointer arithmetic.", + Lang: "en", + }, + "197": { + CweID: "197", + Name: "Numeric Truncation Error", + Description: "Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion.", + ExtendedDescription: "When a primitive is cast to a smaller primitive, the high order bits of the large value are lost in the conversion, potentially resulting in an unexpected value that is not equal to the original value. This value may be required as an index into a buffer, a loop iterator, or simply necessary state data. In any case, the value cannot be trusted and the system will be in an undefined state. While this method may be employed viably to isolate the low bits of a value, this usage is rare, and truncation usually implies that an implementation error has occurred.", + Lang: "en", + }, + "198": { + CweID: "198", + Name: "Use of Incorrect Byte Ordering", + Description: "The software receives input from an upstream component, but it does not account for byte ordering (e.g. big-endian and little-endian) when processing the input, causing an incorrect number or value to be used.", + ExtendedDescription: "", + Lang: "en", + }, + "20": { + CweID: "20", + Name: "Improper Input Validation", + Description: "The product does not validate or incorrectly validates input that can affect the control flow or data flow of a program.", + ExtendedDescription: "When software does not validate input properly, an attacker is able to craft the input in a form that is not expected by the rest of the application. This will lead to parts of the system receiving unintended input, which may result in altered control flow, arbitrary control of a resource, or arbitrary code execution.", + Lang: "en", + }, + "200": { + CweID: "200", + Name: "Information Exposure", + Description: "An information exposure is the intentional or unintentional disclosure of information to an actor that is not explicitly authorized to have access to that information.", + ExtendedDescription: "", + Lang: "en", + }, + "201": { + CweID: "201", + Name: "Information Exposure Through Sent Data", + Description: "The accidental exposure of sensitive information through sent data refers to the transmission of data which are either sensitive in and of itself or useful in the further exploitation of the system through standard data channels.", + ExtendedDescription: "", + Lang: "en", + }, + "202": { + CweID: "202", + Name: "Exposure of Sensitive Data Through Data Queries", + Description: "When trying to keep information confidential, an attacker can often infer some of the information by using statistics.", + ExtendedDescription: "In situations where data should not be tied to individual users, but a large number of users should be able to make queries that 'scrub' the identity of users, it may be possible to get information about a user -- e.g., by specifying search terms that are known to be unique to that user.", + Lang: "en", + }, + "203": { + CweID: "203", + Name: "Information Exposure Through Discrepancy", + Description: "The product behaves differently or sends different responses in a way that exposes security-relevant information about the state of the product, such as whether a particular operation was successful or not.", + ExtendedDescription: "", + Lang: "en", + }, + "204": { + CweID: "204", + Name: "Response Discrepancy Information Exposure", + Description: "The software provides different responses to incoming requests in a way that allows an actor to determine system state information that is outside of that actor's control sphere.", + ExtendedDescription: "This issue frequently occurs during authentication, where a difference in failed-login messages could allow an attacker to determine if the username is valid or not. These exposures can be inadvertent (bug) or intentional (design).", + Lang: "en", + }, + "205": { + CweID: "205", + Name: "Information Exposure Through Behavioral Discrepancy", + Description: "The product's actions indicate important differences based on (1) the internal state of the product or (2) differences from other products in the same class.", + ExtendedDescription: "For example, attacks such as OS fingerprinting rely heavily on both behavioral and response discrepancies.", + Lang: "en", + }, + "206": { + CweID: "206", + Name: "Information Exposure of Internal State Through Behavioral Inconsistency", + Description: "Two separate operations in a product cause the product to behave differently in a way that is observable to an attacker and reveals security-relevant information about the internal state of the product, such as whether a particular operation was successful or not.", + ExtendedDescription: "", + Lang: "en", + }, + "207": { + CweID: "207", + Name: "Information Exposure Through an External Behavioral Inconsistency", + Description: "The product behaves differently than other products like it, in a way that is observable to an attacker and exposes security-relevant information about which product is being used.", + ExtendedDescription: "", + Lang: "en", + }, + "208": { + CweID: "208", + Name: "Information Exposure Through Timing Discrepancy", + Description: "Two separate operations in a product require different amounts of time to complete, in a way that is observable to an actor and reveals security-relevant information about the state of the product, such as whether a particular operation was successful or not.", + ExtendedDescription: "", + Lang: "en", + }, + "209": { + CweID: "209", + Name: "Information Exposure Through an Error Message", + Description: "The software generates an error message that includes sensitive information about its environment, users, or associated data.", + ExtendedDescription: "The sensitive information may be valuable information on its own (such as a password), or it may be useful for launching other, more deadly attacks. If an attack fails, an attacker may use error information provided by the server to launch another more focused attack. For example, an attempt to exploit a path traversal weakness (CWE-22) might yield the full pathname of the installed application. In turn, this could be used to select the proper number of '..' sequences to navigate to the targeted file. An attack using SQL injection (CWE-89) might not initially succeed, but an error message could reveal the malformed query, which would expose query logic and possibly even passwords or other sensitive information used within the query.", + Lang: "en", + }, + "210": { + CweID: "210", + Name: "Information Exposure Through Self-generated Error Message", + Description: "The software identifies an error condition and creates its own diagnostic or error messages that contain sensitive information.", + ExtendedDescription: "", + Lang: "en", + }, + "211": { + CweID: "211", + Name: "Information Exposure Through Externally-Generated Error Message", + Description: "The software performs an operation that triggers an external diagnostic or error message that is not directly generated by the software, such as an error generated by the programming language interpreter that the software uses. The error can contain sensitive system information.", + ExtendedDescription: "", + Lang: "en", + }, + "212": { + CweID: "212", + Name: "Improper Cross-boundary Removal of Sensitive Data", + Description: "The software uses a resource that contains sensitive data, but it does not properly remove that data before it stores, transfers, or shares the resource with actors in another control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "213": { + CweID: "213", + Name: "Intentional Information Exposure", + Description: "A product's design or configuration explicitly requires the publication of information that could be regarded as sensitive by an administrator.", + ExtendedDescription: "", + Lang: "en", + }, + "214": { + CweID: "214", + Name: "Information Exposure Through Process Environment", + Description: "A process is invoked with sensitive arguments, environment variables, or other elements that can be seen by other processes on the operating system.", + ExtendedDescription: "Many operating systems allow a user to list information about processes that are owned by other users. This information could include command line arguments or environment variable settings. When this data contains sensitive information such as credentials, it might allow other users to launch an attack against the software or related resources.", + Lang: "en", + }, + "215": { + CweID: "215", + Name: "Information Exposure Through Debug Information", + Description: "The application contains debugging code that can expose sensitive information to untrusted parties.", + ExtendedDescription: "", + Lang: "en", + }, + "216": { + CweID: "216", + Name: "Containment Errors (Container Errors)", + Description: "This tries to cover various problems in which improper data are included within a 'container.'", + ExtendedDescription: "", + Lang: "en", + }, + "217": { + CweID: "217", + Name: "DEPRECATED: Failure to Protect Stored Data from Modification", + Description: "This weakness has been deprecated because it incorporated and confused multiple weaknesses. The issues formerly covered in this weakness can be found at CWE-766 and CWE-767.", + ExtendedDescription: "", + Lang: "en", + }, + "218": { + CweID: "218", + Name: "DEPRECATED (Duplicate): Failure to provide confidentiality for stored data", + Description: "This weakness has been deprecated because it was a duplicate of CWE-493. All content has been transferred to CWE-493.", + ExtendedDescription: "", + Lang: "en", + }, + "219": { + CweID: "219", + Name: "Sensitive Data Under Web Root", + Description: "The application stores sensitive data under the web document root with insufficient access control, which might make it accessible to untrusted parties.", + ExtendedDescription: "", + Lang: "en", + }, + "22": { + CweID: "22", + Name: "Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')", + Description: "The software uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the software does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.", + ExtendedDescription: "", + Lang: "en", + }, + "220": { + CweID: "220", + Name: "Sensitive Data Under FTP Root", + Description: "The application stores sensitive data under the FTP document root with insufficient access control, which might make it accessible to untrusted parties.", + ExtendedDescription: "", + Lang: "en", + }, + "221": { + CweID: "221", + Name: "Information Loss or Omission", + Description: "The software does not record, or improperly records, security-relevant information that leads to an incorrect decision or hampers later analysis.", + ExtendedDescription: "This can be resultant, e.g. a buffer overflow might trigger a crash before the product can log the event.", + Lang: "en", + }, + "222": { + CweID: "222", + Name: "Truncation of Security-relevant Information", + Description: "The application truncates the display, recording, or processing of security-relevant information in a way that can obscure the source or nature of an attack.", + ExtendedDescription: "", + Lang: "en", + }, + "223": { + CweID: "223", + Name: "Omission of Security-relevant Information", + Description: "The application does not record or display information that would be important for identifying the source or nature of an attack, or determining if an action is safe.", + ExtendedDescription: "", + Lang: "en", + }, + "224": { + CweID: "224", + Name: "Obscured Security-relevant Information by Alternate Name", + Description: "The software records security-relevant information according to an alternate name of the affected entity, instead of the canonical name.", + ExtendedDescription: "", + Lang: "en", + }, + "225": { + CweID: "225", + Name: "DEPRECATED (Duplicate): General Information Management Problems", + Description: "This weakness can be found at CWE-199.", + ExtendedDescription: "", + Lang: "en", + }, + "226": { + CweID: "226", + Name: "Sensitive Information Uncleared Before Release", + Description: "The software does not fully clear previously used information in a data structure, file, or other resource, before making that resource available to a party in another control sphere.", + ExtendedDescription: "This typically results from new data that is not as long as the old data, which leaves portions of the old data still available. Equivalent errors can occur in other situations where the length of data is variable but the associated data structure is not. If memory is not cleared after use, it may allow unintended actors to read the data when the memory is reallocated.", + Lang: "en", + }, + "228": { + CweID: "228", + Name: "Improper Handling of Syntactically Invalid Structure", + Description: "The product does not handle or incorrectly handles input that is not syntactically well-formed with respect to the associated specification.", + ExtendedDescription: "", + Lang: "en", + }, + "229": { + CweID: "229", + Name: "Improper Handling of Values", + Description: "The software does not properly handle when the expected number of values for parameters, fields, or arguments is not provided in input, or if those values are undefined.", + ExtendedDescription: "", + Lang: "en", + }, + "23": { + CweID: "23", + Name: "Relative Path Traversal", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize sequences such as '..' that can resolve to a location that is outside of that directory.", + ExtendedDescription: "This allows attackers to traverse the file system to access files or directories that are outside of the restricted directory.", + Lang: "en", + }, + "230": { + CweID: "230", + Name: "Improper Handling of Missing Values", + Description: "The software does not handle or incorrectly handles when a parameter, field, or argument name is specified, but the associated value is missing, i.e. it is empty, blank, or null.", + ExtendedDescription: "", + Lang: "en", + }, + "231": { + CweID: "231", + Name: "Improper Handling of Extra Values", + Description: "The software does not handle or incorrectly handles when more values are provided than expected.", + ExtendedDescription: "", + Lang: "en", + }, + "232": { + CweID: "232", + Name: "Improper Handling of Undefined Values", + Description: "The software does not handle or incorrectly handles when a value is not defined or supported for the associated parameter, field, or argument name.", + ExtendedDescription: "", + Lang: "en", + }, + "233": { + CweID: "233", + Name: "Improper Handling of Parameters", + Description: "The software does not properly handle when the expected number of parameters, fields, or arguments is not provided in input, or if those parameters are undefined.", + ExtendedDescription: "", + Lang: "en", + }, + "234": { + CweID: "234", + Name: "Failure to Handle Missing Parameter", + Description: "If too few arguments are sent to a function, the function will still pop the expected number of arguments from the stack. Potentially, a variable number of arguments could be exhausted in a function as well.", + ExtendedDescription: "", + Lang: "en", + }, + "235": { + CweID: "235", + Name: "Improper Handling of Extra Parameters", + Description: "The software does not handle or incorrectly handles when the number of parameters, fields, or arguments with the same name exceeds the expected amount.", + ExtendedDescription: "", + Lang: "en", + }, + "236": { + CweID: "236", + Name: "Improper Handling of Undefined Parameters", + Description: "The software does not handle or incorrectly handles when a particular parameter, field, or argument name is not defined or supported by the product.", + ExtendedDescription: "", + Lang: "en", + }, + "237": { + CweID: "237", + Name: "Improper Handling of Structural Elements", + Description: "The software does not handle or incorrectly handles inputs that are related to complex structures.", + ExtendedDescription: "", + Lang: "en", + }, + "238": { + CweID: "238", + Name: "Improper Handling of Incomplete Structural Elements", + Description: "The software does not handle or incorrectly handles when a particular structural element is not completely specified.", + ExtendedDescription: "", + Lang: "en", + }, + "239": { + CweID: "239", + Name: "Failure to Handle Incomplete Element", + Description: "The software does not properly handle when a particular element is not completely specified.", + ExtendedDescription: "", + Lang: "en", + }, + "24": { + CweID: "24", + Name: "Path Traversal: '../filedir'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '../' sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "240": { + CweID: "240", + Name: "Improper Handling of Inconsistent Structural Elements", + Description: "The software does not handle or incorrectly handles when two or more structural elements should be consistent, but are not.", + ExtendedDescription: "", + Lang: "en", + }, + "241": { + CweID: "241", + Name: "Improper Handling of Unexpected Data Type", + Description: "The software does not handle or incorrectly handles when a particular element is not the expected type, e.g. it expects a digit (0-9) but is provided with a letter (A-Z).", + ExtendedDescription: "", + Lang: "en", + }, + "242": { + CweID: "242", + Name: "Use of Inherently Dangerous Function", + Description: "The program calls a function that can never be guaranteed to work safely.", + ExtendedDescription: "Certain functions behave in dangerous ways regardless of how they are used. Functions in this category were often implemented without taking security concerns into account. The gets() function is unsafe because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. Similarly, the >> operator is unsafe to use when reading into a statically-allocated character array because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.", + Lang: "en", + }, + "243": { + CweID: "243", + Name: "Creation of chroot Jail Without Changing Working Directory", + Description: "The program uses the chroot() system call to create a jail, but does not change the working directory afterward. This does not prevent access to files outside of the jail.", + ExtendedDescription: "Improper use of chroot() may allow attackers to escape from the chroot jail. The chroot() function call does not change the process's current working directory, so relative paths may still refer to file system resources outside of the chroot jail after chroot() has been called.", + Lang: "en", + }, + "244": { + CweID: "244", + Name: "Improper Clearing of Heap Memory Before Release ('Heap Inspection')", + Description: "Using realloc() to resize buffers that store sensitive information can leave the sensitive information exposed to attack, because it is not removed from memory.", + ExtendedDescription: "When sensitive data such as a password or an encryption key is not removed from memory, it could be exposed to an attacker using a 'heap inspection' attack that reads the sensitive data using memory dumps or other methods. The realloc() function is commonly used to increase the size of a block of allocated memory. This operation often requires copying the contents of the old memory block into a new and larger block. This operation leaves the contents of the original block intact but inaccessible to the program, preventing the program from being able to scrub sensitive data from memory. If an attacker can later examine the contents of a memory dump, the sensitive data could be exposed.", + Lang: "en", + }, + "245": { + CweID: "245", + Name: "J2EE Bad Practices: Direct Management of Connections", + Description: "The J2EE application directly manages connections, instead of using the container's connection management facilities.", + ExtendedDescription: "The J2EE standard forbids the direct management of connections. It requires that applications use the container's resource management facilities to obtain connections to resources. Every major web application container provides pooled database connection management as part of its resource management framework. Duplicating this functionality in an application is difficult and error prone, which is part of the reason it is forbidden under the J2EE standard.", + Lang: "en", + }, + "246": { + CweID: "246", + Name: "J2EE Bad Practices: Direct Use of Sockets", + Description: "The J2EE application directly uses sockets instead of using framework method calls.", + ExtendedDescription: "", + Lang: "en", + }, + "247": { + CweID: "247", + Name: "DEPRECATED (Duplicate): Reliance on DNS Lookups in a Security Decision", + Description: "This entry has been deprecated because it was a duplicate of CWE-350. All content has been transferred to CWE-350.", + ExtendedDescription: "", + Lang: "en", + }, + "248": { + CweID: "248", + Name: "Uncaught Exception", + Description: "An exception is thrown from a function, but it is not caught.", + ExtendedDescription: "When an exception is not caught, it may cause the program to crash or expose sensitive information.", + Lang: "en", + }, + "249": { + CweID: "249", + Name: "DEPRECATED: Often Misused: Path Manipulation", + Description: "This entry has been deprecated because of name confusion and an accidental combination of multiple weaknesses. Most of its content has been transferred to CWE-785.", + ExtendedDescription: "", + Lang: "en", + }, + "25": { + CweID: "25", + Name: "Path Traversal: '/../filedir'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '/../' sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "250": { + CweID: "250", + Name: "Execution with Unnecessary Privileges", + Description: "The software performs an operation at a privilege level that is higher than the minimum level required, which creates new weaknesses or amplifies the consequences of other weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "252": { + CweID: "252", + Name: "Unchecked Return Value", + Description: "The software does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.", + ExtendedDescription: "Two common programmer assumptions are 'this function call can never fail' and 'it doesn't matter if this function call fails'. If an attacker can force the function to fail or otherwise return a value that is not expected, then the subsequent program logic could lead to a vulnerability, because the software is not in a state that the programmer assumes. For example, if the program calls a function to drop privileges but does not check the return code to ensure that privileges were successfully dropped, then the program will continue to operate with the higher privileges.", + Lang: "en", + }, + "253": { + CweID: "253", + Name: "Incorrect Check of Function Return Value", + Description: "The software incorrectly checks a return value from a function, which prevents the software from detecting errors or exceptional conditions.", + ExtendedDescription: "Important and common functions will return some value about the success of its actions. This will alert the program whether or not to handle any errors caused by that function.", + Lang: "en", + }, + "256": { + CweID: "256", + Name: "Plaintext Storage of a Password", + Description: "Storing a password in plaintext may result in a system compromise.", + ExtendedDescription: "Password management issues occur when a password is stored in plaintext in an application's properties or configuration file. Storing a plaintext password in a configuration file allows anyone who can read the file access to the password-protected resource.", + Lang: "en", + }, + "257": { + CweID: "257", + Name: "Storing Passwords in a Recoverable Format", + Description: "The storage of passwords in a recoverable format makes them subject to password reuse attacks by malicious users. In fact, it should be noted that recoverable encrypted passwords provide no significant benefit over plaintext passwords since they are subject not only to reuse by malicious attackers but also by malicious insiders. If a system administrator can recover a password directly, or use a brute force search on the available information, the administrator can use the password on other accounts.", + ExtendedDescription: "", + Lang: "en", + }, + "258": { + CweID: "258", + Name: "Empty Password in Configuration File", + Description: "Using an empty string as a password is insecure.", + ExtendedDescription: "", + Lang: "en", + }, + "259": { + CweID: "259", + Name: "Use of Hard-coded Password", + Description: "The software contains a hard-coded password, which it uses for its own inbound authentication or for outbound communication to external components.", + ExtendedDescription: "", + Lang: "en", + }, + "26": { + CweID: "26", + Name: "Path Traversal: '/dir/../filename'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '/dir/../filename' sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "260": { + CweID: "260", + Name: "Password in Configuration File", + Description: "The software stores a password in a configuration file that might be accessible to actors who do not know the password.", + ExtendedDescription: "This can result in compromise of the system for which the password is used. An attacker could gain access to this file and learn the stored password or worse yet, change the password to one of their choosing.", + Lang: "en", + }, + "261": { + CweID: "261", + Name: "Weak Cryptography for Passwords", + Description: "Obscuring a password with a trivial encoding does not protect the password.", + ExtendedDescription: "", + Lang: "en", + }, + "262": { + CweID: "262", + Name: "Not Using Password Aging", + Description: "If no mechanism is in place for managing password aging, users will have no incentive to update passwords in a timely manner.", + ExtendedDescription: "", + Lang: "en", + }, + "263": { + CweID: "263", + Name: "Password Aging with Long Expiration", + Description: "Allowing password aging to occur unchecked can result in the possibility of diminished password integrity.", + ExtendedDescription: "Just as neglecting to include functionality for the management of password aging is dangerous, so is allowing password aging to continue unchecked. Passwords must be given a maximum life span, after which a user is required to update with a new and different password.", + Lang: "en", + }, + "266": { + CweID: "266", + Name: "Incorrect Privilege Assignment", + Description: "A product incorrectly assigns a privilege to a particular actor, creating an unintended sphere of control for that actor.", + ExtendedDescription: "", + Lang: "en", + }, + "267": { + CweID: "267", + Name: "Privilege Defined With Unsafe Actions", + Description: "A particular privilege, role, capability, or right can be used to perform unsafe actions that were not intended, even when it is assigned to the correct entity.", + ExtendedDescription: "", + Lang: "en", + }, + "268": { + CweID: "268", + Name: "Privilege Chaining", + Description: "Two distinct privileges, roles, capabilities, or rights can be combined in a way that allows an entity to perform unsafe actions that would not be allowed without that combination.", + ExtendedDescription: "", + Lang: "en", + }, + "269": { + CweID: "269", + Name: "Improper Privilege Management", + Description: "The software does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor.", + ExtendedDescription: "", + Lang: "en", + }, + "27": { + CweID: "27", + Name: "Path Traversal: 'dir/../../filename'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize multiple internal '../' sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "270": { + CweID: "270", + Name: "Privilege Context Switching Error", + Description: "The software does not properly manage privileges while it is switching between different contexts that have different privileges or spheres of control.", + ExtendedDescription: "", + Lang: "en", + }, + "271": { + CweID: "271", + Name: "Privilege Dropping / Lowering Errors", + Description: "The software does not drop privileges before passing control of a resource to an actor that does not have those privileges.", + ExtendedDescription: "In some contexts, a system executing with elevated permissions will hand off a process/file/etc. to another process or user. If the privileges of an entity are not reduced, then elevated privileges are spread throughout a system and possibly to an attacker.", + Lang: "en", + }, + "272": { + CweID: "272", + Name: "Least Privilege Violation", + Description: "The elevated privilege level required to perform operations such as chroot() should be dropped immediately after the operation is performed.", + ExtendedDescription: "", + Lang: "en", + }, + "273": { + CweID: "273", + Name: "Improper Check for Dropped Privileges", + Description: "The software attempts to drop privileges but does not check or incorrectly checks to see if the drop succeeded.", + ExtendedDescription: "If the drop fails, the software will continue to run with the raised privileges, which might provide additional access to unprivileged users.", + Lang: "en", + }, + "274": { + CweID: "274", + Name: "Improper Handling of Insufficient Privileges", + Description: "The software does not handle or incorrectly handles when it has insufficient privileges to perform an operation, leading to resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "276": { + CweID: "276", + Name: "Incorrect Default Permissions", + Description: "The software, upon installation, sets incorrect permissions for an object that exposes it to an unintended actor.", + ExtendedDescription: "", + Lang: "en", + }, + "277": { + CweID: "277", + Name: "Insecure Inherited Permissions", + Description: "A product defines a set of insecure permissions that are inherited by objects that are created by the program.", + ExtendedDescription: "", + Lang: "en", + }, + "278": { + CweID: "278", + Name: "Insecure Preserved Inherited Permissions", + Description: "A product inherits a set of insecure permissions for an object, e.g. when copying from an archive file, without user awareness or involvement.", + ExtendedDescription: "", + Lang: "en", + }, + "279": { + CweID: "279", + Name: "Incorrect Execution-Assigned Permissions", + Description: "While it is executing, the software sets the permissions of an object in a way that violates the intended permissions that have been specified by the user.", + ExtendedDescription: "", + Lang: "en", + }, + "28": { + CweID: "28", + Name: "Path Traversal: '..\\filedir'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '..\\' sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "280": { + CweID: "280", + Name: "Improper Handling of Insufficient Permissions or Privileges", + Description: "The application does not handle or incorrectly handles when it has insufficient privileges to access resources or functionality as specified by their permissions. This may cause it to follow unexpected code paths that may leave the application in an invalid state.", + ExtendedDescription: "", + Lang: "en", + }, + "281": { + CweID: "281", + Name: "Improper Preservation of Permissions", + Description: "The software does not preserve permissions or incorrectly preserves permissions when copying, restoring, or sharing objects, which can cause them to have less restrictive permissions than intended.", + ExtendedDescription: "", + Lang: "en", + }, + "282": { + CweID: "282", + Name: "Improper Ownership Management", + Description: "The software assigns the wrong ownership, or does not properly verify the ownership, of an object or resource.", + ExtendedDescription: "", + Lang: "en", + }, + "283": { + CweID: "283", + Name: "Unverified Ownership", + Description: "The software does not properly verify that a critical resource is owned by the proper entity.", + ExtendedDescription: "", + Lang: "en", + }, + "284": { + CweID: "284", + Name: "Improper Access Control", + Description: "The software does not restrict or incorrectly restricts access to a resource from an unauthorized actor.", + ExtendedDescription: "", + Lang: "en", + }, + "285": { + CweID: "285", + Name: "Improper Authorization", + Description: "The software does not perform or incorrectly performs an authorization check when an actor attempts to access a resource or perform an action.", + ExtendedDescription: "", + Lang: "en", + }, + "286": { + CweID: "286", + Name: "Incorrect User Management", + Description: "The software does not properly manage a user within its environment.", + ExtendedDescription: "Users can be assigned to the wrong group (class) of permissions resulting in unintended access rights to sensitive objects.", + Lang: "en", + }, + "287": { + CweID: "287", + Name: "Improper Authentication", + Description: "When an actor claims to have a given identity, the software does not prove or insufficiently proves that the claim is correct.", + ExtendedDescription: "", + Lang: "en", + }, + "288": { + CweID: "288", + Name: "Authentication Bypass Using an Alternate Path or Channel", + Description: "A product requires authentication, but the product has an alternate path or channel that does not require authentication.", + ExtendedDescription: "", + Lang: "en", + }, + "289": { + CweID: "289", + Name: "Authentication Bypass by Alternate Name", + Description: "The software performs authentication based on the name of a resource being accessed, or the name of the actor performing the access, but it does not properly check all possible names for that resource or actor.", + ExtendedDescription: "", + Lang: "en", + }, + "29": { + CweID: "29", + Name: "Path Traversal: '\\..\\filename'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\\..\\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "290": { + CweID: "290", + Name: "Authentication Bypass by Spoofing", + Description: "This attack-focused weakness is caused by improperly implemented authentication schemes that are subject to spoofing attacks.", + ExtendedDescription: "", + Lang: "en", + }, + "291": { + CweID: "291", + Name: "Reliance on IP Address for Authentication", + Description: "The software uses an IP address for authentication.", + ExtendedDescription: "IP addresses can be easily spoofed. Attackers can forge the source IP address of the packets they send, but response packets will return to the forged IP address. To see the response packets, the attacker has to sniff the traffic between the victim machine and the forged IP address. In order to accomplish the required sniffing, attackers typically attempt to locate themselves on the same subnet as the victim machine. Attackers may be able to circumvent this requirement by using source routing, but source routing is disabled across much of the Internet today. In summary, IP address verification can be a useful part of an authentication scheme, but it should not be the single factor required for authentication.", + Lang: "en", + }, + "292": { + CweID: "292", + Name: "DEPRECATED (Duplicate): Trusting Self-reported DNS Name", + Description: "This entry has been deprecated because it was a duplicate of CWE-350. All content has been transferred to CWE-350.", + ExtendedDescription: "", + Lang: "en", + }, + "293": { + CweID: "293", + Name: "Using Referer Field for Authentication", + Description: "The referer field in HTTP requests can be easily modified and, as such, is not a valid means of message integrity checking.", + ExtendedDescription: "", + Lang: "en", + }, + "294": { + CweID: "294", + Name: "Authentication Bypass by Capture-replay", + Description: "A capture-replay flaw exists when the design of the software makes it possible for a malicious user to sniff network traffic and bypass authentication by replaying it to the server in question to the same effect as the original message (or with minor changes).", + ExtendedDescription: "Capture-replay attacks are common and can be difficult to defeat without cryptography. They are a subset of network injection attacks that rely on observing previously-sent valid commands, then changing them slightly if necessary and resending the same commands to the server.", + Lang: "en", + }, + "295": { + CweID: "295", + Name: "Improper Certificate Validation", + Description: "The software does not validate, or incorrectly validates, a certificate.", + ExtendedDescription: "When a certificate is invalid or malicious, it might allow an attacker to spoof a trusted entity by using a man-in-the-middle (MITM) attack. The software might connect to a malicious host while believing it is a trusted host, or the software might be deceived into accepting spoofed data that appears to originate from a trusted host.", + Lang: "en", + }, + "296": { + CweID: "296", + Name: "Improper Following of a Certificate's Chain of Trust", + Description: "The software does not follow, or incorrectly follows, the chain of trust for a certificate back to a trusted root certificate, resulting in incorrect trust of any resource that is associated with that certificate.", + ExtendedDescription: "", + Lang: "en", + }, + "297": { + CweID: "297", + Name: "Improper Validation of Certificate with Host Mismatch", + Description: "The software communicates with a host that provides a certificate, but the software does not properly ensure that the certificate is actually associated with that host.", + ExtendedDescription: "", + Lang: "en", + }, + "298": { + CweID: "298", + Name: "Improper Validation of Certificate Expiration", + Description: "A certificate expiration is not validated or is incorrectly validated, so trust may be assigned to certificates that have been abandoned due to age.", + ExtendedDescription: "When the expiration of a certificate is not taken into account, no trust has necessarily been conveyed through it. Therefore, the validity of the certificate cannot be verified and all benefit of the certificate is lost.", + Lang: "en", + }, + "299": { + CweID: "299", + Name: "Improper Check for Certificate Revocation", + Description: "The software does not check or incorrectly checks the revocation status of a certificate, which may cause it to use a certificate that has been compromised.", + ExtendedDescription: "An improper check for certificate revocation is a far more serious flaw than related certificate failures. This is because the use of any revoked certificate is almost certainly malicious. The most common reason for certificate revocation is compromise of the system in question, with the result that no legitimate servers will be using a revoked certificate, unless they are sorely out of sync.", + Lang: "en", + }, + "30": { + CweID: "30", + Name: "Path Traversal: '\\dir\\..\\filename'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\\dir\\..\\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "300": { + CweID: "300", + Name: "Channel Accessible by Non-Endpoint ('Man-in-the-Middle')", + Description: "The product does not adequately verify the identity of actors at both ends of a communication channel, or does not adequately ensure the integrity of the channel, in a way that allows the channel to be accessed or influenced by an actor that is not an endpoint.", + ExtendedDescription: "In order to establish secure communication between two parties, it is often important to adequately verify the identity of entities at each end of the communication channel. Inadequate or inconsistent verification may result in insufficient or incorrect identification of either communicating entity. This can have negative consequences such as misplaced trust in the entity at the other end of the channel. An attacker can leverage this by interposing between the communicating entities and masquerading as the original entity. In the absence of sufficient verification of identity, such an attacker can eavesdrop and potentially modify the communication between the original entities.", + Lang: "en", + }, + "301": { + CweID: "301", + Name: "Reflection Attack in an Authentication Protocol", + Description: "Simple authentication protocols are subject to reflection attacks if a malicious user can use the target machine to impersonate a trusted user.", + ExtendedDescription: "A mutual authentication protocol requires each party to respond to a random challenge by the other party by encrypting it with a pre-shared key. Often, however, such protocols employ the same pre-shared key for communication with a number of different entities. A malicious user or an attacker can easily compromise this protocol without possessing the correct key by employing a reflection attack on the protocol.", + Lang: "en", + }, + "302": { + CweID: "302", + Name: "Authentication Bypass by Assumed-Immutable Data", + Description: "The authentication scheme or implementation uses key data elements that are assumed to be immutable, but can be controlled or modified by the attacker.", + ExtendedDescription: "", + Lang: "en", + }, + "303": { + CweID: "303", + Name: "Incorrect Implementation of Authentication Algorithm", + Description: "The requirements for the software dictate the use of an established authentication algorithm, but the implementation of the algorithm is incorrect.", + ExtendedDescription: "This incorrect implementation may allow authentication to be bypassed.", + Lang: "en", + }, + "304": { + CweID: "304", + Name: "Missing Critical Step in Authentication", + Description: "The software implements an authentication technique, but it skips a step that weakens the technique.", + ExtendedDescription: "Authentication techniques should follow the algorithms that define them exactly, otherwise authentication can be bypassed or more easily subjected to brute force attacks.", + Lang: "en", + }, + "305": { + CweID: "305", + Name: "Authentication Bypass by Primary Weakness", + Description: "The authentication algorithm is sound, but the implemented mechanism can be bypassed as the result of a separate weakness that is primary to the authentication error.", + ExtendedDescription: "", + Lang: "en", + }, + "306": { + CweID: "306", + Name: "Missing Authentication for Critical Function", + Description: "The software does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.", + ExtendedDescription: "", + Lang: "en", + }, + "307": { + CweID: "307", + Name: "Improper Restriction of Excessive Authentication Attempts", + Description: "The software does not implement sufficient measures to prevent multiple failed authentication attempts within in a short time frame, making it more susceptible to brute force attacks.", + ExtendedDescription: "", + Lang: "en", + }, + "308": { + CweID: "308", + Name: "Use of Single-factor Authentication", + Description: "The use of single-factor authentication can lead to unnecessary risk of compromise when compared with the benefits of a dual-factor authentication scheme.", + ExtendedDescription: "While the use of multiple authentication schemes is simply piling on more complexity on top of authentication, it is inestimably valuable to have such measures of redundancy. The use of weak, reused, and common passwords is rampant on the internet. Without the added protection of multiple authentication schemes, a single mistake can result in the compromise of an account. For this reason, if multiple schemes are possible and also easy to use, they should be implemented and required.", + Lang: "en", + }, + "309": { + CweID: "309", + Name: "Use of Password System for Primary Authentication", + Description: "The use of password systems as the primary means of authentication may be subject to several flaws or shortcomings, each reducing the effectiveness of the mechanism.", + ExtendedDescription: "", + Lang: "en", + }, + "31": { + CweID: "31", + Name: "Path Traversal: 'dir\\..\\..\\filename'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize 'dir\\..\\..\\filename' (multiple internal backslash dot dot) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "311": { + CweID: "311", + Name: "Missing Encryption of Sensitive Data", + Description: "The software does not encrypt sensitive or critical information before storage or transmission.", + ExtendedDescription: "The lack of proper data encryption passes up the guarantees of confidentiality, integrity, and accountability that properly implemented encryption conveys.", + Lang: "en", + }, + "312": { + CweID: "312", + Name: "Cleartext Storage of Sensitive Information", + Description: "The application stores sensitive information in cleartext within a resource that might be accessible to another control sphere.", + ExtendedDescription: "Because the information is stored in cleartext, attackers could potentially read it. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "313": { + CweID: "313", + Name: "Cleartext Storage in a File or on Disk", + Description: "The application stores sensitive information in cleartext in a file, or on disk.", + ExtendedDescription: "The sensitive information could be read by attackers with access to the file, or with physical or administrator access to the raw disk. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "314": { + CweID: "314", + Name: "Cleartext Storage in the Registry", + Description: "The application stores sensitive information in cleartext in the registry.", + ExtendedDescription: "Attackers can read the information by accessing the registry key. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "315": { + CweID: "315", + Name: "Cleartext Storage of Sensitive Information in a Cookie", + Description: "The application stores sensitive information in cleartext in a cookie.", + ExtendedDescription: "Attackers can use widely-available tools to view the cookie and read the sensitive information. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "316": { + CweID: "316", + Name: "Cleartext Storage of Sensitive Information in Memory", + Description: "The application stores sensitive information in cleartext in memory.", + ExtendedDescription: "", + Lang: "en", + }, + "317": { + CweID: "317", + Name: "Cleartext Storage of Sensitive Information in GUI", + Description: "The application stores sensitive information in cleartext within the GUI.", + ExtendedDescription: "An attacker can often obtain data from a GUI, even if hidden, by using an API to directly access GUI objects such as windows and menus. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "318": { + CweID: "318", + Name: "Cleartext Storage of Sensitive Information in Executable", + Description: "The application stores sensitive information in cleartext in an executable.", + ExtendedDescription: "Attackers can reverse engineer binary code to obtain secret data. This is especially easy when the cleartext is plain ASCII. Even if the information is encoded in a way that is not human-readable, certain techniques could determine which encoding is being used, then decode the information.", + Lang: "en", + }, + "319": { + CweID: "319", + Name: "Cleartext Transmission of Sensitive Information", + Description: "The software transmits sensitive or security-critical data in cleartext in a communication channel that can be sniffed by unauthorized actors.", + ExtendedDescription: "Many communication channels can be 'sniffed' by attackers during data transmission. For example, network traffic can often be sniffed by any attacker who has access to a network interface. This significantly lowers the difficulty of exploitation by attackers.", + Lang: "en", + }, + "32": { + CweID: "32", + Name: "Path Traversal: '...' (Triple Dot)", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '...' (triple dot) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "321": { + CweID: "321", + Name: "Use of Hard-coded Cryptographic Key", + Description: "The use of a hard-coded cryptographic key significantly increases the possibility that encrypted data may be recovered.", + ExtendedDescription: "", + Lang: "en", + }, + "322": { + CweID: "322", + Name: "Key Exchange without Entity Authentication", + Description: "The software performs a key exchange with an actor without verifying the identity of that actor.", + ExtendedDescription: "Performing a key exchange will preserve the integrity of the information sent between two entities, but this will not guarantee that the entities are who they claim they are. This may enable a set of 'man-in-the-middle' attacks. Typically, this involves a victim client that contacts a malicious server that is impersonating a trusted server. If the client skips authentication or ignores an authentication failure, the malicious server may request authentication information from the user. The malicious server can then use this authentication information to log in to the trusted server using the victim's credentials, sniff traffic between the victim and trusted server, etc.", + Lang: "en", + }, + "323": { + CweID: "323", + Name: "Reusing a Nonce, Key Pair in Encryption", + Description: "Nonces should be used for the present occasion and only once.", + ExtendedDescription: "", + Lang: "en", + }, + "324": { + CweID: "324", + Name: "Use of a Key Past its Expiration Date", + Description: "The product uses a cryptographic key or password past its expiration date, which diminishes its safety significantly by increasing the timing window for cracking attacks against that key.", + ExtendedDescription: "While the expiration of keys does not necessarily ensure that they are compromised, it is a significant concern that keys which remain in use for prolonged periods of time have a decreasing probability of integrity. For this reason, it is important to replace keys within a period of time proportional to their strength.", + Lang: "en", + }, + "325": { + CweID: "325", + Name: "Missing Required Cryptographic Step", + Description: "The software does not implement a required step in a cryptographic algorithm, resulting in weaker encryption than advertised by that algorithm.", + ExtendedDescription: "Cryptographic implementations should follow the algorithms that define them exactly, otherwise encryption can be weaker than expected.", + Lang: "en", + }, + "326": { + CweID: "326", + Name: "Inadequate Encryption Strength", + Description: "The software stores or transmits sensitive data using an encryption scheme that is theoretically sound, but is not strong enough for the level of protection required.", + ExtendedDescription: "A weak encryption scheme can be subjected to brute force attacks that have a reasonable chance of succeeding using current attack methods and resources.", + Lang: "en", + }, + "327": { + CweID: "327", + Name: "Use of a Broken or Risky Cryptographic Algorithm", + Description: "The use of a broken or risky cryptographic algorithm is an unnecessary risk that may result in the exposure of sensitive information.", + ExtendedDescription: "The use of a non-standard algorithm is dangerous because a determined attacker may be able to break the algorithm and compromise whatever data has been protected. Well-known techniques may exist to break the algorithm.", + Lang: "en", + }, + "328": { + CweID: "328", + Name: "Reversible One-Way Hash", + Description: "The product uses a hashing algorithm that produces a hash value that can be used to determine the original input, or to find an input that can produce the same hash, more efficiently than brute force techniques.", + ExtendedDescription: "This weakness is especially dangerous when the hash is used in security algorithms that require the one-way property to hold. For example, if an authentication system takes an incoming password and generates a hash, then compares the hash to another hash that it has stored in its authentication database, then the ability to create a collision could allow an attacker to provide an alternate password that produces the same target hash, bypassing authentication.", + Lang: "en", + }, + "329": { + CweID: "329", + Name: "Not Using a Random IV with CBC Mode", + Description: "Not using a random initialization Vector (IV) with Cipher Block Chaining (CBC) Mode causes algorithms to be susceptible to dictionary attacks.", + ExtendedDescription: "", + Lang: "en", + }, + "33": { + CweID: "33", + Name: "Path Traversal: '....' (Multiple Dot)", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '....' (multiple dot) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "330": { + CweID: "330", + Name: "Use of Insufficiently Random Values", + Description: "The software may use insufficiently random numbers or values in a security context that depends on unpredictable numbers.", + ExtendedDescription: "When software generates predictable values in a context requiring unpredictability, it may be possible for an attacker to guess the next value that will be generated, and use this guess to impersonate another user or access sensitive information.", + Lang: "en", + }, + "331": { + CweID: "331", + Name: "Insufficient Entropy", + Description: "The software uses an algorithm or scheme that produces insufficient entropy, leaving patterns or clusters of values that are more likely to occur than others.", + ExtendedDescription: "", + Lang: "en", + }, + "332": { + CweID: "332", + Name: "Insufficient Entropy in PRNG", + Description: "The lack of entropy available for, or used by, a Pseudo-Random Number Generator (PRNG) can be a stability and security threat.", + ExtendedDescription: "", + Lang: "en", + }, + "333": { + CweID: "333", + Name: "Improper Handling of Insufficient Entropy in TRNG", + Description: "True random number generators (TRNG) generally have a limited source of entropy and therefore can fail or block.", + ExtendedDescription: "The rate at which true random numbers can be generated is limited. It is important that one uses them only when they are needed for security.", + Lang: "en", + }, + "334": { + CweID: "334", + Name: "Small Space of Random Values", + Description: "The number of possible random values is smaller than needed by the product, making it more susceptible to brute force attacks.", + ExtendedDescription: "", + Lang: "en", + }, + "335": { + CweID: "335", + Name: "Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG)", + Description: "The software uses a Pseudo-Random Number Generator (PRNG) that does not correctly manage seeds.", + ExtendedDescription: "", + Lang: "en", + }, + "336": { + CweID: "336", + Name: "Same Seed in Pseudo-Random Number Generator (PRNG)", + Description: "A Pseudo-Random Number Generator (PRNG) uses the same seed each time the product is initialized.", + ExtendedDescription: "If an attacker can guess (or knows) the seed, then the attacker may be able to determine the random numbers that will be produced from the PRNG.", + Lang: "en", + }, + "337": { + CweID: "337", + Name: "Predictable Seed in Pseudo-Random Number Generator (PRNG)", + Description: "A Pseudo-Random Number Generator (PRNG) is initialized from a predictable seed, such as the process ID or system time.", + ExtendedDescription: "The use of predictable seeds significantly reduces the number of possible seeds that an attacker would need to test in order to predict which random numnbers will be generated by the PRNG.", + Lang: "en", + }, + "338": { + CweID: "338", + Name: "Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)", + Description: "The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.", + ExtendedDescription: "", + Lang: "en", + }, + "339": { + CweID: "339", + Name: "Small Seed Space in PRNG", + Description: "A PRNG uses a relatively small space of seeds.", + ExtendedDescription: "", + Lang: "en", + }, + "34": { + CweID: "34", + Name: "Path Traversal: '....//'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '....//' (doubled dot dot slash) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "340": { + CweID: "340", + Name: "Predictability Problems", + Description: "Weaknesses in this category are related to schemes that generate numbers or identifiers that are more predictable than required by the application.", + ExtendedDescription: "", + Lang: "en", + }, + "341": { + CweID: "341", + Name: "Predictable from Observable State", + Description: "A number or object is predictable based on observations that the attacker can make about the state of the system or network, such as time, process ID, etc.", + ExtendedDescription: "", + Lang: "en", + }, + "342": { + CweID: "342", + Name: "Predictable Exact Value from Previous Values", + Description: "An exact value or random number can be precisely predicted by observing previous values.", + ExtendedDescription: "", + Lang: "en", + }, + "343": { + CweID: "343", + Name: "Predictable Value Range from Previous Values", + Description: "The software's random number generator produces a series of values which, when observed, can be used to infer a relatively small range of possibilities for the next value that could be generated.", + ExtendedDescription: "The output of a random number generator should not be predictable based on observations of previous values. In some cases, an attacker cannot predict the exact value that will be produced next, but can narrow down the possibilities significantly. This reduces the amount of effort to perform a brute force attack. For example, suppose the product generates random numbers between 1 and 100, but it always produces a larger value until it reaches 100. If the generator produces an 80, then the attacker knows that the next value will be somewhere between 81 and 100. Instead of 100 possibilities, the attacker only needs to consider 20.", + Lang: "en", + }, + "344": { + CweID: "344", + Name: "Use of Invariant Value in Dynamically Changing Context", + Description: "The product uses a constant value, name, or reference, but this value can (or should) vary across different environments.", + ExtendedDescription: "", + Lang: "en", + }, + "345": { + CweID: "345", + Name: "Insufficient Verification of Data Authenticity", + Description: "The software does not sufficiently verify the origin or authenticity of data, in a way that causes it to accept invalid data.", + ExtendedDescription: "", + Lang: "en", + }, + "346": { + CweID: "346", + Name: "Origin Validation Error", + Description: "The software does not properly verify that the source of data or communication is valid.", + ExtendedDescription: "", + Lang: "en", + }, + "347": { + CweID: "347", + Name: "Improper Verification of Cryptographic Signature", + Description: "The software does not verify, or incorrectly verifies, the cryptographic signature for data.", + ExtendedDescription: "", + Lang: "en", + }, + "348": { + CweID: "348", + Name: "Use of Less Trusted Source", + Description: "The software has two different sources of the same data or information, but it uses the source that has less support for verification, is less trusted, or is less resistant to attack.", + ExtendedDescription: "", + Lang: "en", + }, + "349": { + CweID: "349", + Name: "Acceptance of Extraneous Untrusted Data With Trusted Data", + Description: "The software, when processing trusted data, accepts any untrusted data that is also included with the trusted data, treating the untrusted data as if it were trusted.", + ExtendedDescription: "", + Lang: "en", + }, + "35": { + CweID: "35", + Name: "Path Traversal: '.../...//'", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '.../...//' (doubled triple dot slash) sequences that can resolve to a location that is outside of that directory.", + ExtendedDescription: "", + Lang: "en", + }, + "350": { + CweID: "350", + Name: "Reliance on Reverse DNS Resolution for a Security-Critical Action", + Description: "The software performs reverse DNS resolution on an IP address to obtain the hostname and make a security decision, but it does not properly ensure that the IP address is truly associated with the hostname.", + ExtendedDescription: "", + Lang: "en", + }, + "351": { + CweID: "351", + Name: "Insufficient Type Distinction", + Description: "The software does not properly distinguish between different types of elements in a way that leads to insecure behavior.", + ExtendedDescription: "", + Lang: "en", + }, + "352": { + CweID: "352", + Name: "Cross-Site Request Forgery (CSRF)", + Description: "The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request.", + ExtendedDescription: "When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in exposure of data or unintended code execution.", + Lang: "en", + }, + "353": { + CweID: "353", + Name: "Missing Support for Integrity Check", + Description: "The software uses a transmission protocol that does not include a mechanism for verifying the integrity of the data during transmission, such as a checksum.", + ExtendedDescription: "If integrity check values or 'checksums' are omitted from a protocol, there is no way of determining if data has been corrupted in transmission. The lack of checksum functionality in a protocol removes the first application-level check of data that can be used. The end-to-end philosophy of checks states that integrity checks should be performed at the lowest level that they can be completely implemented. Excluding further sanity checks and input validation performed by applications, the protocol's checksum is the most important level of checksum, since it can be performed more completely than at any previous level and takes into account entire messages, as opposed to single packets.", + Lang: "en", + }, + "354": { + CweID: "354", + Name: "Improper Validation of Integrity Check Value", + Description: "The software does not validate or incorrectly validates the integrity check values or 'checksums' of a message. This may prevent it from detecting if the data has been modified or corrupted in transmission.", + ExtendedDescription: "Improper validation of checksums before use results in an unnecessary risk that can easily be mitigated. The protocol specification describes the algorithm used for calculating the checksum. It is then a simple matter of implementing the calculation and verifying that the calculated checksum and the received checksum match. Improper verification of the calculated checksum and the received checksum can lead to far greater consequences.", + Lang: "en", + }, + "356": { + CweID: "356", + Name: "Product UI does not Warn User of Unsafe Actions", + Description: "The software's user interface does not warn the user before undertaking an unsafe action on behalf of that user. This makes it easier for attackers to trick users into inflicting damage to their system.", + ExtendedDescription: "Software systems should warn users that a potentially dangerous action may occur if the user proceeds. For example, if the user downloads a file from an unknown source and attempts to execute the file on their machine, then the application's GUI can indicate that the file is unsafe.", + Lang: "en", + }, + "357": { + CweID: "357", + Name: "Insufficient UI Warning of Dangerous Operations", + Description: "The user interface provides a warning to a user regarding dangerous or sensitive operations, but the warning is not noticeable enough to warrant attention.", + ExtendedDescription: "", + Lang: "en", + }, + "358": { + CweID: "358", + Name: "Improperly Implemented Security Check for Standard", + Description: "The software does not implement or incorrectly implements one or more security-relevant checks as specified by the design of a standardized algorithm, protocol, or technique.", + ExtendedDescription: "", + Lang: "en", + }, + "359": { + CweID: "359", + Name: "Exposure of Private Information ('Privacy Violation')", + Description: "The software does not properly prevent private data (such as credit card numbers) from being accessed by actors who either (1) are not explicitly authorized to access the data or (2) do not have the implicit consent of the people to which the data is related.", + ExtendedDescription: "", + Lang: "en", + }, + "36": { + CweID: "36", + Name: "Absolute Path Traversal", + Description: "The software uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize absolute path sequences such as '/abs/path' that can resolve to a location that is outside of that directory.", + ExtendedDescription: "This allows attackers to traverse the file system to access files or directories that are outside of the restricted directory.", + Lang: "en", + }, + "360": { + CweID: "360", + Name: "Trust of System Event Data", + Description: "Security based on event locations are insecure and can be spoofed.", + ExtendedDescription: "Events are a messaging system which may provide control data to programs listening for events. Events often do not have any type of authentication framework to allow them to be verified from a trusted source. Any application, in Windows, on a given desktop can send a message to any window on the same desktop. There is no authentication framework for these messages. Therefore, any message can be used to manipulate any process on the desktop if the process does not check the validity and safeness of those messages.", + Lang: "en", + }, + "362": { + CweID: "362", + Name: "Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')", + Description: "The program contains a code sequence that can run concurrently with other code, and the code sequence requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence that is operating concurrently.", + ExtendedDescription: "", + Lang: "en", + }, + "363": { + CweID: "363", + Name: "Race Condition Enabling Link Following", + Description: "The software checks the status of a file or directory before accessing it, which produces a race condition in which the file can be replaced with a link before the access is performed, causing the software to access the wrong file.", + ExtendedDescription: "While developers might expect that there is a very narrow time window between the time of check and time of use, there is still a race condition. An attacker could cause the software to slow down (e.g. with memory consumption), causing the time window to become larger. Alternately, in some situations, the attacker could win the race by performing a large number of attacks.", + Lang: "en", + }, + "364": { + CweID: "364", + Name: "Signal Handler Race Condition", + Description: "The software uses a signal handler that introduces a race condition.", + ExtendedDescription: "", + Lang: "en", + }, + "365": { + CweID: "365", + Name: "Race Condition in Switch", + Description: "The code contains a switch statement in which the switched variable can be modified while the switch is still executing, resulting in unexpected behavior.", + ExtendedDescription: "This issue is particularly important in the case of switch statements that involve fall-through style case statements - ie., those which do not end with break. If the variable being tested by the switch changes in the course of execution, this could change the intended logic of the switch so much that it places the process in a contradictory state and in some cases could even result in memory corruption.", + Lang: "en", + }, + "366": { + CweID: "366", + Name: "Race Condition within a Thread", + Description: "If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined.", + ExtendedDescription: "", + Lang: "en", + }, + "367": { + CweID: "367", + Name: "Time-of-check Time-of-use (TOCTOU) Race Condition", + Description: "The software checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. This can cause the software to perform invalid actions when the resource is in an unexpected state.", + ExtendedDescription: "This weakness can be security-relevant when an attacker can influence the state of the resource between check and use. This can happen with shared resources such as files, memory, or even variables in multithreaded programs.", + Lang: "en", + }, + "368": { + CweID: "368", + Name: "Context Switching Race Condition", + Description: "A product performs a series of non-atomic actions to switch between contexts that cross privilege or other security boundaries, but a race condition allows an attacker to modify or misrepresent the product's behavior during the switch.", + ExtendedDescription: "This is commonly seen in web browser vulnerabilities in which the attacker can perform certain actions while the browser is transitioning from a trusted to an untrusted domain, or vice versa, and the browser performs the actions on one domain using the trust level and resources of the other domain.", + Lang: "en", + }, + "369": { + CweID: "369", + Name: "Divide By Zero", + Description: "The product divides a value by zero.", + ExtendedDescription: "This weakness typically occurs when an unexpected value is provided to the product, or if an error occurs that is not properly detected. It frequently occurs in calculations involving physical dimensions such as size, length, width, and height.", + Lang: "en", + }, + "37": { + CweID: "37", + Name: "Path Traversal: '/absolute/pathname/here'", + Description: "A software system that accepts input in the form of a slash absolute path ('/absolute/pathname/here') without appropriate validation can allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "370": { + CweID: "370", + Name: "Missing Check for Certificate Revocation after Initial Check", + Description: "The software does not check the revocation status of a certificate after its initial revocation check, which can cause the software to perform privileged actions even after the certificate is revoked at a later time.", + ExtendedDescription: "If the revocation status of a certificate is not checked before each action that requires privileges, the system may be subject to a race condition. If a certificate is revoked after the initial check, all subsequent actions taken with the owner of the revoked certificate will lose all benefits guaranteed by the certificate. In fact, it is almost certain that the use of a revoked certificate indicates malicious activity.", + Lang: "en", + }, + "372": { + CweID: "372", + Name: "Incomplete Internal State Distinction", + Description: "The software does not properly determine which state it is in, causing it to assume it is in state X when in fact it is in state Y, causing it to perform incorrect operations in a security-relevant manner.", + ExtendedDescription: "", + Lang: "en", + }, + "373": { + CweID: "373", + Name: "DEPRECATED: State Synchronization Error", + Description: "This entry was deprecated because it overlapped the same concepts as race condition (CWE-362) and Improper Synchronization (CWE-662).", + ExtendedDescription: "", + Lang: "en", + }, + "374": { + CweID: "374", + Name: "Passing Mutable Objects to an Untrusted Method", + Description: "The program sends non-cloned mutable data as an argument to a method or function.", + ExtendedDescription: "The function or method that has been called can alter or delete the mutable data. This could violate assumptions that the calling function has made about its state. In situations where unknown code is called with references to mutable data, this external code could make changes to the data sent. If this data was not previously cloned, the modified data might not be valid in the context of execution.", + Lang: "en", + }, + "375": { + CweID: "375", + Name: "Returning a Mutable Object to an Untrusted Caller", + Description: "Sending non-cloned mutable data as a return value may result in that data being altered or deleted by the calling function.", + ExtendedDescription: "In situations where functions return references to mutable data, it is possible that the external code which called the function may make changes to the data sent. If this data was not previously cloned, the class will then be using modified data which may violate assumptions about its internal state.", + Lang: "en", + }, + "377": { + CweID: "377", + Name: "Insecure Temporary File", + Description: "Creating and using insecure temporary files can leave application and system data vulnerable to attack.", + ExtendedDescription: "", + Lang: "en", + }, + "378": { + CweID: "378", + Name: "Creation of Temporary File With Insecure Permissions", + Description: "Opening temporary files without appropriate measures or controls can leave the file, its contents and any function that it impacts vulnerable to attack.", + ExtendedDescription: "", + Lang: "en", + }, + "379": { + CweID: "379", + Name: "Creation of Temporary File in Directory with Incorrect Permissions", + Description: "The software creates a temporary file in a directory whose permissions allow unintended actors to determine the file's existence or otherwise access that file.", + ExtendedDescription: "On some operating systems, the fact that the temporary file exists may be apparent to any user with sufficient privileges to access that directory. Since the file is visible, the application that is using the temporary file could be known. If one has access to list the processes on the system, the attacker has gained information about what the user is doing at that time. By correlating this with the applications the user is running, an attacker could potentially discover what a user's actions are. From this, higher levels of security could be breached.", + Lang: "en", + }, + "38": { + CweID: "38", + Name: "Path Traversal: '\\absolute\\pathname\\here'", + Description: "A software system that accepts input in the form of a backslash absolute path ('\\absolute\\pathname\\here') without appropriate validation can allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "382": { + CweID: "382", + Name: "J2EE Bad Practices: Use of System.exit()", + Description: "A J2EE application uses System.exit(), which also shuts down its container.", + ExtendedDescription: "It is never a good idea for a web application to attempt to shut down the application container. Access to a function that can shut down the application is an avenue for Denial of Service (DoS) attacks.", + Lang: "en", + }, + "383": { + CweID: "383", + Name: "J2EE Bad Practices: Direct Use of Threads", + Description: "Thread management in a Web application is forbidden in some circumstances and is always highly error prone.", + ExtendedDescription: "Thread management in a web application is forbidden by the J2EE standard in some circumstances and is always highly error prone. Managing threads is difficult and is likely to interfere in unpredictable ways with the behavior of the application container. Even without interfering with the container, thread management usually leads to bugs that are hard to detect and diagnose like deadlock, race conditions, and other synchronization errors.", + Lang: "en", + }, + "384": { + CweID: "384", + Name: "Session Fixation", + Description: "Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions.", + ExtendedDescription: "", + Lang: "en", + }, + "385": { + CweID: "385", + Name: "Covert Timing Channel", + Description: "Covert timing channels convey information by modulating some aspect of system behavior over time, so that the program receiving the information can observe system behavior and infer protected information.", + ExtendedDescription: "", + Lang: "en", + }, + "386": { + CweID: "386", + Name: "Symbolic Name not Mapping to Correct Object", + Description: "A constant symbolic reference to an object is used, even though the reference can resolve to a different object over time.", + ExtendedDescription: "", + Lang: "en", + }, + "39": { + CweID: "39", + Name: "Path Traversal: 'C:dirname'", + Description: "An attacker can inject a drive letter or Windows volume letter ('C:dirname') into a software system to potentially redirect access to an unintended location or arbitrary file.", + ExtendedDescription: "", + Lang: "en", + }, + "390": { + CweID: "390", + Name: "Detection of Error Condition Without Action", + Description: "The software detects a specific error, but takes no actions to handle the error.", + ExtendedDescription: "", + Lang: "en", + }, + "391": { + CweID: "391", + Name: "Unchecked Error Condition", + Description: "Ignoring exceptions and other error conditions may allow an attacker to induce unexpected behavior unnoticed.", + ExtendedDescription: "", + Lang: "en", + }, + "392": { + CweID: "392", + Name: "Missing Report of Error Condition", + Description: "The software encounters an error but does not provide a status code or return value to indicate that an error has occurred.", + ExtendedDescription: "", + Lang: "en", + }, + "393": { + CweID: "393", + Name: "Return of Wrong Status Code", + Description: "A function or operation returns an incorrect return value or status code that does not indicate an error, but causes the product to modify its behavior based on the incorrect result.", + ExtendedDescription: "This can lead to unpredictable behavior. If the function is used to make security-critical decisions or provide security-critical information, then the wrong status code can cause the software to assume that an action is safe, even when it is not.", + Lang: "en", + }, + "394": { + CweID: "394", + Name: "Unexpected Status Code or Return Value", + Description: "The software does not properly check when a function or operation returns a value that is legitimate for the function, but is not expected by the software.", + ExtendedDescription: "", + Lang: "en", + }, + "395": { + CweID: "395", + Name: "Use of NullPointerException Catch to Detect NULL Pointer Dereference", + Description: "Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer.", + ExtendedDescription: "", + Lang: "en", + }, + "396": { + CweID: "396", + Name: "Declaration of Catch for Generic Exception", + Description: "Catching overly broad exceptions promotes complex error handling code that is more likely to contain security vulnerabilities.", + ExtendedDescription: "Multiple catch blocks can get ugly and repetitive, but 'condensing' catch blocks by catching a high-level class like Exception can obscure exceptions that deserve special treatment or that should not be caught at this point in the program. Catching an overly broad exception essentially defeats the purpose of Java's typed exceptions, and can become particularly dangerous if the program grows and begins to throw new types of exceptions. The new exception types will not receive any attention.", + Lang: "en", + }, + "397": { + CweID: "397", + Name: "Declaration of Throws for Generic Exception", + Description: "Throwing overly broad exceptions promotes complex error handling code that is more likely to contain security vulnerabilities.", + ExtendedDescription: "Declaring a method to throw Exception or Throwable makes it difficult for callers to perform proper error handling and error recovery. Java's exception mechanism, for example, is set up to make it easy for callers to anticipate what can go wrong and write code to handle each specific exceptional circumstance. Declaring that a method throws a generic form of exception defeats this system.", + Lang: "en", + }, + "40": { + CweID: "40", + Name: "Path Traversal: '\\\\UNC\\share\\name\\' (Windows UNC Share)", + Description: "An attacker can inject a Windows UNC share ('\\\\UNC\\share\\name') into a software system to potentially redirect access to an unintended location or arbitrary file.", + ExtendedDescription: "", + Lang: "en", + }, + "400": { + CweID: "400", + Name: "Uncontrolled Resource Consumption ('Resource Exhaustion')", + Description: "The software does not properly restrict the size or amount of resources that are requested or influenced by an actor, which can be used to consume more resources than intended.", + ExtendedDescription: "", + Lang: "en", + }, + "401": { + CweID: "401", + Name: "Improper Release of Memory Before Removing Last Reference ('Memory Leak')", + Description: "The software does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory.", + ExtendedDescription: "This is often triggered by improper handling of malformed data or unexpectedly interrupted sessions.", + Lang: "en", + }, + "402": { + CweID: "402", + Name: "Transmission of Private Resources into a New Sphere ('Resource Leak')", + Description: "The software makes resources available to untrusted parties when those resources are only intended to be accessed by the software.", + ExtendedDescription: "", + Lang: "en", + }, + "403": { + CweID: "403", + Name: "Exposure of File Descriptor to Unintended Control Sphere ('File Descriptor Leak')", + Description: "A process does not close sensitive file descriptors before invoking a child process, which allows the child to perform unauthorized I/O operations using those descriptors.", + ExtendedDescription: "When a new process is forked or executed, the child process inherits any open file descriptors. When the child process has fewer privileges than the parent process, this might introduce a vulnerability if the child process can access the file descriptor but does not have the privileges to access the associated file.", + Lang: "en", + }, + "404": { + CweID: "404", + Name: "Improper Resource Shutdown or Release", + Description: "The program does not release or incorrectly releases a resource before it is made available for re-use.", + ExtendedDescription: "When a resource is created or allocated, the developer is responsible for properly releasing the resource as well as accounting for all potential paths of expiration or invalidation, such as a set period of time or revocation.", + Lang: "en", + }, + "405": { + CweID: "405", + Name: "Asymmetric Resource Consumption (Amplification)", + Description: "Software that does not appropriately monitor or control resource consumption can lead to adverse system performance.", + ExtendedDescription: "This situation is amplified if the software allows malicious users or attackers to consume more resources than their access level permits. Exploiting such a weakness can lead to asymmetric resource consumption, aiding in amplification attacks against the system or the network.", + Lang: "en", + }, + "406": { + CweID: "406", + Name: "Insufficient Control of Network Message Volume (Network Amplification)", + Description: "The software does not sufficiently monitor or control transmitted network traffic volume, so that an actor can cause the software to transmit more traffic than should be allowed for that actor.", + ExtendedDescription: "In the absence of a policy to restrict asymmetric resource consumption, the application or system cannot distinguish between legitimate transmissions and traffic intended to serve as an amplifying attack on target systems. Systems can often be configured to restrict the amount of traffic sent out on behalf of a client, based on the client's origin or access level. This is usually defined in a resource allocation policy. In the absence of a mechanism to keep track of transmissions, the system or application can be easily abused to transmit asymmetrically greater traffic than the request or client should be permitted to.", + Lang: "en", + }, + "407": { + CweID: "407", + Name: "Algorithmic Complexity", + Description: "An algorithm in a product has an inefficient worst-case computational complexity that may be detrimental to system performance and can be triggered by an attacker, typically using crafted manipulations that ensure that the worst case is being reached.", + ExtendedDescription: "", + Lang: "en", + }, + "408": { + CweID: "408", + Name: "Incorrect Behavior Order: Early Amplification", + Description: "The software allows an entity to perform a legitimate but expensive operation before authentication or authorization has taken place.", + ExtendedDescription: "", + Lang: "en", + }, + "409": { + CweID: "409", + Name: "Improper Handling of Highly Compressed Data (Data Amplification)", + Description: "The software does not handle or incorrectly handles a compressed input with a very high compression ratio that produces a large output.", + ExtendedDescription: "An example of data amplification is a 'decompression bomb,' a small ZIP file that can produce a large amount of data when it is decompressed.", + Lang: "en", + }, + "41": { + CweID: "41", + Name: "Improper Resolution of Path Equivalence", + Description: "The system or application is vulnerable to file system contents disclosure through path equivalence. Path equivalence involves the use of special characters in file and directory names. The associated manipulations are intended to generate multiple names for the same object.", + ExtendedDescription: "Path equivalence is usually employed in order to circumvent access controls expressed using an incomplete set of file name or file path representations. This is different from path traversal, wherein the manipulations are performed to generate a name for a different object.", + Lang: "en", + }, + "410": { + CweID: "410", + Name: "Insufficient Resource Pool", + Description: "The software's resource pool is not large enough to handle peak demand, which allows an attacker to prevent others from accessing the resource by using a (relatively) large number of requests for resources.", + ExtendedDescription: "Frequently the consequence is a 'flood' of connection or sessions.", + Lang: "en", + }, + "412": { + CweID: "412", + Name: "Unrestricted Externally Accessible Lock", + Description: "The software properly checks for the existence of a lock, but the lock can be externally controlled or influenced by an actor that is outside of the intended sphere of control.", + ExtendedDescription: "This prevents the software from acting on associated resources or performing other behaviors that are controlled by the presence of the lock. Relevant locks might include an exclusive lock or mutex, or modifying a shared resource that is treated as a lock. If the lock can be held for an indefinite period of time, then the denial of service could be permanent.", + Lang: "en", + }, + "413": { + CweID: "413", + Name: "Improper Resource Locking", + Description: "The software does not lock or does not correctly lock a resource when the software must have exclusive access to the resource.", + ExtendedDescription: "When a resource is not properly locked, an attacker could modify the resource while it is being operated on by the software. This might violate the software's assumption that the resource will not change, potentially leading to unexpected behaviors.", + Lang: "en", + }, + "414": { + CweID: "414", + Name: "Missing Lock Check", + Description: "A product does not check to see if a lock is present before performing sensitive operations on a resource.", + ExtendedDescription: "", + Lang: "en", + }, + "415": { + CweID: "415", + Name: "Double Free", + Description: "The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.", + ExtendedDescription: "When a program calls free() twice with the same argument, the program's memory management data structures become corrupted. This corruption can cause the program to crash or, in some circumstances, cause two later calls to malloc() to return the same pointer. If malloc() returns the same value twice and the program later gives the attacker control over the data that is written into this doubly-allocated memory, the program becomes vulnerable to a buffer overflow attack.", + Lang: "en", + }, + "416": { + CweID: "416", + Name: "Use After Free", + Description: "Referencing memory after it has been freed can cause a program to crash, use unexpected values, or execute code.", + ExtendedDescription: "", + Lang: "en", + }, + "419": { + CweID: "419", + Name: "Unprotected Primary Channel", + Description: "The software uses a primary channel for administration or restricted functionality, but it does not properly protect the channel.", + ExtendedDescription: "", + Lang: "en", + }, + "42": { + CweID: "42", + Name: "Path Equivalence: 'filename.' (Trailing Dot)", + Description: "A software system that accepts path input in the form of trailing dot ('filedir.') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "420": { + CweID: "420", + Name: "Unprotected Alternate Channel", + Description: "The software protects a primary channel, but it does not use the same level of protection for an alternate channel.", + ExtendedDescription: "", + Lang: "en", + }, + "421": { + CweID: "421", + Name: "Race Condition During Access to Alternate Channel", + Description: "The product opens an alternate channel to communicate with an authorized user, but the channel is accessible to other actors.", + ExtendedDescription: "This creates a race condition that allows an attacker to access the channel before the authorized user does.", + Lang: "en", + }, + "422": { + CweID: "422", + Name: "Unprotected Windows Messaging Channel ('Shatter')", + Description: "The software does not properly verify the source of a message in the Windows Messaging System while running at elevated privileges, creating an alternate channel through which an attacker can directly send a message to the product.", + ExtendedDescription: "", + Lang: "en", + }, + "423": { + CweID: "423", + Name: "DEPRECATED (Duplicate): Proxied Trusted Channel", + Description: "This entry has been deprecated because it was a duplicate of CWE-441. All content has been transferred to CWE-441.", + ExtendedDescription: "", + Lang: "en", + }, + "424": { + CweID: "424", + Name: "Improper Protection of Alternate Path", + Description: "The product does not sufficiently protect all possible paths that a user can take to access restricted functionality or resources.", + ExtendedDescription: "", + Lang: "en", + }, + "425": { + CweID: "425", + Name: "Direct Request ('Forced Browsing')", + Description: "The web application does not adequately enforce appropriate authorization on all restricted URLs, scripts, or files.", + ExtendedDescription: "Web applications susceptible to direct request attacks often make the false assumption that such resources can only be reached through a given navigation path and so only apply authorization at certain points in the path.", + Lang: "en", + }, + "426": { + CweID: "426", + Name: "Untrusted Search Path", + Description: "The application searches for critical resources using an externally-supplied search path that can point to resources that are not under the application's direct control.", + ExtendedDescription: "", + Lang: "en", + }, + "427": { + CweID: "427", + Name: "Uncontrolled Search Path Element", + Description: "The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.", + ExtendedDescription: "", + Lang: "en", + }, + "428": { + CweID: "428", + Name: "Unquoted Search Path or Element", + Description: "The product uses a search path that contains an unquoted element, in which the element contains whitespace or other separators. This can cause the product to access resources in a parent path.", + ExtendedDescription: "If a malicious individual has access to the file system, it is possible to elevate privileges by inserting such a file as 'C:\\Program.exe' to be run by a privileged program making use of WinExec.", + Lang: "en", + }, + "43": { + CweID: "43", + Name: "Path Equivalence: 'filename....' (Multiple Trailing Dot)", + Description: "A software system that accepts path input in the form of multiple trailing dot ('filedir....') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "430": { + CweID: "430", + Name: "Deployment of Wrong Handler", + Description: "The wrong 'handler' is assigned to process an object.", + ExtendedDescription: "An example of deploying the wrong handler would be calling a servlet to reveal source code of a .JSP file, or automatically 'determining' type of the object even if it is contradictory to an explicitly specified type.", + Lang: "en", + }, + "431": { + CweID: "431", + Name: "Missing Handler", + Description: "A handler is not available or implemented.", + ExtendedDescription: "When an exception is thrown and not caught, the process has given up an opportunity to decide if a given failure or event is worth a change in execution.", + Lang: "en", + }, + "432": { + CweID: "432", + Name: "Dangerous Signal Handler not Disabled During Sensitive Operations", + Description: "The application uses a signal handler that shares state with other signal handlers, but it does not properly mask or prevent those signal handlers from being invoked while the original signal handler is still running.", + ExtendedDescription: "During the execution of a signal handler, it can be interrupted by another handler when a different signal is sent. If the two handlers share state - such as global variables - then an attacker can corrupt the state by sending another signal before the first handler has completed execution.", + Lang: "en", + }, + "433": { + CweID: "433", + Name: "Unparsed Raw Web Content Delivery", + Description: "The software stores raw content or supporting code under the web document root with an extension that is not specifically handled by the server.", + ExtendedDescription: "If code is stored in a file with an extension such as '.inc' or '.pl', and the web server does not have a handler for that extension, then the server will likely send the contents of the file directly to the requester without the pre-processing that was expected. When that file contains sensitive information such as database credentials, this may allow the attacker to compromise the application or associated components.", + Lang: "en", + }, + "434": { + CweID: "434", + Name: "Unrestricted Upload of File with Dangerous Type", + Description: "The software allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment.", + ExtendedDescription: "", + Lang: "en", + }, + "435": { + CweID: "435", + Name: "Improper Interaction Between Multiple Entities", + Description: "An interaction error occurs when two entities work correctly when running independently, but they interact in unexpected ways when they are run together.", + ExtendedDescription: "This could apply to products, systems, components, etc.", + Lang: "en", + }, + "436": { + CweID: "436", + Name: "Interpretation Conflict", + Description: "Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.", + ExtendedDescription: "This is generally found in proxies, firewalls, anti-virus software, and other intermediary devices that monitor, allow, deny, or modify traffic based on how the client or server is expected to behave.", + Lang: "en", + }, + "437": { + CweID: "437", + Name: "Incomplete Model of Endpoint Features", + Description: "A product acts as an intermediary or monitor between two or more endpoints, but it does not have a complete model of an endpoint's features, behaviors, or state, potentially causing the product to perform incorrect actions based on this incomplete model.", + ExtendedDescription: "", + Lang: "en", + }, + "439": { + CweID: "439", + Name: "Behavioral Change in New Version or Environment", + Description: "A's behavior or functionality changes with a new version of A, or a new environment, which is not known (or manageable) by B.", + ExtendedDescription: "", + Lang: "en", + }, + "44": { + CweID: "44", + Name: "Path Equivalence: 'file.name' (Internal Dot)", + Description: "A software system that accepts path input in the form of internal dot ('file.ordir') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "440": { + CweID: "440", + Name: "Expected Behavior Violation", + Description: "A feature, API, or function being used by a product behaves differently than the product expects.", + ExtendedDescription: "", + Lang: "en", + }, + "441": { + CweID: "441", + Name: "Unintended Proxy or Intermediary ('Confused Deputy')", + Description: "The software receives a request, message, or directive from an upstream component, but the software does not sufficiently preserve the original source of the request before forwarding the request to an external actor that is outside of the software's control sphere. This causes the software to appear to be the source of the request, leading it to act as a proxy or other intermediary between the upstream component and the external actor.", + ExtendedDescription: "", + Lang: "en", + }, + "443": { + CweID: "443", + Name: "DEPRECATED (Duplicate): HTTP response splitting", + Description: "This weakness can be found at CWE-113.", + ExtendedDescription: "", + Lang: "en", + }, + "444": { + CweID: "444", + Name: "Inconsistent Interpretation of HTTP Requests ('HTTP Request Smuggling')", + Description: "When malformed or abnormal HTTP requests are interpreted by one or more entities in the data flow between the user and the web server, such as a proxy or firewall, they can be interpreted inconsistently, allowing the attacker to 'smuggle' a request to one device without the other device being aware of it.", + ExtendedDescription: "", + Lang: "en", + }, + "446": { + CweID: "446", + Name: "UI Discrepancy for Security Feature", + Description: "The user interface does not correctly enable or configure a security feature, but the interface provides feedback that causes the user to believe that the feature is in a secure state.", + ExtendedDescription: "When the user interface does not properly reflect what the user asks of it, then it can lead the user into a false sense of security. For example, the user might check a box to enable a security option to enable encrypted communications, but the software does not actually enable the encryption. Alternately, the user might provide a 'restrict ALL'' access control rule, but the software only implements 'restrict SOME'.", + Lang: "en", + }, + "447": { + CweID: "447", + Name: "Unimplemented or Unsupported Feature in UI", + Description: "A UI function for a security feature appears to be supported and gives feedback to the user that suggests that it is supported, but the underlying functionality is not implemented.", + ExtendedDescription: "", + Lang: "en", + }, + "448": { + CweID: "448", + Name: "Obsolete Feature in UI", + Description: "A UI function is obsolete and the product does not warn the user.", + ExtendedDescription: "", + Lang: "en", + }, + "449": { + CweID: "449", + Name: "The UI Performs the Wrong Action", + Description: "The UI performs the wrong action with respect to the user's request.", + ExtendedDescription: "", + Lang: "en", + }, + "45": { + CweID: "45", + Name: "Path Equivalence: 'file...name' (Multiple Internal Dot)", + Description: "A software system that accepts path input in the form of multiple internal dot ('file...dir') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "450": { + CweID: "450", + Name: "Multiple Interpretations of UI Input", + Description: "The UI has multiple interpretations of user input but does not prompt the user when it selects the less secure interpretation.", + ExtendedDescription: "", + Lang: "en", + }, + "451": { + CweID: "451", + Name: "User Interface (UI) Misrepresentation of Critical Information", + Description: "The user interface (UI) does not properly represent critical information to the user, allowing the information - or its source - to be obscured or spoofed. This is often a component in phishing attacks.", + ExtendedDescription: "", + Lang: "en", + }, + "453": { + CweID: "453", + Name: "Insecure Default Variable Initialization", + Description: "The software, by default, initializes an internal variable with an insecure or less secure value than is possible.", + ExtendedDescription: "", + Lang: "en", + }, + "454": { + CweID: "454", + Name: "External Initialization of Trusted Variables or Data Stores", + Description: "The software initializes critical internal variables or data stores using inputs that can be modified by untrusted actors.", + ExtendedDescription: "A software system should be reluctant to trust variables that have been initialized outside of its trust boundary, especially if they are initialized by users. The variables may have been initialized incorrectly. If an attacker can initialize the variable, then they can influence what the vulnerable system will do.", + Lang: "en", + }, + "455": { + CweID: "455", + Name: "Non-exit on Failed Initialization", + Description: "The software does not exit or otherwise modify its operation when security-relevant errors occur during initialization, such as when a configuration file has a format error, which can cause the software to execute in a less secure fashion than intended by the administrator.", + ExtendedDescription: "", + Lang: "en", + }, + "456": { + CweID: "456", + Name: "Missing Initialization of a Variable", + Description: "The software does not initialize critical variables, which causes the execution environment to use unexpected values.", + ExtendedDescription: "", + Lang: "en", + }, + "457": { + CweID: "457", + Name: "Use of Uninitialized Variable", + Description: "The code uses a variable that has not been initialized, leading to unpredictable or unintended results.", + ExtendedDescription: "In some languages such as C and C++, stack variables are not initialized by default. They generally contain junk data with the contents of stack memory before the function was invoked. An attacker can sometimes control or read these contents. In other languages or conditions, a variable that is not explicitly initialized can be given a default value that has security implications, depending on the logic of the program. The presence of an uninitialized variable can sometimes indicate a typographic error in the code.", + Lang: "en", + }, + "458": { + CweID: "458", + Name: "DEPRECATED: Incorrect Initialization", + Description: "This weakness has been deprecated because its name and description did not match. The description duplicated CWE-454, while the name suggested a more abstract initialization problem. Please refer to CWE-665 for the more abstract problem.", + ExtendedDescription: "", + Lang: "en", + }, + "459": { + CweID: "459", + Name: "Incomplete Cleanup", + Description: "The software does not properly 'clean up' and remove temporary or supporting resources after they have been used.", + ExtendedDescription: "", + Lang: "en", + }, + "46": { + CweID: "46", + Name: "Path Equivalence: 'filename ' (Trailing Space)", + Description: "A software system that accepts path input in the form of trailing space ('filedir ') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "460": { + CweID: "460", + Name: "Improper Cleanup on Thrown Exception", + Description: "The product does not clean up its state or incorrectly cleans up its state when an exception is thrown, leading to unexpected state or control flow.", + ExtendedDescription: "Often, when functions or loops become complicated, some level of resource cleanup is needed throughout execution. Exceptions can disturb the flow of the code and prevent the necessary cleanup from happening.", + Lang: "en", + }, + "462": { + CweID: "462", + Name: "Duplicate Key in Associative List (Alist)", + Description: "Duplicate keys in associative lists can lead to non-unique keys being mistaken for an error.", + ExtendedDescription: "A duplicate key entry -- if the alist is designed properly -- could be used as a constant time replace function. However, duplicate key entries could be inserted by mistake. Because of this ambiguity, duplicate key entries in an association list are not recommended and should not be allowed.", + Lang: "en", + }, + "463": { + CweID: "463", + Name: "Deletion of Data Structure Sentinel", + Description: "The accidental deletion of a data-structure sentinel can cause serious programming logic problems.", + ExtendedDescription: "Often times data-structure sentinels are used to mark structure of the data structure. A common example of this is the null character at the end of strings. Another common example is linked lists which may contain a sentinel to mark the end of the list. It is dangerous to allow this type of control data to be easily accessible. Therefore, it is important to protect from the deletion or modification outside of some wrapper interface which provides safety.", + Lang: "en", + }, + "464": { + CweID: "464", + Name: "Addition of Data Structure Sentinel", + Description: "The accidental addition of a data-structure sentinel can cause serious programming logic problems.", + ExtendedDescription: "Data-structure sentinels are often used to mark the structure of data. A common example of this is the null character at the end of strings or a special sentinel to mark the end of a linked list. It is dangerous to allow this type of control data to be easily accessible. Therefore, it is important to protect from the addition or modification of sentinels.", + Lang: "en", + }, + "466": { + CweID: "466", + Name: "Return of Pointer Value Outside of Expected Range", + Description: "A function can return a pointer to memory that is outside of the buffer that the pointer is expected to reference.", + ExtendedDescription: "", + Lang: "en", + }, + "467": { + CweID: "467", + Name: "Use of sizeof() on a Pointer Type", + Description: "The code calls sizeof() on a malloced pointer type, which always returns the wordsize/8. This can produce an unexpected result if the programmer intended to determine how much memory has been allocated.", + ExtendedDescription: "The use of sizeof() on a pointer can sometimes generate useful information. An obvious case is to find out the wordsize on a platform. More often than not, the appearance of sizeof(pointer) indicates a bug.", + Lang: "en", + }, + "468": { + CweID: "468", + Name: "Incorrect Pointer Scaling", + Description: "In C and C++, one may often accidentally refer to the wrong memory due to the semantics of when math operations are implicitly scaled.", + ExtendedDescription: "", + Lang: "en", + }, + "469": { + CweID: "469", + Name: "Use of Pointer Subtraction to Determine Size", + Description: "The application subtracts one pointer from another in order to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.", + ExtendedDescription: "", + Lang: "en", + }, + "47": { + CweID: "47", + Name: "Path Equivalence: ' filename' (Leading Space)", + Description: "A software system that accepts path input in the form of leading space (' filedir') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "470": { + CweID: "470", + Name: "Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')", + Description: "The application uses external input with reflection to select which classes or code to use, but it does not sufficiently prevent the input from selecting improper classes or code.", + ExtendedDescription: "If the application uses external inputs to determine which class to instantiate or which method to invoke, then an attacker could supply values to select unexpected classes or methods. If this occurs, then the attacker could create control flow paths that were not intended by the developer. These paths could bypass authentication or access control checks, or otherwise cause the application to behave in an unexpected manner. This situation becomes a doomsday scenario if the attacker can upload files into a location that appears on the application's classpath (CWE-427) or add new entries to the application's classpath (CWE-426). Under either of these conditions, the attacker can use reflection to introduce new, malicious behavior into the application.", + Lang: "en", + }, + "471": { + CweID: "471", + Name: "Modification of Assumed-Immutable Data (MAID)", + Description: "The software does not properly protect an assumed-immutable element from being modified by an attacker.", + ExtendedDescription: "This occurs when a particular input is critical enough to the functioning of the application that it should not be modifiable at all, but it is. Certain resources are often assumed to be immutable when they are not, such as hidden form fields in web applications, cookies, and reverse DNS lookups.", + Lang: "en", + }, + "472": { + CweID: "472", + Name: "External Control of Assumed-Immutable Web Parameter", + Description: "The web application does not sufficiently verify inputs that are assumed to be immutable but are actually externally controllable, such as hidden form fields.", + ExtendedDescription: "", + Lang: "en", + }, + "473": { + CweID: "473", + Name: "PHP External Variable Modification", + Description: "A PHP application does not properly protect against the modification of variables from external sources, such as query parameters or cookies. This can expose the application to numerous weaknesses that would not exist otherwise.", + ExtendedDescription: "", + Lang: "en", + }, + "474": { + CweID: "474", + Name: "Use of Function with Inconsistent Implementations", + Description: "The code uses a function that has inconsistent implementations across operating systems and versions.", + ExtendedDescription: "", + Lang: "en", + }, + "475": { + CweID: "475", + Name: "Undefined Behavior for Input to API", + Description: "The behavior of this function is undefined unless its control parameter is set to a specific value.", + ExtendedDescription: "", + Lang: "en", + }, + "476": { + CweID: "476", + Name: "NULL Pointer Dereference", + Description: "A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit.", + ExtendedDescription: "NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.", + Lang: "en", + }, + "477": { + CweID: "477", + Name: "Use of Obsolete Function", + Description: "The code uses deprecated or obsolete functions, which suggests that the code has not been actively reviewed or maintained.", + ExtendedDescription: "", + Lang: "en", + }, + "478": { + CweID: "478", + Name: "Missing Default Case in Switch Statement", + Description: "The code does not have a default case in a switch statement, which might lead to complex logical errors and resultant weaknesses.", + ExtendedDescription: "This flaw represents a common problem in software development, in which not all possible values for a variable are considered or handled by a given process. Because of this, further decisions are made based on poor information, and cascading failure results. This cascading failure may result in any number of security issues, and constitutes a significant failure in the system.", + Lang: "en", + }, + "479": { + CweID: "479", + Name: "Signal Handler Use of a Non-reentrant Function", + Description: "The program defines a signal handler that calls a non-reentrant function.", + ExtendedDescription: "", + Lang: "en", + }, + "48": { + CweID: "48", + Name: "Path Equivalence: 'file name' (Internal Whitespace)", + Description: "A software system that accepts path input in the form of internal space ('file(SPACE)name') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "480": { + CweID: "480", + Name: "Use of Incorrect Operator", + Description: "The programmer accidentally uses the wrong operator, which changes the application logic in security-relevant ways.", + ExtendedDescription: "These types of errors are generally the result of a typo.", + Lang: "en", + }, + "481": { + CweID: "481", + Name: "Assigning instead of Comparing", + Description: "The code uses an operator for assignment when the intention was to perform a comparison.", + ExtendedDescription: "In many languages the compare statement is very close in appearance to the assignment statement and are often confused. This bug is generally the result of a typo and usually causes obvious problems with program execution. If the comparison is in an if statement, the if statement will usually evaluate the value of the right-hand side of the predicate.", + Lang: "en", + }, + "482": { + CweID: "482", + Name: "Comparing instead of Assigning", + Description: "The code uses an operator for comparison when the intention was to perform an assignment.", + ExtendedDescription: "In many languages, the compare statement is very close in appearance to the assignment statement; they are often confused.", + Lang: "en", + }, + "483": { + CweID: "483", + Name: "Incorrect Block Delimitation", + Description: "The code does not explicitly delimit a block that is intended to contain 2 or more statements, creating a logic error.", + ExtendedDescription: "In some languages, braces (or other delimiters) are optional for blocks. When the delimiter is omitted, it is possible to insert a logic error in which a statement is thought to be in a block but is not. In some cases, the logic error can have security implications.", + Lang: "en", + }, + "484": { + CweID: "484", + Name: "Omitted Break Statement in Switch", + Description: "The program omits a break statement within a switch or similar construct, causing code associated with multiple conditions to execute. This can cause problems when the programmer only intended to execute code associated with one condition.", + ExtendedDescription: "This can lead to critical code executing in situations where it should not.", + Lang: "en", + }, + "486": { + CweID: "486", + Name: "Comparison of Classes by Name", + Description: "The program compares classes by name, which can cause it to use the wrong class when multiple classes can have the same name.", + ExtendedDescription: "If the decision to trust the methods and data of an object is based on the name of a class, it is possible for malicious users to send objects of the same name as trusted classes and thereby gain the trust afforded to known classes and types.", + Lang: "en", + }, + "487": { + CweID: "487", + Name: "Reliance on Package-level Scope", + Description: "Java packages are not inherently closed; therefore, relying on them for code security is not a good practice.", + ExtendedDescription: "The purpose of package scope is to prevent accidental access by other parts of a program. This is an ease-of-software-development feature but not a security feature.", + Lang: "en", + }, + "488": { + CweID: "488", + Name: "Exposure of Data Element to Wrong Session", + Description: "The product does not sufficiently enforce boundaries between the states of different sessions, causing data to be provided to, or used by, the wrong session.", + ExtendedDescription: "", + Lang: "en", + }, + "489": { + CweID: "489", + Name: "Leftover Debug Code", + Description: "The application can be deployed with active debugging code that can create unintended entry points.", + ExtendedDescription: "A common development practice is to add 'back door' code specifically designed for debugging or testing purposes that is not intended to be shipped or deployed with the application. These back door entry points create security risks because they are not considered during design or testing and fall outside of the expected operating conditions of the application.", + Lang: "en", + }, + "49": { + CweID: "49", + Name: "Path Equivalence: 'filename/' (Trailing Slash)", + Description: "A software system that accepts path input in the form of trailing slash ('filedir/') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "491": { + CweID: "491", + Name: "Public cloneable() Method Without Final ('Object Hijack')", + Description: "A class has a cloneable() method that is not declared final, which allows an object to be created without calling the constructor. This can cause the object to be in an unexpected state.", + ExtendedDescription: "", + Lang: "en", + }, + "492": { + CweID: "492", + Name: "Use of Inner Class Containing Sensitive Data", + Description: "Inner classes are translated into classes that are accessible at package scope and may expose code that the programmer intended to keep private to attackers.", + ExtendedDescription: "Inner classes quietly introduce several security concerns because of the way they are translated into Java bytecode. In Java source code, it appears that an inner class can be declared to be accessible only by the enclosing class, but Java bytecode has no concept of an inner class, so the compiler must transform an inner class declaration into a peer class with package level access to the original outer class. More insidiously, since an inner class can access private fields in their enclosing class, once an inner class becomes a peer class in bytecode, the compiler converts private fields accessed by the inner class into protected fields.", + Lang: "en", + }, + "493": { + CweID: "493", + Name: "Critical Public Variable Without Final Modifier", + Description: "The product has a critical public variable that is not final, which allows the variable to be modified to contain unexpected values.", + ExtendedDescription: "If a field is non-final and public, it can be changed once the value is set by any function that has access to the class which contains the field. This could lead to a vulnerability if other parts of the program make assumptions about the contents of that field.", + Lang: "en", + }, + "494": { + CweID: "494", + Name: "Download of Code Without Integrity Check", + Description: "The product downloads source code or an executable from a remote location and executes the code without sufficiently verifying the origin and integrity of the code.", + ExtendedDescription: "An attacker can execute malicious code by compromising the host server, performing DNS spoofing, or modifying the code in transit.", + Lang: "en", + }, + "495": { + CweID: "495", + Name: "Private Array-Typed Field Returned From A Public Method", + Description: "The product has a method that is declared public, but returns a reference to a private array, which could then be modified in unexpected ways.", + ExtendedDescription: "", + Lang: "en", + }, + "496": { + CweID: "496", + Name: "Public Data Assigned to Private Array-Typed Field", + Description: "Assigning public data to a private array is equivalent to giving public access to the array.", + ExtendedDescription: "", + Lang: "en", + }, + "497": { + CweID: "497", + Name: "Exposure of System Data to an Unauthorized Control Sphere", + Description: "Exposing system data or debugging information helps an adversary learn about the system and form an attack plan.", + ExtendedDescription: "An information exposure occurs when system data or debugging information leaves the program through an output stream or logging function that makes it accessible to unauthorized parties. An attacker can also cause errors to occur by submitting unusual requests to the web application. The response to these errors can reveal detailed system information, deny service, cause security mechanisms to fail, and crash the server. An attacker can use error messages that reveal technologies, operating systems, and product versions to tune the attack against known vulnerabilities in these technologies. An application may use diagnostic methods that provide significant implementation details such as stack traces as part of its error handling mechanism.", + Lang: "en", + }, + "498": { + CweID: "498", + Name: "Cloneable Class Containing Sensitive Information", + Description: "The code contains a class with sensitive data, but the class is cloneable. The data can then be accessed by cloning the class.", + ExtendedDescription: "Cloneable classes are effectively open classes, since data cannot be hidden in them. Classes that do not explicitly deny cloning can be cloned by any other class without running the constructor.", + Lang: "en", + }, + "499": { + CweID: "499", + Name: "Serializable Class Containing Sensitive Data", + Description: "The code contains a class with sensitive data, but the class does not explicitly deny serialization. The data can be accessed by serializing the class through another class.", + ExtendedDescription: "Serializable classes are effectively open classes since data cannot be hidden in them. Classes that do not explicitly deny serialization can be serialized by any other class, which can then in turn use the data stored inside it.", + Lang: "en", + }, + "5": { + CweID: "5", + Name: "J2EE Misconfiguration: Data Transmission Without Encryption", + Description: "Information sent over a network can be compromised while in transit. An attacker may be able to read or modify the contents if the data are sent in plaintext or are weakly encrypted.", + ExtendedDescription: "", + Lang: "en", + }, + "50": { + CweID: "50", + Name: "Path Equivalence: '//multiple/leading/slash'", + Description: "A software system that accepts path input in the form of multiple leading slash ('//multiple/leading/slash') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "500": { + CweID: "500", + Name: "Public Static Field Not Marked Final", + Description: "An object contains a public static field that is not marked final, which might allow it to be modified in unexpected ways.", + ExtendedDescription: "Public static variables can be read without an accessor and changed without a mutator by any classes in the application.", + Lang: "en", + }, + "501": { + CweID: "501", + Name: "Trust Boundary Violation", + Description: "The product mixes trusted and untrusted data in the same data structure or structured message.", + ExtendedDescription: "A trust boundary can be thought of as line drawn through a program. On one side of the line, data is untrusted. On the other side of the line, data is assumed to be trustworthy. The purpose of validation logic is to allow data to safely cross the trust boundary - to move from untrusted to trusted. A trust boundary violation occurs when a program blurs the line between what is trusted and what is untrusted. By combining trusted and untrusted data in the same data structure, it becomes easier for programmers to mistakenly trust unvalidated data.", + Lang: "en", + }, + "502": { + CweID: "502", + Name: "Deserialization of Untrusted Data", + Description: "The application deserializes untrusted data without sufficiently verifying that the resulting data will be valid.", + ExtendedDescription: "", + Lang: "en", + }, + "506": { + CweID: "506", + Name: "Embedded Malicious Code", + Description: "The application contains code that appears to be malicious in nature.", + ExtendedDescription: "Malicious flaws have acquired colorful names, including Trojan horse, trapdoor, timebomb, and logic-bomb. A developer might insert malicious code with the intent to subvert the security of an application or its host system at some time in the future. It generally refers to a program that performs a useful service but exploits rights of the program's user in a way the user does not intend.", + Lang: "en", + }, + "507": { + CweID: "507", + Name: "Trojan Horse", + Description: "The software appears to contain benign or useful functionality, but it also contains code that is hidden from normal operation that violates the intended security policy of the user or the system administrator.", + ExtendedDescription: "", + Lang: "en", + }, + "508": { + CweID: "508", + Name: "Non-Replicating Malicious Code", + Description: "Non-replicating malicious code only resides on the target system or software that is attacked; it does not attempt to spread to other systems.", + ExtendedDescription: "", + Lang: "en", + }, + "509": { + CweID: "509", + Name: "Replicating Malicious Code (Virus or Worm)", + Description: "Replicating malicious code, including viruses and worms, will attempt to attack other systems once it has successfully compromised the target system or software.", + ExtendedDescription: "", + Lang: "en", + }, + "51": { + CweID: "51", + Name: "Path Equivalence: '/multiple//internal/slash'", + Description: "A software system that accepts path input in the form of multiple internal slash ('/multiple//internal/slash/') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "510": { + CweID: "510", + Name: "Trapdoor", + Description: "A trapdoor is a hidden piece of code that responds to a special input, allowing its user access to resources without passing through the normal security enforcement mechanism.", + ExtendedDescription: "", + Lang: "en", + }, + "511": { + CweID: "511", + Name: "Logic/Time Bomb", + Description: "The software contains code that is designed to disrupt the legitimate operation of the software (or its environment) when a certain time passes, or when a certain logical condition is met.", + ExtendedDescription: "When the time bomb or logic bomb is detonated, it may perform a denial of service such as crashing the system, deleting critical data, or degrading system response time. This bomb might be placed within either a replicating or non-replicating Trojan horse.", + Lang: "en", + }, + "512": { + CweID: "512", + Name: "Spyware", + Description: "The software collects personally identifiable information about a human user or the user's activities, but the software accesses this information using other resources besides itself, and it does not require that user's explicit approval or direct input into the software.", + ExtendedDescription: "'Spyware' is a commonly used term with many definitions and interpretations. In general, it is meant to software that collects information or installs functionality that human users might not allow if they were fully aware of the actions being taken by the software. For example, a user might expect that tax software would collect a social security number and include it when filing a tax return, but that same user would not expect gaming software to obtain the social security number from that tax software's data.", + Lang: "en", + }, + "514": { + CweID: "514", + Name: "Covert Channel", + Description: "A covert channel is a path that can be used to transfer information in a way not intended by the system's designers.", + ExtendedDescription: "Typically the system has not given authorization for the transmission and has no knowledge of its occurrence.", + Lang: "en", + }, + "515": { + CweID: "515", + Name: "Covert Storage Channel", + Description: "A covert storage channel transfers information through the setting of bits by one program and the reading of those bits by another. What distinguishes this case from that of ordinary operation is that the bits are used to convey encoded information.", + ExtendedDescription: "Covert storage channels occur when out-of-band data is stored in messages for the purpose of memory reuse. Covert channels are frequently classified as either storage or timing channels. Examples would include using a file intended to hold only audit information to convey user passwords--using the name of a file or perhaps status bits associated with it that can be read by all users to signal the contents of the file. Steganography, concealing information in such a manner that no one but the intended recipient knows of the existence of the message, is a good example of a covert storage channel.", + Lang: "en", + }, + "516": { + CweID: "516", + Name: "DEPRECATED (Duplicate): Covert Timing Channel", + Description: "This weakness can be found at CWE-385.", + ExtendedDescription: "", + Lang: "en", + }, + "52": { + CweID: "52", + Name: "Path Equivalence: '/multiple/trailing/slash//'", + Description: "A software system that accepts path input in the form of multiple trailing slash ('/multiple/trailing/slash//') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "520": { + CweID: "520", + Name: ".NET Misconfiguration: Use of Impersonation", + Description: "Allowing a .NET application to run at potentially escalated levels of access to the underlying operating and file systems can be dangerous and result in various forms of attacks.", + ExtendedDescription: ".NET server applications can optionally execute using the identity of the user authenticated to the client. The intention of this functionality is to bypass authentication and access control checks within the .NET application code. Authentication is done by the underlying web server (Microsoft Internet Information Service IIS), which passes the authenticated token, or unauthenticated anonymous token, to the .NET application. Using the token to impersonate the client, the application then relies on the settings within the NTFS directories and files to control access. Impersonation enables the application, on the server running the .NET application, to both execute code and access resources in the context of the authenticated and authorized user.", + Lang: "en", + }, + "521": { + CweID: "521", + Name: "Weak Password Requirements", + Description: "The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts.", + ExtendedDescription: "An authentication mechanism is only as strong as its credentials. For this reason, it is important to require users to have strong passwords. Lack of password complexity significantly reduces the search space when trying to guess user's passwords, making brute-force attacks easier.", + Lang: "en", + }, + "522": { + CweID: "522", + Name: "Insufficiently Protected Credentials", + Description: "This weakness occurs when the application transmits or stores authentication credentials and uses an insecure method that is susceptible to unauthorized interception and/or retrieval.", + ExtendedDescription: "", + Lang: "en", + }, + "523": { + CweID: "523", + Name: "Unprotected Transport of Credentials", + Description: "Login pages not using adequate measures to protect the user name and password while they are in transit from the client to the server.", + ExtendedDescription: "", + Lang: "en", + }, + "524": { + CweID: "524", + Name: "Information Exposure Through Caching", + Description: "The application uses a cache to maintain a pool of objects, threads, connections, pages, or passwords to minimize the time it takes to access them or the resources to which they connect. If implemented improperly, these caches can allow access to unauthorized information or cause a denial of service vulnerability.", + ExtendedDescription: "", + Lang: "en", + }, + "525": { + CweID: "525", + Name: "Information Exposure Through Browser Caching", + Description: "For each web page, the application should have an appropriate caching policy specifying the extent to which the page and its form fields should be cached.", + ExtendedDescription: "", + Lang: "en", + }, + "526": { + CweID: "526", + Name: "Information Exposure Through Environmental Variables", + Description: "Environmental variables may contain sensitive information about a remote server.", + ExtendedDescription: "", + Lang: "en", + }, + "527": { + CweID: "527", + Name: "Exposure of CVS Repository to an Unauthorized Control Sphere", + Description: "The product stores a CVS repository in a directory or other container that is accessible to actors outside of the intended control sphere.", + ExtendedDescription: "Information contained within a CVS subdirectory on a web server or other server could be recovered by an attacker and used for malicious purposes. This information may include usernames, filenames, path root, and IP addresses.", + Lang: "en", + }, + "528": { + CweID: "528", + Name: "Exposure of Core Dump File to an Unauthorized Control Sphere", + Description: "The product generates a core dump file in a directory that is accessible to actors outside of the intended control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "529": { + CweID: "529", + Name: "Exposure of Access Control List Files to an Unauthorized Control Sphere", + Description: "The product stores access control list files in a directory or other container that is accessible to actors outside of the intended control sphere.", + ExtendedDescription: "Exposure of these access control list files may give the attacker information about the configuration of the site or system. This information may then be used to bypass the intended security policy or identify trusted systems from which an attack can be launched.", + Lang: "en", + }, + "53": { + CweID: "53", + Name: "Path Equivalence: '\\multiple\\\\internal\\backslash'", + Description: "A software system that accepts path input in the form of multiple internal backslash ('\\multiple\\trailing\\\\slash') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "530": { + CweID: "530", + Name: "Exposure of Backup File to an Unauthorized Control Sphere", + Description: "A backup file is stored in a directory that is accessible to actors outside of the intended control sphere.", + ExtendedDescription: "Often, old files are renamed with an extension such as .~bk to distinguish them from production files. The source code for old files that have been renamed in this manner and left in the webroot can often be retrieved. This renaming may have been performed automatically by the web server, or manually by the administrator.", + Lang: "en", + }, + "531": { + CweID: "531", + Name: "Information Exposure Through Test Code", + Description: "Accessible test applications can pose a variety of security risks. Since developers or administrators rarely consider that someone besides themselves would even know about the existence of these applications, it is common for them to contain sensitive information or functions.", + ExtendedDescription: "", + Lang: "en", + }, + "532": { + CweID: "532", + Name: "Information Exposure Through Log Files", + Description: "Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information.", + ExtendedDescription: "While logging all information may be helpful during development stages, it is important that logging levels be set appropriately before a product ships so that sensitive user data and system information are not accidentally exposed to potential attackers.", + Lang: "en", + }, + "533": { + CweID: "533", + Name: "Information Exposure Through Server Log Files", + Description: "A server.log file was found. This can give information on whatever application left the file. Usually this can give full path names and system information, and sometimes usernames and passwords.", + ExtendedDescription: "", + Lang: "en", + }, + "534": { + CweID: "534", + Name: "Information Exposure Through Debug Log Files", + Description: "The application does not sufficiently restrict access to a log file that is used for debugging.", + ExtendedDescription: "", + Lang: "en", + }, + "535": { + CweID: "535", + Name: "Information Exposure Through Shell Error Message", + Description: "A command shell error message indicates that there exists an unhandled exception in the web application code. In many cases, an attacker can leverage the conditions that cause these errors in order to gain unauthorized access to the system.", + ExtendedDescription: "", + Lang: "en", + }, + "536": { + CweID: "536", + Name: "Information Exposure Through Servlet Runtime Error Message", + Description: "A servlet error message indicates that there exists an unhandled exception in your web application code and may provide useful information to an attacker.", + ExtendedDescription: "", + Lang: "en", + }, + "537": { + CweID: "537", + Name: "Information Exposure Through Java Runtime Error Message", + Description: "In many cases, an attacker can leverage the conditions that cause unhandled exception errors in order to gain unauthorized access to the system.", + ExtendedDescription: "", + Lang: "en", + }, + "538": { + CweID: "538", + Name: "File and Directory Information Exposure", + Description: "The product stores sensitive information in files or directories that are accessible to actors outside of the intended control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "539": { + CweID: "539", + Name: "Information Exposure Through Persistent Cookies", + Description: "Persistent cookies are cookies that are stored on the browser's hard drive. This can cause security and privacy issues depending on the information stored in the cookie and how it is accessed.", + ExtendedDescription: "Cookies are small bits of data that are sent by the web application but stored locally in the browser. This lets the application use the cookie to pass information between pages and store variable information. The web application controls what information is stored in a cookie and how it is used. Typical types of information stored in cookies are session Identifiers, personalization and customization information, and in rare cases even usernames to enable automated logins. There are two different types of cookies: session cookies and persistent cookies. Session cookies just live in the browser's memory, and are not stored anywhere, but persistent cookies are stored on the browser's hard drive.", + Lang: "en", + }, + "54": { + CweID: "54", + Name: "Path Equivalence: 'filedir\\' (Trailing Backslash)", + Description: "A software system that accepts path input in the form of trailing backslash ('filedir\\') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "540": { + CweID: "540", + Name: "Information Exposure Through Source Code", + Description: "Source code on a web server often contains sensitive information and should generally not be accessible to users.", + ExtendedDescription: "There are situations where it is critical to remove source code from an area or server. For example, obtaining Perl source code on a system allows an attacker to understand the logic of the script and extract extremely useful information such as code bugs or logins and passwords.", + Lang: "en", + }, + "541": { + CweID: "541", + Name: "Information Exposure Through Include Source Code", + Description: "If an include file source is accessible, the file can contain usernames and passwords, as well as sensitive information pertaining to the application and system.", + ExtendedDescription: "", + Lang: "en", + }, + "542": { + CweID: "542", + Name: "Information Exposure Through Cleanup Log Files", + Description: "The application does not properly protect or delete a log file related to cleanup.", + ExtendedDescription: "", + Lang: "en", + }, + "543": { + CweID: "543", + Name: "Use of Singleton Pattern Without Synchronization in a Multithreaded Context", + Description: "The software uses the singleton pattern when creating a resource within a multithreaded environment.", + ExtendedDescription: "The use of a singleton pattern may not be thread-safe.", + Lang: "en", + }, + "544": { + CweID: "544", + Name: "Missing Standardized Error Handling Mechanism", + Description: "The software does not use a standardized method for handling errors throughout the code, which might introduce inconsistent error handling and resultant weaknesses.", + ExtendedDescription: "If the application handles error messages individually, on a one-by-one basis, this is likely to result in inconsistent error handling. The causes of errors may be lost. Also, detailed information about the causes of an error may be unintentionally returned to the user.", + Lang: "en", + }, + "545": { + CweID: "545", + Name: "DEPRECATED: Use of Dynamic Class Loading", + Description: "This weakness has been deprecated because it partially overlaps CWE-470, it describes legitimate programmer behavior, and other portions will need to be integrated into other entries.", + ExtendedDescription: "", + Lang: "en", + }, + "546": { + CweID: "546", + Name: "Suspicious Comment", + Description: "The code contains comments that suggest the presence of bugs, incomplete functionality, or weaknesses.", + ExtendedDescription: "Many suspicious comments, such as BUG, HACK, FIXME, LATER, LATER2, TODO, in the code indicate missing security functionality and checking. Others indicate code problems that programmers should fix, such as hard-coded variables, error handling, not using stored procedures, and performance issues.", + Lang: "en", + }, + "547": { + CweID: "547", + Name: "Use of Hard-coded, Security-relevant Constants", + Description: "The program uses hard-coded constants instead of symbolic names for security-critical values, which increases the likelihood of mistakes during code maintenance or security policy change.", + ExtendedDescription: "If the developer does not find all occurrences of the hard-coded constants, an incorrect policy decision may be made if one of the constants is not changed. Making changes to these values will require code changes that may be difficult or impossible once the system is released to the field. In addition, these hard-coded values may become available to attackers if the code is ever disclosed.", + Lang: "en", + }, + "548": { + CweID: "548", + Name: "Information Exposure Through Directory Listing", + Description: "A directory listing is inappropriately exposed, yielding potentially sensitive information to attackers.", + ExtendedDescription: "A directory listing provides an attacker with the complete index of all the resources located inside of the directory. The specific risks and consequences vary depending on which files are listed and accessible.", + Lang: "en", + }, + "549": { + CweID: "549", + Name: "Missing Password Field Masking", + Description: "The software does not mask passwords during entry, increasing the potential for attackers to observe and capture passwords.", + ExtendedDescription: "", + Lang: "en", + }, + "55": { + CweID: "55", + Name: "Path Equivalence: '/./' (Single Dot Directory)", + Description: "A software system that accepts path input in the form of single dot directory exploit ('/./') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "550": { + CweID: "550", + Name: "Information Exposure Through Server Error Message", + Description: "Certain conditions, such as network failure, will cause a server error message to be displayed.", + ExtendedDescription: "While error messages in and of themselves are not dangerous, per se, it is what an attacker can glean from them that might cause eventual problems.", + Lang: "en", + }, + "551": { + CweID: "551", + Name: "Incorrect Behavior Order: Authorization Before Parsing and Canonicalization", + Description: "If a web server does not fully parse requested URLs before it examines them for authorization, it may be possible for an attacker to bypass authorization protection.", + ExtendedDescription: "For instance, the character strings /./ and / both mean current directory. If /SomeDirectory is a protected directory and an attacker requests /./SomeDirectory, the attacker may be able to gain access to the resource if /./ is not converted to / before the authorization check is performed.", + Lang: "en", + }, + "552": { + CweID: "552", + Name: "Files or Directories Accessible to External Parties", + Description: "Files or directories are accessible in the environment that should not be.", + ExtendedDescription: "", + Lang: "en", + }, + "553": { + CweID: "553", + Name: "Command Shell in Externally Accessible Directory", + Description: "A possible shell file exists in /cgi-bin/ or other accessible directories. This is extremely dangerous and can be used by an attacker to execute commands on the web server.", + ExtendedDescription: "", + Lang: "en", + }, + "554": { + CweID: "554", + Name: "ASP.NET Misconfiguration: Not Using Input Validation Framework", + Description: "The ASP.NET application does not use an input validation framework.", + ExtendedDescription: "", + Lang: "en", + }, + "555": { + CweID: "555", + Name: "J2EE Misconfiguration: Plaintext Password in Configuration File", + Description: "The J2EE application stores a plaintext password in a configuration file.", + ExtendedDescription: "Storing a plaintext password in a configuration file allows anyone who can read the file to access the password-protected resource, making it an easy target for attackers.", + Lang: "en", + }, + "556": { + CweID: "556", + Name: "ASP.NET Misconfiguration: Use of Identity Impersonation", + Description: "Configuring an ASP.NET application to run with impersonated credentials may give the application unnecessary privileges.", + ExtendedDescription: "The use of impersonated credentials allows an ASP.NET application to run with either the privileges of the client on whose behalf it is executing or with arbitrary privileges granted in its configuration.", + Lang: "en", + }, + "558": { + CweID: "558", + Name: "Use of getlogin() in Multithreaded Application", + Description: "The application uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values.", + ExtendedDescription: "The getlogin() function returns a pointer to a string that contains the name of the user associated with the calling process. The function is not reentrant, meaning that if it is called from another process, the contents are not locked out and the value of the string can be changed by another process. This makes it very risky to use because the username can be changed by other processes, so the results of the function cannot be trusted.", + Lang: "en", + }, + "56": { + CweID: "56", + Name: "Path Equivalence: 'filedir*' (Wildcard)", + Description: "A software system that accepts path input in the form of asterisk wildcard ('filedir*') without appropriate validation can lead to ambiguous path resolution and allow an attacker to traverse the file system to unintended locations or access arbitrary files.", + ExtendedDescription: "", + Lang: "en", + }, + "560": { + CweID: "560", + Name: "Use of umask() with chmod-style Argument", + Description: "The product calls umask() with an incorrect argument that is specified as if it is an argument to chmod().", + ExtendedDescription: "", + Lang: "en", + }, + "561": { + CweID: "561", + Name: "Dead Code", + Description: "The software contains dead code, which can never be executed.", + ExtendedDescription: "Dead code is source code that can never be executed in a running program. The surrounding code makes it impossible for a section of code to ever be executed.", + Lang: "en", + }, + "562": { + CweID: "562", + Name: "Return of Stack Variable Address", + Description: "A function returns the address of a stack variable, which will cause unintended program behavior, typically in the form of a crash.", + ExtendedDescription: "Because local variables are allocated on the stack, when a program returns a pointer to a local variable, it is returning a stack address. A subsequent function call is likely to re-use this same stack address, thereby overwriting the value of the pointer, which no longer corresponds to the same variable since a function's stack frame is invalidated when it returns. At best this will cause the value of the pointer to change unexpectedly. In many cases it causes the program to crash the next time the pointer is dereferenced.", + Lang: "en", + }, + "563": { + CweID: "563", + Name: "Assignment to Variable without Use", + Description: "The variable's value is assigned but never used, making it a dead store.", + ExtendedDescription: "After the assignment, the variable is either assigned another value or goes out of scope. It is likely that the variable is simply vestigial, but it is also possible that the unused variable points out a bug.", + Lang: "en", + }, + "564": { + CweID: "564", + Name: "SQL Injection: Hibernate", + Description: "Using Hibernate to execute a dynamic SQL statement built with user-controlled input can allow an attacker to modify the statement's meaning or to execute arbitrary SQL commands.", + ExtendedDescription: "", + Lang: "en", + }, + "565": { + CweID: "565", + Name: "Reliance on Cookies without Validation and Integrity Checking", + Description: "The application relies on the existence or values of cookies when performing security-critical operations, but it does not properly ensure that the setting is valid for the associated user.", + ExtendedDescription: "Attackers can easily modify cookies, within the browser or by implementing the client-side code outside of the browser. Reliance on cookies without detailed validation and integrity checking can allow attackers to bypass authentication, conduct injection attacks such as SQL injection and cross-site scripting, or otherwise modify inputs in unexpected ways.", + Lang: "en", + }, + "566": { + CweID: "566", + Name: "Authorization Bypass Through User-Controlled SQL Primary Key", + Description: "The software uses a database table that includes records that should not be accessible to an actor, but it executes a SQL statement with a primary key that can be controlled by that actor.", + ExtendedDescription: "", + Lang: "en", + }, + "567": { + CweID: "567", + Name: "Unsynchronized Access to Shared Data in a Multithreaded Context", + Description: "The product does not properly synchronize shared data, such as static variables across threads, which can lead to undefined behavior and unpredictable data changes.", + ExtendedDescription: "", + Lang: "en", + }, + "568": { + CweID: "568", + Name: "finalize() Method Without super.finalize()", + Description: "The software contains a finalize() method that does not call super.finalize().", + ExtendedDescription: "The Java Language Specification states that it is a good practice for a finalize() method to call super.finalize().", + Lang: "en", + }, + "57": { + CweID: "57", + Name: "Path Equivalence: 'fakedir/../realdir/filename'", + Description: "The software contains protection mechanisms to restrict access to 'realdir/filename', but it constructs pathnames using external input in the form of 'fakedir/../realdir/filename' that are not handled by those mechanisms. This allows attackers to perform unauthorized actions against the targeted file.", + ExtendedDescription: "", + Lang: "en", + }, + "570": { + CweID: "570", + Name: "Expression is Always False", + Description: "The software contains an expression that will always evaluate to false.", + ExtendedDescription: "", + Lang: "en", + }, + "571": { + CweID: "571", + Name: "Expression is Always True", + Description: "The software contains an expression that will always evaluate to true.", + ExtendedDescription: "", + Lang: "en", + }, + "572": { + CweID: "572", + Name: "Call to Thread run() instead of start()", + Description: "The program calls a thread's run() method instead of calling start(), which causes the code to run in the thread of the caller instead of the callee.", + ExtendedDescription: "In most cases a direct call to a Thread object's run() method is a bug. The programmer intended to begin a new thread of control, but accidentally called run() instead of start(), so the run() method will execute in the caller's thread of control.", + Lang: "en", + }, + "573": { + CweID: "573", + Name: "Improper Following of Specification by Caller", + Description: "The software does not follow or incorrectly follows the specifications as required by the implementation language, environment, framework, protocol, or platform.", + ExtendedDescription: "When leveraging external functionality, such as an API, it is important that the caller does so in accordance with the requirements of the external functionality or else unintended behaviors may result, possibly leaving the system vulnerable to any number of exploits.", + Lang: "en", + }, + "574": { + CweID: "574", + Name: "EJB Bad Practices: Use of Synchronization Primitives", + Description: "The program violates the Enterprise JavaBeans (EJB) specification by using thread synchronization primitives.", + ExtendedDescription: "The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: 'An enterprise bean must not use thread synchronization primitives to synchronize execution of multiple instances.' The specification justifies this requirement in the following way: 'This rule is required to ensure consistent runtime semantics because while some EJB containers may use a single JVM to execute all enterprise bean's instances, others may distribute the instances across multiple JVMs.'", + Lang: "en", + }, + "575": { + CweID: "575", + Name: "EJB Bad Practices: Use of AWT Swing", + Description: "The program violates the Enterprise JavaBeans (EJB) specification by using AWT/Swing.", + ExtendedDescription: "The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: 'An enterprise bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard.' The specification justifies this requirement in the following way: 'Most servers do not allow direct interaction between an application program and a keyboard/display attached to the server system.'", + Lang: "en", + }, + "576": { + CweID: "576", + Name: "EJB Bad Practices: Use of Java I/O", + Description: "The program violates the Enterprise JavaBeans (EJB) specification by using the java.io package.", + ExtendedDescription: "The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: 'An enterprise bean must not use the java.io package to attempt to access files and directories in the file system.' The specification justifies this requirement in the following way: 'The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC, to store data.'", + Lang: "en", + }, + "577": { + CweID: "577", + Name: "EJB Bad Practices: Use of Sockets", + Description: "The program violates the Enterprise JavaBeans (EJB) specification by using sockets.", + ExtendedDescription: "The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: 'An enterprise bean must not attempt to listen on a socket, accept connections on a socket, or use a socket for multicast.' The specification justifies this requirement in the following way: 'The EJB architecture allows an enterprise bean instance to be a network socket client, but it does not allow it to be a network server. Allowing the instance to become a network server would conflict with the basic function of the enterprise bean-- to serve the EJB clients.'", + Lang: "en", + }, + "578": { + CweID: "578", + Name: "EJB Bad Practices: Use of Class Loader", + Description: "The program violates the Enterprise JavaBeans (EJB) specification by using the class loader.", + ExtendedDescription: "The Enterprise JavaBeans specification requires that every bean provider follow a set of programming guidelines designed to ensure that the bean will be portable and behave consistently in any EJB container. In this case, the program violates the following EJB guideline: 'The enterprise bean must not attempt to create a class loader; obtain the current class loader; set the context class loader; set security manager; create a new security manager; stop the JVM; or change the input, output, and error streams.' The specification justifies this requirement in the following way: 'These functions are reserved for the EJB container. Allowing the enterprise bean to use these functions could compromise security and decrease the container's ability to properly manage the runtime environment.'", + Lang: "en", + }, + "579": { + CweID: "579", + Name: "J2EE Bad Practices: Non-serializable Object Stored in Session", + Description: "The application stores a non-serializable object as an HttpSession attribute, which can hurt reliability.", + ExtendedDescription: "A J2EE application can make use of multiple JVMs in order to improve application reliability and performance. In order to make the multiple JVMs appear as a single application to the end user, the J2EE container can replicate an HttpSession object across multiple JVMs so that if one JVM becomes unavailable another can step in and take its place without disrupting the flow of the application. This is only possible if all session data is serializable, allowing the session to be duplicated between the JVMs.", + Lang: "en", + }, + "58": { + CweID: "58", + Name: "Path Equivalence: Windows 8.3 Filename", + Description: "The software contains a protection mechanism that restricts access to a long filename on a Windows operating system, but the software does not properly restrict access to the equivalent short '8.3' filename.", + ExtendedDescription: "On later Windows operating systems, a file can have a 'long name' and a short name that is compatible with older Windows file systems, with up to 8 characters in the filename and 3 characters for the extension. These '8.3' filenames, therefore, act as an alternate name for files with long names, so they are useful pathname equivalence manipulations.", + Lang: "en", + }, + "580": { + CweID: "580", + Name: "clone() Method Without super.clone()", + Description: "The software contains a clone() method that does not call super.clone() to obtain the new object.", + ExtendedDescription: "All implementations of clone() should obtain the new object by calling super.clone(). If a class does not follow this convention, a subclass's clone() method will return an object of the wrong type.", + Lang: "en", + }, + "581": { + CweID: "581", + Name: "Object Model Violation: Just One of Equals and Hashcode Defined", + Description: "The software does not maintain equal hashcodes for equal objects.", + ExtendedDescription: "Java objects are expected to obey a number of invariants related to equality. One of these invariants is that equal objects must have equal hashcodes. In other words, if a.equals(b) == true then a.hashCode() == b.hashCode().", + Lang: "en", + }, + "582": { + CweID: "582", + Name: "Array Declared Public, Final, and Static", + Description: "The program declares an array public, final, and static, which is not sufficient to prevent the array's contents from being modified.", + ExtendedDescription: "Because arrays are mutable objects, the final constraint requires that the array object itself be assigned only once, but makes no guarantees about the values of the array elements. Since the array is public, a malicious program can change the values stored in the array. As such, in most cases an array declared public, final and static is a bug.", + Lang: "en", + }, + "583": { + CweID: "583", + Name: "finalize() Method Declared Public", + Description: "The program violates secure coding principles for mobile code by declaring a finalize() method public.", + ExtendedDescription: "A program should never call finalize explicitly, except to call super.finalize() inside an implementation of finalize(). In mobile code situations, the otherwise error prone practice of manual garbage collection can become a security threat if an attacker can maliciously invoke one of your finalize() methods because it is declared with public access.", + Lang: "en", + }, + "584": { + CweID: "584", + Name: "Return Inside Finally Block", + Description: "The code has a return statement inside a finally block, which will cause any thrown exception in the try block to be discarded.", + ExtendedDescription: "", + Lang: "en", + }, + "585": { + CweID: "585", + Name: "Empty Synchronized Block", + Description: "The software contains an empty synchronized block.", + ExtendedDescription: "An empty synchronized block does not actually accomplish any synchronization and may indicate a troubled section of code. An empty synchronized block can occur because code no longer needed within the synchronized block is commented out without removing the synchronized block.", + Lang: "en", + }, + "586": { + CweID: "586", + Name: "Explicit Call to Finalize()", + Description: "The software makes an explicit call to the finalize() method from outside the finalizer.", + ExtendedDescription: "While the Java Language Specification allows an object's finalize() method to be called from outside the finalizer, doing so is usually a bad idea. For example, calling finalize() explicitly means that finalize() will be called more than once: the first time will be the explicit call and the last time will be the call that is made after the object is garbage collected.", + Lang: "en", + }, + "587": { + CweID: "587", + Name: "Assignment of a Fixed Address to a Pointer", + Description: "The software sets a pointer to a specific address other than NULL or 0.", + ExtendedDescription: "Using a fixed address is not portable because that address will probably not be valid in all environments or platforms.", + Lang: "en", + }, + "588": { + CweID: "588", + Name: "Attempt to Access Child of a Non-structure Pointer", + Description: "Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption.", + ExtendedDescription: "", + Lang: "en", + }, + "589": { + CweID: "589", + Name: "Call to Non-ubiquitous API", + Description: "The software uses an API function that does not exist on all versions of the target platform. This could cause portability problems or inconsistencies that allow denial of service or other consequences.", + ExtendedDescription: "Some functions that offer security features supported by the OS are not available on all versions of the OS in common use. Likewise, functions are often deprecated or made obsolete for security reasons and should not be used.", + Lang: "en", + }, + "59": { + CweID: "59", + Name: "Improper Link Resolution Before File Access ('Link Following')", + Description: "The software attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource.", + ExtendedDescription: "", + Lang: "en", + }, + "590": { + CweID: "590", + Name: "Free of Memory not on the Heap", + Description: "The application calls free() on a pointer to memory that was not allocated using associated heap allocation functions such as malloc(), calloc(), or realloc().", + ExtendedDescription: "When free() is called on an invalid pointer, the program's memory management data structures may become corrupted. This corruption can cause the program to crash or, in some circumstances, an attacker may be able to cause free() to operate on controllable memory locations to modify critical program variables or execute code.", + Lang: "en", + }, + "591": { + CweID: "591", + Name: "Sensitive Data Storage in Improperly Locked Memory", + Description: "The application stores sensitive data in memory that is not locked, or that has been incorrectly locked, which might cause the memory to be written to swap files on disk by the virtual memory manager. This can make the data more accessible to external actors.", + ExtendedDescription: "On Windows systems the VirtualLock function can lock a page of memory to ensure that it will remain present in memory and not be swapped to disk. However, on older versions of Windows, such as 95, 98, or Me, the VirtualLock() function is only a stub and provides no protection. On POSIX systems the mlock() call ensures that a page will stay resident in memory but does not guarantee that the page will not appear in the swap. Therefore, it is unsuitable for use as a protection mechanism for sensitive data. Some platforms, in particular Linux, do make the guarantee that the page will not be swapped, but this is non-standard and is not portable. Calls to mlock() also require supervisor privilege. Return values for both of these calls must be checked to ensure that the lock operation was actually successful.", + Lang: "en", + }, + "592": { + CweID: "592", + Name: "DEPRECATED: Authentication Bypass Issues", + Description: "This weakness has been deprecated because it covered redundant concepts already described in CWE-287.", + ExtendedDescription: "", + Lang: "en", + }, + "593": { + CweID: "593", + Name: "Authentication Bypass: OpenSSL CTX Object Modified after SSL Objects are Created", + Description: "The software modifies the SSL context after connection creation has begun.", + ExtendedDescription: "If the program modifies the SSL_CTX object after creating SSL objects from it, there is the possibility that older SSL objects created from the original context could all be affected by that change.", + Lang: "en", + }, + "594": { + CweID: "594", + Name: "J2EE Framework: Saving Unserializable Objects to Disk", + Description: "When the J2EE container attempts to write unserializable objects to disk there is no guarantee that the process will complete successfully.", + ExtendedDescription: "In heavy load conditions, most J2EE application frameworks flush objects to disk to manage memory requirements of incoming requests. For example, session scoped objects, and even application scoped objects, are written to disk when required. While these application frameworks do the real work of writing objects to disk, they do not enforce that those objects be serializable, thus leaving the web application vulnerable to crashes induced by serialization failure. An attacker may be able to mount a denial of service attack by sending enough requests to the server to force the web application to save objects to disk.", + Lang: "en", + }, + "595": { + CweID: "595", + Name: "Comparison of Object References Instead of Object Contents", + Description: "The program compares object references instead of the contents of the objects themselves, preventing it from detecting equivalent objects.", + ExtendedDescription: "", + Lang: "en", + }, + "596": { + CweID: "596", + Name: "Incorrect Semantic Object Comparison", + Description: "The software does not correctly compare two objects based on their conceptual content.", + ExtendedDescription: "", + Lang: "en", + }, + "597": { + CweID: "597", + Name: "Use of Wrong Operator in String Comparison", + Description: "The product uses the wrong operator when comparing a string, such as using '==' when the equals() method should be used instead.", + ExtendedDescription: "In Java, using == or != to compare two strings for equality actually compares two objects for equality, not their values. Chances are good that the two references will never be equal. While this weakness often only affects program correctness, if the equality is used for a security decision, it could be leveraged to affect program security.", + Lang: "en", + }, + "598": { + CweID: "598", + Name: "Information Exposure Through Query Strings in GET Request", + Description: "The web application uses the GET method to process requests that contain sensitive information, which can expose that information through the browser's history, Referers, web logs, and other sources.", + ExtendedDescription: "", + Lang: "en", + }, + "599": { + CweID: "599", + Name: "Missing Validation of OpenSSL Certificate", + Description: "The software uses OpenSSL and trusts or uses a certificate without using the SSL_get_verify_result() function to ensure that the certificate satisfies all necessary security requirements.", + ExtendedDescription: "This could allow an attacker to use an invalid certificate to claim to be a trusted host, use expired certificates, or conduct other attacks that could be detected if the certificate is properly validated.", + Lang: "en", + }, + "6": { + CweID: "6", + Name: "J2EE Misconfiguration: Insufficient Session-ID Length", + Description: "The J2EE application is configured to use an insufficient session ID length.", + ExtendedDescription: "If an attacker can guess or steal a session ID, then they may be able to take over the user's session (called session hijacking). The number of possible session IDs increases with increased session ID length, making it more difficult to guess or steal a session ID.", + Lang: "en", + }, + "600": { + CweID: "600", + Name: "Uncaught Exception in Servlet", + Description: "The Servlet does not catch all exceptions, which may reveal sensitive debugging information.", + ExtendedDescription: "When a Servlet throws an exception, the default error response the Servlet container sends back to the user typically includes debugging information. This information is of great value to an attacker. For example, a stack trace might show the attacker a malformed SQL query string, the type of database being used, and the version of the application container. This information enables the attacker to target known vulnerabilities in these components.", + Lang: "en", + }, + "601": { + CweID: "601", + Name: "URL Redirection to Untrusted Site ('Open Redirect')", + Description: "A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect. This simplifies phishing attacks.", + ExtendedDescription: "An http parameter may contain a URL value and could cause the web application to redirect the request to the specified URL. By modifying the URL value to a malicious site, an attacker may successfully launch a phishing scam and steal user credentials. Because the server name in the modified link is identical to the original site, phishing attempts have a more trustworthy appearance.", + Lang: "en", + }, + "602": { + CweID: "602", + Name: "Client-Side Enforcement of Server-Side Security", + Description: "The software is composed of a server that relies on the client to implement a mechanism that is intended to protect the server.", + ExtendedDescription: "When the server relies on protection mechanisms placed on the client side, an attacker can modify the client-side behavior to bypass the protection mechanisms resulting in potentially unexpected interactions between the client and server. The consequences will vary, depending on what the mechanisms are trying to protect.", + Lang: "en", + }, + "603": { + CweID: "603", + Name: "Use of Client-Side Authentication", + Description: "A client/server product performs authentication within client code but not in server code, allowing server-side authentication to be bypassed via a modified client that omits the authentication check.", + ExtendedDescription: "Client-side authentication is extremely weak and may be breached easily. Any attacker may read the source code and reverse-engineer the authentication mechanism to access parts of the application which would otherwise be protected.", + Lang: "en", + }, + "605": { + CweID: "605", + Name: "Multiple Binds to the Same Port", + Description: "When multiple sockets are allowed to bind to the same port, other services on that port may be stolen or spoofed.", + ExtendedDescription: "On most systems, a combination of setting the SO_REUSEADDR socket option, and a call to bind() allows any process to bind to a port to which a previous process has bound with INADDR_ANY. This allows a user to bind to the specific address of a server bound to INADDR_ANY on an unprivileged port, and steal its UDP packets/TCP connection.", + Lang: "en", + }, + "606": { + CweID: "606", + Name: "Unchecked Input for Loop Condition", + Description: "The product does not properly check inputs that are used for loop conditions, potentially leading to a denial of service because of excessive looping.", + ExtendedDescription: "", + Lang: "en", + }, + "607": { + CweID: "607", + Name: "Public Static Final Field References Mutable Object", + Description: "A public or protected static final field references a mutable object, which allows the object to be changed by malicious code, or accidentally from another package.", + ExtendedDescription: "", + Lang: "en", + }, + "608": { + CweID: "608", + Name: "Struts: Non-private Field in ActionForm Class", + Description: "An ActionForm class contains a field that has not been declared private, which can be accessed without using a setter or getter.", + ExtendedDescription: "", + Lang: "en", + }, + "609": { + CweID: "609", + Name: "Double-Checked Locking", + Description: "The program uses double-checked locking to access a resource without the overhead of explicit synchronization, but the locking is insufficient.", + ExtendedDescription: "Double-checked locking refers to the situation where a programmer checks to see if a resource has been initialized, grabs a lock, checks again to see if the resource has been initialized, and then performs the initialization if it has not occurred yet. This should not be done, as is not guaranteed to work in all languages and on all architectures. In summary, other threads may not be operating inside the synchronous block and are not guaranteed to see the operations execute in the same order as they would appear inside the synchronous block.", + Lang: "en", + }, + "61": { + CweID: "61", + Name: "UNIX Symbolic Link (Symlink) Following", + Description: "The software, when opening a file or directory, does not sufficiently account for when the file is a symbolic link that resolves to a target outside of the intended control sphere. This could allow an attacker to cause the software to operate on unauthorized files.", + ExtendedDescription: "A software system that allows UNIX symbolic links (symlink) as part of paths whether in internal code or through user input can allow an attacker to spoof the symbolic link and traverse the file system to unintended locations or access arbitrary files. The symbolic link can permit an attacker to read/write/corrupt a file that they originally did not have permissions to access.", + Lang: "en", + }, + "610": { + CweID: "610", + Name: "Externally Controlled Reference to a Resource in Another Sphere", + Description: "The product uses an externally controlled name or reference that resolves to a resource that is outside of the intended control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "611": { + CweID: "611", + Name: "Improper Restriction of XML External Entity Reference ('XXE')", + Description: "The software processes an XML document that can contain XML entities with URIs that resolve to documents outside of the intended sphere of control, causing the product to embed incorrect documents into its output.", + ExtendedDescription: "", + Lang: "en", + }, + "612": { + CweID: "612", + Name: "Information Exposure Through Indexing of Private Data", + Description: "The product performs an indexing routine against private documents, but does not sufficiently verify that the actors who can access the index also have the privileges to access the private documents.", + ExtendedDescription: "When an indexing routine is applied against a group of private documents, and that index's results are available to outsiders who do not have access to those documents, then outsiders might be able to obtain sensitive information by conducting targeted searches. The risk is especially dangerous if search results include surrounding text that was not part of the search query. This issue can appear in search engines that are not configured (or implemented) to ignore critical files that should remain hidden; even without permissions to download these files directly, the remote user could read them.", + Lang: "en", + }, + "613": { + CweID: "613", + Name: "Insufficient Session Expiration", + Description: "According to WASC, 'Insufficient Session Expiration is when a web site permits an attacker to reuse old session credentials or session IDs for authorization.'", + ExtendedDescription: "", + Lang: "en", + }, + "614": { + CweID: "614", + Name: "Sensitive Cookie in HTTPS Session Without 'Secure' Attribute", + Description: "The Secure attribute for sensitive cookies in HTTPS sessions is not set, which could cause the user agent to send those cookies in plaintext over an HTTP session.", + ExtendedDescription: "", + Lang: "en", + }, + "615": { + CweID: "615", + Name: "Information Exposure Through Comments", + Description: "While adding general comments is very useful, some programmers tend to leave important data, such as: filenames related to the web application, old links or links which were not meant to be browsed by users, old code fragments, etc.", + ExtendedDescription: "An attacker who finds these comments can map the application's structure and files, expose hidden parts of the site, and study the fragments of code to reverse engineer the application, which may help develop further attacks against the site.", + Lang: "en", + }, + "616": { + CweID: "616", + Name: "Incomplete Identification of Uploaded File Variables (PHP)", + Description: "The PHP application uses an old method for processing uploaded files by referencing the four global variables that are set for each file (e.g. $varname, $varname_size, $varname_name, $varname_type). These variables could be overwritten by attackers, causing the application to process unauthorized files.", + ExtendedDescription: "These global variables could be overwritten by POST requests, cookies, or other methods of populating or overwriting these variables. This could be used to read or process arbitrary files by providing values such as '/etc/passwd'.", + Lang: "en", + }, + "617": { + CweID: "617", + Name: "Reachable Assertion", + Description: "The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.", + ExtendedDescription: "", + Lang: "en", + }, + "618": { + CweID: "618", + Name: "Exposed Unsafe ActiveX Method", + Description: "An ActiveX control is intended for use in a web browser, but it exposes dangerous methods that perform actions that are outside of the browser's security model (e.g. the zone or domain).", + ExtendedDescription: "ActiveX controls can exercise far greater control over the operating system than typical Java or javascript. Exposed methods can be subject to various vulnerabilities, depending on the implemented behaviors of those methods, and whether input validation is performed on the provided arguments. If there is no integrity checking or origin validation, this method could be invoked by attackers.", + Lang: "en", + }, + "619": { + CweID: "619", + Name: "Dangling Database Cursor ('Cursor Injection')", + Description: "If a database cursor is not closed properly, then it could become accessible to other users while retaining the same privileges that were originally assigned, leaving the cursor 'dangling.'", + ExtendedDescription: "For example, an improper dangling cursor could arise from unhandled exceptions. The impact of the issue depends on the cursor's role, but SQL injection attacks are commonly possible.", + Lang: "en", + }, + "62": { + CweID: "62", + Name: "UNIX Hard Link", + Description: "The software, when opening a file or directory, does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere. This could allow an attacker to cause the software to operate on unauthorized files.", + ExtendedDescription: "Failure for a system to check for hard links can result in vulnerability to different types of attacks. For example, an attacker can escalate their privileges if a file used by a privileged program is replaced with a hard link to a sensitive file (e.g. /etc/passwd). When the process opens the file, the attacker can assume the privileges of that process.", + Lang: "en", + }, + "620": { + CweID: "620", + Name: "Unverified Password Change", + Description: "When setting a new password for a user, the product does not require knowledge of the original password, or using another form of authentication.", + ExtendedDescription: "This could be used by an attacker to change passwords for another user, thus gaining the privileges associated with that user.", + Lang: "en", + }, + "621": { + CweID: "621", + Name: "Variable Extraction Error", + Description: "The product uses external input to determine the names of variables into which information is extracted, without verifying that the names of the specified variables are valid. This could cause the program to overwrite unintended variables.", + ExtendedDescription: "", + Lang: "en", + }, + "622": { + CweID: "622", + Name: "Improper Validation of Function Hook Arguments", + Description: "A product adds hooks to user-accessible API functions, but does not properly validate the arguments. This could lead to resultant vulnerabilities.", + ExtendedDescription: "Such hooks can be used in defensive software that runs with privileges, such as anti-virus or firewall, which hooks kernel calls. When the arguments are not validated, they could be used to bypass the protection scheme or attack the product itself.", + Lang: "en", + }, + "623": { + CweID: "623", + Name: "Unsafe ActiveX Control Marked Safe For Scripting", + Description: "An ActiveX control is intended for restricted use, but it has been marked as safe-for-scripting.", + ExtendedDescription: "This might allow attackers to use dangerous functionality via a web page that accesses the control, which can lead to different resultant vulnerabilities, depending on the control's behavior.", + Lang: "en", + }, + "624": { + CweID: "624", + Name: "Executable Regular Expression Error", + Description: "The product uses a regular expression that either (1) contains an executable component with user-controlled inputs, or (2) allows a user to enable execution by inserting pattern modifiers.", + ExtendedDescription: "Case (2) is possible in the PHP preg_replace() function, and possibly in other languages when a user-controlled input is inserted into a string that is later parsed as a regular expression.", + Lang: "en", + }, + "625": { + CweID: "625", + Name: "Permissive Regular Expression", + Description: "The product uses a regular expression that does not sufficiently restrict the set of allowed values.", + ExtendedDescription: "", + Lang: "en", + }, + "626": { + CweID: "626", + Name: "Null Byte Interaction Error (Poison Null Byte)", + Description: "The product does not properly handle null bytes or NUL characters when passing data between different representations or components.", + ExtendedDescription: "", + Lang: "en", + }, + "627": { + CweID: "627", + Name: "Dynamic Variable Evaluation", + Description: "In a language where the user can influence the name of a variable at runtime, if the variable names are not controlled, an attacker can read or write to arbitrary variables, or access arbitrary functions.", + ExtendedDescription: "The resultant vulnerabilities depend on the behavior of the application, both at the crossover point and in any control/data flow that is reachable by the related variables or functions.", + Lang: "en", + }, + "628": { + CweID: "628", + Name: "Function Call with Incorrectly Specified Arguments", + Description: "The product calls a function, procedure, or routine with arguments that are not correctly specified, leading to always-incorrect behavior and resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "636": { + CweID: "636", + Name: "Not Failing Securely ('Failing Open')", + Description: "When the product encounters an error condition or failure, its design requires it to fall back to a state that is less secure than other options that are available, such as selecting the weakest encryption algorithm or using the most permissive access control restrictions.", + ExtendedDescription: "By entering a less secure state, the product inherits the weaknesses associated with that state, making it easier to compromise. At the least, it causes administrators to have a false sense of security. This weakness typically occurs as a result of wanting to 'fail functional' to minimize administration and support costs, instead of 'failing safe.'", + Lang: "en", + }, + "637": { + CweID: "637", + Name: "Unnecessary Complexity in Protection Mechanism (Not Using 'Economy of Mechanism')", + Description: "The software uses a more complex mechanism than necessary, which could lead to resultant weaknesses when the mechanism is not correctly understood, modeled, configured, implemented, or used.", + ExtendedDescription: "Security mechanisms should be as simple as possible. Complex security mechanisms may engender partial implementations and compatibility problems, with resulting mismatches in assumptions and implemented security. A corollary of this principle is that data specifications should be as simple as possible, because complex data specifications result in complex validation code. Complex tasks and systems may also need to be guarded by complex security checks, so simple systems should be preferred.", + Lang: "en", + }, + "638": { + CweID: "638", + Name: "Not Using Complete Mediation", + Description: "The software does not perform access checks on a resource every time the resource is accessed by an entity, which can create resultant weaknesses if that entity's rights or privileges change over time.", + ExtendedDescription: "", + Lang: "en", + }, + "639": { + CweID: "639", + Name: "Authorization Bypass Through User-Controlled Key", + Description: "The system's authorization functionality does not prevent one user from gaining access to another user's data or record by modifying the key value identifying the data.", + ExtendedDescription: "", + Lang: "en", + }, + "64": { + CweID: "64", + Name: "Windows Shortcut Following (.LNK)", + Description: "The software, when opening a file or directory, does not sufficiently handle when the file is a Windows shortcut (.LNK) whose target is outside of the intended control sphere. This could allow an attacker to cause the software to operate on unauthorized files.", + ExtendedDescription: "The shortcut (file with the .lnk extension) can permit an attacker to read/write a file that they originally did not have permissions to access.", + Lang: "en", + }, + "640": { + CweID: "640", + Name: "Weak Password Recovery Mechanism for Forgotten Password", + Description: "The software contains a mechanism for users to recover or change their passwords without knowing the original password, but the mechanism is weak.", + ExtendedDescription: "", + Lang: "en", + }, + "641": { + CweID: "641", + Name: "Improper Restriction of Names for Files and Other Resources", + Description: "The application constructs the name of a file or other resource using input from an upstream component, but it does not restrict or incorrectly restricts the resulting name.", + ExtendedDescription: "This may produce resultant weaknesses. For instance, if the names of these resources contain scripting characters, it is possible that a script may get executed in the client's browser if the application ever displays the name of the resource on a dynamically generated web page. Alternately, if the resources are consumed by some application parser, a specially crafted name can exploit some vulnerability internal to the parser, potentially resulting in execution of arbitrary code on the server machine. The problems will vary based on the context of usage of such malformed resource names and whether vulnerabilities are present in or assumptions are made by the targeted technology that would make code execution possible.", + Lang: "en", + }, + "642": { + CweID: "642", + Name: "External Control of Critical State Data", + Description: "The software stores security-critical state information about its users, or the software itself, in a location that is accessible to unauthorized actors.", + ExtendedDescription: "", + Lang: "en", + }, + "643": { + CweID: "643", + Name: "Improper Neutralization of Data within XPath Expressions ('XPath Injection')", + Description: "The software uses external input to dynamically construct an XPath expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input. This allows an attacker to control the structure of the query.", + ExtendedDescription: "The net effect is that the attacker will have control over the information selected from the XML database and may use that ability to control application flow, modify logic, retrieve unauthorized data, or bypass important checks (e.g. authentication).", + Lang: "en", + }, + "644": { + CweID: "644", + Name: "Improper Neutralization of HTTP Headers for Scripting Syntax", + Description: "The application does not neutralize or incorrectly neutralizes web scripting syntax in HTTP headers that can be used by web browser components that can process raw headers, such as Flash.", + ExtendedDescription: "", + Lang: "en", + }, + "645": { + CweID: "645", + Name: "Overly Restrictive Account Lockout Mechanism", + Description: "The software contains an account lockout protection mechanism, but the mechanism is too restrictive and can be triggered too easily, which allows attackers to deny service to legitimate users by causing their accounts to be locked out.", + ExtendedDescription: "Account lockout is a security feature often present in applications as a countermeasure to the brute force attack on the password based authentication mechanism of the system. After a certain number of failed login attempts, the users' account may be disabled for a certain period of time or until it is unlocked by an administrator. Other security events may also possibly trigger account lockout. However, an attacker may use this very security feature to deny service to legitimate system users. It is therefore important to ensure that the account lockout security mechanism is not overly restrictive.", + Lang: "en", + }, + "646": { + CweID: "646", + Name: "Reliance on File Name or Extension of Externally-Supplied File", + Description: "The software allows a file to be uploaded, but it relies on the file name or extension of the file to determine the appropriate behaviors. This could be used by attackers to cause the file to be misclassified and processed in a dangerous fashion.", + ExtendedDescription: "An application might use the file name or extension of of a user-supplied file to determine the proper course of action, such as selecting the correct process to which control should be passed, deciding what data should be made available, or what resources should be allocated. If the attacker can cause the code to misclassify the supplied file, then the wrong action could occur. For example, an attacker could supply a file that ends in a '.php.gif' extension that appears to be a GIF image, but would be processed as PHP code. In extreme cases, code execution is possible, but the attacker could also cause exhaustion of resources, denial of service, exposure of debug or system data (including application source code), or being bound to a particular server side process. This weakness may be due to a vulnerability in any of the technologies used by the web and application servers, due to misconfiguration, or resultant from another flaw in the application itself.", + Lang: "en", + }, + "647": { + CweID: "647", + Name: "Use of Non-Canonical URL Paths for Authorization Decisions", + Description: "The software defines policy namespaces and makes authorization decisions based on the assumption that a URL is canonical. This can allow a non-canonical URL to bypass the authorization.", + ExtendedDescription: "", + Lang: "en", + }, + "648": { + CweID: "648", + Name: "Incorrect Use of Privileged APIs", + Description: "The application does not conform to the API requirements for a function call that requires extra privileges. This could allow attackers to gain privileges by causing the function to be called incorrectly.", + ExtendedDescription: "", + Lang: "en", + }, + "649": { + CweID: "649", + Name: "Reliance on Obfuscation or Encryption of Security-Relevant Inputs without Integrity Checking", + Description: "The software uses obfuscation or encryption of inputs that should not be mutable by an external actor, but the software does not use integrity checks to detect if those inputs have been modified.", + ExtendedDescription: "When an application relies on obfuscation or incorrectly applied / weak encryption to protect client-controllable tokens or parameters, that may have an effect on the user state, system state, or some decision made on the server. Without protecting the tokens/parameters for integrity, the application is vulnerable to an attack where an adversary blindly traverses the space of possible values of the said token/parameter in order to attempt to gain an advantage. The goal of the attacker is to find another admissible value that will somehow elevate their privileges in the system, disclose information or change the behavior of the system in some way beneficial to the attacker. If the application does not protect these critical tokens/parameters for integrity, it will not be able to determine that these values have been tampered with. Measures that are used to protect data for confidentiality should not be relied upon to provide the integrity service.", + Lang: "en", + }, + "65": { + CweID: "65", + Name: "Windows Hard Link", + Description: "The software, when opening a file or directory, does not sufficiently handle when the name is associated with a hard link to a target that is outside of the intended control sphere. This could allow an attacker to cause the software to operate on unauthorized files.", + ExtendedDescription: "Failure for a system to check for hard links can result in vulnerability to different types of attacks. For example, an attacker can escalate their privileges if a file used by a privileged program is replaced with a hard link to a sensitive file (e.g. AUTOEXEC.BAT). When the process opens the file, the attacker can assume the privileges of that process, or prevent the program from accurately processing data.", + Lang: "en", + }, + "650": { + CweID: "650", + Name: "Trusting HTTP Permission Methods on the Server Side", + Description: "The server contains a protection mechanism that assumes that any URI that is accessed using HTTP GET will not cause a state change to the associated resource. This might allow attackers to bypass intended access restrictions and conduct resource modification and deletion attacks, since some applications allow GET to modify state.", + ExtendedDescription: "The HTTP GET method and some other methods are designed to retrieve resources and not to alter the state of the application or resources on the server side. Furthermore, the HTTP specification requires that GET requests (and other requests) should not have side effects. Believing that it will be enough to prevent unintended resource alterations, an application may disallow the HTTP requests to perform DELETE, PUT and POST operations on the resource representation. However, there is nothing in the HTTP protocol itself that actually prevents the HTTP GET method from performing more than just query of the data. Developers can easily code programs that accept a HTTP GET request that do in fact create, update or delete data on the server. For instance, it is a common practice with REST based Web Services to have HTTP GET requests modifying resources on the server side. However, whenever that happens, the access control needs to be properly enforced in the application. No assumptions should be made that only HTTP DELETE, PUT, POST, and other methods have the power to alter the representation of the resource being accessed in the request.", + Lang: "en", + }, + "651": { + CweID: "651", + Name: "Information Exposure Through WSDL File", + Description: "The Web services architecture may require exposing a Web Service Definition Language (WSDL) file that contains information on the publicly accessible services and how callers of these services should interact with them (e.g. what parameters they expect and what types they return).", + ExtendedDescription: "", + Lang: "en", + }, + "652": { + CweID: "652", + Name: "Improper Neutralization of Data within XQuery Expressions ('XQuery Injection')", + Description: "The software uses external input to dynamically construct an XQuery expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input. This allows an attacker to control the structure of the query.", + ExtendedDescription: "The net effect is that the attacker will have control over the information selected from the XML database and may use that ability to control application flow, modify logic, retrieve unauthorized data, or bypass important checks (e.g. authentication).", + Lang: "en", + }, + "653": { + CweID: "653", + Name: "Insufficient Compartmentalization", + Description: "The product does not sufficiently compartmentalize functionality or processes that require different privilege levels, rights, or permissions.", + ExtendedDescription: "When a weakness occurs in functionality that is accessible by lower-privileged users, then without strong boundaries, an attack might extend the scope of the damage to higher-privileged users.", + Lang: "en", + }, + "654": { + CweID: "654", + Name: "Reliance on a Single Factor in a Security Decision", + Description: "A protection mechanism relies exclusively, or to a large extent, on the evaluation of a single condition or the integrity of a single object or entity in order to make a decision about granting access to restricted resources or functionality.", + ExtendedDescription: "", + Lang: "en", + }, + "655": { + CweID: "655", + Name: "Insufficient Psychological Acceptability", + Description: "The software has a protection mechanism that is too difficult or inconvenient to use, encouraging non-malicious users to disable or bypass the mechanism, whether by accident or on purpose.", + ExtendedDescription: "", + Lang: "en", + }, + "656": { + CweID: "656", + Name: "Reliance on Security Through Obscurity", + Description: "The software uses a protection mechanism whose strength depends heavily on its obscurity, such that knowledge of its algorithms or key data is sufficient to defeat the mechanism.", + ExtendedDescription: "This reliance on 'security through obscurity' can produce resultant weaknesses if an attacker is able to reverse engineer the inner workings of the mechanism. Note that obscurity can be one small part of defense in depth, since it can create more work for an attacker; however, it is a significant risk if used as the primary means of protection.", + Lang: "en", + }, + "657": { + CweID: "657", + Name: "Violation of Secure Design Principles", + Description: "The product violates well-established principles for secure design.", + ExtendedDescription: "This can introduce resultant weaknesses or make it easier for developers to introduce related weaknesses during implementation. Because code is centered around design, it can be resource-intensive to fix design problems.", + Lang: "en", + }, + "66": { + CweID: "66", + Name: "Improper Handling of File Names that Identify Virtual Resources", + Description: "The product does not handle or incorrectly handles a file name that identifies a 'virtual' resource that is not directly specified within the directory that is associated with the file name, causing the product to perform file-based operations on a resource that is not a file.", + ExtendedDescription: "Virtual file names are represented like normal file names, but they are effectively aliases for other resources that do not behave like normal files. Depending on their functionality, they could be alternate entities. They are not necessarily listed in directories.", + Lang: "en", + }, + "662": { + CweID: "662", + Name: "Improper Synchronization", + Description: "The software attempts to use a shared resource in an exclusive manner, but does not prevent or incorrectly prevents use of the resource by another thread or process.", + ExtendedDescription: "", + Lang: "en", + }, + "663": { + CweID: "663", + Name: "Use of a Non-reentrant Function in a Concurrent Context", + Description: "The software calls a non-reentrant function in a concurrent context in which a competing code sequence (e.g. thread or signal handler) may have an opportunity to call the same function or otherwise influence its state.", + ExtendedDescription: "", + Lang: "en", + }, + "664": { + CweID: "664", + Name: "Improper Control of a Resource Through its Lifetime", + Description: "The software does not maintain or incorrectly maintains control over a resource throughout its lifetime of creation, use, and release.", + ExtendedDescription: "", + Lang: "en", + }, + "665": { + CweID: "665", + Name: "Improper Initialization", + Description: "The software does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used.", + ExtendedDescription: "This can have security implications when the associated resource is expected to have certain properties or values, such as a variable that determines whether a user has been authenticated or not.", + Lang: "en", + }, + "666": { + CweID: "666", + Name: "Operation on Resource in Wrong Phase of Lifetime", + Description: "The software performs an operation on a resource at the wrong phase of the resource's lifecycle, which can lead to unexpected behaviors.", + ExtendedDescription: "When a developer wants to initialize, use or release a resource, it is important to follow the specifications outlined for how to operate on that resource and to ensure that the resource is in the expected state. In this case, the software wants to perform a normally valid operation, initialization, use or release, on a resource when it is in the incorrect phase of its lifetime.", + Lang: "en", + }, + "667": { + CweID: "667", + Name: "Improper Locking", + Description: "The software does not properly acquire a lock on a resource, or it does not properly release a lock on a resource, leading to unexpected resource state changes and behaviors.", + ExtendedDescription: "", + Lang: "en", + }, + "668": { + CweID: "668", + Name: "Exposure of Resource to Wrong Sphere", + Description: "The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource.", + ExtendedDescription: "", + Lang: "en", + }, + "669": { + CweID: "669", + Name: "Incorrect Resource Transfer Between Spheres", + Description: "The product does not properly transfer a resource/behavior to another sphere, or improperly imports a resource/behavior from another sphere, in a manner that provides unintended control over that resource.", + ExtendedDescription: "", + Lang: "en", + }, + "67": { + CweID: "67", + Name: "Improper Handling of Windows Device Names", + Description: "The software constructs pathnames from user input, but it does not handle or incorrectly handles a pathname containing a Windows device name such as AUX or CON. This typically leads to denial of service or an information exposure when the application attempts to process the pathname as a regular file.", + ExtendedDescription: "Not properly handling virtual filenames (e.g. AUX, CON, PRN, COM1, LPT1) can result in different types of vulnerabilities. In some cases an attacker can request a device via injection of a virtual filename in a URL, which may cause an error that leads to a denial of service or an error page that reveals sensitive information. A software system that allows device names to bypass filtering runs the risk of an attacker injecting malicious code in a file with the name of a device.", + Lang: "en", + }, + "670": { + CweID: "670", + Name: "Always-Incorrect Control Flow Implementation", + Description: "The code contains a control flow path that does not reflect the algorithm that the path is intended to implement, leading to incorrect behavior any time this path is navigated.", + ExtendedDescription: "This weakness captures cases in which a particular code segment is always incorrect with respect to the algorithm that it is implementing. For example, if a C programmer intends to include multiple statements in a single block but does not include the enclosing braces (CWE-483), then the logic is always incorrect. This issue is in contrast to most weaknesses in which the code usually behaves correctly, except when it is externally manipulated in malicious ways.", + Lang: "en", + }, + "671": { + CweID: "671", + Name: "Lack of Administrator Control over Security", + Description: "The product uses security features in a way that prevents the product's administrator from tailoring security settings to reflect the environment in which the product is being used. This introduces resultant weaknesses or prevents it from operating at a level of security that is desired by the administrator.", + ExtendedDescription: "If the product's administrator does not have the ability to manage security-related decisions at all times, then protecting the product from outside threats - including the product's developer - can become impossible. For example, a hard-coded account name and password cannot be changed by the administrator, thus exposing that product to attacks that the administrator can not prevent.", + Lang: "en", + }, + "672": { + CweID: "672", + Name: "Operation on a Resource after Expiration or Release", + Description: "The software uses, accesses, or otherwise operates on a resource after that resource has been expired, released, or revoked.", + ExtendedDescription: "", + Lang: "en", + }, + "673": { + CweID: "673", + Name: "External Influence of Sphere Definition", + Description: "The product does not prevent the definition of control spheres from external actors.", + ExtendedDescription: "Typically, a product defines its control sphere within the code itself, or through configuration by the product's administrator. In some cases, an external party can change the definition of the control sphere. This is typically a resultant weakness.", + Lang: "en", + }, + "674": { + CweID: "674", + Name: "Uncontrolled Recursion", + Description: "The product does not properly control the amount of recursion that takes place, which consumes excessive resources, such as allocated memory or the program stack.", + ExtendedDescription: "", + Lang: "en", + }, + "675": { + CweID: "675", + Name: "Duplicate Operations on Resource", + Description: "The product performs the same operation on a resource two or more times, when the operation should only be applied once.", + ExtendedDescription: "", + Lang: "en", + }, + "676": { + CweID: "676", + Name: "Use of Potentially Dangerous Function", + Description: "The program invokes a potentially dangerous function that could introduce a vulnerability if it is used incorrectly, but the function can also be used safely.", + ExtendedDescription: "", + Lang: "en", + }, + "680": { + CweID: "680", + Name: "Integer Overflow to Buffer Overflow", + Description: "The product performs a calculation to determine how much memory to allocate, but an integer overflow can occur that causes less memory to be allocated than expected, leading to a buffer overflow.", + ExtendedDescription: "", + Lang: "en", + }, + "681": { + CweID: "681", + Name: "Incorrect Conversion between Numeric Types", + Description: "When converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.", + ExtendedDescription: "", + Lang: "en", + }, + "682": { + CweID: "682", + Name: "Incorrect Calculation", + Description: "The software performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management.", + ExtendedDescription: "When software performs a security-critical calculation incorrectly, it might lead to incorrect resource allocations, incorrect privilege assignments, or failed comparisons among other things. Many of the direct results of an incorrect calculation can lead to even larger problems such as failed protection mechanisms or even arbitrary code execution.", + Lang: "en", + }, + "683": { + CweID: "683", + Name: "Function Call With Incorrect Order of Arguments", + Description: "The software calls a function, procedure, or routine, but the caller specifies the arguments in an incorrect order, leading to resultant weaknesses.", + ExtendedDescription: "While this weakness might be caught by the compiler in some languages, it can occur more frequently in cases in which the called function accepts variable numbers or types of arguments, such as format strings in C. It also can occur in languages or environments that do not enforce strong typing.", + Lang: "en", + }, + "684": { + CweID: "684", + Name: "Incorrect Provision of Specified Functionality", + Description: "The code does not function according to its published specifications, potentially leading to incorrect usage.", + ExtendedDescription: "When providing functionality to an external party, it is important that the software behaves in accordance with the details specified. When requirements of nuances are not documented, the functionality may produce unintended behaviors for the caller, possibly leading to an exploitable state.", + Lang: "en", + }, + "685": { + CweID: "685", + Name: "Function Call With Incorrect Number of Arguments", + Description: "The software calls a function, procedure, or routine, but the caller specifies too many arguments, or too few arguments, which may lead to undefined behavior and resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "686": { + CweID: "686", + Name: "Function Call With Incorrect Argument Type", + Description: "The software calls a function, procedure, or routine, but the caller specifies an argument that is the wrong data type, which may lead to resultant weaknesses.", + ExtendedDescription: "This weakness is most likely to occur in loosely typed languages, or in strongly typed languages in which the types of variable arguments cannot be enforced at compilation time, or where there is implicit casting.", + Lang: "en", + }, + "687": { + CweID: "687", + Name: "Function Call With Incorrectly Specified Argument Value", + Description: "The software calls a function, procedure, or routine, but the caller specifies an argument that contains the wrong value, which may lead to resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "688": { + CweID: "688", + Name: "Function Call With Incorrect Variable or Reference as Argument", + Description: "The software calls a function, procedure, or routine, but the caller specifies the wrong variable or reference as one of the arguments, which may lead to undefined behavior and resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "689": { + CweID: "689", + Name: "Permission Race Condition During Resource Copy", + Description: "The product, while copying or cloning a resource, does not set the resource's permissions or access control until the copy is complete, leaving the resource exposed to other spheres while the copy is taking place.", + ExtendedDescription: "", + Lang: "en", + }, + "69": { + CweID: "69", + Name: "Improper Handling of Windows ::DATA Alternate Data Stream", + Description: "The software does not properly prevent access to, or detect usage of, alternate data streams (ADS).", + ExtendedDescription: "An attacker can use an ADS to hide information about a file (e.g. size, the name of the process) from a system or file browser tools such as Windows Explorer and 'dir' at the command line utility. Alternately, the attacker might be able to bypass intended access restrictions for the associated data fork.", + Lang: "en", + }, + "690": { + CweID: "690", + Name: "Unchecked Return Value to NULL Pointer Dereference", + Description: "The product does not check for an error after calling a function that can return with a NULL pointer if the function fails, which leads to a resultant NULL pointer dereference.", + ExtendedDescription: "While unchecked return value weaknesses are not limited to returns of NULL pointers (see the examples in CWE-252), functions often return NULL to indicate an error status. When this error condition is not checked, a NULL pointer dereference can occur.", + Lang: "en", + }, + "691": { + CweID: "691", + Name: "Insufficient Control Flow Management", + Description: "The code does not sufficiently manage its control flow during execution, creating conditions in which the control flow can be modified in unexpected ways.", + ExtendedDescription: "", + Lang: "en", + }, + "692": { + CweID: "692", + Name: "Incomplete Blacklist to Cross-Site Scripting", + Description: "The product uses a blacklist-based protection mechanism to defend against XSS attacks, but the blacklist is incomplete, allowing XSS variants to succeed.", + ExtendedDescription: "While XSS might seem simple to prevent, web browsers vary so widely in how they parse web pages, that a blacklist cannot keep track of all the variations. The 'XSS Cheat Sheet' [REF-564] contains a large number of attacks that are intended to bypass incomplete blacklists.", + Lang: "en", + }, + "693": { + CweID: "693", + Name: "Protection Mechanism Failure", + Description: "The product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product.", + ExtendedDescription: "This weakness covers three distinct situations. A 'missing' protection mechanism occurs when the application does not define any mechanism against a certain class of attack. An 'insufficient' protection mechanism might provide some defenses - for example, against the most common attacks - but it does not protect against everything that is intended. Finally, an 'ignored' mechanism occurs when a mechanism is available and in active use within the product, but the developer has not applied it in some code path.", + Lang: "en", + }, + "694": { + CweID: "694", + Name: "Use of Multiple Resources with Duplicate Identifier", + Description: "The software uses multiple resources that can have the same identifier, in a context in which unique identifiers are required.", + ExtendedDescription: "If the software assumes that each resource has a unique identifier, the software could operate on the wrong resource if attackers can cause multiple resources to be associated with the same identifier.", + Lang: "en", + }, + "695": { + CweID: "695", + Name: "Use of Low-Level Functionality", + Description: "The software uses low-level functionality that is explicitly prohibited by the framework or specification under which the software is supposed to operate.", + ExtendedDescription: "The use of low-level functionality can violate the specification in unexpected ways that effectively disable built-in protection mechanisms, introduce exploitable inconsistencies, or otherwise expose the functionality to attack.", + Lang: "en", + }, + "696": { + CweID: "696", + Name: "Incorrect Behavior Order", + Description: "The software performs multiple related behaviors, but the behaviors are performed in the wrong order in ways which may produce resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "697": { + CweID: "697", + Name: "Insufficient Comparison", + Description: "The software compares two entities in a security-relevant context, but the comparison is insufficient, which may lead to resultant weaknesses.", + ExtendedDescription: "", + Lang: "en", + }, + "698": { + CweID: "698", + Name: "Execution After Redirect (EAR)", + Description: "The web application sends a redirect to another location, but instead of exiting, it executes additional code.", + ExtendedDescription: "", + Lang: "en", + }, + "7": { + CweID: "7", + Name: "J2EE Misconfiguration: Missing Custom Error Page", + Description: "The default error page of a web application should not display sensitive information about the software system.", + ExtendedDescription: "", + Lang: "en", + }, + "703": { + CweID: "703", + Name: "Improper Check or Handling of Exceptional Conditions", + Description: "The software does not properly anticipate or handle exceptional conditions that rarely occur during normal operation of the software.", + ExtendedDescription: "", + Lang: "en", + }, + "704": { + CweID: "704", + Name: "Incorrect Type Conversion or Cast", + Description: "The software does not correctly convert an object, resource or structure from one type to a different type.", + ExtendedDescription: "", + Lang: "en", + }, + "705": { + CweID: "705", + Name: "Incorrect Control Flow Scoping", + Description: "The software does not properly return control flow to the proper location after it has completed a task or detected an unusual condition.", + ExtendedDescription: "", + Lang: "en", + }, + "706": { + CweID: "706", + Name: "Use of Incorrectly-Resolved Name or Reference", + Description: "The software uses a name or reference to access a resource, but the name/reference resolves to a resource that is outside of the intended control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "707": { + CweID: "707", + Name: "Improper Enforcement of Message or Data Structure", + Description: "The software does not enforce or incorrectly enforces that structured messages or data are well-formed before being read from an upstream component or sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "708": { + CweID: "708", + Name: "Incorrect Ownership Assignment", + Description: "The software assigns an owner to a resource, but the owner is outside of the intended control sphere.", + ExtendedDescription: "This may allow the resource to be manipulated by actors outside of the intended control sphere.", + Lang: "en", + }, + "71": { + CweID: "71", + Name: "DEPRECATED: Apple '.DS_Store'", + Description: "This entry has been deprecated as it represents a specific observed example of a UNIX Hard Link weakness type rather than its own individual weakness type. Please refer to CWE-62.", + ExtendedDescription: "", + Lang: "en", + }, + "710": { + CweID: "710", + Name: "Improper Adherence to Coding Standards", + Description: "The software does not follow certain coding rules for development, which can lead to resultant weaknesses or increase the severity of the associated vulnerabilities.", + ExtendedDescription: "", + Lang: "en", + }, + "72": { + CweID: "72", + Name: "Improper Handling of Apple HFS+ Alternate Data Stream Path", + Description: "The software does not properly handle special paths that may identify the data or resource fork of a file on the HFS+ file system.", + ExtendedDescription: "If the software chooses actions to take based on the file name, then if an attacker provides the data or resource fork, the software may take unexpected actions. Further, if the software intends to restrict access to a file, then an attacker might still be able to bypass intended access restrictions by requesting the data or resource fork for that file.", + Lang: "en", + }, + "73": { + CweID: "73", + Name: "External Control of File Name or Path", + Description: "The software allows user input to control or influence paths or file names that are used in filesystem operations.", + ExtendedDescription: "", + Lang: "en", + }, + "732": { + CweID: "732", + Name: "Incorrect Permission Assignment for Critical Resource", + Description: "The software specifies permissions for a security-critical resource in a way that allows that resource to be read or modified by unintended actors.", + ExtendedDescription: "When a resource is given a permissions setting that provides access to a wider range of actors than required, it could lead to the exposure of sensitive information, or the modification of that resource by unintended parties. This is especially dangerous when the resource is related to program configuration, execution or sensitive user data.", + Lang: "en", + }, + "733": { + CweID: "733", + Name: "Compiler Optimization Removal or Modification of Security-critical Code", + Description: "The developer builds a security-critical protection mechanism into the software but the compiler optimizes the program such that the mechanism is removed or modified.", + ExtendedDescription: "", + Lang: "en", + }, + "74": { + CweID: "74", + Name: "Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')", + Description: "The software constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.", + ExtendedDescription: "Software has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.", + Lang: "en", + }, + "749": { + CweID: "749", + Name: "Exposed Dangerous Method or Function", + Description: "The software provides an Applications Programming Interface (API) or similar interface for interaction with external actors, but the interface includes a dangerous method or function that is not properly restricted.", + ExtendedDescription: "", + Lang: "en", + }, + "75": { + CweID: "75", + Name: "Failure to Sanitize Special Elements into a Different Plane (Special Element Injection)", + Description: "The software does not adequately filter user-controlled input for special elements with control implications.", + ExtendedDescription: "", + Lang: "en", + }, + "754": { + CweID: "754", + Name: "Improper Check for Unusual or Exceptional Conditions", + Description: "The software does not check or improperly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the software.", + ExtendedDescription: "", + Lang: "en", + }, + "755": { + CweID: "755", + Name: "Improper Handling of Exceptional Conditions", + Description: "The software does not handle or incorrectly handles an exceptional condition.", + ExtendedDescription: "", + Lang: "en", + }, + "756": { + CweID: "756", + Name: "Missing Custom Error Page", + Description: "The software does not return custom error pages to the user, possibly exposing sensitive information.", + ExtendedDescription: "", + Lang: "en", + }, + "757": { + CweID: "757", + Name: "Selection of Less-Secure Algorithm During Negotiation ('Algorithm Downgrade')", + Description: "A protocol or its implementation supports interaction between multiple actors and allows those actors to negotiate which algorithm should be used as a protection mechanism such as encryption or authentication, but it does not select the strongest algorithm that is available to both parties.", + ExtendedDescription: "When a security mechanism can be forced to downgrade to use a less secure algorithm, this can make it easier for attackers to compromise the software by exploiting weaker algorithm. The victim might not be aware that the less secure algorithm is being used. For example, if an attacker can force a communications channel to use cleartext instead of strongly-encrypted data, then the attacker could read the channel by sniffing, instead of going through extra effort of trying to decrypt the data using brute force techniques.", + Lang: "en", + }, + "758": { + CweID: "758", + Name: "Reliance on Undefined, Unspecified, or Implementation-Defined Behavior", + Description: "The software uses an API function, data structure, or other entity in a way that relies on properties that are not always guaranteed to hold for that entity.", + ExtendedDescription: "This can lead to resultant weaknesses when the required properties change, such as when the software is ported to a different platform or if an interaction error (CWE-435) occurs.", + Lang: "en", + }, + "759": { + CweID: "759", + Name: "Use of a One-Way Hash without a Salt", + Description: "The software uses a one-way cryptographic hash against an input that should not be reversible, such as a password, but the software does not also use a salt as part of the input.", + ExtendedDescription: "", + Lang: "en", + }, + "76": { + CweID: "76", + Name: "Improper Neutralization of Equivalent Special Elements", + Description: "The software properly neutralizes certain special elements, but it improperly neutralizes equivalent special elements.", + ExtendedDescription: "The software may have a fixed list of special characters it believes is complete. However, there may be alternate encodings, or representations that also have the same meaning. For example, the software may filter out a leading slash (/) to prevent absolute path names, but does not account for a tilde (~) followed by a user name, which on some *nix systems could be expanded to an absolute pathname. Alternately, the software might filter a dangerous '-e' command-line switch when calling an external program, but it might not account for '--exec' or other switches that have the same semantics.", + Lang: "en", + }, + "760": { + CweID: "760", + Name: "Use of a One-Way Hash with a Predictable Salt", + Description: "The software uses a one-way cryptographic hash against an input that should not be reversible, such as a password, but the software uses a predictable salt as part of the input.", + ExtendedDescription: "", + Lang: "en", + }, + "761": { + CweID: "761", + Name: "Free of Pointer not at Start of Buffer", + Description: "The application calls free() on a pointer to a memory resource that was allocated on the heap, but the pointer is not at the start of the buffer.", + ExtendedDescription: "", + Lang: "en", + }, + "762": { + CweID: "762", + Name: "Mismatched Memory Management Routines", + Description: "The application attempts to return a memory resource to the system, but it calls a release function that is not compatible with the function that was originally used to allocate that resource.", + ExtendedDescription: "", + Lang: "en", + }, + "763": { + CweID: "763", + Name: "Release of Invalid Pointer or Reference", + Description: "The application attempts to return a memory resource to the system, but calls the wrong release function or calls the appropriate release function incorrectly.", + ExtendedDescription: "", + Lang: "en", + }, + "764": { + CweID: "764", + Name: "Multiple Locks of a Critical Resource", + Description: "The software locks a critical resource more times than intended, leading to an unexpected state in the system.", + ExtendedDescription: "When software is operating in a concurrent environment and repeatedly locks a critical resource, the consequences will vary based on the type of lock, the lock's implementation, and the resource being protected. In some situations such as with semaphores, the resources are pooled and extra locking calls will reduce the size of the total available pool, possibly leading to degraded performance or a denial of service. If this can be triggered by an attacker, it will be similar to an unrestricted lock (CWE-412). In the context of a binary lock, it is likely that any duplicate locking attempts will never succeed since the lock is already held and progress may not be possible.", + Lang: "en", + }, + "765": { + CweID: "765", + Name: "Multiple Unlocks of a Critical Resource", + Description: "The software unlocks a critical resource more times than intended, leading to an unexpected state in the system.", + ExtendedDescription: "When software is operating in a concurrent environment and repeatedly unlocks a critical resource, the consequences will vary based on the type of lock, the lock's implementation, and the resource being protected. In some situations such as with semaphores, the resources are pooled and extra calls to unlock will increase the count for the number of available resources, likely resulting in a crash or unpredictable behavior when the system nears capacity.", + Lang: "en", + }, + "766": { + CweID: "766", + Name: "Critical Variable Declared Public", + Description: "The software declares a critical variable or field to be public when intended security policy requires it to be private.", + ExtendedDescription: "", + Lang: "en", + }, + "767": { + CweID: "767", + Name: "Access to Critical Private Variable via Public Method", + Description: "The software defines a public method that reads or modifies a private variable.", + ExtendedDescription: "If an attacker modifies the variable to contain unexpected values, this could violate assumptions from other parts of the code. Additionally, if an attacker can read the private variable, it may expose sensitive information or make it easier to launch further attacks.", + Lang: "en", + }, + "768": { + CweID: "768", + Name: "Incorrect Short Circuit Evaluation", + Description: "The software contains a conditional statement with multiple logical expressions in which one of the non-leading expressions may produce side effects. This may lead to an unexpected state in the program after the execution of the conditional, because short-circuiting logic may prevent the side effects from occurring.", + ExtendedDescription: "", + Lang: "en", + }, + "769": { + CweID: "769", + Name: "Uncontrolled File Descriptor Consumption", + Description: "The software does not properly limit the number of open file descriptors that it uses.", + ExtendedDescription: "", + Lang: "en", + }, + "77": { + CweID: "77", + Name: "Improper Neutralization of Special Elements used in a Command ('Command Injection')", + Description: "The software constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "770": { + CweID: "770", + Name: "Allocation of Resources Without Limits or Throttling", + Description: "The software allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on how many resources can be allocated, in violation of the intended security policy for that actor.", + ExtendedDescription: "", + Lang: "en", + }, + "771": { + CweID: "771", + Name: "Missing Reference to Active Allocated Resource", + Description: "The software does not properly maintain a reference to a resource that has been allocated, which prevents the resource from being reclaimed.", + ExtendedDescription: "This does not necessarily apply in languages or frameworks that automatically perform garbage collection, since the removal of all references may act as a signal that the resource is ready to be reclaimed.", + Lang: "en", + }, + "772": { + CweID: "772", + Name: "Missing Release of Resource after Effective Lifetime", + Description: "The software does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.", + ExtendedDescription: "When a resource is not released after use, it can allow attackers to cause a denial of service.", + Lang: "en", + }, + "773": { + CweID: "773", + Name: "Missing Reference to Active File Descriptor or Handle", + Description: "The software does not properly maintain references to a file descriptor or handle, which prevents that file descriptor/handle from being reclaimed.", + ExtendedDescription: "This can cause the software to consume all available file descriptors or handles, which can prevent other processes from performing critical file processing operations.", + Lang: "en", + }, + "774": { + CweID: "774", + Name: "Allocation of File Descriptors or Handles Without Limits or Throttling", + Description: "The software allocates file descriptors or handles on behalf of an actor without imposing any restrictions on how many descriptors can be allocated, in violation of the intended security policy for that actor.", + ExtendedDescription: "This can cause the software to consume all available file descriptors or handles, which can prevent other processes from performing critical file processing operations.", + Lang: "en", + }, + "775": { + CweID: "775", + Name: "Missing Release of File Descriptor or Handle after Effective Lifetime", + Description: "The software does not release a file descriptor or handle after its effective lifetime has ended, i.e., after the file descriptor/handle is no longer needed.", + ExtendedDescription: "When a file descriptor or handle is not released after use (typically by explicitly closing it), attackers can cause a denial of service by consuming all available file descriptors/handles, or otherwise preventing other system processes from obtaining their own file descriptors/handles.", + Lang: "en", + }, + "776": { + CweID: "776", + Name: "Improper Restriction of Recursive Entity References in DTDs ('XML Entity Expansion')", + Description: "The software uses XML documents and allows their structure to be defined with a Document Type Definition (DTD), but it does not properly control the number of recursive definitions of entities.", + ExtendedDescription: "If the DTD contains a large number of nested or recursive entities, this can lead to explosive growth of data when parsed, causing a denial of service.", + Lang: "en", + }, + "777": { + CweID: "777", + Name: "Regular Expression without Anchors", + Description: "The software uses a regular expression to perform neutralization, but the regular expression is not anchored and may allow malicious or malformed data to slip through.", + ExtendedDescription: "When performing tasks such as whitelist validation, data is examined and possibly modified to ensure that it is well-formed and adheres to a list of safe values. If the regular expression is not anchored, malicious or malformed data may be included before or after any string matching the regular expression. The type of malicious data that is allowed will depend on the context of the application and which anchors are omitted from the regular expression.", + Lang: "en", + }, + "778": { + CweID: "778", + Name: "Insufficient Logging", + Description: "When a security-critical event occurs, the software either does not record the event or omits important details about the event when logging it.", + ExtendedDescription: "When security-critical events are not logged properly, such as a failed login attempt, this can make malicious behavior more difficult to detect and may hinder forensic analysis after an attack succeeds.", + Lang: "en", + }, + "779": { + CweID: "779", + Name: "Logging of Excessive Data", + Description: "The software logs too much information, making log files hard to process and possibly hindering recovery efforts or forensic analysis after an attack.", + ExtendedDescription: "While logging is a good practice in general, and very high levels of logging are appropriate for debugging stages of development, too much logging in a production environment might hinder a system administrator's ability to detect anomalous conditions. This can provide cover for an attacker while attempting to penetrate a system, clutter the audit trail for forensic analysis, or make it more difficult to debug problems in a production environment.", + Lang: "en", + }, + "78": { + CweID: "78", + Name: "Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')", + Description: "The software constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "780": { + CweID: "780", + Name: "Use of RSA Algorithm without OAEP", + Description: "The software uses the RSA algorithm but does not incorporate Optimal Asymmetric Encryption Padding (OAEP), which might weaken the encryption.", + ExtendedDescription: "Padding schemes are often used with cryptographic algorithms to make the plaintext less predictable and complicate attack efforts. The OAEP scheme is often used with RSA to nullify the impact of predictable common text.", + Lang: "en", + }, + "781": { + CweID: "781", + Name: "Improper Address Validation in IOCTL with METHOD_NEITHER I/O Control Code", + Description: "The software defines an IOCTL that uses METHOD_NEITHER for I/O, but it does not validate or incorrectly validates the addresses that are provided.", + ExtendedDescription: "When an IOCTL uses the METHOD_NEITHER option for I/O control, it is the responsibility of the IOCTL to validate the addresses that have been supplied to it. If validation is missing or incorrect, attackers can supply arbitrary memory addresses, leading to code execution or a denial of service.", + Lang: "en", + }, + "782": { + CweID: "782", + Name: "Exposed IOCTL with Insufficient Access Control", + Description: "The software implements an IOCTL with functionality that should be restricted, but it does not properly enforce access control for the IOCTL.", + ExtendedDescription: "", + Lang: "en", + }, + "783": { + CweID: "783", + Name: "Operator Precedence Logic Error", + Description: "The program uses an expression in which operator precedence causes incorrect logic to be used.", + ExtendedDescription: "While often just a bug, operator precedence logic errors can have serious consequences if they are used in security-critical code, such as making an authentication decision.", + Lang: "en", + }, + "784": { + CweID: "784", + Name: "Reliance on Cookies without Validation and Integrity Checking in a Security Decision", + Description: "The application uses a protection mechanism that relies on the existence or values of a cookie, but it does not properly ensure that the cookie is valid for the associated user.", + ExtendedDescription: "Attackers can easily modify cookies, within the browser or by implementing the client-side code outside of the browser. Attackers can bypass protection mechanisms such as authorization and authentication by modifying the cookie to contain an expected value.", + Lang: "en", + }, + "785": { + CweID: "785", + Name: "Use of Path Manipulation Function without Maximum-sized Buffer", + Description: "The software invokes a function for normalizing paths or file names, but it provides an output buffer that is smaller than the maximum possible size, such as PATH_MAX.", + ExtendedDescription: "Passing an inadequately-sized output buffer to a path manipulation function can result in a buffer overflow. Such functions include realpath(), readlink(), PathAppend(), and others.", + Lang: "en", + }, + "786": { + CweID: "786", + Name: "Access of Memory Location Before Start of Buffer", + Description: "The software reads or writes to a buffer using an index or pointer that references a memory location prior to the beginning of the buffer.", + ExtendedDescription: "This typically occurs when a pointer or its index is decremented to a position before the buffer, when pointer arithmetic results in a position before the beginning of the valid memory location, or when a negative index is used.", + Lang: "en", + }, + "787": { + CweID: "787", + Name: "Out-of-bounds Write", + Description: "The software writes data past the end, or before the beginning, of the intended buffer.", + ExtendedDescription: "This typically occurs when the pointer or its index is incremented or decremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in corruption of sensitive information, a crash, or code execution among other things.", + Lang: "en", + }, + "788": { + CweID: "788", + Name: "Access of Memory Location After End of Buffer", + Description: "The software reads or writes to a buffer using an index or pointer that references a memory location after the end of the buffer.", + ExtendedDescription: "This typically occurs when a pointer or its index is decremented to a position before the buffer; when pointer arithmetic results in a position before the buffer; or when a negative index is used, which generates a position before the buffer.", + Lang: "en", + }, + "789": { + CweID: "789", + Name: "Uncontrolled Memory Allocation", + Description: "The product allocates memory based on an untrusted size value, but it does not validate or incorrectly validates the size, allowing arbitrary amounts of memory to be allocated.", + ExtendedDescription: "", + Lang: "en", + }, + "79": { + CweID: "79", + Name: "Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')", + Description: "The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.", + ExtendedDescription: "", + Lang: "en", + }, + "790": { + CweID: "790", + Name: "Improper Filtering of Special Elements", + Description: "The software receives data from an upstream component, but does not filter or incorrectly filters special elements before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "791": { + CweID: "791", + Name: "Incomplete Filtering of Special Elements", + Description: "The software receives data from an upstream component, but does not completely filter special elements before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "792": { + CweID: "792", + Name: "Incomplete Filtering of One or More Instances of Special Elements", + Description: "The software receives data from an upstream component, but does not completely filter one or more instances of special elements before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "793": { + CweID: "793", + Name: "Only Filtering One Instance of a Special Element", + Description: "The software receives data from an upstream component, but only filters a single instance of a special element before sending it to a downstream component.", + ExtendedDescription: "Incomplete filtering of this nature may be location-dependent, as in only the first or last element is filtered.", + Lang: "en", + }, + "794": { + CweID: "794", + Name: "Incomplete Filtering of Multiple Instances of Special Elements", + Description: "The software receives data from an upstream component, but does not filter all instances of a special element before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "795": { + CweID: "795", + Name: "Only Filtering Special Elements at a Specified Location", + Description: "The software receives data from an upstream component, but only accounts for special elements at a specified location, thereby missing remaining special elements that may exist before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "796": { + CweID: "796", + Name: "Only Filtering Special Elements Relative to a Marker", + Description: "The software receives data from an upstream component, but only accounts for special elements positioned relative to a marker (e.g. 'at the beginning/end of a string; the second argument'), thereby missing remaining special elements that may exist before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "797": { + CweID: "797", + Name: "Only Filtering Special Elements at an Absolute Position", + Description: "The software receives data from an upstream component, but only accounts for special elements at an absolute position (e.g. 'byte number 10'), thereby missing remaining special elements that may exist before sending it to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "798": { + CweID: "798", + Name: "Use of Hard-coded Credentials", + Description: "The software contains hard-coded credentials, such as a password or cryptographic key, which it uses for its own inbound authentication, outbound communication to external components, or encryption of internal data.", + ExtendedDescription: "", + Lang: "en", + }, + "799": { + CweID: "799", + Name: "Improper Control of Interaction Frequency", + Description: "The software does not properly limit the number or frequency of interactions that it has with an actor, such as the number of incoming requests.", + ExtendedDescription: "This can allow the actor to perform actions more frequently than expected. The actor could be a human or an automated process such as a virus or bot. This could be used to cause a denial of service, compromise program logic (such as limiting humans to a single vote), or other consequences. For example, an authentication routine might not limit the number of times an attacker can guess a password. Or, a web site might conduct a poll but only expect humans to vote a maximum of once a day.", + Lang: "en", + }, + "8": { + CweID: "8", + Name: "J2EE Misconfiguration: Entity Bean Declared Remote", + Description: "When an application exposes a remote interface for an entity bean, it might also expose methods that get or set the bean's data. These methods could be leveraged to read sensitive information, or to change data in ways that violate the application's expectations, potentially leading to other vulnerabilities.", + ExtendedDescription: "", + Lang: "en", + }, + "80": { + CweID: "80", + Name: "Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as '<', '>', and '&' that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages.", + ExtendedDescription: "This may allow such characters to be treated as control characters, which are executed client-side in the context of the user's session. Although this can be classified as an injection problem, the more pertinent issue is the improper conversion of such special characters to respective context-appropriate entities before displaying them to the user.", + Lang: "en", + }, + "804": { + CweID: "804", + Name: "Guessable CAPTCHA", + Description: "The software uses a CAPTCHA challenge, but the challenge can be guessed or automatically recognized by a non-human actor.", + ExtendedDescription: "", + Lang: "en", + }, + "805": { + CweID: "805", + Name: "Buffer Access with Incorrect Length Value", + Description: "The software uses a sequential operation to read or write a buffer, but it uses an incorrect length value that causes it to access memory that is outside of the bounds of the buffer.", + ExtendedDescription: "When the length value exceeds the size of the destination, a buffer overflow could occur.", + Lang: "en", + }, + "806": { + CweID: "806", + Name: "Buffer Access Using Size of Source Buffer", + Description: "The software uses the size of a source buffer when reading from or writing to a destination buffer, which may cause it to access memory that is outside of the bounds of the buffer.", + ExtendedDescription: "When the size of the destination is smaller than the size of the source, a buffer overflow could occur.", + Lang: "en", + }, + "807": { + CweID: "807", + Name: "Reliance on Untrusted Inputs in a Security Decision", + Description: "The application uses a protection mechanism that relies on the existence or values of an input, but the input can be modified by an untrusted actor in a way that bypasses the protection mechanism.", + ExtendedDescription: "", + Lang: "en", + }, + "81": { + CweID: "81", + Name: "Improper Neutralization of Script in an Error Message Web Page", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters that could be interpreted as web-scripting elements when they are sent to an error page.", + ExtendedDescription: "", + Lang: "en", + }, + "82": { + CweID: "82", + Name: "Improper Neutralization of Script in Attributes of IMG Tags in a Web Page", + Description: "The web application does not neutralize or incorrectly neutralizes scripting elements within attributes of HTML IMG tags, such as the src attribute.", + ExtendedDescription: "Attackers can embed XSS exploits into the values for IMG attributes (e.g. SRC) that is streamed and then executed in a victim's browser. Note that when the page is loaded into a user's browsers, the exploit will automatically execute.", + Lang: "en", + }, + "820": { + CweID: "820", + Name: "Missing Synchronization", + Description: "The software utilizes a shared resource in a concurrent manner but does not attempt to synchronize access to the resource.", + ExtendedDescription: "If access to a shared resource is not synchronized, then the resource may not be in a state that is expected by the software. This might lead to unexpected or insecure behaviors, especially if an attacker can influence the shared resource.", + Lang: "en", + }, + "821": { + CweID: "821", + Name: "Incorrect Synchronization", + Description: "The software utilizes a shared resource in a concurrent manner but it does not correctly synchronize access to the resource.", + ExtendedDescription: "If access to a shared resource is not correctly synchronized, then the resource may not be in a state that is expected by the software. This might lead to unexpected or insecure behaviors, especially if an attacker can influence the shared resource.", + Lang: "en", + }, + "822": { + CweID: "822", + Name: "Untrusted Pointer Dereference", + Description: "The program obtains a value from an untrusted source, converts this value to a pointer, and dereferences the resulting pointer.", + ExtendedDescription: "", + Lang: "en", + }, + "823": { + CweID: "823", + Name: "Use of Out-of-range Pointer Offset", + Description: "The program performs pointer arithmetic on a valid pointer, but it uses an offset that can point outside of the intended range of valid memory locations for the resulting pointer.", + ExtendedDescription: "", + Lang: "en", + }, + "824": { + CweID: "824", + Name: "Access of Uninitialized Pointer", + Description: "The program accesses or uses a pointer that has not been initialized.", + ExtendedDescription: "", + Lang: "en", + }, + "825": { + CweID: "825", + Name: "Expired Pointer Dereference", + Description: "The program dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid.", + ExtendedDescription: "When a program releases memory, but it maintains a pointer to that memory, then the memory might be re-allocated at a later time. If the original pointer is accessed to read or write data, then this could cause the program to read or modify data that is in use by a different function or process. Depending on how the newly-allocated memory is used, this could lead to a denial of service, information exposure, or code execution.", + Lang: "en", + }, + "826": { + CweID: "826", + Name: "Premature Release of Resource During Expected Lifetime", + Description: "The program releases a resource that is still intended to be used by the program itself or another actor.", + ExtendedDescription: "", + Lang: "en", + }, + "827": { + CweID: "827", + Name: "Improper Control of Document Type Definition", + Description: "The software does not restrict a reference to a Document Type Definition (DTD) to the intended control sphere. This might allow attackers to reference arbitrary DTDs, possibly causing the software to expose files, consume excessive system resources, or execute arbitrary http requests on behalf of the attacker.", + ExtendedDescription: "", + Lang: "en", + }, + "828": { + CweID: "828", + Name: "Signal Handler with Functionality that is not Asynchronous-Safe", + Description: "The software defines a signal handler that contains code sequences that are not asynchronous-safe, i.e., the functionality is not reentrant, or it can be interrupted.", + ExtendedDescription: "", + Lang: "en", + }, + "829": { + CweID: "829", + Name: "Inclusion of Functionality from Untrusted Control Sphere", + Description: "The software imports, requires, or includes executable functionality (such as a library) from a source that is outside of the intended control sphere.", + ExtendedDescription: "", + Lang: "en", + }, + "83": { + CweID: "83", + Name: "Improper Neutralization of Script in Attributes in a Web Page", + Description: "The software does not neutralize or incorrectly neutralizes 'javascript:' or other URIs from dangerous attributes within tags, such as onmouseover, onload, onerror, or style.", + ExtendedDescription: "", + Lang: "en", + }, + "830": { + CweID: "830", + Name: "Inclusion of Web Functionality from an Untrusted Source", + Description: "The software includes web functionality (such as a web widget) from another domain, which causes it to operate within the domain of the software, potentially granting total access and control of the software to the untrusted source.", + ExtendedDescription: "", + Lang: "en", + }, + "831": { + CweID: "831", + Name: "Signal Handler Function Associated with Multiple Signals", + Description: "The software defines a function that is used as a handler for more than one signal.", + ExtendedDescription: "", + Lang: "en", + }, + "832": { + CweID: "832", + Name: "Unlock of a Resource that is not Locked", + Description: "The software attempts to unlock a resource that is not locked.", + ExtendedDescription: "Depending on the locking functionality, an unlock of a non-locked resource might cause memory corruption or other modification to the resource (or its associated metadata that is used for tracking locks).", + Lang: "en", + }, + "833": { + CweID: "833", + Name: "Deadlock", + Description: "The software contains multiple threads or executable segments that are waiting for each other to release a necessary lock, resulting in deadlock.", + ExtendedDescription: "", + Lang: "en", + }, + "834": { + CweID: "834", + Name: "Excessive Iteration", + Description: "The software performs an iteration or loop without sufficiently limiting the number of times that the loop is executed.", + ExtendedDescription: "If the iteration can be influenced by an attacker, this weakness could allow attackers to consume excessive resources such as CPU or memory. In many cases, a loop does not need to be infinite in order to cause enough resource consumption to adversely affect the software or its host system; it depends on the amount of resources consumed per iteration.", + Lang: "en", + }, + "835": { + CweID: "835", + Name: "Loop with Unreachable Exit Condition ('Infinite Loop')", + Description: "The program contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.", + ExtendedDescription: "If the loop can be influenced by an attacker, this weakness could allow attackers to consume excessive resources such as CPU or memory.", + Lang: "en", + }, + "836": { + CweID: "836", + Name: "Use of Password Hash Instead of Password for Authentication", + Description: "The software records password hashes in a data store, receives a hash of a password from a client, and compares the supplied hash to the hash obtained from the data store.", + ExtendedDescription: "", + Lang: "en", + }, + "837": { + CweID: "837", + Name: "Improper Enforcement of a Single, Unique Action", + Description: "The software requires that an actor should only be able to perform an action once, or to have only one unique action, but the software does not enforce or improperly enforces this restriction.", + ExtendedDescription: "In various applications, a user is only expected to perform a certain action once, such as voting, requesting a refund, or making a purchase. When this restriction is not enforced, sometimes this can have security implications. For example, in a voting application, an attacker could attempt to 'stuff the ballot box' by voting multiple times. If these votes are counted separately, then the attacker could directly affect who wins the vote. This could have significant business impact depending on the purpose of the software.", + Lang: "en", + }, + "838": { + CweID: "838", + Name: "Inappropriate Encoding for Output Context", + Description: "The software uses or specifies an encoding when generating output to a downstream component, but the specified encoding is not the same as the encoding that is expected by the downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "839": { + CweID: "839", + Name: "Numeric Range Comparison Without Minimum Check", + Description: "The program checks a value to ensure that it does not exceed a maximum, but it does not verify that the value exceeds the minimum.", + ExtendedDescription: "", + Lang: "en", + }, + "84": { + CweID: "84", + Name: "Improper Neutralization of Encoded URI Schemes in a Web Page", + Description: "The web application improperly neutralizes user-controlled input for executable script disguised with URI encodings.", + ExtendedDescription: "", + Lang: "en", + }, + "841": { + CweID: "841", + Name: "Improper Enforcement of Behavioral Workflow", + Description: "The software supports a session in which more than one behavior must be performed by an actor, but it does not properly ensure that the actor performs the behaviors in the required sequence.", + ExtendedDescription: "", + Lang: "en", + }, + "842": { + CweID: "842", + Name: "Placement of User into Incorrect Group", + Description: "The software or the administrator places a user into an incorrect group.", + ExtendedDescription: "If the incorrect group has more access or privileges than the intended group, the user might be able to bypass intended security policy to access unexpected resources or perform unexpected actions. The access-control system might not be able to detect malicious usage of this group membership.", + Lang: "en", + }, + "843": { + CweID: "843", + Name: "Access of Resource Using Incompatible Type ('Type Confusion')", + Description: "The program allocates or initializes a resource such as a pointer, object, or variable using one type, but it later accesses that resource using a type that is incompatible with the original type.", + ExtendedDescription: "", + Lang: "en", + }, + "85": { + CweID: "85", + Name: "Doubled Character XSS Manipulations", + Description: "The web application does not filter user-controlled input for executable script disguised using doubling of the involved characters.", + ExtendedDescription: "", + Lang: "en", + }, + "86": { + CweID: "86", + Name: "Improper Neutralization of Invalid Characters in Identifiers in Web Pages", + Description: "The software does not neutralize or incorrectly neutralizes invalid characters or byte sequences in the middle of tag names, URI schemes, and other identifiers.", + ExtendedDescription: "Some web browsers may remove these sequences, resulting in output that may have unintended control implications. For example, the software may attempt to remove a 'javascript:' URI scheme, but a 'java%00script:' URI may bypass this check and still be rendered as active javascript by some browsers, allowing XSS or other attacks.", + Lang: "en", + }, + "862": { + CweID: "862", + Name: "Missing Authorization", + Description: "The software does not perform an authorization check when an actor attempts to access a resource or perform an action.", + ExtendedDescription: "", + Lang: "en", + }, + "863": { + CweID: "863", + Name: "Incorrect Authorization", + Description: "The software performs an authorization check when an actor attempts to access a resource or perform an action, but it does not correctly perform the check. This allows attackers to bypass intended access restrictions.", + ExtendedDescription: "", + Lang: "en", + }, + "87": { + CweID: "87", + Name: "Improper Neutralization of Alternate XSS Syntax", + Description: "The software does not neutralize or incorrectly neutralizes user-controlled input for alternate script syntax.", + ExtendedDescription: "", + Lang: "en", + }, + "88": { + CweID: "88", + Name: "Argument Injection or Modification", + Description: "The software does not sufficiently delimit the arguments being passed to a component in another control sphere, allowing alternate arguments to be provided, leading to potentially security-relevant changes.", + ExtendedDescription: "", + Lang: "en", + }, + "89": { + CweID: "89", + Name: "Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')", + Description: "The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "9": { + CweID: "9", + Name: "J2EE Misconfiguration: Weak Access Permissions for EJB Methods", + Description: "If elevated access rights are assigned to EJB methods, then an attacker can take advantage of the permissions to exploit the software system.", + ExtendedDescription: "If the EJB deployment descriptor contains one or more method permissions that grant access to the special ANYONE role, it indicates that access control for the application has not been fully thought through or that the application is structured in such a way that reasonable access control restrictions are impossible.", + Lang: "en", + }, + "90": { + CweID: "90", + Name: "Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection')", + Description: "The software constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended LDAP query when it is sent to a downstream component.", + ExtendedDescription: "", + Lang: "en", + }, + "908": { + CweID: "908", + Name: "Use of Uninitialized Resource", + Description: "The software uses a resource that has not been properly initialized.", + ExtendedDescription: "This can have security implications when the associated resource is expected to have certain properties or values.", + Lang: "en", + }, + "909": { + CweID: "909", + Name: "Missing Initialization of Resource", + Description: "The software does not initialize a critical resource.", + ExtendedDescription: "Many resources require initialization before they can be properly used. If a resource is not initialized, it could contain unpredictable or expired data, or it could be initialized to defaults that are invalid. This can have security implications when the resource is expected to have certain properties or values.", + Lang: "en", + }, + "91": { + CweID: "91", + Name: "XML Injection (aka Blind XPath Injection)", + Description: "The software does not properly neutralize special elements that are used in XML, allowing attackers to modify the syntax, content, or commands of the XML before it is processed by an end system.", + ExtendedDescription: "Within XML, special elements could include reserved words or characters such as '<', '>', ''', and '&', which could then be used to add new data or modify XML syntax.", + Lang: "en", + }, + "910": { + CweID: "910", + Name: "Use of Expired File Descriptor", + Description: "The software uses or accesses a file descriptor after it has been closed.", + ExtendedDescription: "After a file descriptor for a particular file or device has been released, it can be reused. The code might not write to the original file, since the reused file descriptor might reference a different file or device.", + Lang: "en", + }, + "911": { + CweID: "911", + Name: "Improper Update of Reference Count", + Description: "The software uses a reference count to manage a resource, but it does not update or incorrectly updates the reference count.", + ExtendedDescription: "Reference counts can be used when tracking how many objects contain a reference to a particular resource, such as in memory management or garbage collection. When the reference count reaches zero, the resource can be de-allocated or reused because there are no more objects that use it. If the reference count accidentally reaches zero, then the resource might be released too soon, even though it is still in use. If all objects no longer use the resource, but the reference count is not zero, then the resource might not ever be released.", + Lang: "en", + }, + "912": { + CweID: "912", + Name: "Hidden Functionality", + Description: "The software contains functionality that is not documented, not part of the specification, and not accessible through an interface or command sequence that is obvious to the software's users or administrators.", + ExtendedDescription: "Hidden functionality can take many forms, such as intentionally malicious code, 'Easter Eggs' that contain extraneous functionality such as games, developer-friendly shortcuts that reduce maintenance or support costs such as hard-coded accounts, etc. From a security perspective, even when the functionality is not intentionally malicious or damaging, it can increase the software's attack surface and expose additional weaknesses beyond what is already exposed by the intended functionality. Even if it is not easily accessible, the hidden functionality could be useful for attacks that modify the control flow of the application.", + Lang: "en", + }, + "913": { + CweID: "913", + Name: "Improper Control of Dynamically-Managed Code Resources", + Description: "The software does not properly restrict reading from or writing to dynamically-managed code resources such as variables, objects, classes, attributes, functions, or executable instructions or statements.", + ExtendedDescription: "Many languages offer powerful features that allow the programmer to dynamically create or modify existing code, or resources used by code such as variables and objects. While these features can offer significant flexibility and reduce development time, they can be extremely dangerous if attackers can directly influence these code resources in unexpected ways.", + Lang: "en", + }, + "914": { + CweID: "914", + Name: "Improper Control of Dynamically-Identified Variables", + Description: "The software does not properly restrict reading from or writing to dynamically-identified variables.", + ExtendedDescription: "Many languages offer powerful features that allow the programmer to access arbitrary variables that are specified by an input string. While these features can offer significant flexibility and reduce development time, they can be extremely dangerous if attackers can modify unintended variables that have security implications.", + Lang: "en", + }, + "915": { + CweID: "915", + Name: "Improperly Controlled Modification of Dynamically-Determined Object Attributes", + Description: "The software receives input from an upstream component that specifies multiple attributes, properties, or fields that are to be initialized or updated in an object, but it does not properly control which attributes can be modified.", + ExtendedDescription: "", + Lang: "en", + }, + "916": { + CweID: "916", + Name: "Use of Password Hash With Insufficient Computational Effort", + Description: "The software generates a hash for a password, but it uses a scheme that does not provide a sufficient level of computational effort that would make password cracking attacks infeasible or expensive.", + ExtendedDescription: "", + Lang: "en", + }, + "917": { + CweID: "917", + Name: "Improper Neutralization of Special Elements used in an Expression Language Statement ('Expression Language Injection')", + Description: "The software constructs all or part of an expression language (EL) statement in a Java Server Page (JSP) using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended EL statement before it is executed.", + ExtendedDescription: "", + Lang: "en", + }, + "918": { + CweID: "918", + Name: "Server-Side Request Forgery (SSRF)", + Description: "The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.", + ExtendedDescription: "By providing URLs to unexpected hosts or ports, attackers can make it appear that the server is sending the request, possibly bypassing access controls such as firewalls that prevent the attackers from accessing the URLs directly. The server can be used as a proxy to conduct port scanning of hosts in internal networks, use other URLs such as that can access documents on the system (using file://), or use other protocols such as gopher:// or tftp://, which may provide greater control over the contents of requests.", + Lang: "en", + }, + "92": { + CweID: "92", + Name: "DEPRECATED: Improper Sanitization of Custom Special Characters", + Description: "This entry has been deprecated. It originally came from PLOVER, which sometimes defined 'other' and 'miscellaneous' categories in order to satisfy exhaustiveness requirements for taxonomies. Within the context of CWE, the use of a more abstract entry is preferred in mapping situations. CWE-75 is a more appropriate mapping.", + ExtendedDescription: "", + Lang: "en", + }, + "920": { + CweID: "920", + Name: "Improper Restriction of Power Consumption", + Description: "The software operates in an environment in which power is a limited resource that cannot be automatically replenished, but the software does not properly restrict the amount of power that its operation consumes.", + ExtendedDescription: "", + Lang: "en", + }, + "921": { + CweID: "921", + Name: "Storage of Sensitive Data in a Mechanism without Access Control", + Description: "The software stores sensitive information in a file system or device that does not have built-in access control.", + ExtendedDescription: "", + Lang: "en", + }, + "922": { + CweID: "922", + Name: "Insecure Storage of Sensitive Information", + Description: "The software stores sensitive information without properly limiting read or write access by unauthorized actors.", + ExtendedDescription: "If read access is not properly restricted, then attackers can steal the sensitive information. If write access is not properly restricted, then attackers can modify and possibly delete the data, causing incorrect results and possibly a denial of service.", + Lang: "en", + }, + "923": { + CweID: "923", + Name: "Improper Restriction of Communication Channel to Intended Endpoints", + Description: "The software establishes a communication channel to (or from) an endpoint for privileged or protected operations, but it does not properly ensure that it is communicating with the correct endpoint.", + ExtendedDescription: "", + Lang: "en", + }, + "924": { + CweID: "924", + Name: "Improper Enforcement of Message Integrity During Transmission in a Communication Channel", + Description: "The software establishes a communication channel with an endpoint and receives a message from that endpoint, but it does not sufficiently ensure that the message was not modified during transmission.", + ExtendedDescription: "A man-in-the-middle (MITM) attacker might be able to modify the message and spoof the endpoint.", + Lang: "en", + }, + "925": { + CweID: "925", + Name: "Improper Verification of Intent by Broadcast Receiver", + Description: "The Android application uses a Broadcast Receiver that receives an Intent but does not properly verify that the Intent came from an authorized source.", + ExtendedDescription: "Certain types of Intents, identified by action string, can only be broadcast by the operating system itself, not by third-party applications. However, when an application registers to receive these implicit system intents, it is also registered to receive any explicit intents. While a malicious application cannot send an implicit system intent, it can send an explicit intent to the target application, which may assume that any received intent is a valid implicit system intent and not an explicit intent from another application. This may lead to unintended behavior.", + Lang: "en", + }, + "926": { + CweID: "926", + Name: "Improper Export of Android Application Components", + Description: "The Android application exports a component for use by other applications, but does not properly restrict which applications can launch the component or access the data it contains.", + ExtendedDescription: "", + Lang: "en", + }, + "927": { + CweID: "927", + Name: "Use of Implicit Intent for Sensitive Communication", + Description: "The Android application uses an implicit intent for transmitting sensitive data to other applications.", + ExtendedDescription: "", + Lang: "en", + }, + "93": { + CweID: "93", + Name: "Improper Neutralization of CRLF Sequences ('CRLF Injection')", + Description: "The software uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs.", + ExtendedDescription: "", + Lang: "en", + }, + "939": { + CweID: "939", + Name: "Improper Authorization in Handler for Custom URL Scheme", + Description: "The software uses a handler for a custom URL scheme, but it does not properly restrict which actors can invoke the handler using the scheme.", + ExtendedDescription: "Mobile platforms and other architectures allow the use of custom URL schemes to facilitate communication between applications. In the case of iOS, this is the only method to do inter-application communication. The implementation is at the developer's discretion which may open security flaws in the application. An example could be potentially dangerous functionality such as modifying files through a custom URL scheme.", + Lang: "en", + }, + "94": { + CweID: "94", + Name: "Improper Control of Generation of Code ('Code Injection')", + Description: "The software constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.", + ExtendedDescription: "", + Lang: "en", + }, + "940": { + CweID: "940", + Name: "Improper Verification of Source of a Communication Channel", + Description: "The software establishes a communication channel to handle an incoming request that has been initiated by an actor, but it does not properly verify that the request is coming from the expected origin.", + ExtendedDescription: "When an attacker can successfully establish a communication channel from an untrusted origin, the attacker may be able to gain privileges and access unexpected functionality.", + Lang: "en", + }, + "941": { + CweID: "941", + Name: "Incorrectly Specified Destination in a Communication Channel", + Description: "The software creates a communication channel to initiate an outgoing request to an actor, but it does not correctly specify the intended destination for that actor.", + ExtendedDescription: "", + Lang: "en", + }, + "942": { + CweID: "942", + Name: "Overly Permissive Cross-domain Whitelist", + Description: "The software uses a cross-domain policy file that includes domains that should not be trusted.", + ExtendedDescription: "", + Lang: "en", + }, + "943": { + CweID: "943", + Name: "Improper Neutralization of Special Elements in Data Query Logic", + Description: "The application generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query.", + ExtendedDescription: "", + Lang: "en", + }, + "95": { + CweID: "95", + Name: "Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. 'eval').", + ExtendedDescription: "This may allow an attacker to execute arbitrary code, or at least modify what code can be executed.", + Lang: "en", + }, + "96": { + CweID: "96", + Name: "Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')", + Description: "The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template.", + ExtendedDescription: "", + Lang: "en", + }, + "97": { + CweID: "97", + Name: "Improper Neutralization of Server-Side Includes (SSI) Within a Web Page", + Description: "The software generates a web page, but does not neutralize or incorrectly neutralizes user-controllable input that could be interpreted as a server-side include (SSI) directive.", + ExtendedDescription: "", + Lang: "en", + }, + "98": { + CweID: "98", + Name: "Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')", + Description: "The PHP application receives input from an upstream component, but it does not restrict or incorrectly restricts the input before its usage in 'require,' 'include,' or similar functions.", + ExtendedDescription: "In certain versions and configurations of PHP, this can allow an attacker to specify a URL to a remote location from which the software will obtain the code to execute. In other cases in association with path traversal, the attacker can specify a local file that may contain executable statements that can be parsed by PHP.", + Lang: "en", + }, + "99": { + CweID: "99", + Name: "Improper Control of Resource Identifiers ('Resource Injection')", + Description: "The software receives input from an upstream component, but it does not restrict or incorrectly restricts the input before it is used as an identifier for a resource that may be outside the intended sphere of control.", + ExtendedDescription: "", + Lang: "en", + }, +} diff --git a/cwe/ja.go b/cwe/ja.go new file mode 100644 index 00000000..2e23e3ca --- /dev/null +++ b/cwe/ja.go @@ -0,0 +1,1027 @@ +package cwe + +// CweDictJa is the Cwe dictionary +var CweDictJa = map[string]Cwe{ + "119": { + CweID: "119", + Name: "バッファエラー(CWE-119)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "20": { + CweID: "20", + Name: "不適切な入力確認(CWE-20)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "264": { + CweID: "264", + Name: "認可・権限・アクセス制御(CWE-264)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "362": { + CweID: "362", + Name: "競合状態(CWE-362)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "59": { + CweID: "59", + Name: "リンク解釈の問題(CWE-59)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "310": { + CweID: "310", + Name: "暗号の問題(CWE-310)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "288": { + CweID: "288", + Name: "代替パスまたはチャネルを使用した認証回避(CWE-288)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "384": { + CweID: "384", + Name: "セッションの固定化(CWE-384)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "89": { + CweID: "89", + Name: "SQLインジェクション(CWE-89)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "74": { + CweID: "74", + Name: "インジェクション(CWE-74)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "79": { + CweID: "79", + Name: "クロスサイトスクリプティング(CWE-79)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "601": { + CweID: "601", + Name: "オープンリダイレクト(CWE-601)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "352": { + CweID: "352", + Name: "クロスサイトリクエストフォージェリ(CWE-352)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "200": { + CweID: "200", + Name: "情報漏えい(CWE-200)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "285": { + CweID: "285", + Name: "不適切な認可(CWE-285)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "77": { + CweID: "77", + Name: "コマンドインジェクション(CWE-77)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "611": { + CweID: "611", + Name: "XML 外部エンティティ参照の不適切な制限(CWE-611)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "noinfo": { + CweID: "noinfo", + Name: "情報不足(CWE-noinfo)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "284": { + CweID: "284", + Name: "不適切なアクセス制御(CWE-284)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "190": { + CweID: "190", + Name: "整数オーバーフローまたはラップアラウンド(CWE-190)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "129": { + CweID: "129", + Name: "配列インデックスの不適切な検証(CWE-129)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "416": { + CweID: "416", + Name: "解放済みメモリの使用(CWE-416)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "918": { + CweID: "918", + Name: "サーバサイドのリクエストフォージェリ(CWE-918)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "22": { + CweID: "22", + Name: "パス・トラバーサル(CWE-22)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "78": { + CweID: "78", + Name: "OSコマンドインジェクション(CWE-78)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "287": { + CweID: "287", + Name: "不適切な認証(CWE-287)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "254": { + CweID: "254", + Name: "セキュリティ機能(CWE-254)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "798": { + CweID: "798", + Name: "ハードコードされた認証情報の使用(CWE-798)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "415": { + CweID: "415", + Name: "二重解放(CWE-415)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "399": { + CweID: "399", + Name: "リソース管理の問題(CWE-399)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "125": { + CweID: "125", + Name: "境界外読み取り(CWE-125)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "434": { + CweID: "434", + Name: "危険なタイプのファイルの無制限アップロード(CWE-434)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "295": { + CweID: "295", + Name: "不正な証明書検証(CWE-295)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "16": { + CweID: "16", + Name: "環境設定(CWE-16)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "172": { + CweID: "172", + Name: "エンコーディングエラー(CWE-172)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "134": { + CweID: "134", + Name: "書式文字列の問題(CWE-134)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "255": { + CweID: "255", + Name: "証明書・パスワードの管理(CWE-255)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "476": { + CweID: "476", + Name: "NULL ポインタデリファレンス(CWE-476)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "787": { + CweID: "787", + Name: "境界外書き込み(CWE-787)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "275": { + CweID: "275", + Name: "パーミッションの問題(CWE-275)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "502": { + CweID: "502", + Name: "信頼性のないデータのデシリアライゼーション(CWE-502)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "19": { + CweID: "19", + Name: "データ処理(CWE-19)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "94": { + CweID: "94", + Name: "コード・インジェクション(CWE-94)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "189": { + CweID: "189", + Name: "数値処理の問題(CWE-189)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "121": { + CweID: "121", + Name: "スタックベースのバッファオーバーフロー(CWE-121)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "326": { + CweID: "326", + Name: "不適切な暗号強度(CWE-326)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "532": { + CweID: "532", + Name: "ログファイルからの情報漏えい(CWE-532)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "320": { + CweID: "320", + Name: "鍵管理のエラー(CWE-320)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "306": { + CweID: "306", + Name: "重要な機能に対する認証の欠如(CWE-306)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "754": { + CweID: "754", + Name: "例外的な状態における不適切なチェック(CWE-754)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "613": { + CweID: "613", + Name: "不適切なセッション期限(CWE-613)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "400": { + CweID: "400", + Name: "リソースの枯渇(CWE-400)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "228": { + CweID: "228", + Name: "不正な構文構造の不適切な処理(CWE-228)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "428": { + CweID: "428", + Name: "引用されない検索パスまたは要素(CWE-428)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "184": { + CweID: "184", + Name: "不完全なブラックリスト(CWE-184)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "426": { + CweID: "426", + Name: "信頼性のない検索パス(CWE-426)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "347": { + CweID: "347", + Name: "デジタル署名の不適切な検証(CWE-347)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "345": { + CweID: "345", + Name: "データの信頼性についての不十分な検証(CWE-345)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "388": { + CweID: "388", + Name: "エラー処理(CWE-388)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "704": { + CweID: "704", + Name: "不正な型変換またはキャスト(CWE-704)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "369": { + CweID: "369", + Name: "ゼロ除算(CWE-369)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "122": { + CweID: "122", + Name: "ヒープベースのバッファオーバーフロー(CWE-122)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "824": { + CweID: "824", + Name: "初期化されていないポインタのアクセス(CWE-824)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "822": { + CweID: "822", + Name: "信頼性のないポインタデリファレンス(CWE-822)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "90": { + CweID: "90", + Name: "LDAP インジェクション(CWE-90)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "nocwe": { + CweID: "nocwe", + Name: "CWE以外(CWE-nocwe)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "330": { + CweID: "330", + Name: "不十分なランダム値の使用(CWE-330)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "91": { + CweID: "91", + Name: "ブラインド XPath インジェクション(CWE-91)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "404": { + CweID: "404", + Name: "リソースの不適切なシャットダウンおよびリリース(CWE-404)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "327": { + CweID: "327", + Name: "不完全、または危険な暗号アルゴリズムの使用(CWE-327)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "441": { + CweID: "441", + Name: "フィルタリング回避(CWE-441)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "294": { + CweID: "294", + Name: "Capture-replay による認証回避(CWE-294)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "821": { + CweID: "821", + Name: "不正な同期(CWE-821)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "835": { + CweID: "835", + Name: "無限ループ(CWE-835)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "123": { + CweID: "123", + Name: "任意の場所に任意の値を書き込むことができる状態(CWE-123)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "640": { + CweID: "640", + Name: "パスワードを忘れた場合の脆弱なパスワードリカバリの仕組み(CWE-640)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "93": { + CweID: "93", + Name: "CRLF インジェクション(CWE-93)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "361": { + CweID: "361", + Name: "時間とステータス(CWE-361)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "191": { + CweID: "191", + Name: "整数アンダーフロー(CWE-191)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "534": { + CweID: "534", + Name: "デバッグログファイルからの情報漏えい(CWE-534)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "331": { + CweID: "331", + Name: "エントロピー不足(CWE-331)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "113": { + CweID: "113", + Name: "HTTP レスポンスの分割(CWE-113)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "444": { + CweID: "444", + Name: "HTTP リクエストスマグリング(CWE-444)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "757": { + CweID: "757", + Name: "アルゴリズムのダウングレード(CWE-757)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "120": { + CweID: "120", + Name: "古典的バッファオーバーフロー(CWE-120)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "257": { + CweID: "257", + Name: "復元可能な形式でのパスワード保存(CWE-257)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "451": { + CweID: "451", + Name: "ユーザインターフェースにおける重要情報の誤った表示(CWE-451)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "775": { + CweID: "775", + Name: "有効期限後のファイル記述子またはハンドルの解放の欠如(CWE-775)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "332": { + CweID: "332", + Name: "PRNG における不十分なエントロピー(CWE-332)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "749": { + CweID: "749", + Name: "危険なメソッドや機能の公開(CWE-749)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "590": { + CweID: "590", + Name: "ヒープ領域の不適切な解放(CWE-590)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "290": { + CweID: "290", + Name: "スプーフィングによる認証回避(CWE-290)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "843": { + CweID: "843", + Name: "型の取り違え(CWE-843)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "417": { + CweID: "417", + Name: "チャネルおよびパスのエラー(CWE-417)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "410": { + CweID: "410", + Name: "不十分なリソースプール(CWE-410)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "18": { + CweID: "18", + Name: "ソースコード(CWE-18)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "605": { + CweID: "605", + Name: "同一ポートに複数のソケットをバインドする問題(CWE-605)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "682": { + CweID: "682", + Name: "計算の誤り(CWE-682)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "17": { + CweID: "17", + Name: "コード(CWE-17)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "338": { + CweID: "338", + Name: "暗号における脆弱な PRNG の使用(CWE-338)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "358": { + CweID: "358", + Name: "不適切に実装されたセキュリティチェック(CWE-358)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "674": { + CweID: "674", + Name: "不適切な再帰制御(CWE-674)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "412": { + CweID: "412", + Name: "外部からの操作の制限不備(CWE-412)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "378": { + CweID: "378", + Name: "不適切なアクセスパーミションでの一時ファイル作成(CWE-378)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "379": { + CweID: "379", + Name: "不適切なアクセスパーミションのディレクトリに一時ファイル作成(CWE-379)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "302": { + CweID: "302", + Name: "認証回避の脆弱性(CWE-302)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "75": { + CweID: "75", + Name: "特殊要素の不適切なサニタイジング(CWE-75)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "116": { + CweID: "116", + Name: "不適切なエンコード、または出力のエスケープ(CWE-116)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "346": { + CweID: "346", + Name: "同一生成元ポリシー違反(CWE-346)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "521": { + CweID: "521", + Name: "脆弱なパスワードの要求(CWE-521)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "664": { + CweID: "664", + Name: "ライフタイムを通してのリソースの不適切な制御(CWE-664)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "80": { + CweID: "80", + Name: "クロスサイトスクリプティング (Basic XSS)(CWE-80)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "204": { + CweID: "204", + Name: "リクエストに対するレスポンス内容の違いに起因する情報漏えい(CWE-204)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "199": { + CweID: "199", + Name: "情報管理の問題(CWE-199)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "88": { + CweID: "88", + Name: "引数の挿入または変更(CWE-88)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "407": { + CweID: "407", + Name: "アルゴリズムの複雑性(CWE-407)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "913": { + CweID: "913", + Name: "動的に操作されるコードリソースの不適切な制御(CWE-913)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "118": { + CweID: "118", + Name: "インデックス化が可能なリソースの不適切なアクセス (範囲エラー)(CWE-118)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "427": { + CweID: "427", + Name: "制御されていない検索パスの要素(CWE-427)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "485": { + CweID: "485", + Name: "不十分なカプセル化(CWE-485)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "494": { + CweID: "494", + Name: "ダウンロードしたコードの完全性検証不備(CWE-494)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "639": { + CweID: "639", + Name: "ユーザ制御の鍵による認証回避(CWE-639)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "99": { + CweID: "99", + Name: "リソースの挿入(CWE-99)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "276": { + CweID: "276", + Name: "不適切なデフォルトパーミッション(CWE-276)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "598": { + CweID: "598", + Name: "GET リクエストにおけるクエリ文字列からの情報漏えい(CWE-598)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "260": { + CweID: "260", + Name: "設定ファイル内のパスワード(CWE-260)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "836": { + CweID: "836", + Name: "パスワードの代わりにパスワードハッシュを使用する認証(CWE-836)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "943": { + CweID: "943", + Name: "データクエリロジックの特殊要素の不適切な中立化(CWE-943)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "665": { + CweID: "665", + Name: "不適切な初期化(CWE-665)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "769": { + CweID: "769", + Name: "ファイル記述子の枯渇(CWE-769)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "522": { + CweID: "522", + Name: "認証情報の不十分な保護(CWE-522)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "693": { + CweID: "693", + Name: "保護メカニズムの不具合(CWE-693)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "538": { + CweID: "538", + Name: "ファイルおよびディレクトリ情報の漏えい(CWE-538)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "863": { + CweID: "863", + Name: "不正な認証(CWE-863)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "862": { + CweID: "862", + Name: "認証の欠如(CWE-862)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "321": { + CweID: "321", + Name: "ハードコードされた暗号鍵の使用(CWE-321)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "1": { + CweID: "1", + Name: "ロケーション(CWE-1)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "354": { + CweID: "354", + Name: "データの整合性検証不備(CWE-354)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "552": { + CweID: "552", + Name: "外部からアクセス可能なファイルまたはディレクトリ(CWE-552)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "297": { + CweID: "297", + Name: "ホストの不一致による証明書の不適切な検証(CWE-297)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "150": { + CweID: "150", + Name: "エスケープ、メタ、またはコントロールシーケンスの不適切な無効化(CWE-150)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "371": { + CweID: "371", + Name: "状態の問題(CWE-371)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "203": { + CweID: "203", + Name: "セキュリティ関連の処理に対するレスポンスの違いに起因する情報漏えい(CWE-203)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "208": { + CweID: "208", + Name: "タイミングの違いに起因する情報漏えい(CWE-208)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "329": { + CweID: "329", + Name: "CBC モードにおけるランダムな初期化ベクトルの不使用(CWE-329)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, + "21": { + CweID: "21", + Name: "パス名トラバーサルおよび同値エラー(CWE-21)", + Description: "", + ExtendedDescription: "", + Lang: "ja", + }, +} diff --git a/cwe/owasp.go b/cwe/owasp.go new file mode 100644 index 00000000..3f3466da --- /dev/null +++ b/cwe/owasp.go @@ -0,0 +1,65 @@ +package cwe + +// OwaspTopTen2017 has CWE-ID in OWSP Top 10 +var OwaspTopTen2017 = map[string]string{ + "77": "1", + "89": "1", + "564": "1", + "917": "1", + + "287": "2", + "384": "2", + + "220": "3", + "310": "3", + "312": "3", + "319": "3", + "326": "3", + "359": "3", + + "611": "4", + + "22": "5", + "284": "5", + "285": "5", + "639": "5", + + "2": "6", + "16": "6", + "388": "6", + + "79": "7", + + "502": "8", + + "223": "10", + "778": "10", +} + +// OwaspTopTen2017GitHubURLEn has GitHub links +var OwaspTopTen2017GitHubURLEn = map[string]string{ + "1": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa1-injection.md", + "2": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa2-broken-authentication.md", + "3": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa3-sensitive-data-disclosure.md", + "4": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa4-xxe.md", + "5": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa5-broken-access-control.md", + "6": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa6-security-misconfiguration.md", + "7": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa7-xss.md", + "8": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa8-insecure-deserialization.md", + "9": "https://github.com/OWASP/Top10/blob/master/2017/en/0xa9-known-vulns.md", + "10": "https://github.com/OWASP/Top10/blob/master/2017/en/0xaa-logging-detection-response.md", +} + +// OwaspTopTen2017GitHubURLJa has GitHub links +var OwaspTopTen2017GitHubURLJa = map[string]string{ + "1": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa1-injection.md", + "2": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa2-broken-authentication.md", + "3": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa3-sensitive-data-disclosure.md", + "4": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa4-xxe.md", + "5": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa5-broken-access-control.md", + "6": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa6-security-misconfiguration.md", + "7": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa7-xss.md", + "8": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa8-insecure-deserialization.md", + "9": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xa9-known-vulns.md", + "10": "https://github.com/OWASP/Top10/blob/master/2017/ja/0xaa-logging-detection-response.md", +} diff --git a/gost/debian.go b/gost/debian.go new file mode 100644 index 00000000..6e3f7c32 --- /dev/null +++ b/gost/debian.go @@ -0,0 +1,178 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package gost + +import ( + "encoding/json" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" + "github.com/knqyf263/gost/db" + gostmodels "github.com/knqyf263/gost/models" +) + +// Debian is Gost client for Debian GNU/Linux +type Debian struct { + Base +} + +type packCves struct { + packName string + isSrcPack bool + cves []models.CveContent +} + +// FillWithGost fills cve information that has in Gost +func (deb Debian) FillWithGost(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { + linuxImage := "linux-image-" + r.RunningKernel.Release + // Add linux and set the version of running kernel to search OVAL. + if r.Container.ContainerID == "" { + newVer := "" + if p, ok := r.Packages[linuxImage]; ok { + newVer = p.NewVersion + } + r.Packages["linux"] = models.Package{ + Name: "linux", + Version: r.RunningKernel.Version, + NewVersion: newVer, + } + } + + packCvesList := []packCves{} + if deb.isFetchViaHTTP() { + url, _ := util.URLPathJoin(config.Conf.Gost.URL, "debian", major(r.Release), "pkgs") + responses, err := getAllUnfixedCvesViaHTTP(r, url) + if err != nil { + return 0, err + } + + for _, res := range responses { + debCves := map[string]gostmodels.DebianCVE{} + if err := json.Unmarshal([]byte(res.json), &debCves); err != nil { + return 0, err + } + cves := []models.CveContent{} + for _, debcve := range debCves { + cves = append(cves, *deb.ConvertToModel(&debcve)) + } + packCvesList = append(packCvesList, packCves{ + packName: res.request.packName, + isSrcPack: res.request.isSrcPack, + cves: cves, + }) + } + } else { + if driver == nil { + return 0, nil + } + for _, pack := range r.Packages { + cveDebs := driver.GetUnfixedCvesDebian(major(r.Release), pack.Name) + cves := []models.CveContent{} + for _, cveDeb := range cveDebs { + cves = append(cves, *deb.ConvertToModel(&cveDeb)) + } + packCvesList = append(packCvesList, packCves{ + packName: pack.Name, + isSrcPack: false, + cves: cves, + }) + } + + // SrcPack + for _, pack := range r.SrcPackages { + cveDebs := driver.GetUnfixedCvesDebian(major(r.Release), pack.Name) + cves := []models.CveContent{} + for _, cveDeb := range cveDebs { + cves = append(cves, *deb.ConvertToModel(&cveDeb)) + } + packCvesList = append(packCvesList, packCves{ + packName: pack.Name, + isSrcPack: true, + cves: cves, + }) + } + } + + delete(r.Packages, "linux") + + for _, p := range packCvesList { + for _, cve := range p.cves { + v, ok := r.ScannedCves[cve.CveID] + if ok { + v.CveContents[models.DebianSecurityTracker] = cve + } else { + v = models.VulnInfo{ + CveID: cve.CveID, + CveContents: models.NewCveContents(cve), + Confidences: models.Confidences{models.DebianSecurityTrackerMatch}, + } + nCVEs++ + } + + names := []string{} + if p.isSrcPack { + if srcPack, ok := r.SrcPackages[p.packName]; ok { + for _, binName := range srcPack.BinaryNames { + if _, ok := r.Packages[binName]; ok { + names = append(names, binName) + } + } + } + } else { + if p.packName == "linux" { + names = append(names, linuxImage) + } else { + names = append(names, p.packName) + } + } + + for _, name := range names { + v.AffectedPackages = v.AffectedPackages.Store(models.PackageStatus{ + Name: name, + FixState: "open", + NotFixedYet: true, + }) + } + r.ScannedCves[cve.CveID] = v + } + } + return nCVEs, nil +} + +// ConvertToModel converts gost model to vuls model +func (deb Debian) ConvertToModel(cve *gostmodels.DebianCVE) *models.CveContent { + severity := "" + for _, p := range cve.Package { + for _, r := range p.Release { + severity = r.Urgency + break + } + } + return &models.CveContent{ + Type: models.DebianSecurityTracker, + CveID: cve.CveID, + Summary: cve.Description, + Cvss2Severity: severity, + Cvss3Severity: severity, + SourceLink: "https://security-tracker.debian.org/tracker/" + cve.CveID, + Optional: map[string]string{ + "attack range": cve.Scope, + }, + } +} diff --git a/gost/gost.go b/gost/gost.go new file mode 100644 index 00000000..66ec4ae1 --- /dev/null +++ b/gost/gost.go @@ -0,0 +1,107 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package gost + +import ( + "fmt" + "net/http" + "strings" + + cnf "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/knqyf263/gost/db" + "github.com/parnurzeal/gorequest" +) + +// Client is the interface of OVAL client. +type Client interface { + FillWithGost(db.DB, *models.ScanResult) (int, error) + + //TODO implement + // CheckHTTPHealth() error + // CheckIfGostFetched checks if Gost entries are fetched + // CheckIfGostFetched(db.DB, string, string) (bool, error) + // CheckIfGostFresh(db.DB, string, string) (bool, error) +} + +// NewClient make Client by family +func NewClient(family string) Client { + switch family { + case cnf.RedHat, cnf.CentOS: + return RedHat{} + case cnf.Debian: + return Debian{} + default: + return Pseudo{} + } +} + +// Base is a base struct +type Base struct { + family string +} + +// CheckHTTPHealth do health check +func (b Base) CheckHTTPHealth() error { + if !b.isFetchViaHTTP() { + return nil + } + + url := fmt.Sprintf("%s/health", cnf.Conf.Gost.URL) + var errs []error + var resp *http.Response + resp, _, errs = gorequest.New().Get(url).End() + // resp, _, errs = gorequest.New().SetDebug(config.Conf.Debug).Get(url).End() + // resp, _, errs = gorequest.New().Proxy(api.httpProxy).Get(url).End() + if 0 < len(errs) || resp == nil || resp.StatusCode != 200 { + return fmt.Errorf("Failed to connect to gost server. url: %s, errs: %v", + url, errs) + } + return nil +} + +// CheckIfGostFetched checks if oval entries are in DB by family, release. +func (b Base) CheckIfGostFetched(driver db.DB, osFamily string) (fetched bool, err error) { + //TODO + return true, nil +} + +// CheckIfGostFresh checks if oval entries are fresh enough +func (b Base) CheckIfGostFresh(driver db.DB, osFamily string) (ok bool, err error) { + //TODO + return true, nil +} + +func (b Base) isFetchViaHTTP() bool { + // Default value of OvalDBType is sqlite3 + return cnf.Conf.Gost.URL != "" && cnf.Conf.Gost.Type == "sqlite3" +} + +// Pseudo is Gost client except for RedHat family and Debian +type Pseudo struct { + Base +} + +// FillWithGost fills cve information that has in Gost +func (pse Pseudo) FillWithGost(driver db.DB, r *models.ScanResult) (int, error) { + return 0, nil +} + +func major(osVer string) (majorVersion string) { + return strings.Split(osVer, ".")[0] +} diff --git a/gost/gost_test.go b/gost/gost_test.go new file mode 100644 index 00000000..f748e716 --- /dev/null +++ b/gost/gost_test.go @@ -0,0 +1,129 @@ +package gost + +import ( + "reflect" + "testing" + + "github.com/future-architect/vuls/models" + gostmodels "github.com/knqyf263/gost/models" +) + +func TestSetPackageStates(t *testing.T) { + var tests = []struct { + pkgstats []gostmodels.RedhatPackageState + installed models.Packages + release string + in models.VulnInfo + out models.PackageStatuses + }{ + + //0 one + { + pkgstats: []gostmodels.RedhatPackageState{ + { + FixState: "Will not fix", + PackageName: "bouncycastle", + Cpe: "cpe:/o:redhat:enterprise_linux:7", + }, + }, + installed: models.Packages{ + "bouncycastle": models.Package{}, + }, + release: "7", + in: models.VulnInfo{}, + out: []models.PackageStatus{ + { + Name: "bouncycastle", + FixState: "Will not fix", + NotFixedYet: true, + }, + }, + }, + + //1 two + { + pkgstats: []gostmodels.RedhatPackageState{ + { + FixState: "Will not fix", + PackageName: "bouncycastle", + Cpe: "cpe:/o:redhat:enterprise_linux:7", + }, + { + FixState: "Fix deferred", + PackageName: "pack_a", + Cpe: "cpe:/o:redhat:enterprise_linux:7", + }, + // ignore not-installed-package + { + FixState: "Fix deferred", + PackageName: "pack_b", + Cpe: "cpe:/o:redhat:enterprise_linux:7", + }, + }, + installed: models.Packages{ + "bouncycastle": models.Package{}, + "pack_a": models.Package{}, + }, + release: "7", + in: models.VulnInfo{}, + out: []models.PackageStatus{ + { + Name: "bouncycastle", + FixState: "Will not fix", + NotFixedYet: true, + }, + { + Name: "pack_a", + FixState: "Fix deferred", + NotFixedYet: true, + }, + }, + }, + + //2 ignore affected + { + pkgstats: []gostmodels.RedhatPackageState{ + { + FixState: "affected", + PackageName: "bouncycastle", + Cpe: "cpe:/o:redhat:enterprise_linux:7", + }, + }, + installed: models.Packages{ + "bouncycastle": models.Package{}, + }, + release: "7", + in: models.VulnInfo{ + AffectedPackages: models.PackageStatuses{}, + }, + out: models.PackageStatuses{}, + }, + + //3 look only the same os release. + { + pkgstats: []gostmodels.RedhatPackageState{ + { + FixState: "Will not fix", + PackageName: "bouncycastle", + Cpe: "cpe:/o:redhat:enterprise_linux:6", + }, + }, + installed: models.Packages{ + "bouncycastle": models.Package{}, + }, + release: "7", + in: models.VulnInfo{ + AffectedPackages: models.PackageStatuses{}, + }, + out: models.PackageStatuses{}, + }, + } + + r := RedHat{} + for i, tt := range tests { + out := r.mergePackageStates(tt.in, tt.pkgstats, tt.installed, tt.release) + if ok := reflect.DeepEqual(tt.out, out); !ok { + t.Errorf("[%d]\nexpected: %v:%T\n actual: %v:%T\n", i, tt.out, tt.out, out, out) + } + } +} diff --git a/gost/redhat.go b/gost/redhat.go new file mode 100644 index 00000000..40f73207 --- /dev/null +++ b/gost/redhat.go @@ -0,0 +1,253 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package gost + +import ( + "encoding/json" + "strconv" + "strings" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" + "github.com/knqyf263/gost/db" + gostmodels "github.com/knqyf263/gost/models" +) + +// RedHat is Gost client for RedHat family linux +type RedHat struct { + Base +} + +// FillWithGost fills cve information that has in Gost +func (red RedHat) FillWithGost(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { + if nCVEs, err = red.fillUnfixed(driver, r); err != nil { + return 0, err + } + return nCVEs, red.fillFixed(driver, r) +} + +func (red RedHat) fillFixed(driver db.DB, r *models.ScanResult) error { + var cveIDs []string + for cveID, vuln := range r.ScannedCves { + if _, ok := vuln.CveContents[models.RedHatAPI]; ok { + continue + } + cveIDs = append(cveIDs, cveID) + } + + if red.isFetchViaHTTP() { + prefix, _ := util.URLPathJoin(config.Conf.Gost.URL, + "redhat", "cves") + responses, err := getCvesViaHTTP(cveIDs, prefix) + if err != nil { + return err + } + for _, res := range responses { + redCve := gostmodels.RedhatCVE{} + if err := json.Unmarshal([]byte(res.json), &redCve); err != nil { + return err + } + if redCve.ID == 0 { + continue + } + cveCont := red.ConvertToModel(&redCve) + v, _ := r.ScannedCves[res.request.cveID] + v.CveContents[models.RedHatAPI] = *cveCont + r.ScannedCves[res.request.cveID] = v + } + } else { + if driver == nil { + return nil + } + for cveID, redCve := range driver.GetRedhatMulti(cveIDs) { + if redCve.ID == 0 { + continue + } + cveCont := red.ConvertToModel(&redCve) + v, _ := r.ScannedCves[cveID] + v.CveContents[models.RedHatAPI] = *cveCont + r.ScannedCves[cveID] = v + } + } + + return nil +} + +func (red RedHat) fillUnfixed(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { + if red.isFetchViaHTTP() { + prefix, _ := util.URLPathJoin(config.Conf.Gost.URL, + "redhat", major(r.Release), "pkgs") + responses, err := getAllUnfixedCvesViaHTTP(r, prefix) + if err != nil { + return 0, err + } + for _, res := range responses { + // CVE-ID: RedhatCVE + cves := map[string]gostmodels.RedhatCVE{} + if err := json.Unmarshal([]byte(res.json), &cves); err != nil { + return 0, err + } + + for _, cve := range cves { + cveCont := red.ConvertToModel(&cve) + v, ok := r.ScannedCves[cve.Name] + if ok { + v.CveContents[models.RedHatAPI] = *cveCont + } else { + v = models.VulnInfo{ + CveID: cveCont.CveID, + CveContents: models.NewCveContents(*cveCont), + Confidences: models.Confidences{models.RedHatAPIMatch}, + } + nCVEs++ + } + + pkgStats := red.mergePackageStates(v, + cve.PackageState, r.Packages, r.Release) + if 0 < len(pkgStats) { + v.AffectedPackages = pkgStats + r.ScannedCves[cve.Name] = v + } + } + } + } else { + if driver == nil { + return 0, nil + } + for _, pack := range r.Packages { + // CVE-ID: RedhatCVE + cves := map[string]gostmodels.RedhatCVE{} + cves = driver.GetUnfixedCvesRedhat(major(r.Release), pack.Name) + for _, cve := range cves { + cveCont := red.ConvertToModel(&cve) + v, ok := r.ScannedCves[cve.Name] + if ok { + v.CveContents[models.RedHatAPI] = *cveCont + } else { + v = models.VulnInfo{ + CveID: cveCont.CveID, + CveContents: models.NewCveContents(*cveCont), + Confidences: models.Confidences{models.RedHatAPIMatch}, + } + nCVEs++ + } + + pkgStats := red.mergePackageStates(v, + cve.PackageState, r.Packages, r.Release) + if 0 < len(pkgStats) { + v.AffectedPackages = pkgStats + r.ScannedCves[cve.Name] = v + } + } + } + } + return nCVEs, nil +} + +func (red RedHat) mergePackageStates(v models.VulnInfo, ps []gostmodels.RedhatPackageState, installed models.Packages, release string) (pkgStats models.PackageStatuses) { + pkgStats = v.AffectedPackages + for _, pstate := range ps { + if pstate.Cpe != + "cpe:/o:redhat:enterprise_linux:"+major(release) { + return + } + + if !(pstate.FixState == "Will not fix" || + pstate.FixState == "Fix deferred") { + return + } + + if _, ok := installed[pstate.PackageName]; !ok { + return + } + + notFixedYet := false + switch pstate.FixState { + case "Will not fix", "Fix deferred": + notFixedYet = true + } + + pkgStats = pkgStats.Store(models.PackageStatus{ + Name: pstate.PackageName, + FixState: pstate.FixState, + NotFixedYet: notFixedYet, + }) + } + return +} + +// ConvertToModel converts gost model to vuls model +func (red RedHat) ConvertToModel(cve *gostmodels.RedhatCVE) *models.CveContent { + cwes := []string{} + if cve.Cwe != "" { + s := strings.TrimPrefix(cve.Cwe, "(") + s = strings.TrimSuffix(s, ")") + if strings.Contains(cve.Cwe, "|") { + cwes = strings.Split(cve.Cwe, "|") + } else { + cwes = strings.Split(s, "->") + } + } + + details := []string{} + for _, detail := range cve.Details { + details = append(details, detail.Detail) + } + + v2score := 0.0 + if cve.Cvss.CvssBaseScore != "" { + v2score, _ = strconv.ParseFloat(cve.Cvss.CvssBaseScore, 64) + } + v2severity := "" + if v2score != 0 { + v2severity = cve.ThreatSeverity + } + + v3score := 0.0 + if cve.Cvss3.Cvss3BaseScore != "" { + v3score, _ = strconv.ParseFloat(cve.Cvss3.Cvss3BaseScore, 64) + } + v3severity := "" + if v3score != 0 { + v3severity = cve.ThreatSeverity + } + + var refs []models.Reference + for _, r := range cve.References { + refs = append(refs, models.Reference{Link: r.Reference}) + } + + return &models.CveContent{ + Type: models.RedHatAPI, + CveID: cve.Name, + Title: cve.Bugzilla.Description, + Summary: strings.Join(details, "\n"), + Cvss2Score: v2score, + Cvss2Vector: cve.Cvss.CvssScoringVector, + Cvss2Severity: v2severity, + Cvss3Score: v3score, + Cvss3Vector: cve.Cvss3.Cvss3ScoringVector, + Cvss3Severity: v3severity, + References: refs, + CweIDs: cwes, + Mitigation: cve.Mitigation, + Published: cve.PublicDate, + SourceLink: "https://access.redhat.com/security/cve/" + cve.Name, + } +} diff --git a/gost/util.go b/gost/util.go new file mode 100644 index 00000000..b5ae77aa --- /dev/null +++ b/gost/util.go @@ -0,0 +1,201 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package gost + +import ( + "fmt" + "net/http" + "time" + + "github.com/cenkalti/backoff" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" + "github.com/parnurzeal/gorequest" +) + +type response struct { + request request + json string +} + +func getCvesViaHTTP(cveIDs []string, urlPrefix string) ( + responses []response, err error) { + nReq := len(cveIDs) + reqChan := make(chan request, nReq) + resChan := make(chan response, nReq) + errChan := make(chan error, nReq) + defer close(reqChan) + defer close(resChan) + defer close(errChan) + + go func() { + for _, cveID := range cveIDs { + reqChan <- request{ + cveID: cveID, + } + } + }() + + concurrency := 10 + tasks := util.GenWorkers(concurrency) + for i := 0; i < nReq; i++ { + tasks <- func() { + select { + case req := <-reqChan: + url, err := util.URLPathJoin( + urlPrefix, + req.cveID, + ) + if err != nil { + errChan <- err + } else { + util.Log.Debugf("HTTP Request to %s", url) + httpGet(url, req, resChan, errChan) + } + } + } + } + + timeout := time.After(2 * 60 * time.Second) + var errs []error + for i := 0; i < nReq; i++ { + select { + case res := <-resChan: + responses = append(responses, res) + case err := <-errChan: + errs = append(errs, err) + case <-timeout: + return nil, fmt.Errorf("Timeout Fetching OVAL") + } + } + if len(errs) != 0 { + return nil, fmt.Errorf("Failed to fetch OVAL. err: %v", errs) + } + return +} + +type request struct { + osMajorVersion string + packName string + isSrcPack bool + cveID string +} + +func getAllUnfixedCvesViaHTTP(r *models.ScanResult, urlPrefix string) ( + responses []response, err error) { + + nReq := len(r.Packages) + len(r.SrcPackages) + reqChan := make(chan request, nReq) + resChan := make(chan response, nReq) + errChan := make(chan error, nReq) + defer close(reqChan) + defer close(resChan) + defer close(errChan) + + go func() { + for _, pack := range r.Packages { + reqChan <- request{ + osMajorVersion: major(r.Release), + packName: pack.Name, + isSrcPack: false, + } + } + for _, pack := range r.SrcPackages { + reqChan <- request{ + osMajorVersion: major(r.Release), + packName: pack.Name, + isSrcPack: true, + } + } + }() + + concurrency := 10 + tasks := util.GenWorkers(concurrency) + for i := 0; i < nReq; i++ { + tasks <- func() { + select { + case req := <-reqChan: + url, err := util.URLPathJoin( + urlPrefix, + req.packName, + "unfixed-cves", + ) + if err != nil { + errChan <- err + } else { + util.Log.Debugf("HTTP Request to %s", url) + httpGet(url, req, resChan, errChan) + } + } + } + } + + timeout := time.After(2 * 60 * time.Second) + var errs []error + for i := 0; i < nReq; i++ { + select { + case res := <-resChan: + responses = append(responses, res) + case err := <-errChan: + errs = append(errs, err) + case <-timeout: + return nil, fmt.Errorf("Timeout Fetching OVAL") + } + } + if len(errs) != 0 { + return nil, fmt.Errorf("Failed to fetch OVAL. err: %v", errs) + } + return +} + +func httpGet(url string, req request, resChan chan<- response, errChan chan<- error) { + var body string + var errs []error + var resp *http.Response + count, retryMax := 0, 3 + f := func() (err error) { + // resp, body, errs = gorequest.New().SetDebug(config.Conf.Debug).Get(url).End() + resp, body, errs = gorequest.New().Get(url).End() + if 0 < len(errs) || resp == nil || resp.StatusCode != 200 { + count++ + if count == retryMax { + return nil + } + return fmt.Errorf("HTTP GET error: %v, url: %s, resp: %v", + errs, url, resp) + } + return nil + } + notify := func(err error, t time.Duration) { + util.Log.Warnf("Failed to HTTP GET. retrying in %s seconds. err: %s", t, err) + } + err := backoff.RetryNotify(f, backoff.NewExponentialBackOff(), notify) + if err != nil { + errChan <- fmt.Errorf("HTTP Error %s", err) + return + } + if count == retryMax { + errChan <- fmt.Errorf("HRetry count exceeded") + return + } + + resChan <- response{ + request: req, + json: body, + } +} diff --git a/main.go b/main.go index ffc58073..ed584cd1 100644 --- a/main.go +++ b/main.go @@ -25,15 +25,10 @@ import ( "context" "github.com/future-architect/vuls/commands" + "github.com/future-architect/vuls/config" "github.com/google/subcommands" ) -// Version of Vuls -var version = "0.4.2" - -// Revision of Git -var revision string - func main() { subcommands.Register(subcommands.HelpCommand(), "") subcommands.Register(subcommands.FlagsCommand(), "") @@ -44,13 +39,14 @@ func main() { subcommands.Register(&commands.HistoryCmd{}, "history") subcommands.Register(&commands.ReportCmd{}, "report") subcommands.Register(&commands.ConfigtestCmd{}, "configtest") + subcommands.Register(&commands.ServerCmd{}, "server") var v = flag.Bool("v", false, "Show version") flag.Parse() if *v { - fmt.Printf("vuls %s %s\n", version, revision) + fmt.Printf("vuls %s %s\n", config.Version, config.Revision) os.Exit(int(subcommands.ExitSuccess)) } diff --git a/models/cvecontents.go b/models/cvecontents.go index e69dfe28..a2f100e0 100644 --- a/models/cvecontents.go +++ b/models/cvecontents.go @@ -18,7 +18,6 @@ along with this program. If not, see . package models import ( - "strings" "time" ) @@ -61,12 +60,12 @@ func (v CveContents) Except(exceptCtypes ...CveContentType) (values CveContents) // SourceLinks returns link of source func (v CveContents) SourceLinks(lang, myFamily, cveID string) (values []CveContentStr) { if lang == "ja" { - if cont, found := v[JVN]; found && 0 < len(cont.SourceLink) { - values = append(values, CveContentStr{JVN, cont.SourceLink}) + if cont, found := v[Jvn]; found && 0 < len(cont.SourceLink) { + values = append(values, CveContentStr{Jvn, cont.SourceLink}) } } - order := CveContentTypes{NVD, NewCveContentType(myFamily)} + order := CveContentTypes{Nvd, NvdXML, NewCveContentType(myFamily)} for _, ctype := range order { if cont, found := v[ctype]; found { values = append(values, CveContentStr{ctype, cont.SourceLink}) @@ -75,7 +74,7 @@ func (v CveContents) SourceLinks(lang, myFamily, cveID string) (values []CveCont if len(values) == 0 { return []CveContentStr{{ - Type: NVD, + Type: Nvd, Value: "https://nvd.nist.gov/vuln/detail/" + cveID, }} } @@ -148,11 +147,14 @@ func (v CveContents) References(myFamily string) (values []CveContentRefs) { func (v CveContents) CweIDs(myFamily string) (values []CveContentStr) { order := CveContentTypes{NewCveContentType(myFamily)} order = append(order, AllCveContetTypes.Except(append(order)...)...) - for _, ctype := range order { - if cont, found := v[ctype]; found && 0 < len(cont.CweID) { - // RedHat's OVAL sometimes contains multiple CWE-IDs separated by spaces - for _, cweID := range strings.Fields(cont.CweID) { + if cont, found := v[ctype]; found && 0 < len(cont.CweIDs) { + for _, cweID := range cont.CweIDs { + for _, val := range values { + if val.Value == cweID { + continue + } + } values = append(values, CveContentStr{ Type: ctype, Value: cweID, @@ -163,23 +165,38 @@ func (v CveContents) CweIDs(myFamily string) (values []CveContentStr) { return } +// UniqCweIDs returns Uniq CweIDs +func (v CveContents) UniqCweIDs(myFamily string) (values []CveContentStr) { + uniq := map[string]CveContentStr{} + for _, cwes := range v.CweIDs(myFamily) { + uniq[cwes.Value] = cwes + } + for _, cwe := range uniq { + values = append(values, cwe) + } + return values +} + // CveContent has abstraction of various vulnerability information type CveContent struct { - Type CveContentType - CveID string - Title string - Summary string - Severity string - Cvss2Score float64 - Cvss2Vector string - Cvss3Score float64 - Cvss3Vector string - SourceLink string - Cpes []Cpe - References References - CweID string - Published time.Time - LastModified time.Time + Type CveContentType `json:"type"` + CveID string `json:"cveID"` + Title string `json:"title"` + Summary string `json:"summary"` + Cvss2Score float64 `json:"cvss2Score"` + Cvss2Vector string `json:"cvss2Vector"` + Cvss2Severity string `json:"cvss2Severity"` + Cvss3Score float64 `json:"cvss3Score"` + Cvss3Vector string `json:"cvss3Vector"` + Cvss3Severity string `json:"cvss3Severity"` + SourceLink string `json:"sourceLink"` + Cpes []Cpe `json:"cpes,omitempty"` + References References `json:"references,omitempty"` + CweIDs []string `json:"cweIDs,omitempty"` + Published time.Time `json:"published"` + LastModified time.Time `json:"lastModified"` + Mitigation string `json:"mitigation"` // RedHat API + Optional map[string]string `json:"optional,omitempty"` } // Empty checks the content is empty @@ -193,10 +210,12 @@ type CveContentType string // NewCveContentType create CveContentType func NewCveContentType(name string) CveContentType { switch name { + case "nvdxml": + return NvdXML case "nvd": - return NVD + return Nvd case "jvn": - return JVN + return Jvn case "redhat", "centos": return RedHat case "oracle": @@ -205,21 +224,34 @@ func NewCveContentType(name string) CveContentType { return Ubuntu case "debian": return Debian + case "redhat_api": + return RedHatAPI + case "debian_security_tracker": + return DebianSecurityTracker default: return Unknown } } const ( - // NVD is NVD - NVD CveContentType = "nvd" + // NvdXML is NvdXML + NvdXML CveContentType = "nvdxml" - // JVN is JVN - JVN CveContentType = "jvn" + // Nvd is Nvd + Nvd CveContentType = "nvd" + + // Jvn is Jvn + Jvn CveContentType = "jvn" // RedHat is RedHat RedHat CveContentType = "redhat" + // RedHatAPI is RedHat + RedHatAPI CveContentType = "redhat_api" + + // DebianSecurityTracker is Debian Secury tracker + DebianSecurityTracker CveContentType = "debian_security_tracker" + // Debian is Debian Debian CveContentType = "debian" @@ -240,7 +272,16 @@ const ( type CveContentTypes []CveContentType // AllCveContetTypes has all of CveContentTypes -var AllCveContetTypes = CveContentTypes{NVD, JVN, RedHat, Debian, Ubuntu} +var AllCveContetTypes = CveContentTypes{ + Nvd, + NvdXML, + Jvn, + RedHat, + Debian, + Ubuntu, + RedHatAPI, + DebianSecurityTracker, +} // Except returns CveContentTypes except for given args func (c CveContentTypes) Except(excepts ...CveContentType) (excepted CveContentTypes) { @@ -261,7 +302,8 @@ func (c CveContentTypes) Except(excepts ...CveContentType) (excepted CveContentT // Cpe is Common Platform Enumeration type Cpe struct { - CpeName string + URI string `json:"uri"` + FormattedString string `json:"formattedString"` } // References is a slice of Reference @@ -269,7 +311,7 @@ type References []Reference // Reference has a related link of the CVE type Reference struct { - Source string - Link string - RefID string + Source string `json:"source"` + Link string `json:"link"` + RefID string `json:"refID"` } diff --git a/models/cvecontents_test.go b/models/cvecontents_test.go index 6a926dd9..1df1187e 100644 --- a/models/cvecontents_test.go +++ b/models/cvecontents_test.go @@ -60,27 +60,27 @@ func TestSourceLinks(t *testing.T) { lang: "ja", cveID: "CVE-2017-6074", cont: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, SourceLink: "https://jvn.jp/vu/JVNVU93610402/", }, RedHat: { Type: RedHat, SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, SourceLink: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, }, }, out: []CveContentStr{ { - Type: JVN, + Type: Jvn, Value: "https://jvn.jp/vu/JVNVU93610402/", }, { - Type: NVD, + Type: NvdXML, Value: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, { @@ -95,23 +95,23 @@ func TestSourceLinks(t *testing.T) { lang: "en", cveID: "CVE-2017-6074", cont: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, SourceLink: "https://jvn.jp/vu/JVNVU93610402/", }, RedHat: { Type: RedHat, SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, SourceLink: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, }, }, out: []CveContentStr{ { - Type: NVD, + Type: NvdXML, Value: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, { @@ -129,16 +129,16 @@ func TestSourceLinks(t *testing.T) { }, out: []CveContentStr{ { - Type: NVD, + Type: Nvd, Value: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, }, }, } - for _, tt := range tests { + for i, tt := range tests { actual := tt.in.cont.SourceLinks(tt.in.lang, "redhat", tt.in.cveID) if !reflect.DeepEqual(tt.out, actual) { - t.Errorf("\nexpected: %v\n actual: %v\n", tt.out, actual) + t.Errorf("\n[%d] expected: %v\n actual: %v\n", i, tt.out, actual) } } } @@ -158,16 +158,16 @@ func TestVendorLink(t *testing.T) { vinfo: VulnInfo{ CveID: "CVE-2017-6074", CveContents: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, SourceLink: "https://jvn.jp/vu/JVNVU93610402/", }, RedHat: { Type: RedHat, SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, SourceLink: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", }, }, diff --git a/models/models.go b/models/models.go index 2285d553..90b673f1 100644 --- a/models/models.go +++ b/models/models.go @@ -18,4 +18,4 @@ along with this program. If not, see . package models // JSONVersion is JSON Version -const JSONVersion = 3 +const JSONVersion = 4 diff --git a/models/packages.go b/models/packages.go index ada64b9c..54238396 100644 --- a/models/packages.go +++ b/models/packages.go @@ -21,8 +21,6 @@ import ( "bytes" "fmt" "strings" - - "github.com/future-architect/vuls/config" ) // Packages is Map of Package @@ -40,6 +38,12 @@ func NewPackages(packs ...Package) Packages { // MergeNewVersion merges candidate version information to the receiver struct func (ps Packages) MergeNewVersion(as Packages) { + for name, pack := range ps { + pack.NewVersion = pack.Version + pack.NewRelease = pack.Release + ps[name] = pack + } + for _, a := range as { if pack, ok := ps[a.Name]; ok { pack.NewVersion = a.NewVersion @@ -62,22 +66,7 @@ func (ps Packages) Merge(other Packages) Packages { return merged } -// FormatUpdatablePacksSummary returns a summary of updatable packages -func (ps Packages) FormatUpdatablePacksSummary() string { - if config.Conf.Offline { - return fmt.Sprintf("%d installed", len(ps)) - } - - nUpdatable := 0 - for _, p := range ps { - if p.NewVersion != "" { - nUpdatable++ - } - } - return fmt.Sprintf("%d installed, %d updatable", len(ps), nUpdatable) -} - -// FindOne search a element by name-newver-newrel-arch +// FindOne search a element func (ps Packages) FindOne(f func(Package) bool) (string, Package, bool) { for key, p := range ps { if f(p) { @@ -87,16 +76,44 @@ func (ps Packages) FindOne(f func(Package) bool) (string, Package, bool) { return "", Package{}, false } +// FindByFQPN search a package by Fully-Qualified-Package-Name +func (ps Packages) FindByFQPN(nameVerRelArc string) (*Package, error) { + for _, p := range ps { + if nameVerRelArc == p.FQPN() { + return &p, nil + } + } + return nil, fmt.Errorf("Failed to find the package: %s", nameVerRelArc) +} + // Package has installed binary packages. type Package struct { - Name string - Version string - Release string - NewVersion string - NewRelease string - Arch string - Repository string - Changelog Changelog + Name string `json:"name"` + Version string `json:"version"` + Release string `json:"release"` + NewVersion string `json:"newVersion"` + NewRelease string `json:"newRelease"` + Arch string `json:"arch"` + Repository string `json:"repository"` + Changelog Changelog `json:"changelog"` + AffectedProcs []AffectedProcess `json:",omitempty"` + NeedRestartProcs []NeedRestartProcess `json:",omitempty"` +} + +// FQPN returns Fully-Qualified-Package-Name +// name-version-release.arch +func (p Package) FQPN() string { + fqpn := p.Name + if p.Version != "" { + fqpn += fmt.Sprintf("-%s", p.Version) + } + if p.Release != "" { + fqpn += fmt.Sprintf("-%s", p.Release) + } + if p.Arch != "" { + fqpn += fmt.Sprintf(".%s", p.Arch) + } + return fqpn } // FormatVer returns package version-release @@ -118,10 +135,14 @@ func (p Package) FormatNewVer() string { } // FormatVersionFromTo formats installed and new package version -func (p Package) FormatVersionFromTo(notFixedYet bool) string { +func (p Package) FormatVersionFromTo(notFixedYet bool, status string) string { to := p.FormatNewVer() if notFixedYet { - to = "Not Fixed Yet" + if status != "" { + to = status + } else { + to = "Not Fixed Yet" + } } else if p.NewVersion == "" { to = "Unknown" } @@ -156,8 +177,23 @@ func (p Package) FormatChangelog() string { // Changelog has contents of changelog and how to get it. // Method: models.detectionMethodStr type Changelog struct { - Contents string - Method DetectionMethod + Contents string `json:"contents"` + Method DetectionMethod `json:"method"` +} + +// AffectedProcess keep a processes information affected by software update +type AffectedProcess struct { + PID string `json:"pid"` + Name string `json:"name"` +} + +// NeedRestartProcess keep a processes information affected by software update +type NeedRestartProcess struct { + PID string `json:"pid"` + Path string `json:"path"` + ServiceName string `json:"serviceName"` + InitSystem string `json:"initSystem"` + HasInit bool `json:"-"` } // SrcPackage has installed source package information. @@ -166,9 +202,9 @@ type Changelog struct { // so it is also needed to capture source version for OVAL version comparison. // https://github.com/future-architect/vuls/issues/504 type SrcPackage struct { - Name string - Version string - BinaryNames []string + Name string `json:"name"` + Version string `json:"version"` + BinaryNames []string `json:"binaryNames"` } // AddBinaryName add the name if not exists diff --git a/models/scanresults.go b/models/scanresults.go index 6472394d..f5b511c5 100644 --- a/models/scanresults.go +++ b/models/scanresults.go @@ -20,9 +20,13 @@ package models import ( "bytes" "fmt" + "regexp" + "strings" "time" "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/cwe" + "github.com/future-architect/vuls/util" ) // ScanResults is a slide of ScanResult @@ -30,40 +34,83 @@ type ScanResults []ScanResult // ScanResult has the result of scanned CVE information. type ScanResult struct { - ScannedAt time.Time - ReportedAt time.Time - JSONVersion int - Lang string - ServerUUID string - ServerName string // TOML Section key - Family string - Release string - Container Container - Platform Platform - IPv4Addrs []string // only global unicast address (https://golang.org/pkg/net/#IP.IsGlobalUnicast) - IPv6Addrs []string // only global unicast address (https://golang.org/pkg/net/#IP.IsGlobalUnicast) + JSONVersion int `json:"jsonVersion"` + Lang string `json:"lang"` + ServerUUID string `json:"serverUUID"` + ServerName string `json:"serverName"` // TOML Section key + Family string `json:"family"` + Release string `json:"release"` + Container Container `json:"container"` + Platform Platform `json:"platform"` + IPv4Addrs []string `json:"ipv4Addrs,omitempty"` // only global unicast address (https://golang.org/pkg/net/#IP.IsGlobalUnicast) + IPv6Addrs []string `json:"ipv6Addrs,omitempty"` // only global unicast address (https://golang.org/pkg/net/#IP.IsGlobalUnicast) + ScannedAt time.Time `json:"scannedAt"` + ScannedVersion string `json:"scannedVersion"` + ScannedRevision string `json:"scannedRevision"` + ScannedBy string `json:"scannedBy"` + ReportedAt time.Time `json:"reportedAt"` + ReportedVersion string `json:"reportedVersion"` + ReportedRevision string `json:"reportedRevision"` + ReportedBy string `json:"reportedBy"` + ScannedCves VulnInfos `json:"scannedCves"` + RunningKernel Kernel `json:"runningKernel"` + Packages Packages `json:"packages"` + CweDict CweDict `json:"cweDict"` + Optional map[string]interface{} `json:",omitempty"` + SrcPackages SrcPackages `json:",omitempty"` + Errors []string `json:"errors"` + Config struct { + Scan config.Config `json:"scan"` + Report config.Config `json:"report"` + } `json:"config"` +} - // Scanned Vulns by SSH scan + CPE + OVAL - ScannedCves VulnInfos +// CweDict is a dictionary for CWE +type CweDict map[string]CweDictEntry - RunningKernel Kernel - Packages Packages - SrcPackages SrcPackages - - Errors []string - Optional [][]interface{} - - Config struct { - Scan config.Config - Report config.Config +// Get the name, url, top10URL for the specified cweID, lang +func (c CweDict) Get(cweID, lang string) (name, url, top10Rank, top10URL string) { + cweNum := strings.TrimPrefix(cweID, "CWE-") + switch config.Conf.Lang { + case "ja": + if dict, ok := c[cweNum]; ok && dict.OwaspTopTen2017 != "" { + top10Rank = dict.OwaspTopTen2017 + top10URL = cwe.OwaspTopTen2017GitHubURLJa[dict.OwaspTopTen2017] + } + if dict, ok := cwe.CweDictJa[cweNum]; ok { + name = dict.Name + url = fmt.Sprintf("http://jvndb.jvn.jp/ja/cwe/%s.html", cweID) + } else { + if dict, ok := cwe.CweDictEn[cweNum]; ok { + name = dict.Name + } + url = fmt.Sprintf("https://cwe.mitre.org/data/definitions/%s.html", cweID) + } + default: + if dict, ok := c[cweNum]; ok && dict.OwaspTopTen2017 != "" { + top10Rank = dict.OwaspTopTen2017 + top10URL = cwe.OwaspTopTen2017GitHubURLEn[dict.OwaspTopTen2017] + } + url = fmt.Sprintf("https://cwe.mitre.org/data/definitions/%s.html", cweID) + if dict, ok := cwe.CweDictEn[cweNum]; ok { + name = dict.Name + } } + return +} + +// CweDictEntry is a entry of CWE +type CweDictEntry struct { + En *cwe.Cwe `json:"en,omitempty"` + Ja *cwe.Cwe `json:"ja,omitempty"` + OwaspTopTen2017 string `json:"owaspTopTen2017"` } // Kernel has the Release, version and whether need restart type Kernel struct { - Release string - Version string - RebootRequired bool + Release string `json:"release"` + Version string `json:"version"` + RebootRequired bool `json:"rebootRequired"` } // FilterByCvssOver is filter function. @@ -85,9 +132,29 @@ func (r ScanResult) FilterByCvssOver(over float64) ScanResult { } // FilterIgnoreCves is filter function. -func (r ScanResult) FilterIgnoreCves(cveIDs []string) ScanResult { +func (r ScanResult) FilterIgnoreCves() ScanResult { + + ignoreCves := []string{} + if len(r.Container.Name) == 0 { + ignoreCves = config.Conf.Servers[r.ServerName].IgnoreCves + } else { + if s, ok := config.Conf.Servers[r.ServerName]; ok { + if con, ok := s.Containers[r.Container.Name]; ok { + ignoreCves = con.IgnoreCves + } else { + util.Log.Errorf("%s is not found in config.toml", + r.Container.Name) + return r + } + } else { + util.Log.Errorf("%s is not found in config.toml", + r.ServerName) + return r + } + } + filtered := r.ScannedCves.Find(func(v VulnInfo) bool { - for _, c := range cveIDs { + for _, c := range ignoreCves { if v.CveID == c { return false } @@ -114,6 +181,63 @@ func (r ScanResult) FilterUnfixed() ScanResult { return r } +// FilterIgnorePkgs is filter function. +func (r ScanResult) FilterIgnorePkgs() ScanResult { + ignorePkgsRegexps := []string{} + if len(r.Container.Name) == 0 { + ignorePkgsRegexps = config.Conf.Servers[r.ServerName].IgnorePkgsRegexp + } else { + if s, ok := config.Conf.Servers[r.ServerName]; ok { + if con, ok := s.Containers[r.Container.Name]; ok { + ignorePkgsRegexps = con.IgnorePkgsRegexp + } else { + util.Log.Errorf("%s is not found in config.toml", + r.Container.Name) + return r + } + } else { + util.Log.Errorf("%s is not found in config.toml", + r.ServerName) + return r + } + } + + regexps := []*regexp.Regexp{} + for _, pkgRegexp := range ignorePkgsRegexps { + re, err := regexp.Compile(pkgRegexp) + if err != nil { + util.Log.Errorf("Faild to parse %s, %s", pkgRegexp, err) + continue + } else { + regexps = append(regexps, re) + } + } + if len(regexps) == 0 { + return r + } + + filtered := r.ScannedCves.Find(func(v VulnInfo) bool { + if len(v.AffectedPackages) == 0 { + return true + } + for _, p := range v.AffectedPackages { + match := false + for _, re := range regexps { + if re.MatchString(p.Name) { + match = true + } + } + if !match { + return true + } + } + return false + }) + + r.ScannedCves = filtered + return r +} + // ReportFileName returns the filename on localhost without extention func (r ScanResult) ReportFileName() (name string) { if len(r.Container.ContainerID) == 0 { @@ -180,29 +304,94 @@ func (r ScanResult) FormatServerName() (name string) { // FormatTextReportHeadedr returns header of text report func (r ScanResult) FormatTextReportHeadedr() string { - serverInfo := r.ServerInfo() var buf bytes.Buffer - for i := 0; i < len(serverInfo); i++ { + for i := 0; i < len(r.ServerInfo()); i++ { buf.WriteString("=") } - return fmt.Sprintf("%s\n%s\n%s\t%s\n", + + return fmt.Sprintf("%s\n%s\n%s, %s, %s\n", r.ServerInfo(), buf.String(), r.ScannedCves.FormatCveSummary(), - r.Packages.FormatUpdatablePacksSummary(), + r.ScannedCves.FormatFixedStatus(r.Packages), + r.FormatUpdatablePacksSummary(), ) } +// FormatUpdatablePacksSummary returns a summary of updatable packages +func (r ScanResult) FormatUpdatablePacksSummary() string { + if !r.isDisplayUpdatableNum() { + return fmt.Sprintf("%d installed", len(r.Packages)) + } + + nUpdatable := 0 + for _, p := range r.Packages { + if p.NewVersion == "" { + continue + } + if p.Version != p.NewVersion || p.Release != p.NewRelease { + nUpdatable++ + } + } + return fmt.Sprintf("%d installed, %d updatable", + len(r.Packages), + nUpdatable) +} + +func (r ScanResult) isDisplayUpdatableNum() bool { + var mode config.ScanMode + s, _ := config.Conf.Servers[r.ServerName] + mode = s.Mode + + if mode.IsOffline() { + return false + } + if mode.IsFastRoot() || mode.IsDeep() { + return true + } + if mode.IsFast() { + switch r.Family { + case config.RedHat, + config.Oracle, + config.Debian, + config.Ubuntu, + config.Raspbian: + return false + default: + return true + } + } + return false +} + +// IsContainer returns whether this ServerInfo is about container +func (r ScanResult) IsContainer() bool { + return 0 < len(r.Container.ContainerID) +} + +// IsDeepScanMode checks if the scan mode is deep scan mode. +func (r ScanResult) IsDeepScanMode() bool { + for _, s := range r.Config.Scan.Servers { + for _, m := range s.ScanMode { + if m == "deep" { + return true + } + } + } + return false +} + // Container has Container information type Container struct { - ContainerID string - Name string - Image string - Type string + ContainerID string `json:"containerID"` + Name string `json:"name"` + Image string `json:"image"` + Type string `json:"type"` + UUID string `json:"uuid"` } // Platform has platform information type Platform struct { - Name string // aws or azure or gcp or other... - InstanceID string + Name string `json:"name"` // aws or azure or gcp or other... + InstanceID string `json:"instanceID"` } diff --git a/models/scanresults_test.go b/models/scanresults_test.go index 7de38408..89821c71 100644 --- a/models/scanresults_test.go +++ b/models/scanresults_test.go @@ -43,7 +43,7 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0001", CveContents: NewCveContents( CveContent{ - Type: NVD, + Type: NvdXML, CveID: "CVE-2017-0001", Cvss2Score: 7.1, LastModified: time.Time{}, @@ -54,7 +54,7 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0002", CveContents: NewCveContents( CveContent{ - Type: NVD, + Type: NvdXML, CveID: "CVE-2017-0002", Cvss2Score: 6.9, LastModified: time.Time{}, @@ -65,13 +65,13 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0003", CveContents: NewCveContents( CveContent{ - Type: NVD, + Type: NvdXML, CveID: "CVE-2017-0003", Cvss2Score: 6.9, LastModified: time.Time{}, }, CveContent{ - Type: JVN, + Type: Jvn, CveID: "CVE-2017-0003", Cvss2Score: 7.2, LastModified: time.Time{}, @@ -87,7 +87,7 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0001", CveContents: NewCveContents( CveContent{ - Type: NVD, + Type: NvdXML, CveID: "CVE-2017-0001", Cvss2Score: 7.1, LastModified: time.Time{}, @@ -98,13 +98,13 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0003", CveContents: NewCveContents( CveContent{ - Type: NVD, + Type: NvdXML, CveID: "CVE-2017-0003", Cvss2Score: 6.9, LastModified: time.Time{}, }, CveContent{ - Type: JVN, + Type: Jvn, CveID: "CVE-2017-0003", Cvss2Score: 7.2, LastModified: time.Time{}, @@ -124,10 +124,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0001", CveContents: NewCveContents( CveContent{ - Type: Ubuntu, - CveID: "CVE-2017-0001", - Severity: "HIGH", - LastModified: time.Time{}, + Type: Ubuntu, + CveID: "CVE-2017-0001", + Cvss2Severity: "HIGH", + LastModified: time.Time{}, }, ), }, @@ -135,10 +135,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0002", CveContents: NewCveContents( CveContent{ - Type: RedHat, - CveID: "CVE-2017-0002", - Severity: "CRITICAL", - LastModified: time.Time{}, + Type: RedHat, + CveID: "CVE-2017-0002", + Cvss2Severity: "CRITICAL", + LastModified: time.Time{}, }, ), }, @@ -146,10 +146,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0003", CveContents: NewCveContents( CveContent{ - Type: Oracle, - CveID: "CVE-2017-0003", - Severity: "IMPORTANT", - LastModified: time.Time{}, + Type: Oracle, + CveID: "CVE-2017-0003", + Cvss2Severity: "IMPORTANT", + LastModified: time.Time{}, }, ), }, @@ -162,10 +162,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0001", CveContents: NewCveContents( CveContent{ - Type: Ubuntu, - CveID: "CVE-2017-0001", - Severity: "HIGH", - LastModified: time.Time{}, + Type: Ubuntu, + CveID: "CVE-2017-0001", + Cvss2Severity: "HIGH", + LastModified: time.Time{}, }, ), }, @@ -173,10 +173,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0002", CveContents: NewCveContents( CveContent{ - Type: RedHat, - CveID: "CVE-2017-0002", - Severity: "CRITICAL", - LastModified: time.Time{}, + Type: RedHat, + CveID: "CVE-2017-0002", + Cvss2Severity: "CRITICAL", + LastModified: time.Time{}, }, ), }, @@ -184,10 +184,10 @@ func TestFilterByCvssOver(t *testing.T) { CveID: "CVE-2017-0003", CveContents: NewCveContents( CveContent{ - Type: Oracle, - CveID: "CVE-2017-0003", - Severity: "IMPORTANT", - LastModified: time.Time{}, + Type: Oracle, + CveID: "CVE-2017-0003", + Cvss2Severity: "IMPORTANT", + LastModified: time.Time{}, }, ), }, @@ -206,7 +206,6 @@ func TestFilterByCvssOver(t *testing.T) { } } } - func TestFilterIgnoreCveIDs(t *testing.T) { type in struct { cves []string @@ -220,6 +219,7 @@ func TestFilterIgnoreCveIDs(t *testing.T) { in: in{ cves: []string{"CVE-2017-0002"}, rs: ScanResult{ + ServerName: "name", ScannedCves: VulnInfos{ "CVE-2017-0001": { CveID: "CVE-2017-0001", @@ -234,6 +234,7 @@ func TestFilterIgnoreCveIDs(t *testing.T) { }, }, out: ScanResult{ + ServerName: "name", ScannedCves: VulnInfos{ "CVE-2017-0001": { CveID: "CVE-2017-0001", @@ -246,7 +247,10 @@ func TestFilterIgnoreCveIDs(t *testing.T) { }, } for _, tt := range tests { - actual := tt.in.rs.FilterIgnoreCves(tt.in.cves) + config.Conf.Servers = map[string]config.ServerInfo{ + "name": {IgnoreCves: tt.in.cves}, + } + actual := tt.in.rs.FilterIgnoreCves() for k := range tt.out.ScannedCves { if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { o := pp.Sprintf("%v", tt.out.ScannedCves[k]) @@ -254,6 +258,83 @@ func TestFilterIgnoreCveIDs(t *testing.T) { t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) } } + for k := range actual.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + } +} + +func TestFilterIgnoreCveIDsContainer(t *testing.T) { + type in struct { + cves []string + rs ScanResult + } + var tests = []struct { + in in + out ScanResult + }{ + { + in: in{ + cves: []string{"CVE-2017-0002"}, + rs: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + }, + "CVE-2017-0002": { + CveID: "CVE-2017-0002", + }, + "CVE-2017-0003": { + CveID: "CVE-2017-0003", + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + }, + "CVE-2017-0003": { + CveID: "CVE-2017-0003", + }, + }, + }, + }, + } + for _, tt := range tests { + config.Conf.Servers = map[string]config.ServerInfo{ + "name": { + Containers: map[string]config.ContainerSetting{ + "dockerA": { + IgnoreCves: tt.in.cves, + }, + }, + }, + } + actual := tt.in.rs.FilterIgnoreCves() + for k := range tt.out.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + for k := range actual.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } } } @@ -336,3 +417,322 @@ func TestFilterUnfixed(t *testing.T) { } } } + +func TestFilterIgnorePkgs(t *testing.T) { + type in struct { + ignorePkgsRegexp []string + rs ScanResult + } + var tests = []struct { + in in + out ScanResult + }{ + { + in: in{ + ignorePkgsRegexp: []string{"^kernel"}, + rs: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + }, + }, + "CVE-2017-0002": { + CveID: "CVE-2017-0002", + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{ + "CVE-2017-0002": { + CveID: "CVE-2017-0002", + }, + }, + }, + }, + { + in: in{ + ignorePkgsRegexp: []string{"^kernel"}, + rs: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + { + in: in{ + ignorePkgsRegexp: []string{"^kernel", "^vim", "^bind"}, + rs: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + ScannedCves: VulnInfos{}, + }, + }, + } + for _, tt := range tests { + config.Conf.Servers = map[string]config.ServerInfo{ + "name": {IgnorePkgsRegexp: tt.in.ignorePkgsRegexp}, + } + actual := tt.in.rs.FilterIgnorePkgs() + for k := range tt.out.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + for k := range actual.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + } +} + +func TestFilterIgnorePkgsContainer(t *testing.T) { + type in struct { + ignorePkgsRegexp []string + rs ScanResult + } + var tests = []struct { + in in + out ScanResult + }{ + { + in: in{ + ignorePkgsRegexp: []string{"^kernel"}, + rs: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + }, + }, + "CVE-2017-0002": { + CveID: "CVE-2017-0002", + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0002": { + CveID: "CVE-2017-0002", + }, + }, + }, + }, + { + in: in{ + ignorePkgsRegexp: []string{"^kernel"}, + rs: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + { + in: in{ + ignorePkgsRegexp: []string{"^kernel", "^vim", "^bind"}, + rs: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{ + "CVE-2017-0001": { + CveID: "CVE-2017-0001", + AffectedPackages: PackageStatuses{ + {Name: "kernel"}, + {Name: "vim"}, + }, + }, + }, + }, + }, + out: ScanResult{ + ServerName: "name", + Container: Container{Name: "dockerA"}, + ScannedCves: VulnInfos{}, + }, + }, + } + for _, tt := range tests { + config.Conf.Servers = map[string]config.ServerInfo{ + "name": { + Containers: map[string]config.ContainerSetting{ + "dockerA": { + IgnorePkgsRegexp: tt.in.ignorePkgsRegexp, + }, + }, + }, + } + actual := tt.in.rs.FilterIgnorePkgs() + for k := range tt.out.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + for k := range actual.ScannedCves { + if !reflect.DeepEqual(tt.out.ScannedCves[k], actual.ScannedCves[k]) { + o := pp.Sprintf("%v", tt.out.ScannedCves[k]) + a := pp.Sprintf("%v", actual.ScannedCves[k]) + t.Errorf("[%s] expected: %v\n actual: %v\n", k, o, a) + } + } + } +} + +func TestIsDisplayUpdatableNum(t *testing.T) { + var tests = []struct { + mode []byte + family string + expected bool + }{ + { + mode: []byte{config.Offline}, + expected: false, + }, + { + mode: []byte{config.FastRoot}, + expected: true, + }, + { + mode: []byte{config.Deep}, + expected: true, + }, + { + mode: []byte{config.Fast}, + family: config.RedHat, + expected: false, + }, + { + mode: []byte{config.Fast}, + family: config.Oracle, + expected: false, + }, + { + mode: []byte{config.Fast}, + family: config.Debian, + expected: false, + }, + { + mode: []byte{config.Fast}, + family: config.Ubuntu, + expected: false, + }, + { + mode: []byte{config.Fast}, + family: config.Raspbian, + expected: false, + }, + { + mode: []byte{config.Fast}, + family: config.CentOS, + expected: true, + }, + { + mode: []byte{config.Fast}, + family: config.Amazon, + expected: true, + }, + { + mode: []byte{config.Fast}, + family: config.FreeBSD, + expected: true, + }, + { + mode: []byte{config.Fast}, + family: config.OpenSUSE, + expected: true, + }, + { + mode: []byte{config.Fast}, + family: config.Alpine, + expected: true, + }, + } + + for i, tt := range tests { + mode := config.ScanMode{} + for _, m := range tt.mode { + mode.Set(m) + } + config.Conf.Servers = map[string]config.ServerInfo{ + "name": {Mode: mode}, + } + r := ScanResult{ + ServerName: "name", + Family: tt.family, + } + act := r.isDisplayUpdatableNum() + if tt.expected != act { + t.Errorf("[%d] expected %#v, actual %#v", i, tt.expected, act) + } + } +} diff --git a/models/utils.go b/models/utils.go index 9abb3ce5..248db4a7 100644 --- a/models/utils.go +++ b/models/utils.go @@ -18,17 +18,22 @@ along with this program. If not, see . package models import ( - "fmt" "strings" cvedict "github.com/kotakanbe/go-cve-dictionary/models" ) -// ConvertNvdToModel convert NVD to CveContent -func ConvertNvdToModel(cveID string, nvd cvedict.Nvd) *CveContent { +// ConvertNvdXMLToModel convert NVD to CveContent +func ConvertNvdXMLToModel(cveID string, nvd *cvedict.NvdXML) *CveContent { + if nvd == nil { + return nil + } var cpes []Cpe for _, c := range nvd.Cpes { - cpes = append(cpes, Cpe{CpeName: c.CpeName}) + cpes = append(cpes, Cpe{ + FormattedString: c.FormattedString, + URI: c.URI, + }) } var refs []Reference @@ -39,42 +44,21 @@ func ConvertNvdToModel(cveID string, nvd cvedict.Nvd) *CveContent { }) } - validVec := true - for _, v := range []string{ - nvd.AccessVector, - nvd.AccessComplexity, - nvd.Authentication, - nvd.ConfidentialityImpact, - nvd.IntegrityImpact, - nvd.AvailabilityImpact, - } { - if len(v) == 0 { - validVec = false - } + cweIDs := []string{} + for _, cid := range nvd.Cwes { + cweIDs = append(cweIDs, cid.CweID) } - vector := "" - if validVec { - vector = fmt.Sprintf("AV:%s/AC:%s/Au:%s/C:%s/I:%s/A:%s", - string(nvd.AccessVector[0]), - string(nvd.AccessComplexity[0]), - string(nvd.Authentication[0]), - string(nvd.ConfidentialityImpact[0]), - string(nvd.IntegrityImpact[0]), - string(nvd.AvailabilityImpact[0])) - } - - //TODO CVSSv3 return &CveContent{ - Type: NVD, - CveID: cveID, - Summary: nvd.Summary, - Cvss2Score: nvd.Score, - Cvss2Vector: vector, - Severity: "", // severity is not contained in NVD - SourceLink: "https://nvd.nist.gov/vuln/detail/" + cveID, - Cpes: cpes, - CweID: nvd.CweID, + Type: Nvd, + CveID: cveID, + Summary: nvd.Summary, + Cvss2Score: nvd.Cvss2.BaseScore, + Cvss2Vector: nvd.Cvss2.VectorString, + Cvss2Severity: nvd.Cvss2.Severity, + SourceLink: "https://nvd.nist.gov/vuln/detail/" + cveID, + // Cpes: cpes, + CweIDs: cweIDs, References: refs, Published: nvd.PublishedDate, LastModified: nvd.LastModifiedDate, @@ -82,10 +66,16 @@ func ConvertNvdToModel(cveID string, nvd cvedict.Nvd) *CveContent { } // ConvertJvnToModel convert JVN to CveContent -func ConvertJvnToModel(cveID string, jvn cvedict.Jvn) *CveContent { +func ConvertJvnToModel(cveID string, jvn *cvedict.Jvn) *CveContent { + if jvn == nil { + return nil + } var cpes []Cpe for _, c := range jvn.Cpes { - cpes = append(cpes, Cpe{CpeName: c.CpeName}) + cpes = append(cpes, Cpe{ + FormattedString: c.FormattedString, + URI: c.URI, + }) } refs := []Reference{} @@ -96,19 +86,71 @@ func ConvertJvnToModel(cveID string, jvn cvedict.Jvn) *CveContent { }) } - vector := strings.TrimSuffix(strings.TrimPrefix(jvn.Vector, "("), ")") return &CveContent{ - Type: JVN, - CveID: cveID, - Title: jvn.Title, - Summary: jvn.Summary, - Severity: jvn.Severity, - Cvss2Score: jvn.Score, - Cvss2Vector: vector, - SourceLink: jvn.JvnLink, - Cpes: cpes, + Type: Jvn, + CveID: cveID, + Title: jvn.Title, + Summary: jvn.Summary, + Cvss2Score: jvn.Cvss2.BaseScore, + Cvss2Vector: jvn.Cvss2.VectorString, + Cvss2Severity: jvn.Cvss2.Severity, + Cvss3Score: jvn.Cvss3.BaseScore, + Cvss3Vector: jvn.Cvss3.VectorString, + Cvss3Severity: jvn.Cvss3.BaseSeverity, + SourceLink: jvn.JvnLink, + // Cpes: cpes, References: refs, Published: jvn.PublishedDate, LastModified: jvn.LastModifiedDate, } } + +// ConvertNvdJSONToModel convert NVD to CveContent +func ConvertNvdJSONToModel(cveID string, nvd *cvedict.NvdJSON) *CveContent { + if nvd == nil { + return nil + } + var cpes []Cpe + for _, c := range nvd.Cpes { + cpes = append(cpes, Cpe{ + FormattedString: c.FormattedString, + URI: c.URI, + }) + } + + var refs []Reference + for _, r := range nvd.References { + refs = append(refs, Reference{ + Link: r.Link, + Source: r.Source, + }) + } + + cweIDs := []string{} + for _, cid := range nvd.Cwes { + cweIDs = append(cweIDs, cid.CweID) + } + + desc := []string{} + for _, d := range nvd.Descriptions { + desc = append(desc, d.Value) + } + + return &CveContent{ + Type: Nvd, + CveID: cveID, + Summary: strings.Join(desc, "\n"), + Cvss2Score: nvd.Cvss2.BaseScore, + Cvss2Vector: nvd.Cvss2.VectorString, + Cvss2Severity: nvd.Cvss2.Severity, + Cvss3Score: nvd.Cvss3.BaseScore, + Cvss3Vector: nvd.Cvss3.VectorString, + Cvss3Severity: nvd.Cvss3.BaseSeverity, + SourceLink: "https://nvd.nist.gov/vuln/detail/" + cveID, + // Cpes: cpes, + CweIDs: cweIDs, + References: refs, + Published: nvd.PublishedDate, + LastModified: nvd.LastModifiedDate, + } +} diff --git a/models/vulninfos.go b/models/vulninfos.go index 50deee3a..3984070c 100644 --- a/models/vulninfos.go +++ b/models/vulninfos.go @@ -104,43 +104,85 @@ func (v VulnInfos) FormatCveSummary() string { m["High"], m["Medium"], m["Low"], m["Unknown"]) } +// FormatFixedStatus summarize the number of cves are fixed. +func (v VulnInfos) FormatFixedStatus(packs Packages) string { + total, fixed := 0, 0 + for _, vInfo := range v { + if len(vInfo.CpeURIs) != 0 { + continue + } + total++ + if vInfo.PatchStatus(packs) == "Fixed" { + fixed++ + } + } + return fmt.Sprintf("%d/%d Fixed", fixed, total) +} + // PackageStatuses is a list of PackageStatus type PackageStatuses []PackageStatus +// FormatTuiSummary format packname to show TUI summary +func (ps PackageStatuses) FormatTuiSummary() string { + names := []string{} + for _, p := range ps { + names = append(names, p.Name) + } + return strings.Join(names, ", ") +} + +// Store insert given pkg if missing, update pkg if exists +func (ps PackageStatuses) Store(pkg PackageStatus) PackageStatuses { + for i, p := range ps { + if p.Name == pkg.Name { + ps[i] = pkg + return ps + } + } + ps = append(ps, pkg) + return ps +} + // Sort by Name -func (p PackageStatuses) Sort() { - sort.Slice(p, func(i, j int) bool { - return p[i].Name < p[j].Name +func (ps PackageStatuses) Sort() { + sort.Slice(ps, func(i, j int) bool { + return ps[i].Name < ps[j].Name }) return } // PackageStatus has name and other status abount the package type PackageStatus struct { - Name string - NotFixedYet bool + Name string `json:"name"` + NotFixedYet bool `json:"notFixedYet"` + FixState string `json:"fixState"` } // VulnInfo has a vulnerability information and unsecure packages type VulnInfo struct { - CveID string - Confidence Confidence - AffectedPackages PackageStatuses - DistroAdvisories []DistroAdvisory // for Aamazon, RHEL, FreeBSD - CpeNames []string - CveContents CveContents + CveID string `json:"cveID"` + Confidences Confidences `json:"confidences"` + AffectedPackages PackageStatuses `json:"affectedPackages"` + DistroAdvisories []DistroAdvisory `json:"distroAdvisories,omitempty"` // for Aamazon, RHEL, FreeBSD + CpeURIs []string `json:"cpeURIs,omitempty"` // CpeURIs related to this CVE defined in config.toml + CveContents CveContents `json:"cveContents"` } // Titles returns tilte (TUI) func (v VulnInfo) Titles(lang, myFamily string) (values []CveContentStr) { if lang == "ja" { - if cont, found := v.CveContents[JVN]; found && 0 < len(cont.Title) { - values = append(values, CveContentStr{JVN, cont.Title}) + if cont, found := v.CveContents[Jvn]; found && 0 < len(cont.Title) { + values = append(values, CveContentStr{Jvn, cont.Title}) } } - order := CveContentTypes{NVD, NewCveContentType(myFamily)} - order = append(order, AllCveContetTypes.Except(append(order, JVN)...)...) + // RedHat API has one line title. + if cont, found := v.CveContents[RedHatAPI]; found && 0 < len(cont.Title) { + values = append(values, CveContentStr{RedHatAPI, cont.Title}) + } + + order := CveContentTypes{Nvd, NvdXML, NewCveContentType(myFamily)} + order = append(order, AllCveContetTypes.Except(append(order, Jvn)...)...) for _, ctype := range order { // Only JVN has meaningful title. so return first 100 char of summary if cont, found := v.CveContents[ctype]; found && 0 < len(cont.Summary) { @@ -171,16 +213,16 @@ func (v VulnInfo) Titles(lang, myFamily string) (values []CveContentStr) { // Summaries returns summaries func (v VulnInfo) Summaries(lang, myFamily string) (values []CveContentStr) { if lang == "ja" { - if cont, found := v.CveContents[JVN]; found && 0 < len(cont.Summary) { + if cont, found := v.CveContents[Jvn]; found && 0 < len(cont.Summary) { summary := cont.Title summary += "\n" + strings.Replace( strings.Replace(cont.Summary, "\n", " ", -1), "\r", " ", -1) - values = append(values, CveContentStr{JVN, summary}) + values = append(values, CveContentStr{Jvn, summary}) } } - order := CveContentTypes{NVD, NewCveContentType(myFamily)} - order = append(order, AllCveContetTypes.Except(append(order, JVN)...)...) + order := CveContentTypes{Nvd, NvdXML, NewCveContentType(myFamily)} + order = append(order, AllCveContetTypes.Except(append(order, Jvn)...)...) for _, ctype := range order { if cont, found := v.CveContents[ctype]; found && 0 < len(cont.Summary) { summary := strings.Replace(cont.Summary, "\n", " ", -1) @@ -208,28 +250,71 @@ func (v VulnInfo) Summaries(lang, myFamily string) (values []CveContentStr) { return } -// Cvss2Scores returns CVSS V2 Scores -func (v VulnInfo) Cvss2Scores() (values []CveContentCvss) { - order := []CveContentType{NVD, RedHat, JVN} +// Mitigations returns mitigations +func (v VulnInfo) Mitigations(myFamily string) (values []CveContentStr) { + order := CveContentTypes{RedHatAPI} for _, ctype := range order { - if cont, found := v.CveContents[ctype]; found && 0 < cont.Cvss2Score { - // https://nvd.nist.gov/vuln-metrics/cvss - sev := cont.Severity - if ctype == NVD { - sev = cvss2ScoreToSeverity(cont.Cvss2Score) + if cont, found := v.CveContents[ctype]; found && 0 < len(cont.Mitigation) { + values = append(values, CveContentStr{ + Type: ctype, + Value: cont.Mitigation, + }) + } + } + + if len(values) == 0 { + return []CveContentStr{{ + Type: Unknown, + Value: "-", + }} + } + return +} + +// Cvss2Scores returns CVSS V2 Scores +func (v VulnInfo) Cvss2Scores(myFamily string) (values []CveContentCvss) { + order := []CveContentType{Nvd, NvdXML, RedHat, Jvn} + if myFamily != config.RedHat && myFamily != config.CentOS { + order = append(order, NewCveContentType(myFamily)) + } + for _, ctype := range order { + if cont, found := v.CveContents[ctype]; found { + if cont.Cvss2Score == 0 && cont.Cvss2Severity == "" { + continue } + // https://nvd.nist.gov/vuln-metrics/cvss values = append(values, CveContentCvss{ Type: ctype, Value: Cvss{ Type: CVSS2, Score: cont.Cvss2Score, Vector: cont.Cvss2Vector, - Severity: strings.ToUpper(sev), + Severity: strings.ToUpper(cont.Cvss2Severity), }, }) } } + for _, v := range values { + if v.Type == RedHat { + return + } + } + // Set the CVSS v2 score of vuln that exists only in gost. + // Unfixed vulnerabilities detected by gost are not in OVAL, because + // OVAL data has only vulnerabilities for already fixed. + if cont, found := v.CveContents[RedHatAPI]; found { + values = append(values, CveContentCvss{ + Type: RedHatAPI, + Value: Cvss{ + Type: CVSS2, + Score: cont.Cvss2Score, + Vector: cont.Cvss2Vector, + Severity: strings.ToUpper(cont.Cvss2Severity), + }, + }) + } + for _, adv := range v.DistroAdvisories { if adv.Severity != "" { values = append(values, CveContentCvss{ @@ -246,22 +331,22 @@ func (v VulnInfo) Cvss2Scores() (values []CveContentCvss) { } // An OVAL entry in Ubuntu and Debian has only severity (CVSS score isn't included). - // Show severity and dummy score calculated roghly. + // Show severity and dummy score calculated roughly. order = append(order, AllCveContetTypes.Except(order...)...) for _, ctype := range order { if cont, found := v.CveContents[ctype]; found && cont.Cvss2Score == 0 && cont.Cvss3Score == 0 && - cont.Severity != "" { + cont.Cvss2Severity != "" { values = append(values, CveContentCvss{ Type: cont.Type, Value: Cvss{ Type: CVSS2, - Score: severityToV2ScoreRoughly(cont.Severity), + Score: severityToV2ScoreRoughly(cont.Cvss2Severity), CalculatedBySeverity: true, Vector: "-", - Severity: strings.ToUpper(cont.Severity), + Severity: strings.ToUpper(cont.Cvss2Severity), }, }) } @@ -272,30 +357,48 @@ func (v VulnInfo) Cvss2Scores() (values []CveContentCvss) { // Cvss3Scores returns CVSS V3 Score func (v VulnInfo) Cvss3Scores() (values []CveContentCvss) { - // TODO implement NVD - order := []CveContentType{RedHat} + order := []CveContentType{Nvd, RedHat, Jvn} for _, ctype := range order { - if cont, found := v.CveContents[ctype]; found && 0 < cont.Cvss3Score { + if cont, found := v.CveContents[ctype]; found { // https://nvd.nist.gov/vuln-metrics/cvss - sev := cont.Severity values = append(values, CveContentCvss{ Type: ctype, Value: Cvss{ Type: CVSS3, Score: cont.Cvss3Score, Vector: cont.Cvss3Vector, - Severity: strings.ToUpper(sev), + Severity: strings.ToUpper(cont.Cvss3Severity), }, }) } } + + for _, v := range values { + if v.Type == RedHat { + return + } + } + + // Set the CVSS v3 score of vuln that exists only in gost. + // Unfixed vulnerabilities detected by gost are not in OVAL, because + // OVAL data has only vulnerabilities for already fixed. + if cont, found := v.CveContents[RedHatAPI]; found { + values = append(values, CveContentCvss{ + Type: RedHatAPI, + Value: Cvss{ + Type: CVSS3, + Score: cont.Cvss3Score, + Vector: cont.Cvss3Vector, + Severity: strings.ToUpper(cont.Cvss3Severity), + }, + }) + } return } // MaxCvss3Score returns Max CVSS V3 Score func (v VulnInfo) MaxCvss3Score() CveContentCvss { - // TODO implement NVD - order := []CveContentType{RedHat} + order := []CveContentType{Nvd, RedHat, RedHatAPI, Jvn} max := 0.0 value := CveContentCvss{ Type: Unknown, @@ -304,14 +407,13 @@ func (v VulnInfo) MaxCvss3Score() CveContentCvss { for _, ctype := range order { if cont, found := v.CveContents[ctype]; found && max < cont.Cvss3Score { // https://nvd.nist.gov/vuln-metrics/cvss - sev := cont.Severity value = CveContentCvss{ Type: ctype, Value: Cvss{ Type: CVSS3, Score: cont.Cvss3Score, Vector: cont.Cvss3Vector, - Severity: sev, + Severity: strings.ToUpper(cont.Cvss3Severity), }, } max = cont.Cvss3Score @@ -338,7 +440,7 @@ func (v VulnInfo) MaxCvssScore() CveContentCvss { // MaxCvss2Score returns Max CVSS V2 Score func (v VulnInfo) MaxCvss2Score() CveContentCvss { - order := []CveContentType{NVD, RedHat, JVN} + order := []CveContentType{Nvd, NvdXML, RedHat, RedHatAPI, Jvn} max := 0.0 value := CveContentCvss{ Type: Unknown, @@ -347,17 +449,13 @@ func (v VulnInfo) MaxCvss2Score() CveContentCvss { for _, ctype := range order { if cont, found := v.CveContents[ctype]; found && max < cont.Cvss2Score { // https://nvd.nist.gov/vuln-metrics/cvss - sev := cont.Severity - if ctype == NVD { - sev = cvss2ScoreToSeverity(cont.Cvss2Score) - } value = CveContentCvss{ Type: ctype, Value: Cvss{ Type: CVSS2, Score: cont.Cvss2Score, Vector: cont.Cvss2Vector, - Severity: sev, + Severity: strings.ToUpper(cont.Cvss2Severity), }, } max = cont.Cvss2Score @@ -372,8 +470,8 @@ func (v VulnInfo) MaxCvss2Score() CveContentCvss { // Only Ubuntu, RedHat and Oracle have severity data in OVAL. order = []CveContentType{Ubuntu, RedHat, Oracle} for _, ctype := range order { - if cont, found := v.CveContents[ctype]; found && 0 < len(cont.Severity) { - score := severityToV2ScoreRoughly(cont.Severity) + if cont, found := v.CveContents[ctype]; found && 0 < len(cont.Cvss2Severity) { + score := severityToV2ScoreRoughly(cont.Cvss2Severity) if max < score { value = CveContentCvss{ Type: ctype, @@ -382,7 +480,7 @@ func (v VulnInfo) MaxCvss2Score() CveContentCvss { Score: score, CalculatedBySeverity: true, Vector: cont.Cvss2Vector, - Severity: cont.Severity, + Severity: strings.ToUpper(cont.Cvss2Severity), }, } } @@ -411,10 +509,55 @@ func (v VulnInfo) MaxCvss2Score() CveContentCvss { return value } -// CveContentCvss has CveContentType and Cvss2 +// AttackVector returns attack vector string +func (v VulnInfo) AttackVector() string { + for _, cnt := range v.CveContents { + if strings.HasPrefix(cnt.Cvss2Vector, "AV:N") || + strings.HasPrefix(cnt.Cvss3Vector, "CVSS:3.0/AV:N") { + return "Network" + } else if strings.HasPrefix(cnt.Cvss2Vector, "AV:A") || + strings.HasPrefix(cnt.Cvss3Vector, "CVSS:3.0/AV:A") { + return "Adjacent" + } else if strings.HasPrefix(cnt.Cvss2Vector, "AV:L") || + strings.HasPrefix(cnt.Cvss3Vector, "CVSS:3.0/AV:L") { + return "Local" + } else if strings.HasPrefix(cnt.Cvss3Vector, "CVSS:3.0/AV:P") { + return "Physical" + } + } + if cont, found := v.CveContents[DebianSecurityTracker]; found { + if attackRange, found := cont.Optional["attack range"]; found { + return attackRange + } + } + return "" +} + +// PatchStatus returns attack vector string +func (v VulnInfo) PatchStatus(packs Packages) string { + // Vuls don't know patch status of the CPE + if len(v.CpeURIs) != 0 { + return "" + } + for _, p := range v.AffectedPackages { + if p.NotFixedYet { + return "Unfixed" + } + + // fast, offline mode doesn't have new version + if pack, ok := packs[p.Name]; ok { + if pack.NewVersion == "" { + return "Unknown" + } + } + } + return "Fixed" +} + +// CveContentCvss has CVSS information type CveContentCvss struct { - Type CveContentType - Value Cvss + Type CveContentType `json:"type"` + Value Cvss `json:"value"` } // CvssType Represent the type of CVSS @@ -430,20 +573,23 @@ const ( // Cvss has CVSS Score type Cvss struct { - Type CvssType - Score float64 - CalculatedBySeverity bool - Vector string - Severity string + Type CvssType `json:"type"` + Score float64 `json:"score"` + CalculatedBySeverity bool `json:"calculatedBySeverity"` + Vector string `json:"vector"` + Severity string `json:"severity"` } // Format CVSS Score and Vector func (c Cvss) Format() string { + if c.Score == 0 || c.Vector == "" { + return c.Severity + } switch c.Type { case CVSS2: - return fmt.Sprintf("%3.1f/%s", c.Score, c.Vector) + return fmt.Sprintf("%3.1f/%s %s", c.Score, c.Vector, c.Severity) case CVSS3: - return fmt.Sprintf("%3.1f/CVSS:3.0/%s", c.Score, c.Vector) + return fmt.Sprintf("%3.1f/%s %s", c.Score, c.Vector, c.Severity) } return "" } @@ -483,35 +629,6 @@ func severityToV2ScoreRoughly(severity string) float64 { return 0 } -// CveContentCvss3 has CveContentType and Cvss3 -// type CveContentCvss3 struct { -// Type CveContentType -// Value Cvss3 -// } - -// Cvss3 has CVSS v3 Score, Vector and Severity -// type Cvss3 struct { -// Score float64 -// Vector string -// Severity string -// } - -// Format CVSS Score and Vector -// func (c Cvss3) Format() string { -// return fmt.Sprintf("%3.1f/CVSS:3.0/%s", c.Score, c.Vector) -// } - -// func cvss3ScoreToSeverity(score float64) string { -// if 9.0 <= score { -// return "CRITICAL" -// } else if 7.0 <= score { -// return "HIGH" -// } else if 4.0 <= score { -// return "MEDIUM" -// } -// return "LOW" -// } - // FormatMaxCvssScore returns Max CVSS Score func (v VulnInfo) FormatMaxCvssScore() string { max := v.MaxCvssScore() @@ -573,37 +690,13 @@ func (v VulnInfo) VendorLinks(family string) map[string]string { return links } -// NilToEmpty set nil slice or map fields to empty to avoid null in JSON -func (v *VulnInfo) NilToEmpty() *VulnInfo { - if v.CpeNames == nil { - v.CpeNames = []string{} - } - if v.DistroAdvisories == nil { - v.DistroAdvisories = []DistroAdvisory{} - } - if v.AffectedPackages == nil { - v.AffectedPackages = PackageStatuses{} - } - if v.CveContents == nil { - v.CveContents = NewCveContents() - } - for key := range v.CveContents { - if v.CveContents[key].Cpes == nil { - cont := v.CveContents[key] - cont.Cpes = []Cpe{} - v.CveContents[key] = cont - } - } - return v -} - // DistroAdvisory has Amazon Linux, RHEL, FreeBSD Security Advisory information. type DistroAdvisory struct { - AdvisoryID string - Severity string - Issued time.Time - Updated time.Time - Description string + AdvisoryID string `json:"advisoryID"` + Severity string `json:"severity"` + Issued time.Time `json:"issued"` + Updated time.Time `json:"updated"` + Description string `json:"description"` } // Format the distro advisory information @@ -620,11 +713,33 @@ func (p DistroAdvisory) Format() string { return strings.Join(buf, "\n") } +// Confidences is a list of Confidence +type Confidences []Confidence + +// AppendIfMissing appends confidence to the list if missiong +func (cs *Confidences) AppendIfMissing(confidence Confidence) { + for _, c := range *cs { + if c.DetectionMethod == confidence.DetectionMethod { + return + } + } + *cs = append(*cs, confidence) +} + +// SortByConfident sorts Confidences +func (cs Confidences) SortByConfident() Confidences { + sort.Slice(cs, func(i, j int) bool { + return cs[i].SortOrder < cs[j].SortOrder + }) + return cs +} + // Confidence is a ranking how confident the CVE-ID was deteted correctly // Score: 0 - 100 type Confidence struct { - Score int - DetectionMethod DetectionMethod + Score int `json:"score"` + DetectionMethod DetectionMethod `json:"detectionMethod"` + SortOrder int `json:"-"` } func (c Confidence) String() string { @@ -649,6 +764,12 @@ const ( // OvalMatchStr is a String representation of OvalMatch OvalMatchStr = "OvalMatch" + // RedHatAPIStr is a String representation of RedHatAPIMatch + RedHatAPIStr = "RedHatAPIMatch" + + // DebianSecurityTrackerMatchStr is a String representation of DebianSecurityTrackerMatch + DebianSecurityTrackerMatchStr = "DebianSecurityTrackerMatch" + // ChangelogExactMatchStr is a String representation of ChangelogExactMatch ChangelogExactMatchStr = "ChangelogExactMatch" @@ -664,20 +785,26 @@ const ( var ( // CpeNameMatch is a ranking how confident the CVE-ID was deteted correctly - CpeNameMatch = Confidence{100, CpeNameMatchStr} + CpeNameMatch = Confidence{100, CpeNameMatchStr, 1} // YumUpdateSecurityMatch is a ranking how confident the CVE-ID was deteted correctly - YumUpdateSecurityMatch = Confidence{100, YumUpdateSecurityMatchStr} + YumUpdateSecurityMatch = Confidence{100, YumUpdateSecurityMatchStr, 2} // PkgAuditMatch is a ranking how confident the CVE-ID was deteted correctly - PkgAuditMatch = Confidence{100, PkgAuditMatchStr} + PkgAuditMatch = Confidence{100, PkgAuditMatchStr, 2} // OvalMatch is a ranking how confident the CVE-ID was deteted correctly - OvalMatch = Confidence{100, OvalMatchStr} + OvalMatch = Confidence{100, OvalMatchStr, 0} + + // RedHatAPIMatch ranking how confident the CVE-ID was deteted correctly + RedHatAPIMatch = Confidence{100, RedHatAPIStr, 0} + + // DebianSecurityTrackerMatch ranking how confident the CVE-ID was deteted correctly + DebianSecurityTrackerMatch = Confidence{100, DebianSecurityTrackerMatchStr, 0} // ChangelogExactMatch is a ranking how confident the CVE-ID was deteted correctly - ChangelogExactMatch = Confidence{95, ChangelogExactMatchStr} + ChangelogExactMatch = Confidence{95, ChangelogExactMatchStr, 3} // ChangelogLenientMatch is a ranking how confident the CVE-ID was deteted correctly - ChangelogLenientMatch = Confidence{50, ChangelogLenientMatchStr} + ChangelogLenientMatch = Confidence{50, ChangelogLenientMatchStr, 4} ) diff --git a/models/vulninfos_test.go b/models/vulninfos_test.go index 3174ca4a..c142c84b 100644 --- a/models/vulninfos_test.go +++ b/models/vulninfos_test.go @@ -36,16 +36,16 @@ func TestTitles(t *testing.T) { lang: "ja", cont: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, Title: "Title1", }, RedHat: { Type: RedHat, Summary: "Summary RedHat", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Summary: "Summary NVD", // Severity is NIOT included in NVD }, @@ -54,11 +54,11 @@ func TestTitles(t *testing.T) { }, out: []CveContentStr{ { - Type: JVN, + Type: Jvn, Value: "Title1", }, { - Type: NVD, + Type: NvdXML, Value: "Summary NVD", }, { @@ -73,16 +73,16 @@ func TestTitles(t *testing.T) { lang: "en", cont: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, Title: "Title1", }, RedHat: { Type: RedHat, Summary: "Summary RedHat", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Summary: "Summary NVD", // Severity is NIOT included in NVD }, @@ -91,7 +91,7 @@ func TestTitles(t *testing.T) { }, out: []CveContentStr{ { - Type: NVD, + Type: NvdXML, Value: "Summary NVD", }, { @@ -137,8 +137,8 @@ func TestSummaries(t *testing.T) { lang: "ja", cont: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, Title: "Title JVN", Summary: "Summary JVN", }, @@ -146,8 +146,8 @@ func TestSummaries(t *testing.T) { Type: RedHat, Summary: "Summary RedHat", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Summary: "Summary NVD", // Severity is NIOT included in NVD }, @@ -156,11 +156,11 @@ func TestSummaries(t *testing.T) { }, out: []CveContentStr{ { - Type: JVN, + Type: Jvn, Value: "Title JVN\nSummary JVN", }, { - Type: NVD, + Type: NvdXML, Value: "Summary NVD", }, { @@ -175,8 +175,8 @@ func TestSummaries(t *testing.T) { lang: "en", cont: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, + Jvn: { + Type: Jvn, Title: "Title JVN", Summary: "Summary JVN", }, @@ -184,8 +184,8 @@ func TestSummaries(t *testing.T) { Type: RedHat, Summary: "Summary RedHat", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Summary: "Summary NVD", // Severity is NIOT included in NVD }, @@ -194,7 +194,7 @@ func TestSummaries(t *testing.T) { }, out: []CveContentStr{ { - Type: NVD, + Type: NvdXML, Value: "Summary NVD", }, { @@ -235,8 +235,8 @@ func TestCountGroupBySeverity(t *testing.T) { "CVE-2017-0002": { CveID: "CVE-2017-0002", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 6.0, }, RedHat: { @@ -248,8 +248,8 @@ func TestCountGroupBySeverity(t *testing.T) { "CVE-2017-0003": { CveID: "CVE-2017-0003", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 2.0, }, }, @@ -257,8 +257,8 @@ func TestCountGroupBySeverity(t *testing.T) { "CVE-2017-0004": { CveID: "CVE-2017-0004", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 5.0, }, }, @@ -296,8 +296,8 @@ func TestToSortedSlice(t *testing.T) { "CVE-2017-0002": { CveID: "CVE-2017-0002", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 6.0, }, RedHat: { @@ -309,8 +309,8 @@ func TestToSortedSlice(t *testing.T) { "CVE-2017-0001": { CveID: "CVE-2017-0001", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 7.0, }, RedHat: { @@ -324,8 +324,8 @@ func TestToSortedSlice(t *testing.T) { { CveID: "CVE-2017-0001", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 7.0, }, RedHat: { @@ -337,8 +337,8 @@ func TestToSortedSlice(t *testing.T) { { CveID: "CVE-2017-0002", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 6.0, }, RedHat: { @@ -355,8 +355,8 @@ func TestToSortedSlice(t *testing.T) { "CVE-2017-0002": { CveID: "CVE-2017-0002", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 6.0, }, RedHat: { @@ -388,8 +388,8 @@ func TestToSortedSlice(t *testing.T) { { CveID: "CVE-2017-0002", CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 6.0, }, RedHat: { @@ -407,8 +407,8 @@ func TestToSortedSlice(t *testing.T) { CveID: "CVE-2017-0002", CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "High", + Type: Ubuntu, + Cvss2Severity: "High", }, }, }, @@ -416,8 +416,8 @@ func TestToSortedSlice(t *testing.T) { CveID: "CVE-2017-0001", CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "Low", + Type: Ubuntu, + Cvss2Severity: "Low", }, }, }, @@ -427,8 +427,8 @@ func TestToSortedSlice(t *testing.T) { CveID: "CVE-2017-0002", CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "High", + Type: Ubuntu, + Cvss2Severity: "High", }, }, }, @@ -436,8 +436,8 @@ func TestToSortedSlice(t *testing.T) { CveID: "CVE-2017-0001", CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "Low", + Type: Ubuntu, + Cvss2Severity: "Low", }, }, }, @@ -460,29 +460,29 @@ func TestCvss2Scores(t *testing.T) { { in: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, - Severity: "HIGH", - Cvss2Score: 8.2, - Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", + Jvn: { + Type: Jvn, + Cvss2Severity: "HIGH", + Cvss2Score: 8.2, + Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", }, RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss2Score: 8.0, - Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", + Type: RedHat, + Cvss2Severity: "HIGH", + Cvss2Score: 8.0, + Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", }, - NVD: { - Type: NVD, - Cvss2Score: 8.1, - Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", - // Severity is NIOT included in NVD + NvdXML: { + Type: NvdXML, + Cvss2Score: 8.1, + Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", + Cvss2Severity: "HIGH", }, }, }, out: []CveContentCvss{ { - Type: NVD, + Type: NvdXML, Value: Cvss{ Type: CVSS2, Score: 8.1, @@ -500,7 +500,7 @@ func TestCvss2Scores(t *testing.T) { }, }, { - Type: JVN, + Type: Jvn, Value: Cvss{ Type: CVSS2, Score: 8.2, @@ -517,9 +517,9 @@ func TestCvss2Scores(t *testing.T) { }, } for i, tt := range tests { - actual := tt.in.Cvss2Scores() + actual := tt.in.Cvss2Scores("redhat") if !reflect.DeepEqual(tt.out, actual) { - t.Errorf("[%d] expected: %v\n actual: %v\n", i, tt.out, actual) + t.Errorf("[%d]\nexpected: %v\n actual: %v\n", i, tt.out, actual) } } } @@ -532,20 +532,20 @@ func TestMaxCvss2Scores(t *testing.T) { { in: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, - Severity: "HIGH", - Cvss2Score: 8.2, - Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", + Jvn: { + Type: Jvn, + Cvss2Severity: "HIGH", + Cvss2Score: 8.2, + Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", }, RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss2Score: 8.0, - Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", + Type: RedHat, + Cvss2Severity: "HIGH", + Cvss2Score: 8.0, + Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 8.1, Cvss2Vector: "AV:N/AC:L/Au:N/C:N/I:N/A:P", // Severity is NIOT included in NVD @@ -553,7 +553,7 @@ func TestMaxCvss2Scores(t *testing.T) { }, }, out: CveContentCvss{ - Type: JVN, + Type: Jvn, Value: Cvss{ Type: CVSS2, Score: 8.2, @@ -567,8 +567,8 @@ func TestMaxCvss2Scores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "HIGH", + Type: Ubuntu, + Cvss2Severity: "HIGH", }, }, }, @@ -613,16 +613,16 @@ func TestCvss3Scores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss3Score: 8.0, - Cvss3Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", + Type: RedHat, + Cvss3Severity: "HIGH", + Cvss3Score: 8.0, + Cvss3Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", }, - NVD: { - Type: NVD, - Cvss3Score: 8.1, - Cvss3Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", - // Severity is NIOT included in NVD + NvdXML: { + Type: NvdXML, + Cvss2Score: 8.1, + Cvss2Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", + Cvss2Severity: "HIGH", }, }, }, @@ -661,10 +661,10 @@ func TestMaxCvss3Scores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss3Score: 8.0, - Cvss3Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", + Type: RedHat, + Cvss3Severity: "HIGH", + Cvss3Score: 8.0, + Cvss3Vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", }, }, }, @@ -708,8 +708,8 @@ func TestMaxCvssScores(t *testing.T) { { in: VulnInfo{ CveContents: CveContents{ - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss3Score: 7.0, }, RedHat: { @@ -748,8 +748,8 @@ func TestMaxCvssScores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "HIGH", + Type: Ubuntu, + Cvss2Severity: "HIGH", }, }, }, @@ -768,17 +768,18 @@ func TestMaxCvssScores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "MEDIUM", + Type: Ubuntu, + Cvss2Severity: "MEDIUM", }, - NVD: { - Type: NVD, - Cvss2Score: 7.0, + NvdXML: { + Type: NvdXML, + Cvss2Score: 7.0, + Cvss2Severity: "HIGH", }, }, }, out: CveContentCvss{ - Type: NVD, + Type: NvdXML, Value: Cvss{ Type: CVSS2, Score: 7.0, @@ -810,12 +811,13 @@ func TestMaxCvssScores(t *testing.T) { in: VulnInfo{ CveContents: CveContents{ Ubuntu: { - Type: Ubuntu, - Severity: "MEDIUM", + Type: Ubuntu, + Cvss2Severity: "MEDIUM", }, - NVD: { - Type: NVD, - Cvss2Score: 4.0, + NvdXML: { + Type: NvdXML, + Cvss2Score: 4.0, + Cvss2Severity: "MEDIUM", }, }, DistroAdvisories: []DistroAdvisory{ @@ -825,7 +827,7 @@ func TestMaxCvssScores(t *testing.T) { }, }, out: CveContentCvss{ - Type: NVD, + Type: NvdXML, Value: Cvss{ Type: CVSS2, Score: 4, @@ -861,18 +863,18 @@ func TestFormatMaxCvssScore(t *testing.T) { { in: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, - Severity: "HIGH", - Cvss2Score: 8.3, + Jvn: { + Type: Jvn, + Cvss2Severity: "HIGH", + Cvss2Score: 8.3, }, RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss3Score: 8.0, + Type: RedHat, + Cvss2Severity: "HIGH", + Cvss3Score: 8.0, }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 8.1, // Severity is NIOT included in NVD }, @@ -883,19 +885,20 @@ func TestFormatMaxCvssScore(t *testing.T) { { in: VulnInfo{ CveContents: CveContents{ - JVN: { - Type: JVN, - Severity: "HIGH", - Cvss2Score: 8.3, + Jvn: { + Type: Jvn, + Cvss2Severity: "HIGH", + Cvss2Score: 8.3, }, RedHat: { - Type: RedHat, - Severity: "HIGH", - Cvss2Score: 8.0, - Cvss3Score: 9.9, + Type: RedHat, + Cvss2Severity: "HIGH", + Cvss2Score: 8.0, + Cvss3Severity: "HIGH", + Cvss3Score: 9.9, }, - NVD: { - Type: NVD, + NvdXML: { + Type: NvdXML, Cvss2Score: 8.1, }, }, @@ -934,3 +937,100 @@ func TestSortPackageStatues(t *testing.T) { } } } + +func TestStorePackageStatueses(t *testing.T) { + var tests = []struct { + pkgstats PackageStatuses + in PackageStatus + out PackageStatuses + }{ + { + pkgstats: PackageStatuses{ + {Name: "a"}, + {Name: "b"}, + }, + in: PackageStatus{ + Name: "c", + }, + out: PackageStatuses{ + {Name: "a"}, + {Name: "b"}, + {Name: "c"}, + }, + }, + } + for _, tt := range tests { + out := tt.pkgstats.Store(tt.in) + if ok := reflect.DeepEqual(tt.out, out); !ok { + t.Errorf("\nexpected: %v\n actual: %v\n", tt.out, out) + } + } +} + +func TestAppendIfMissing(t *testing.T) { + var tests = []struct { + in Confidences + arg Confidence + out Confidences + }{ + { + in: Confidences{ + CpeNameMatch, + }, + arg: CpeNameMatch, + out: Confidences{ + CpeNameMatch, + }, + }, + { + in: Confidences{ + CpeNameMatch, + }, + arg: ChangelogExactMatch, + out: Confidences{ + CpeNameMatch, + ChangelogExactMatch, + }, + }, + } + for _, tt := range tests { + tt.in.AppendIfMissing(tt.arg) + if !reflect.DeepEqual(tt.in, tt.out) { + t.Errorf("\nexpected: %v\n actual: %v\n", tt.out, tt.in) + } + } +} + +func TestSortByConfiden(t *testing.T) { + var tests = []struct { + in Confidences + out Confidences + }{ + { + in: Confidences{ + OvalMatch, + CpeNameMatch, + }, + out: Confidences{ + OvalMatch, + CpeNameMatch, + }, + }, + { + in: Confidences{ + CpeNameMatch, + OvalMatch, + }, + out: Confidences{ + OvalMatch, + CpeNameMatch, + }, + }, + } + for _, tt := range tests { + act := tt.in.SortByConfident() + if !reflect.DeepEqual(tt.out, act) { + t.Errorf("\nexpected: %v\n actual: %v\n", tt.out, act) + } + } +} diff --git a/oval/alpine.go b/oval/alpine.go index 7cc09843..5d683a03 100644 --- a/oval/alpine.go +++ b/oval/alpine.go @@ -21,6 +21,7 @@ import ( "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" + "github.com/kotakanbe/goval-dictionary/db" ) // Alpine is the struct of Alpine Linux @@ -38,22 +39,22 @@ func NewAlpine() Alpine { } // FillWithOval returns scan result after updating CVE info by OVAL -func (o Alpine) FillWithOval(r *models.ScanResult) (err error) { +func (o Alpine) FillWithOval(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { var relatedDefs ovalResult - if o.isFetchViaHTTP() { + if o.IsFetchViaHTTP() { if relatedDefs, err = getDefsByPackNameViaHTTP(r); err != nil { - return err + return 0, err } } else { - if relatedDefs, err = getDefsByPackNameFromOvalDB(r); err != nil { - return err + if relatedDefs, err = getDefsByPackNameFromOvalDB(driver, r); err != nil { + return 0, err } } for _, defPacks := range relatedDefs.entries { o.update(r, defPacks) } - return nil + return len(relatedDefs.entries), nil } func (o Alpine) update(r *models.ScanResult, defPacks defPacks) { @@ -62,8 +63,8 @@ func (o Alpine) update(r *models.ScanResult, defPacks defPacks) { if !ok { util.Log.Debugf("%s is newly detected by OVAL", cveID) vinfo = models.VulnInfo{ - CveID: cveID, - Confidence: models.OvalMatch, + CveID: cveID, + Confidences: []models.Confidence{models.OvalMatch}, } } diff --git a/oval/debian.go b/oval/debian.go index b2566e49..590b2ece 100644 --- a/oval/debian.go +++ b/oval/debian.go @@ -21,6 +21,7 @@ import ( "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" + "github.com/kotakanbe/goval-dictionary/db" ovalmodels "github.com/kotakanbe/goval-dictionary/models" ) @@ -37,7 +38,7 @@ func (o DebianBase) update(r *models.ScanResult, defPacks defPacks) { util.Log.Debugf("%s is newly detected by OVAL", defPacks.def.Debian.CveID) vinfo = models.VulnInfo{ CveID: defPacks.def.Debian.CveID, - Confidence: models.OvalMatch, + Confidences: []models.Confidence{models.OvalMatch}, CveContents: models.NewCveContents(ovalContent), } } else { @@ -51,17 +52,14 @@ func (o DebianBase) update(r *models.ScanResult, defPacks defPacks) { defPacks.def.Debian.CveID) cveContents = models.CveContents{} } - if vinfo.Confidence.Score < models.OvalMatch.Score { - vinfo.Confidence = models.OvalMatch - } + vinfo.Confidences.AppendIfMissing(models.OvalMatch) cveContents[ctype] = ovalContent vinfo.CveContents = cveContents } // uniq(vinfo.PackNames + defPacks.actuallyAffectedPackNames) for _, pack := range vinfo.AffectedPackages { - notFixedYet, _ := defPacks.actuallyAffectedPackNames[pack.Name] - defPacks.actuallyAffectedPackNames[pack.Name] = notFixedYet + defPacks.actuallyAffectedPackNames[pack.Name] = pack.NotFixedYet } // update notFixedYet of SrcPackage @@ -91,11 +89,11 @@ func (o DebianBase) convertToModel(def *ovalmodels.Definition) *models.CveConten } return &models.CveContent{ - CveID: def.Debian.CveID, - Title: def.Title, - Summary: def.Description, - Severity: def.Advisory.Severity, - References: refs, + CveID: def.Debian.CveID, + Title: def.Title, + Summary: def.Description, + Cvss2Severity: def.Advisory.Severity, + References: refs, } } @@ -116,17 +114,17 @@ func NewDebian() Debian { } // FillWithOval returns scan result after updating CVE info by OVAL -func (o Debian) FillWithOval(r *models.ScanResult) (err error) { +func (o Debian) FillWithOval(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { //Debian's uname gives both of kernel release(uname -r), version(kernel-image version) linuxImage := "linux-image-" + r.RunningKernel.Release // Add linux and set the version of running kernel to search OVAL. - newVer := "" - if p, ok := r.Packages[linuxImage]; ok { - newVer = p.NewVersion - } if r.Container.ContainerID == "" { + newVer := "" + if p, ok := r.Packages[linuxImage]; ok { + newVer = p.NewVersion + } r.Packages["linux"] = models.Package{ Name: "linux", Version: r.RunningKernel.Version, @@ -135,13 +133,13 @@ func (o Debian) FillWithOval(r *models.ScanResult) (err error) { } var relatedDefs ovalResult - if o.isFetchViaHTTP() { + if o.IsFetchViaHTTP() { if relatedDefs, err = getDefsByPackNameViaHTTP(r); err != nil { - return err + return 0, err } } else { - if relatedDefs, err = getDefsByPackNameFromOvalDB(r); err != nil { - return err + if relatedDefs, err = getDefsByPackNameFromOvalDB(driver, r); err != nil { + return 0, err } } @@ -170,7 +168,7 @@ func (o Debian) FillWithOval(r *models.ScanResult) (err error) { vuln.CveContents[models.Debian] = cont } } - return nil + return len(relatedDefs.entries), nil } // Ubuntu is the interface for Debian OVAL @@ -190,7 +188,7 @@ func NewUbuntu() Ubuntu { } // FillWithOval returns scan result after updating CVE info by OVAL -func (o Ubuntu) FillWithOval(r *models.ScanResult) (err error) { +func (o Ubuntu) FillWithOval(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { ovalKernelImageNames := []string{ "linux-aws", "linux-azure", @@ -245,13 +243,13 @@ func (o Ubuntu) FillWithOval(r *models.ScanResult) (err error) { } var relatedDefs ovalResult - if o.isFetchViaHTTP() { + if o.IsFetchViaHTTP() { if relatedDefs, err = getDefsByPackNameViaHTTP(r); err != nil { - return err + return 0, err } } else { - if relatedDefs, err = getDefsByPackNameFromOvalDB(r); err != nil { - return err + if relatedDefs, err = getDefsByPackNameFromOvalDB(driver, r); err != nil { + return 0, err } } @@ -282,5 +280,5 @@ func (o Ubuntu) FillWithOval(r *models.ScanResult) (err error) { vuln.CveContents[models.Ubuntu] = cont } } - return nil + return len(relatedDefs.entries), nil } diff --git a/oval/oval.go b/oval/oval.go index 4cece20a..209e9b51 100644 --- a/oval/oval.go +++ b/oval/oval.go @@ -23,7 +23,7 @@ import ( "net/http" "time" - "github.com/future-architect/vuls/config" + cnf "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" "github.com/kotakanbe/goval-dictionary/db" @@ -33,11 +33,12 @@ import ( // Client is the interface of OVAL client. type Client interface { CheckHTTPHealth() error - FillWithOval(r *models.ScanResult) error + FillWithOval(db.DB, *models.ScanResult) (int, error) // CheckIfOvalFetched checks if oval entries are in DB by family, release. - CheckIfOvalFetched(string, string) (bool, error) - CheckIfOvalFresh(string, string) (bool, error) + CheckIfOvalFetched(db.DB, string, string) (bool, error) + CheckIfOvalFresh(db.DB, string, string) (bool, error) + IsFetchViaHTTP() bool } // Base is a base struct @@ -47,11 +48,11 @@ type Base struct { // CheckHTTPHealth do health check func (b Base) CheckHTTPHealth() error { - if !b.isFetchViaHTTP() { + if !b.IsFetchViaHTTP() { return nil } - url := fmt.Sprintf("%s/health", config.Conf.OvalDBURL) + url := fmt.Sprintf("%s/health", cnf.Conf.OvalDict.URL) var errs []error var resp *http.Response resp, _, errs = gorequest.New().Get(url).End() @@ -65,19 +66,9 @@ func (b Base) CheckHTTPHealth() error { } // CheckIfOvalFetched checks if oval entries are in DB by family, release. -func (b Base) CheckIfOvalFetched(osFamily, release string) (fetched bool, err error) { - if !b.isFetchViaHTTP() { - var ovaldb db.DB - if ovaldb, _, err = db.NewDB( - osFamily, - config.Conf.OvalDBType, - config.Conf.OvalDBPath, - config.Conf.DebugSQL, - ); err != nil { - return false, err - } - defer ovaldb.CloseDB() - count, err := ovaldb.CountDefs(osFamily, release) +func (b Base) CheckIfOvalFetched(driver db.DB, osFamily, release string) (fetched bool, err error) { + if !b.IsFetchViaHTTP() { + count, err := driver.CountDefs(osFamily, release) if err != nil { return false, fmt.Errorf("Failed to count OVAL defs: %s, %s, %v", osFamily, release, err) @@ -85,7 +76,7 @@ func (b Base) CheckIfOvalFetched(osFamily, release string) (fetched bool, err er return 0 < count, nil } - url, _ := util.URLPathJoin(config.Conf.OvalDBURL, "count", osFamily, release) + url, _ := util.URLPathJoin(cnf.Conf.OvalDict.URL, "count", osFamily, release) resp, body, errs := gorequest.New().Get(url).End() if 0 < len(errs) || resp == nil || resp.StatusCode != 200 { return false, fmt.Errorf("HTTP GET error: %v, url: %s, resp: %v", @@ -100,22 +91,12 @@ func (b Base) CheckIfOvalFetched(osFamily, release string) (fetched bool, err er } // CheckIfOvalFresh checks if oval entries are fresh enough -func (b Base) CheckIfOvalFresh(osFamily, release string) (ok bool, err error) { +func (b Base) CheckIfOvalFresh(driver db.DB, osFamily, release string) (ok bool, err error) { var lastModified time.Time - if !b.isFetchViaHTTP() { - var ovaldb db.DB - if ovaldb, _, err = db.NewDB( - osFamily, - config.Conf.OvalDBType, - config.Conf.OvalDBPath, - config.Conf.DebugSQL, - ); err != nil { - return false, err - } - defer ovaldb.CloseDB() - lastModified = ovaldb.GetLastModified(osFamily, release) + if !b.IsFetchViaHTTP() { + lastModified = driver.GetLastModified(osFamily, release) } else { - url, _ := util.URLPathJoin(config.Conf.OvalDBURL, "lastmodified", osFamily, release) + url, _ := util.URLPathJoin(cnf.Conf.OvalDict.URL, "lastmodified", osFamily, release) resp, body, errs := gorequest.New().Get(url).End() if 0 < len(errs) || resp == nil || resp.StatusCode != 200 { return false, fmt.Errorf("HTTP GET error: %v, url: %s, resp: %v", @@ -139,7 +120,8 @@ func (b Base) CheckIfOvalFresh(osFamily, release string) (ok bool, err error) { return true, nil } -func (b Base) isFetchViaHTTP() bool { +// IsFetchViaHTTP checks whether fetch via HTTP +func (b Base) IsFetchViaHTTP() bool { // Default value of OvalDBType is sqlite3 - return config.Conf.OvalDBURL != "" && config.Conf.OvalDBType == "sqlite3" + return cnf.Conf.OvalDict.URL != "" && cnf.Conf.OvalDict.Type == "sqlite3" } diff --git a/oval/redhat.go b/oval/redhat.go index 5fd5a048..54229e48 100644 --- a/oval/redhat.go +++ b/oval/redhat.go @@ -25,6 +25,7 @@ import ( "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" + "github.com/kotakanbe/goval-dictionary/db" ovalmodels "github.com/kotakanbe/goval-dictionary/models" ) @@ -34,20 +35,20 @@ type RedHatBase struct { } // FillWithOval returns scan result after updating CVE info by OVAL -func (o RedHatBase) FillWithOval(r *models.ScanResult) (err error) { +func (o RedHatBase) FillWithOval(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { var relatedDefs ovalResult - if o.isFetchViaHTTP() { + if o.IsFetchViaHTTP() { if relatedDefs, err = getDefsByPackNameViaHTTP(r); err != nil { - return err + return 0, err } } else { - if relatedDefs, err = getDefsByPackNameFromOvalDB(r); err != nil { - return err + if relatedDefs, err = getDefsByPackNameFromOvalDB(driver, r); err != nil { + return 0, err } } for _, defPacks := range relatedDefs.entries { - o.update(r, defPacks) + nCVEs += o.update(r, defPacks) } for _, vuln := range r.ScannedCves { @@ -64,7 +65,8 @@ func (o RedHatBase) FillWithOval(r *models.ScanResult) (err error) { } } } - return nil + + return nCVEs, nil } var kernelRelatedPackNames = map[string]bool{ @@ -98,7 +100,7 @@ var kernelRelatedPackNames = map[string]bool{ "python-perf": true, } -func (o RedHatBase) update(r *models.ScanResult, defPacks defPacks) { +func (o RedHatBase) update(r *models.ScanResult, defPacks defPacks) (nCVEs int) { ctype := models.NewCveContentType(o.family) for _, cve := range defPacks.def.Advisory.Cves { ovalContent := *o.convertToModel(cve.CveID, &defPacks.def) @@ -107,9 +109,10 @@ func (o RedHatBase) update(r *models.ScanResult, defPacks defPacks) { util.Log.Debugf("%s is newly detected by OVAL", cve.CveID) vinfo = models.VulnInfo{ CveID: cve.CveID, - Confidence: models.OvalMatch, + Confidences: models.Confidences{models.OvalMatch}, CveContents: models.NewCveContents(ovalContent), } + nCVEs++ } else { cveContents := vinfo.CveContents if v, ok := vinfo.CveContents[ctype]; ok { @@ -125,22 +128,24 @@ func (o RedHatBase) update(r *models.ScanResult, defPacks defPacks) { cveContents = models.CveContents{} } - if vinfo.Confidence.Score < models.OvalMatch.Score { - vinfo.Confidence = models.OvalMatch - } + vinfo.Confidences.AppendIfMissing(models.OvalMatch) cveContents[ctype] = ovalContent vinfo.CveContents = cveContents } // uniq(vinfo.PackNames + defPacks.actuallyAffectedPackNames) for _, pack := range vinfo.AffectedPackages { - notFixedYet, _ := defPacks.actuallyAffectedPackNames[pack.Name] - defPacks.actuallyAffectedPackNames[pack.Name] = notFixedYet + if nfy, ok := defPacks.actuallyAffectedPackNames[pack.Name]; !ok { + defPacks.actuallyAffectedPackNames[pack.Name] = pack.NotFixedYet + } else if nfy { + defPacks.actuallyAffectedPackNames[pack.Name] = true + } } vinfo.AffectedPackages = defPacks.toPackStatuses() vinfo.AffectedPackages.Sort() r.ScannedCves[cve.CveID] = vinfo } + return } func (o RedHatBase) convertToModel(cveID string, def *ovalmodels.Definition) *models.CveContent { @@ -165,20 +170,32 @@ func (o RedHatBase) convertToModel(cveID string, def *ovalmodels.Definition) *mo severity = cve.Impact } + sev2, sev3 := "", "" + if score2 != 0 { + sev2 = severity + } + if score3 != 0 { + sev3 = severity + } + + // CWE-ID in RedHat OVAL may have multiple cweIDs separated by space + cwes := strings.Fields(cve.Cwe) + return &models.CveContent{ - Type: models.NewCveContentType(o.family), - CveID: cve.CveID, - Title: def.Title, - Summary: def.Description, - Severity: severity, - Cvss2Score: score2, - Cvss2Vector: vec2, - Cvss3Score: score3, - Cvss3Vector: vec3, - References: refs, - CweID: cve.Cwe, - Published: def.Advisory.Issued, - LastModified: def.Advisory.Updated, + Type: models.NewCveContentType(o.family), + CveID: cve.CveID, + Title: def.Title, + Summary: def.Description, + Cvss2Score: score2, + Cvss2Vector: vec2, + Cvss2Severity: sev2, + Cvss3Score: score3, + Cvss3Vector: vec3, + Cvss3Severity: sev3, + References: refs, + CweIDs: cwes, + Published: def.Advisory.Issued, + LastModified: def.Advisory.Updated, } } return nil @@ -207,7 +224,7 @@ func (o RedHatBase) parseCvss3(scoreVector string) (score float64, vector string if score, err = strconv.ParseFloat(ss[0], 64); err != nil { return 0, "" } - return score, strings.Join(ss[1:], "/") + return score, fmt.Sprintf("CVSS:3.0/%s", ss[1]) } return 0, "" } diff --git a/oval/redhat_test.go b/oval/redhat_test.go index 41c89941..ac6ea7a6 100644 --- a/oval/redhat_test.go +++ b/oval/redhat_test.go @@ -72,7 +72,7 @@ func TestParseCvss3(t *testing.T) { in: "5.6/CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", out: out{ score: 5.6, - vector: "AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", + vector: "CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L", }, }, { diff --git a/oval/suse.go b/oval/suse.go index d6f9eb3a..cfd9ab4f 100644 --- a/oval/suse.go +++ b/oval/suse.go @@ -21,6 +21,7 @@ import ( "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" + "github.com/kotakanbe/goval-dictionary/db" ovalmodels "github.com/kotakanbe/goval-dictionary/models" ) @@ -40,15 +41,15 @@ func NewSUSE() SUSE { } // FillWithOval returns scan result after updating CVE info by OVAL -func (o SUSE) FillWithOval(r *models.ScanResult) (err error) { +func (o SUSE) FillWithOval(driver db.DB, r *models.ScanResult) (nCVEs int, err error) { var relatedDefs ovalResult - if o.isFetchViaHTTP() { + if o.IsFetchViaHTTP() { if relatedDefs, err = getDefsByPackNameViaHTTP(r); err != nil { - return err + return 0, err } } else { - if relatedDefs, err = getDefsByPackNameFromOvalDB(r); err != nil { - return err + if relatedDefs, err = getDefsByPackNameFromOvalDB(driver, r); err != nil { + return 0, err } } for _, defPacks := range relatedDefs.entries { @@ -61,7 +62,7 @@ func (o SUSE) FillWithOval(r *models.ScanResult) (err error) { vuln.CveContents[models.SUSE] = cont } } - return nil + return len(relatedDefs.entries), nil } func (o SUSE) update(r *models.ScanResult, defPacks defPacks) { @@ -72,7 +73,7 @@ func (o SUSE) update(r *models.ScanResult, defPacks defPacks) { util.Log.Debugf("%s is newly detected by OVAL", defPacks.def.Title) vinfo = models.VulnInfo{ CveID: defPacks.def.Title, - Confidence: models.OvalMatch, + Confidences: models.Confidences{models.OvalMatch}, CveContents: models.NewCveContents(ovalContent), } } else { @@ -84,17 +85,14 @@ func (o SUSE) update(r *models.ScanResult, defPacks defPacks) { util.Log.Debugf("%s is also detected by OVAL", defPacks.def.Title) cveContents = models.CveContents{} } - if vinfo.Confidence.Score < models.OvalMatch.Score { - vinfo.Confidence = models.OvalMatch - } + vinfo.Confidences.AppendIfMissing(models.OvalMatch) cveContents[ctype] = ovalContent vinfo.CveContents = cveContents } // uniq(vinfo.PackNames + defPacks.actuallyAffectedPackNames) for _, pack := range vinfo.AffectedPackages { - notFixedYet, _ := defPacks.actuallyAffectedPackNames[pack.Name] - defPacks.actuallyAffectedPackNames[pack.Name] = notFixedYet + defPacks.actuallyAffectedPackNames[pack.Name] = pack.NotFixedYet } vinfo.AffectedPackages = defPacks.toPackStatuses() vinfo.AffectedPackages.Sort() diff --git a/oval/util.go b/oval/util.go index 1956e9ea..867f7c55 100644 --- a/oval/util.go +++ b/oval/util.go @@ -126,7 +126,7 @@ func getDefsByPackNameViaHTTP(r *models.ScanResult) ( select { case req := <-reqChan: url, err := util.URLPathJoin( - config.Conf.OvalDBURL, + config.Conf.OvalDict.URL, "packs", r.Family, r.Release, @@ -216,20 +216,7 @@ func httpGet(url string, req request, resChan chan<- response, errChan chan<- er } } -func getDefsByPackNameFromOvalDB(r *models.ScanResult) (relatedDefs ovalResult, err error) { - path := config.Conf.OvalDBURL - if config.Conf.OvalDBType == "sqlite3" { - path = config.Conf.OvalDBPath - } - util.Log.Debugf("Open oval-dictionary db (%s): %s", config.Conf.OvalDBType, path) - - var ovaldb db.DB - if ovaldb, _, err = db.NewDB(r.Family, config.Conf.OvalDBType, - path, config.Conf.DebugSQL); err != nil { - return - } - defer ovaldb.CloseDB() - +func getDefsByPackNameFromOvalDB(driver db.DB, r *models.ScanResult) (relatedDefs ovalResult, err error) { requests := []request{} for _, pack := range r.Packages { requests = append(requests, request{ @@ -249,9 +236,9 @@ func getDefsByPackNameFromOvalDB(r *models.ScanResult) (relatedDefs ovalResult, } for _, req := range requests { - definitions, err := ovaldb.GetByPackName(r.Release, req.packName) + definitions, err := driver.GetByPackName(r.Release, req.packName) if err != nil { - return relatedDefs, fmt.Errorf("Failed to get %s OVAL info by package name: %v", r.Family, err) + return relatedDefs, fmt.Errorf("Failed to get %s OVAL info by package: %#v, err: %s", r.Family, req, err) } for _, def := range definitions { affected, notFixedYet := isOvalDefAffected(def, req, r.Family, r.RunningKernel) @@ -316,8 +303,12 @@ func isOvalDefAffected(def ovalmodels.Definition, req request, family string, ru // Unable to judge whether fixed or not fixed of src package(Ubuntu, Debian) return true, false } + + // `offline` or `fast` scan mode can't get a updatable version. + // In these mode, the blow field was set empty. + // Vuls can not judge fixed or unfixed. if req.NewVersionRelease == "" { - return true, true + return true, false } // compare version: newVer vs oval diff --git a/oval/util_test.go b/oval/util_test.go index 2b425b2f..4c999a73 100644 --- a/oval/util_test.go +++ b/oval/util_test.go @@ -319,7 +319,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: false, }, - // RedHat + // 5 RedHat { in: in{ family: "redhat", @@ -337,64 +337,16 @@ func TestIsOvalDefAffected(t *testing.T) { }, }, req: request{ - packName: "b", - isSrcPack: false, - versionRelease: "0:1.2.3-45.el6_7.7", + packName: "b", + isSrcPack: false, + versionRelease: "0:1.2.3-45.el6_7.7", + NewVersionRelease: "", }, }, affected: true, - notFixedYet: true, - }, - { - in: in{ - family: "redhat", - def: ovalmodels.Definition{ - AffectedPacks: []ovalmodels.Package{ - { - Name: "a", - NotFixedYet: false, - }, - { - Name: "b", - NotFixedYet: false, - Version: "0:1.2.3-45.el6_7.8", - }, - }, - }, - req: request{ - packName: "b", - isSrcPack: false, - versionRelease: "0:1.2.3-45.el6_7.8", - }, - }, - affected: false, - notFixedYet: false, - }, - { - in: in{ - family: "redhat", - def: ovalmodels.Definition{ - AffectedPacks: []ovalmodels.Package{ - { - Name: "a", - NotFixedYet: false, - }, - { - Name: "b", - NotFixedYet: false, - Version: "0:1.2.3-45.el6_7.8", - }, - }, - }, - req: request{ - packName: "b", - isSrcPack: false, - versionRelease: "0:1.2.3-45.el6_7.9", - }, - }, - affected: false, notFixedYet: false, }, + // 6 RedHat { in: in{ family: "redhat", @@ -421,6 +373,86 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: true, }, + // 7 RedHat + { + in: in{ + family: "redhat", + def: ovalmodels.Definition{ + AffectedPacks: []ovalmodels.Package{ + { + Name: "a", + NotFixedYet: false, + }, + { + Name: "b", + NotFixedYet: false, + Version: "0:1.2.3-45.el6_7.8", + }, + }, + }, + req: request{ + packName: "b", + isSrcPack: false, + versionRelease: "0:1.2.3-45.el6_7.8", + }, + }, + affected: false, + notFixedYet: false, + }, + // 8 RedHat + { + in: in{ + family: "redhat", + def: ovalmodels.Definition{ + AffectedPacks: []ovalmodels.Package{ + { + Name: "a", + NotFixedYet: false, + }, + { + Name: "b", + NotFixedYet: false, + Version: "0:1.2.3-45.el6_7.8", + }, + }, + }, + req: request{ + packName: "b", + isSrcPack: false, + versionRelease: "0:1.2.3-45.el6_7.9", + }, + }, + affected: false, + notFixedYet: false, + }, + // 9 RedHat + { + in: in{ + family: "redhat", + def: ovalmodels.Definition{ + AffectedPacks: []ovalmodels.Package{ + { + Name: "a", + NotFixedYet: false, + }, + { + Name: "b", + NotFixedYet: false, + Version: "0:1.2.3-45.el6_7.8", + }, + }, + }, + req: request{ + packName: "b", + isSrcPack: false, + versionRelease: "0:1.2.3-45.el6_7.6", + NewVersionRelease: "0:1.2.3-45.el6_7.7", + }, + }, + affected: true, + notFixedYet: true, + }, + // 10 RedHat { in: in{ family: "redhat", @@ -447,6 +479,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: false, }, + // 11 RedHat { in: in{ family: "redhat", @@ -456,8 +489,7 @@ func TestIsOvalDefAffected(t *testing.T) { Name: "a", NotFixedYet: false, }, - { - Name: "b", + {Name: "b", NotFixedYet: false, Version: "0:1.2.3-45.el6_7.8", }, @@ -473,6 +505,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: false, }, + // 12 RedHat { in: in{ family: "redhat", @@ -498,6 +531,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, + // 13 RedHat { in: in{ family: "redhat", @@ -523,7 +557,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, - // CentOS + // 14 CentOS { in: in{ family: "centos", @@ -541,14 +575,16 @@ func TestIsOvalDefAffected(t *testing.T) { }, }, req: request{ - packName: "b", - isSrcPack: false, - versionRelease: "0:1.2.3-45.el6.centos.7", + packName: "b", + isSrcPack: false, + versionRelease: "0:1.2.3-45.el6.centos.7", + NewVersionRelease: "", }, }, affected: true, - notFixedYet: true, + notFixedYet: false, }, + // 15 { in: in{ family: "centos", @@ -574,6 +610,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, + // 16 { in: in{ family: "centos", @@ -599,6 +636,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, + // 17 { in: in{ family: "centos", @@ -625,6 +663,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: true, }, + // 18 { in: in{ family: "centos", @@ -651,6 +690,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: false, }, + // 19 { in: in{ family: "centos", @@ -677,6 +717,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: true, notFixedYet: false, }, + // 20 { in: in{ family: "centos", @@ -702,6 +743,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, + // 21 { in: in{ family: "centos", @@ -727,7 +769,7 @@ func TestIsOvalDefAffected(t *testing.T) { affected: false, notFixedYet: false, }, - // TODO: If vuls support Scientific, replace "centos" below to "scientific". + // 22 { in: in{ family: "centos", @@ -751,7 +793,7 @@ func TestIsOvalDefAffected(t *testing.T) { }, }, affected: true, - notFixedYet: true, + notFixedYet: false, }, { in: in{ diff --git a/report/azureblob.go b/report/azureblob.go index 788141af..5636298b 100644 --- a/report/azureblob.go +++ b/report/azureblob.go @@ -67,9 +67,9 @@ func (w AzureBlobWriter) Write(rs ...models.ScanResult) (err error) { } } - if c.Conf.FormatShortText { + if c.Conf.FormatList { k := key + "_short.txt" - b := []byte(formatShortPlainText(r)) + b := []byte(formatList(r)) if err := createBlockBlob(cli, k, b); err != nil { return err } @@ -111,19 +111,19 @@ func CheckIfAzureContainerExists() error { found := false for _, con := range r.Containers { - if con.Name == c.Conf.AzureContainer { + if con.Name == c.Conf.Azure.ContainerName { found = true break } } if !found { - return fmt.Errorf("Container not found. Container: %s", c.Conf.AzureContainer) + return fmt.Errorf("Container not found. Container: %s", c.Conf.Azure.ContainerName) } return nil } func getBlobClient() (storage.BlobStorageClient, error) { - api, err := storage.NewBasicClient(c.Conf.AzureAccount, c.Conf.AzureKey) + api, err := storage.NewBasicClient(c.Conf.Azure.AccountName, c.Conf.Azure.AccountKey) if err != nil { return storage.BlobStorageClient{}, err } @@ -139,11 +139,11 @@ func createBlockBlob(cli storage.BlobStorageClient, k string, b []byte) error { k = k + ".gz" } - ref := cli.GetContainerReference(c.Conf.AzureContainer) + ref := cli.GetContainerReference(c.Conf.Azure.ContainerName) blob := ref.GetBlobReference(k) if err := blob.CreateBlockBlobFromReader(bytes.NewReader(b), nil); err != nil { return fmt.Errorf("Failed to upload data to %s/%s, %s", - c.Conf.AzureContainer, k, err) + c.Conf.Azure.ContainerName, k, err) } return nil } diff --git a/report/cve_client.go b/report/cve_client.go index bc1eab9c..957d28ae 100644 --- a/report/cve_client.go +++ b/report/cve_client.go @@ -28,10 +28,8 @@ import ( "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/util" - cveconfig "github.com/kotakanbe/go-cve-dictionary/config" cvedb "github.com/kotakanbe/go-cve-dictionary/db" cve "github.com/kotakanbe/go-cve-dictionary/models" - log "github.com/sirupsen/logrus" ) // CveClient is api client of CVE disctionary service. @@ -43,12 +41,12 @@ type cvedictClient struct { } func (api *cvedictClient) initialize() { - api.baseURL = config.Conf.CveDBURL + api.baseURL = config.Conf.CveDict.URL } func (api cvedictClient) CheckHealth() error { if !api.isFetchViaHTTP() { - util.Log.Debugf("get cve-dictionary from %s", config.Conf.CveDBType) + util.Log.Debugf("get cve-dictionary from %s", config.Conf.CveDict.Type) return nil } @@ -70,12 +68,25 @@ type response struct { CveDetail cve.CveDetail } -func (api cvedictClient) FetchCveDetails(cveIDs []string) (cveDetails []*cve.CveDetail, err error) { +func (api cvedictClient) FetchCveDetails(driver cvedb.DB, cveIDs []string) (cveDetails []cve.CveDetail, err error) { if !api.isFetchViaHTTP() { - return api.FetchCveDetailsFromCveDB(cveIDs) + for _, cveID := range cveIDs { + cveDetail, err := driver.Get(cveID) + if err != nil { + return nil, fmt.Errorf("Failed to fetch CVE. err: %s", err) + } + if len(cveDetail.CveID) == 0 { + cveDetails = append(cveDetails, cve.CveDetail{ + CveID: cveID, + }) + } else { + cveDetails = append(cveDetails, *cveDetail) + } + } + return } - api.baseURL = config.Conf.CveDBURL + api.baseURL = config.Conf.CveDict.URL reqChan := make(chan string, len(cveIDs)) resChan := make(chan response, len(cveIDs)) errChan := make(chan error, len(cveIDs)) @@ -112,55 +123,25 @@ func (api cvedictClient) FetchCveDetails(cveIDs []string) (cveDetails []*cve.Cve select { case res := <-resChan: if len(res.CveDetail.CveID) == 0 { - cveDetails = append(cveDetails, &cve.CveDetail{ + cveDetails = append(cveDetails, cve.CveDetail{ CveID: res.Key, }) } else { - cveDetails = append(cveDetails, &res.CveDetail) + cveDetails = append(cveDetails, res.CveDetail) } case err := <-errChan: errs = append(errs, err) case <-timeout: - return []*cve.CveDetail{}, fmt.Errorf("Timeout Fetching CVE") + return nil, fmt.Errorf("Timeout Fetching CVE") } } if len(errs) != 0 { - return []*cve.CveDetail{}, + return nil, fmt.Errorf("Failed to fetch CVE. err: %v", errs) } return } -func (api cvedictClient) FetchCveDetailsFromCveDB(cveIDs []string) (cveDetails []*cve.CveDetail, err error) { - util.Log.Debugf("open cve-dictionary db (%s)", config.Conf.CveDBType) - cveconfig.Conf.DBType = config.Conf.CveDBType - if config.Conf.CveDBType == "sqlite3" { - cveconfig.Conf.DBPath = config.Conf.CveDBPath - } else { - cveconfig.Conf.DBPath = config.Conf.CveDBURL - } - cveconfig.Conf.DebugSQL = config.Conf.DebugSQL - - var driver cvedb.DB - if driver, err = cvedb.NewDB(cveconfig.Conf.DBType, cveconfig.Conf.DBPath, cveconfig.Conf.DebugSQL); err != nil { - log.Error(err) - return []*cve.CveDetail{}, fmt.Errorf("Failed to New DB. err: %s", err) - } - defer driver.CloseDB() - - for _, cveID := range cveIDs { - cveDetail := driver.Get(cveID) - if len(cveDetail.CveID) == 0 { - cveDetails = append(cveDetails, &cve.CveDetail{ - CveID: cveID, - }) - } else { - cveDetails = append(cveDetails, cveDetail) - } - } - return -} - func (api cvedictClient) httpGet(key, url string, resChan chan<- response, errChan chan<- error) { var body string var errs []error @@ -195,36 +176,30 @@ func (api cvedictClient) httpGet(key, url string, resChan chan<- response, errCh } } -type responseGetCveDetailByCpeName struct { - CpeName string - CveDetails []cve.CveDetail -} - func (api cvedictClient) isFetchViaHTTP() bool { // Default value of CveDBType is sqlite3 - if config.Conf.CveDBURL != "" && config.Conf.CveDBType == "sqlite3" { + if config.Conf.CveDict.URL != "" && config.Conf.CveDict.Type == "sqlite3" { return true } return false } -func (api cvedictClient) FetchCveDetailsByCpeName(cpeName string) ([]*cve.CveDetail, error) { +func (api cvedictClient) FetchCveDetailsByCpeName(driver cvedb.DB, cpeName string) ([]cve.CveDetail, error) { if api.isFetchViaHTTP() { - api.baseURL = config.Conf.CveDBURL + api.baseURL = config.Conf.CveDict.URL url, err := util.URLPathJoin(api.baseURL, "cpes") if err != nil { - return []*cve.CveDetail{}, err + return nil, err } query := map[string]string{"name": cpeName} util.Log.Debugf("HTTP Request to %s, query: %#v", url, query) return api.httpPost(cpeName, url, query) } - - return api.FetchCveDetailsByCpeNameFromDB(cpeName) + return driver.GetByCpeURI(cpeName) } -func (api cvedictClient) httpPost(key, url string, query map[string]string) ([]*cve.CveDetail, error) { +func (api cvedictClient) httpPost(key, url string, query map[string]string) ([]cve.CveDetail, error) { var body string var errs []error var resp *http.Response @@ -245,33 +220,13 @@ func (api cvedictClient) httpPost(key, url string, query map[string]string) ([]* } err := backoff.RetryNotify(f, backoff.NewExponentialBackOff(), notify) if err != nil { - return []*cve.CveDetail{}, fmt.Errorf("HTTP Error %s", err) + return nil, fmt.Errorf("HTTP Error %s", err) } - cveDetails := []*cve.CveDetail{} + cveDetails := []cve.CveDetail{} if err := json.Unmarshal([]byte(body), &cveDetails); err != nil { - return []*cve.CveDetail{}, + return nil, fmt.Errorf("Failed to Unmarshall. body: %s, err: %s", body, err) } return cveDetails, nil } - -func (api cvedictClient) FetchCveDetailsByCpeNameFromDB(cpeName string) (cveDetails []*cve.CveDetail, err error) { - util.Log.Debugf("open cve-dictionary db (%s)", config.Conf.CveDBType) - cveconfig.Conf.DBType = config.Conf.CveDBType - if config.Conf.CveDBType == "sqlite3" { - cveconfig.Conf.DBPath = config.Conf.CveDBPath - } else { - cveconfig.Conf.DBPath = config.Conf.CveDBURL - } - cveconfig.Conf.DebugSQL = config.Conf.DebugSQL - - var driver cvedb.DB - if driver, err = cvedb.NewDB(cveconfig.Conf.DBType, cveconfig.Conf.DBPath, cveconfig.Conf.DebugSQL); err != nil { - log.Error(err) - return []*cve.CveDetail{}, fmt.Errorf("Failed to New DB. err: %s", err) - } - - util.Log.Debugf("Opening DB (%s).", driver.Name()) - return driver.GetByCpeName(cpeName), nil -} diff --git a/report/db_client.go b/report/db_client.go new file mode 100644 index 00000000..ad7b4188 --- /dev/null +++ b/report/db_client.go @@ -0,0 +1,158 @@ +package report + +import ( + "fmt" + "os" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/util" + gostdb "github.com/knqyf263/gost/db" + cvedb "github.com/kotakanbe/go-cve-dictionary/db" + ovaldb "github.com/kotakanbe/goval-dictionary/db" +) + +// DBClient is a dictionarie's db client for reporting +type DBClient struct { + CveDB cvedb.DB + OvalDB ovaldb.DB + GostDB gostdb.DB +} + +// DBClientConf has a configuration of Vulnerability DBs +type DBClientConf struct { + CveDictCnf config.GoCveDictConf + OvalDictCnf config.GovalDictConf + GostCnf config.GostConf + DebugSQL bool +} + +func (c DBClientConf) isCveDBViaHTTP() bool { + return c.CveDictCnf.URL != "" && c.CveDictCnf.Type == "sqlite3" +} + +func (c DBClientConf) isOvalViaHTTP() bool { + return c.OvalDictCnf.URL != "" && c.OvalDictCnf.Type == "sqlite3" +} + +func (c DBClientConf) isGostViaHTTP() bool { + return c.GostCnf.URL != "" && c.GostCnf.Type == "sqlite3" +} + +// NewDBClient returns db clients +func NewDBClient(cnf DBClientConf) (dbclient *DBClient, locked bool, err error) { + cveDriver, locked, err := NewCveDB(cnf) + if err != nil { + return nil, locked, err + } + + ovaldb, locked, err := NewOvalDB(cnf) + if locked { + return nil, true, fmt.Errorf("OvalDB is locked: %s", + cnf.OvalDictCnf.SQLite3Path) + } else if err != nil { + util.Log.Warnf("Unable to use OvalDB: %s, err: %s", + cnf.OvalDictCnf.SQLite3Path, err) + } + + gostdb, locked, err := NewGostDB(cnf) + if locked { + return nil, true, fmt.Errorf("gostDB is locked: %s", + cnf.GostCnf.SQLite3Path) + } else if err != nil { + util.Log.Warnf("Unable to use gostDB: %s, err: %s", + cnf.GostCnf.SQLite3Path, err) + } + + return &DBClient{ + CveDB: cveDriver, + OvalDB: ovaldb, + GostDB: gostdb, + }, false, nil +} + +// NewCveDB returns cve db client +func NewCveDB(cnf DBClientConf) (driver cvedb.DB, locked bool, err error) { + if cnf.isCveDBViaHTTP() { + return nil, false, nil + } + util.Log.Debugf("open cve-dictionary db (%s)", cnf.CveDictCnf.Type) + path := cnf.CveDictCnf.URL + if cnf.CveDictCnf.Type == "sqlite3" { + path = cnf.CveDictCnf.SQLite3Path + } + + util.Log.Debugf("Open cve-dictionary db (%s): %s", cnf.CveDictCnf.Type, path) + driver, locked, err = cvedb.NewDB(cnf.CveDictCnf.Type, path, cnf.DebugSQL) + if err != nil { + err = fmt.Errorf("Failed to init CVE DB. err: %s, path: %s", err, path) + return nil, locked, err + } + return driver, false, nil +} + +// NewOvalDB returns oval db client +func NewOvalDB(cnf DBClientConf) (driver ovaldb.DB, locked bool, err error) { + if cnf.isOvalViaHTTP() { + return nil, false, nil + } + path := cnf.OvalDictCnf.URL + if cnf.OvalDictCnf.Type == "sqlite3" { + path = cnf.OvalDictCnf.SQLite3Path + + if _, err := os.Stat(path); os.IsNotExist(err) { + util.Log.Warnf("--ovaldb-path=%s is not found. It's recommended to use OVAL to improve scanning accuracy. For details, see https://github.com/kotakanbe/goval-dictionary#usage", path) + return nil, false, nil + } + } + + util.Log.Debugf("Open oval-dictionary db (%s): %s", cnf.OvalDictCnf.Type, path) + driver, locked, err = ovaldb.NewDB("", cnf.OvalDictCnf.Type, path, cnf.DebugSQL) + if err != nil { + err = fmt.Errorf("Failed to new OVAL DB. err: %s", err) + if locked { + return nil, true, err + } + return nil, false, err + } + return driver, false, nil +} + +// NewGostDB returns db client for Gost +func NewGostDB(cnf DBClientConf) (driver gostdb.DB, locked bool, err error) { + if cnf.isGostViaHTTP() { + return nil, false, nil + } + path := cnf.GostCnf.URL + if cnf.GostCnf.Type == "sqlite3" { + path = cnf.GostCnf.SQLite3Path + + if _, err := os.Stat(path); os.IsNotExist(err) { + util.Log.Warnf("--gostdb-path=%s is not found. If the scan target server is Debian, RHEL or CentOS, it's recommended to use gost to improve scanning accuracy. To use gost database, see https://github.com/knqyf263/gost#fetch-redhat", path) + return nil, false, nil + } + } + + util.Log.Debugf("Open gost db (%s): %s", cnf.GostCnf.Type, path) + if driver, locked, err = gostdb.NewDB(cnf.GostCnf.Type, path, cnf.DebugSQL); err != nil { + if locked { + util.Log.Errorf("gostDB is locked: %s", err) + return nil, true, err + } + return nil, false, err + } + return driver, false, nil +} + +// CloseDB close dbs +func (d DBClient) CloseDB() { + if d.CveDB != nil { + if err := d.CveDB.CloseDB(); err != nil { + util.Log.Errorf("Failed to close DB: %s", err) + } + } + if d.OvalDB != nil { + if err := d.OvalDB.CloseDB(); err != nil { + util.Log.Errorf("Failed to close DB: %s", err) + } + } +} diff --git a/report/http.go b/report/http.go new file mode 100644 index 00000000..980a3870 --- /dev/null +++ b/report/http.go @@ -0,0 +1,62 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package report + +import ( + "bytes" + "encoding/json" + "net/http" + + "github.com/pkg/errors" + + c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" +) + +// HTTPRequestWriter writes results to HTTP request +type HTTPRequestWriter struct{} + +// Write sends results as HTTP response +func (w HTTPRequestWriter) Write(rs ...models.ScanResult) (err error) { + for _, r := range rs { + b := new(bytes.Buffer) + json.NewEncoder(b).Encode(r) + _, err = http.Post(c.Conf.HTTP.URL, "application/json; charset=utf-8", b) + if err != nil { + return err + } + } + return nil +} + +// HTTPResponseWriter writes results to HTTP response +type HTTPResponseWriter struct { + Writer http.ResponseWriter +} + +// Write sends results as HTTP response +func (w HTTPResponseWriter) Write(rs ...models.ScanResult) (err error) { + res, err := json.Marshal(rs) + if err != nil { + return errors.Wrap(err, "Failed to marshal scah results") + } + w.Writer.Header().Set("Content-Type", "application/json") + _, err = w.Writer.Write(res) + + return err +} diff --git a/report/localfile.go b/report/localfile.go index 2db9a7b7..d121e885 100644 --- a/report/localfile.go +++ b/report/localfile.go @@ -72,7 +72,7 @@ func (w LocalFileWriter) Write(rs ...models.ScanResult) (err error) { } } - if c.Conf.FormatShortText { + if c.Conf.FormatList { var p string if c.Conf.Diff { p = path + "_short_diff.txt" @@ -81,7 +81,7 @@ func (w LocalFileWriter) Write(rs ...models.ScanResult) (err error) { } if err := writeFile( - p, []byte(formatShortPlainText(r)), 0600); err != nil { + p, []byte(formatList(r)), 0600); err != nil { return fmt.Errorf( "Failed to write text files. path: %s, err: %s", p, err) } @@ -131,11 +131,5 @@ func writeFile(path string, data []byte, perm os.FileMode) error { } path = path + ".gz" } - - if err := ioutil.WriteFile( - path, []byte(data), perm); err != nil { - return err - } - - return nil + return ioutil.WriteFile(path, []byte(data), perm) } diff --git a/report/report.go b/report/report.go index 78bfa74e..3a436125 100644 --- a/report/report.go +++ b/report/report.go @@ -18,13 +18,28 @@ along with this program. If not, see . package report import ( + "bytes" "fmt" + "io/ioutil" + "os" + "reflect" + "regexp" + "sort" + "strings" "time" + "github.com/BurntSushi/toml" c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/contrib/owasp-dependency-check/parser" + "github.com/future-architect/vuls/cwe" + "github.com/future-architect/vuls/gost" "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/oval" "github.com/future-architect/vuls/util" + "github.com/hashicorp/uuid" + gostdb "github.com/knqyf263/gost/db" + cvedb "github.com/kotakanbe/go-cve-dictionary/db" + ovaldb "github.com/kotakanbe/goval-dictionary/db" ) const ( @@ -33,16 +48,49 @@ const ( ) // FillCveInfos fills CVE Detailed Information -func FillCveInfos(rs []models.ScanResult, dir string) ([]models.ScanResult, error) { +func FillCveInfos(dbclient DBClient, rs []models.ScanResult, dir string) ([]models.ScanResult, error) { var filledResults []models.ScanResult reportedAt := time.Now() + hostname, _ := os.Hostname() for _, r := range rs { if c.Conf.RefreshCve || needToRefreshCve(r) { - if err := FillCveInfo(&r); err != nil { + cpeURIs := []string{} + if len(r.Container.ContainerID) == 0 { + cpeURIs = c.Conf.Servers[r.ServerName].CpeNames + owaspDCXMLPath := c.Conf.Servers[r.ServerName].OwaspDCXMLPath + if owaspDCXMLPath != "" { + cpes, err := parser.Parse(owaspDCXMLPath) + if err != nil { + return nil, fmt.Errorf("Failed to read OWASP Dependency Check XML: %s, %s, %s", + r.ServerName, owaspDCXMLPath, err) + } + cpeURIs = append(cpeURIs, cpes...) + } + } else { + if s, ok := c.Conf.Servers[r.ServerName]; ok { + if con, ok := s.Containers[r.Container.Name]; ok { + cpeURIs = con.Cpes + owaspDCXMLPath := con.OwaspDCXMLPath + if owaspDCXMLPath != "" { + cpes, err := parser.Parse(owaspDCXMLPath) + if err != nil { + return nil, fmt.Errorf("Failed to read OWASP Dependency Check XML: %s, %s, %s", + r.ServerInfo(), owaspDCXMLPath, err) + } + cpeURIs = append(cpeURIs, cpes...) + } + } + } + } + + if err := FillCveInfo(dbclient, &r, cpeURIs); err != nil { return nil, err } r.Lang = c.Conf.Lang r.ReportedAt = reportedAt + r.ReportedVersion = c.Version + r.ReportedRevision = c.Revision + r.ReportedBy = hostname r.Config.Report = c.Conf r.Config.Report.Servers = map[string]c.ServerInfo{ r.ServerName: c.Conf.Servers[r.ServerName], @@ -69,7 +117,7 @@ func FillCveInfos(rs []models.ScanResult, dir string) ([]models.ScanResult, erro } filledResults = []models.ScanResult{} for _, r := range diff { - if err := fillCveDetail(&r); err != nil { + if err := fillCveDetail(dbclient.CveDB, &r); err != nil { return nil, err } filledResults = append(filledResults, r) @@ -79,8 +127,9 @@ func FillCveInfos(rs []models.ScanResult, dir string) ([]models.ScanResult, erro filtered := []models.ScanResult{} for _, r := range filledResults { r = r.FilterByCvssOver(c.Conf.CvssScoreOver) - r = r.FilterIgnoreCves(c.Conf.Servers[r.ServerName].IgnoreCves) + r = r.FilterIgnoreCves() r = r.FilterUnfixed() + r = r.FilterIgnorePkgs() if c.Conf.IgnoreUnscoredCves { r.ScannedCves = r.ScannedCves.FindScoredVulns() } @@ -90,48 +139,73 @@ func FillCveInfos(rs []models.ScanResult, dir string) ([]models.ScanResult, erro } // FillCveInfo fill scanResult with cve info. -func FillCveInfo(r *models.ScanResult) error { +func FillCveInfo(dbclient DBClient, r *models.ScanResult, cpeURIs []string) error { util.Log.Debugf("need to refresh") - util.Log.Infof("Fill CVE detailed information with OVAL") - if err := FillWithOval(r); err != nil { - return fmt.Errorf("Failed to fill OVAL information: %s", err) + nCVEs, err := FillWithOval(dbclient.OvalDB, r) + if err != nil { + return fmt.Errorf("Failed to fill with OVAL: %s", err) } + util.Log.Infof("%s: %d CVEs are detected with OVAL", + r.FormatServerName(), nCVEs) + + for i, v := range r.ScannedCves { + for j, p := range v.AffectedPackages { + if p.NotFixedYet && p.FixState == "" { + p.FixState = "Not fixed yet" + r.ScannedCves[i].AffectedPackages[j] = p + } + } + } + + nCVEs, err = fillVulnByCpeURIs(dbclient.CveDB, r, cpeURIs) + if err != nil { + return fmt.Errorf("Failed to detect vulns of %s: %s", cpeURIs, err) + } + util.Log.Infof("%s: %d CVEs are detected with CPE", r.FormatServerName(), nCVEs) + + nCVEs, err = FillWithGost(dbclient.GostDB, r) + if err != nil { + return fmt.Errorf("Failed to fill with gost: %s", err) + } + util.Log.Infof("%s: %d unfixed CVEs are detected with gost", + r.FormatServerName(), nCVEs) util.Log.Infof("Fill CVE detailed information with CVE-DB") - if err := fillWithCveDB(r); err != nil { - return fmt.Errorf("Failed to fill CVE information: %s", err) + if err := fillCveDetail(dbclient.CveDB, r); err != nil { + return fmt.Errorf("Failed to fill with CVE: %s", err) } - for cveID := range r.ScannedCves { - vinfo := r.ScannedCves[cveID] - r.ScannedCves[cveID] = *vinfo.NilToEmpty() - } + fillCweDict(r) return nil } -// fillCveDetail fetches NVD, JVN from CVE Database, and then set to fields. -func fillCveDetail(r *models.ScanResult) error { +// fillCveDetail fetches NVD, JVN from CVE Database +func fillCveDetail(driver cvedb.DB, r *models.ScanResult) error { var cveIDs []string for _, v := range r.ScannedCves { cveIDs = append(cveIDs, v.CveID) } - ds, err := CveClient.FetchCveDetails(cveIDs) + ds, err := CveClient.FetchCveDetails(driver, cveIDs) if err != nil { return err } for _, d := range ds { - nvd := models.ConvertNvdToModel(d.CveID, d.Nvd) + nvd := models.ConvertNvdJSONToModel(d.CveID, d.NvdJSON) + if nvd == nil { + nvd = models.ConvertNvdXMLToModel(d.CveID, d.NvdXML) + } jvn := models.ConvertJvnToModel(d.CveID, d.Jvn) + for cveID, vinfo := range r.ScannedCves { if vinfo.CveID == d.CveID { if vinfo.CveContents == nil { vinfo.CveContents = models.CveContents{} } - for _, con := range []models.CveContent{*nvd, *jvn} { - if !con.Empty() { - vinfo.CveContents[con.Type] = con + for _, con := range []*models.CveContent{nvd, jvn} { + if con != nil && !con.Empty() { + vinfo.CveContents[con.Type] = *con } } r.ScannedCves[cveID] = vinfo @@ -142,23 +216,11 @@ func fillCveDetail(r *models.ScanResult) error { return nil } -func fillWithCveDB(r *models.ScanResult) error { - sInfo := c.Conf.Servers[r.ServerName] - if err := fillVulnByCpeNames(sInfo.CpeNames, r.ScannedCves); err != nil { - return err - } - if err := fillCveDetail(r); err != nil { - return err - } - return nil -} - -// FillWithOval fetches OVAL database, and then set to fields. -func FillWithOval(r *models.ScanResult) (err error) { +// FillWithOval fetches OVAL database +func FillWithOval(driver ovaldb.DB, r *models.ScanResult) (nCVEs int, err error) { var ovalClient oval.Client var ovalFamily string - // TODO switch r.Family { case c.Debian: ovalClient = oval.NewDebian() @@ -184,60 +246,367 @@ func FillWithOval(r *models.ScanResult) (err error) { ovalClient = oval.NewAlpine() ovalFamily = c.Alpine case c.Amazon, c.Raspbian, c.FreeBSD, c.Windows: - return nil + return 0, nil case c.ServerTypePseudo: - return nil + return 0, nil default: if r.Family == "" { - return fmt.Errorf("Probably an error occurred during scanning. Check the error message") + return 0, fmt.Errorf("Probably an error occurred during scanning. Check the error message") } - return fmt.Errorf("OVAL for %s is not implemented yet", r.Family) + return 0, fmt.Errorf("OVAL for %s is not implemented yet", r.Family) } - util.Log.Debugf("Check whether oval is already fetched: %s %s", + if !ovalClient.IsFetchViaHTTP() && driver == nil { + return 0, nil + } + + if err = driver.NewOvalDB(ovalFamily); err != nil { + return 0, fmt.Errorf("Failed to New Oval DB. err: %s", err) + } + + util.Log.Debugf("Check whether oval fetched: %s %s", ovalFamily, r.Release) - ok, err := ovalClient.CheckIfOvalFetched(ovalFamily, r.Release) + ok, err := ovalClient.CheckIfOvalFetched(driver, ovalFamily, r.Release) if err != nil { - return err + return 0, err } if !ok { util.Log.Warnf("OVAL entries of %s %s are not found. It's recommended to use OVAL to improve scanning accuracy. For details, see https://github.com/kotakanbe/goval-dictionary#usage , Then report with --ovaldb-path or --ovaldb-url flag", ovalFamily, r.Release) - return nil + return 0, nil } - _, err = ovalClient.CheckIfOvalFresh(ovalFamily, r.Release) + _, err = ovalClient.CheckIfOvalFresh(driver, ovalFamily, r.Release) if err != nil { - return err + return 0, err } - if err := ovalClient.FillWithOval(r); err != nil { - return err - } - return nil + return ovalClient.FillWithOval(driver, r) } -func fillVulnByCpeNames(cpeNames []string, scannedVulns models.VulnInfos) error { - for _, name := range cpeNames { - details, err := CveClient.FetchCveDetailsByCpeName(name) +// FillWithGost fills CVEs with gost dataabase +// https://github.com/knqyf263/gost +func FillWithGost(driver gostdb.DB, r *models.ScanResult) (nCVEs int, err error) { + gostClient := gost.NewClient(r.Family) + // TODO chekc if fetched + // TODO chekc if fresh enough + return gostClient.FillWithGost(driver, r) +} + +func fillVulnByCpeURIs(driver cvedb.DB, r *models.ScanResult, cpeURIs []string) (nCVEs int, err error) { + for _, name := range cpeURIs { + details, err := CveClient.FetchCveDetailsByCpeName(driver, name) if err != nil { - return err + return 0, err } for _, detail := range details { - if val, ok := scannedVulns[detail.CveID]; ok { - names := val.CpeNames + if val, ok := r.ScannedCves[detail.CveID]; ok { + names := val.CpeURIs names = util.AppendIfMissing(names, name) - val.CpeNames = names - val.Confidence = models.CpeNameMatch - scannedVulns[detail.CveID] = val + val.CpeURIs = names + val.Confidences.AppendIfMissing(models.CpeNameMatch) + r.ScannedCves[detail.CveID] = val } else { v := models.VulnInfo{ - CveID: detail.CveID, - CpeNames: []string{name}, - Confidence: models.CpeNameMatch, + CveID: detail.CveID, + CpeURIs: []string{name}, + Confidences: models.Confidences{models.CpeNameMatch}, } - scannedVulns[detail.CveID] = v + r.ScannedCves[detail.CveID] = v + nCVEs++ } } } - return nil + return nCVEs, nil +} + +func fillCweDict(r *models.ScanResult) { + uniqCweIDMap := map[string]bool{} + for _, vinfo := range r.ScannedCves { + for _, cont := range vinfo.CveContents { + for _, id := range cont.CweIDs { + if strings.HasPrefix(id, "CWE-") { + id = strings.TrimPrefix(id, "CWE-") + uniqCweIDMap[id] = true + } + } + } + } + + // TODO check the format of CWEID, clean CWEID + // JVN, NVD XML, JSON, OVALs + + dict := map[string]models.CweDictEntry{} + for id := range uniqCweIDMap { + entry := models.CweDictEntry{} + if e, ok := cwe.CweDictEn[id]; ok { + if rank, ok := cwe.OwaspTopTen2017[id]; ok { + entry.OwaspTopTen2017 = rank + } + entry.En = &e + } else { + util.Log.Debugf("CWE-ID %s is not found in English CWE Dict", id) + entry.En = &cwe.Cwe{CweID: id} + } + + if c.Conf.Lang == "ja" { + if e, ok := cwe.CweDictJa[id]; ok { + if rank, ok := cwe.OwaspTopTen2017[id]; ok { + entry.OwaspTopTen2017 = rank + } + entry.Ja = &e + } else { + util.Log.Debugf("CWE-ID %s is not found in Japanese CWE Dict", id) + entry.Ja = &cwe.Cwe{CweID: id} + } + } + dict[id] = entry + } + r.CweDict = dict + return +} + +const reUUID = "[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}" + +// EnsureUUIDs generate a new UUID of the scan target server if UUID is not assigned yet. +// And then set the generated UUID to config.toml and scan results. +func EnsureUUIDs(configPath string, results models.ScanResults) error { + // Sort Host->Container + sort.Slice(results, func(i, j int) bool { + if results[i].ServerName == results[j].ServerName { + return results[i].Container.ContainerID < results[j].Container.ContainerID + } + return results[i].ServerName < results[j].ServerName + }) + + for i, r := range results { + server := c.Conf.Servers[r.ServerName] + if server.UUIDs == nil { + server.UUIDs = map[string]string{} + } + + name := "" + if r.IsContainer() { + name = fmt.Sprintf("%s@%s", r.Container.Name, r.ServerName) + + // Scanning with the -containers-only flag at scan time, the UUID of Container Host may not be generated, + // so check it. Otherwise create a UUID of the Container Host and set it. + serverUUID := "" + if id, ok := server.UUIDs[r.ServerName]; !ok { + serverUUID = uuid.GenerateUUID() + } else { + matched, err := regexp.MatchString(reUUID, id) + if !matched || err != nil { + serverUUID = uuid.GenerateUUID() + } + } + if serverUUID != "" { + server.UUIDs[r.ServerName] = serverUUID + } + } else { + name = r.ServerName + } + + if id, ok := server.UUIDs[name]; ok { + matched, err := regexp.MatchString(reUUID, id) + if !matched || err != nil { + util.Log.Warnf("UUID is invalid. Re-generate UUID %s: %s", id, err) + } else { + if r.IsContainer() { + results[i].Container.UUID = id + results[i].ServerUUID = server.UUIDs[r.ServerName] + } else { + results[i].ServerUUID = id + } + // continue if the UUID has already assigned and valid + continue + } + } + + // Generate a new UUID and set to config and scan result + id := uuid.GenerateUUID() + server.UUIDs[name] = id + server = cleanForTOMLEncoding(server, c.Conf.Default) + c.Conf.Servers[r.ServerName] = server + + if r.IsContainer() { + results[i].Container.UUID = id + results[i].ServerUUID = server.UUIDs[r.ServerName] + } else { + results[i].ServerUUID = id + } + } + + for name, server := range c.Conf.Servers { + server = cleanForTOMLEncoding(server, c.Conf.Default) + c.Conf.Servers[name] = server + } + + email := &c.Conf.EMail + if email.SMTPAddr == "" { + email = nil + } + + slack := &c.Conf.Slack + if slack.HookURL == "" { + slack = nil + } + + cveDict := &c.Conf.CveDict + ovalDict := &c.Conf.OvalDict + gost := &c.Conf.Gost + http := &c.Conf.HTTP + if http.URL == "" { + http = nil + } + + syslog := &c.Conf.Syslog + if syslog.Host == "" { + syslog = nil + } + + aws := &c.Conf.AWS + if aws.S3Bucket == "" { + aws = nil + } + + azure := &c.Conf.Azure + if azure.AccountName == "" { + azure = nil + } + + stride := &c.Conf.Stride + if stride.HookURL == "" { + stride = nil + } + + hipChat := &c.Conf.HipChat + if hipChat.AuthToken == "" { + hipChat = nil + } + + chatWork := &c.Conf.ChatWork + if chatWork.APIToken == "" { + chatWork = nil + } + + saas := &c.Conf.Saas + if saas.GroupID == 0 { + saas = nil + } + + c := struct { + CveDict *c.GoCveDictConf `toml:"cveDict"` + OvalDict *c.GovalDictConf `toml:"ovalDict"` + Gost *c.GostConf `toml:"gost"` + Slack *c.SlackConf `toml:"slack"` + Email *c.SMTPConf `toml:"email"` + HTTP *c.HTTPConf `toml:"http"` + Syslog *c.SyslogConf `toml:"syslog"` + AWS *c.AWS `toml:"aws"` + Azure *c.Azure `toml:"azure"` + Stride *c.StrideConf `toml:"stride"` + HipChat *c.HipChatConf `toml:"hipChat"` + ChatWork *c.ChatWorkConf `toml:"chatWork"` + Saas *c.SaasConf `toml:"saas"` + + Default c.ServerInfo `toml:"default"` + Servers map[string]c.ServerInfo `toml:"servers"` + }{ + CveDict: cveDict, + OvalDict: ovalDict, + Gost: gost, + Slack: slack, + Email: email, + HTTP: http, + Syslog: syslog, + AWS: aws, + Azure: azure, + Stride: stride, + HipChat: hipChat, + ChatWork: chatWork, + Saas: saas, + + Default: c.Conf.Default, + Servers: c.Conf.Servers, + } + + // rename the current config.toml to config.toml.bak + info, err := os.Lstat(configPath) + if err != nil { + return fmt.Errorf("Failed to lstat %s: %s", configPath, err) + } + realPath := configPath + if info.Mode()&os.ModeSymlink == os.ModeSymlink { + if realPath, err = os.Readlink(configPath); err != nil { + return fmt.Errorf("Failed to Read link %s: %s", configPath, err) + } + } + if err := os.Rename(realPath, realPath+".bak"); err != nil { + return fmt.Errorf("Failed to rename %s: %s", configPath, err) + } + + var buf bytes.Buffer + if err := toml.NewEncoder(&buf).Encode(c); err != nil { + return fmt.Errorf("Failed to encode to toml: %s", err) + } + str := strings.Replace(buf.String(), "\n [", "\n\n [", -1) + str = fmt.Sprintf("%s\n\n%s", + "# See REAME for details: https://vuls.io/docs/en/usage-settings.html", + str) + + return ioutil.WriteFile(realPath, []byte(str), 0600) +} + +func cleanForTOMLEncoding(server c.ServerInfo, def c.ServerInfo) c.ServerInfo { + if reflect.DeepEqual(server.Optional, def.Optional) { + server.Optional = nil + } + + if def.User == server.User { + server.User = "" + } + + if def.Host == server.Host { + server.Host = "" + } + + if def.Port == server.Port { + server.Port = "" + } + + if def.KeyPath == server.KeyPath { + server.KeyPath = "" + } + + if reflect.DeepEqual(server.ScanMode, def.ScanMode) { + server.ScanMode = nil + } + + if def.Type == server.Type { + server.Type = "" + } + + if reflect.DeepEqual(server.CpeNames, def.CpeNames) { + server.CpeNames = nil + } + + if def.OwaspDCXMLPath == server.OwaspDCXMLPath { + server.OwaspDCXMLPath = "" + } + + if reflect.DeepEqual(server.IgnoreCves, def.IgnoreCves) { + server.IgnoreCves = nil + } + + if reflect.DeepEqual(server.Enablerepo, def.Enablerepo) { + server.Enablerepo = nil + } + + for k, v := range def.Optional { + if vv, ok := server.Optional[k]; ok && v == vv { + delete(server.Optional, k) + } + } + + return server } diff --git a/report/s3.go b/report/s3.go index 791f9753..66ba587c 100644 --- a/report/s3.go +++ b/report/s3.go @@ -41,10 +41,10 @@ type S3Writer struct{} func getS3() *s3.S3 { Config := &aws.Config{ - Region: aws.String(c.Conf.AwsRegion), + Region: aws.String(c.Conf.AWS.Region), Credentials: credentials.NewChainCredentials([]credentials.Provider{ &credentials.EnvProvider{}, - &credentials.SharedCredentialsProvider{Filename: "", Profile: c.Conf.AwsProfile}, + &credentials.SharedCredentialsProvider{Filename: "", Profile: c.Conf.AWS.Profile}, &ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())}, }), } @@ -82,9 +82,9 @@ func (w S3Writer) Write(rs ...models.ScanResult) (err error) { } } - if c.Conf.FormatShortText { + if c.Conf.FormatList { k := key + "_short.txt" - text := formatShortPlainText(r) + text := formatList(r) if err := putObject(svc, k, []byte(text)); err != nil { return err } @@ -120,12 +120,12 @@ func CheckIfBucketExists() error { if err != nil { return fmt.Errorf( "Failed to list buckets. err: %s, profile: %s, region: %s", - err, c.Conf.AwsProfile, c.Conf.AwsRegion) + err, c.Conf.AWS.Profile, c.Conf.AWS.Region) } found := false for _, bucket := range result.Buckets { - if *bucket.Name == c.Conf.S3Bucket { + if *bucket.Name == c.Conf.AWS.S3Bucket { found = true break } @@ -133,7 +133,7 @@ func CheckIfBucketExists() error { if !found { return fmt.Errorf( "Failed to find the buckets. profile: %s, region: %s, bucket: %s", - c.Conf.AwsProfile, c.Conf.AwsRegion, c.Conf.S3Bucket) + c.Conf.AWS.Profile, c.Conf.AWS.Region, c.Conf.AWS.S3Bucket) } return nil } @@ -148,18 +148,18 @@ func putObject(svc *s3.S3, k string, b []byte) error { } putObjectInput := &s3.PutObjectInput{ - Bucket: aws.String(c.Conf.S3Bucket), - Key: aws.String(path.Join(c.Conf.S3ResultsDir, k)), + Bucket: aws.String(c.Conf.AWS.S3Bucket), + Key: aws.String(path.Join(c.Conf.AWS.S3ResultsDir, k)), Body: bytes.NewReader(b), } - if c.Conf.S3ServerSideEncryption != "" { - putObjectInput.ServerSideEncryption = aws.String(c.Conf.S3ServerSideEncryption) + if c.Conf.AWS.S3ServerSideEncryption != "" { + putObjectInput.ServerSideEncryption = aws.String(c.Conf.AWS.S3ServerSideEncryption) } if _, err := svc.PutObject(putObjectInput); err != nil { return fmt.Errorf("Failed to upload data to %s/%s, %s", - c.Conf.S3Bucket, k, err) + c.Conf.AWS.S3Bucket, k, err) } return nil } diff --git a/report/saas.go b/report/saas.go new file mode 100644 index 00000000..5173f47c --- /dev/null +++ b/report/saas.go @@ -0,0 +1,153 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Corporation , Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package report + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "path" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/sts" + c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" +) + +// SaasWriter writes results to SaaS +type SaasWriter struct{} + +// TempCredential : TempCredential +type TempCredential struct { + Credential *sts.Credentials `json:"Credential"` + S3Bucket string `json:"S3Bucket"` + S3ResultsDir string `json:"S3ResultsDir"` +} + +type payload struct { + GroupID int `json:"GroupID"` + Token string `json:"Token"` +} + +// UploadSaas : UploadSaas +func (w SaasWriter) Write(rs ...models.ScanResult) (err error) { + // dir string, configPath string, config *c.Config + if len(rs) == 0 { + return nil + } + + payload := payload{ + GroupID: c.Conf.Saas.GroupID, + Token: c.Conf.Saas.Token, + } + + var body []byte + if body, err = json.Marshal(payload); err != nil { + return fmt.Errorf("Failed to Marshal to JSON: %s", err) + } + + var req *http.Request + if req, err = http.NewRequest("POST", c.Conf.Saas.URL, bytes.NewBuffer(body)); err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Accept", "application/json") + + proxy := c.Conf.HTTPProxy + var client http.Client + if proxy != "" { + proxyURL, _ := url.Parse(proxy) + client = http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyURL(proxyURL), + }, + } + } else { + client = http.Client{} + } + + var resp *http.Response + if resp, err = client.Do(req); err != nil { + return err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return fmt.Errorf("Failed to get Credential. Request JSON : %s,", string(body)) + } + + var t []byte + if t, err = ioutil.ReadAll(resp.Body); err != nil { + return err + } + + var tempCredential TempCredential + if err = json.Unmarshal(t, &tempCredential); err != nil { + return fmt.Errorf("Failed to unmarshal saas credential file. err : %s", err) + } + + credential := credentials.NewStaticCredentialsFromCreds(credentials.Value{ + AccessKeyID: *tempCredential.Credential.AccessKeyId, + SecretAccessKey: *tempCredential.Credential.SecretAccessKey, + SessionToken: *tempCredential.Credential.SessionToken, + }) + + var sess *session.Session + if sess, err = session.NewSession(&aws.Config{ + Credentials: credential, + Region: aws.String("ap-northeast-1"), + }); err != nil { + return fmt.Errorf("Failed to new aws session. err : %s", err) + } + + svc := s3.New(sess) + for _, r := range rs { + s3Key := renameKeyNameUTC(r.ScannedAt, r.ServerUUID, r.Container) + var b []byte + if b, err = json.Marshal(r); err != nil { + return fmt.Errorf("Failed to Marshal to JSON: %s", err) + } + util.Log.Infof("Uploading...: ServerName: %s, ", r.ServerName) + putObjectInput := &s3.PutObjectInput{ + Bucket: aws.String(tempCredential.S3Bucket), + Key: aws.String(path.Join(tempCredential.S3ResultsDir, s3Key)), + Body: bytes.NewReader(b), + } + + if _, err := svc.PutObject(putObjectInput); err != nil { + return fmt.Errorf("Failed to upload data to %s/%s, %s", + tempCredential.S3Bucket, s3Key, err) + } + } + return nil +} + +func renameKeyNameUTC(scannedAt time.Time, uuid string, container models.Container) string { + timestr := scannedAt.UTC().Format(time.RFC3339) + if len(container.ContainerID) == 0 { + return fmt.Sprintf("%s/%s.json", timestr, uuid) + } + return fmt.Sprintf("%s/%s@%s.json", timestr, container.UUID, uuid) +} diff --git a/report/slack.go b/report/slack.go index fb664aa9..a6e891ad 100644 --- a/report/slack.go +++ b/report/slack.go @@ -177,18 +177,20 @@ func msgText(r models.ScanResult) string { serverInfo := fmt.Sprintf("*%s*", r.ServerInfo()) if 0 < len(r.Errors) { - return fmt.Sprintf("%s\n%s\n%s\n%s\nError: %s", + return fmt.Sprintf("%s\n%s\n%s\n%s\n%s\nError: %s", notifyUsers, serverInfo, r.ScannedCves.FormatCveSummary(), - r.Packages.FormatUpdatablePacksSummary(), + r.ScannedCves.FormatFixedStatus(r.Packages), + r.FormatUpdatablePacksSummary(), r.Errors) } - return fmt.Sprintf("%s\n%s\n%s\n%s", + return fmt.Sprintf("%s\n%s\n%s\n%s\n%s", notifyUsers, serverInfo, r.ScannedCves.FormatCveSummary(), - r.Packages.FormatUpdatablePacksSummary()) + r.ScannedCves.FormatFixedStatus(r.Packages), + r.FormatUpdatablePacksSummary()) } func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) { @@ -203,7 +205,7 @@ func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) { curent = append(curent, affected.Name) } } - for _, n := range vinfo.CpeNames { + for _, n := range vinfo.CpeURIs { curent = append(curent, n) } @@ -219,14 +221,14 @@ func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) { new = append(new, "?") } } - for range vinfo.CpeNames { + for range vinfo.CpeURIs { new = append(new, "?") } a := slack.Attachment{ Title: vinfo.CveID, TitleLink: "https://nvd.nist.gov/vuln/detail/" + vinfo.CveID, - Text: attachmentText(vinfo, r.Family), + Text: attachmentText(vinfo, r.Family, r.CweDict, r.Packages), MarkdownIn: []string{"text", "pretext"}, Fields: []slack.AttachmentField{ { @@ -241,7 +243,7 @@ func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) { Short: true, }, }, - Color: color(vinfo.MaxCvssScore().Value.Score), + Color: cvssColor(vinfo.MaxCvssScore().Value.Score), } attaches = append(attaches, a) } @@ -249,7 +251,7 @@ func toSlackAttachments(r models.ScanResult) (attaches []slack.Attachment) { } // https://api.slack.com/docs/attachments -func color(cvssScore float64) string { +func cvssColor(cvssScore float64) string { switch { case 7 <= cvssScore: return "danger" @@ -262,10 +264,15 @@ func color(cvssScore float64) string { } } -func attachmentText(vinfo models.VulnInfo, osFamily string) string { +func attachmentText(vinfo models.VulnInfo, osFamily string, cweDict map[string]models.CweDictEntry, packs models.Packages) string { maxCvss := vinfo.MaxCvssScore() vectors := []string{} - for _, cvss := range vinfo.Cvss2Scores() { + + scores := append(vinfo.Cvss3Scores(), vinfo.Cvss2Scores(osFamily)...) + for _, cvss := range scores { + if cvss.Value.Severity == "" { + continue + } calcURL := "" switch cvss.Value.Type { case models.CVSS2: @@ -279,9 +286,10 @@ func attachmentText(vinfo models.VulnInfo, osFamily string) string { } if cont, ok := vinfo.CveContents[cvss.Type]; ok { - v := fmt.Sprintf("<%s|%s> (<%s|%s>)", + v := fmt.Sprintf("<%s|%s> %s (<%s|%s>)", calcURL, - cvss.Value.Format(), + fmt.Sprintf("%3.1f/%s", cvss.Value.Score, cvss.Value.Vector), + cvss.Value.Severity, cont.SourceLink, cvss.Type) vectors = append(vectors, v) @@ -294,9 +302,10 @@ func attachmentText(vinfo models.VulnInfo, osFamily string) string { v, k)) } - v := fmt.Sprintf("<%s|%s> (%s)", + v := fmt.Sprintf("<%s|%s> %s (%s)", calcURL, - cvss.Value.Format(), + fmt.Sprintf("%3.1f/%s", cvss.Value.Score, cvss.Value.Vector), + cvss.Value.Severity, strings.Join(links, ", ")) vectors = append(vectors, v) } @@ -308,27 +317,42 @@ func attachmentText(vinfo models.VulnInfo, osFamily string) string { severity = "?" } - return fmt.Sprintf("*%4.1f (%s)* %s\n%s\n```%s```", + nwvec := vinfo.AttackVector() + if nwvec == "Network" || nwvec == "remote" { + nwvec = fmt.Sprintf("*%s*", nwvec) + } + + mitigation := "" + if vinfo.Mitigations(osFamily)[0].Type != models.Unknown { + mitigation = fmt.Sprintf("\nMitigation:\n```%s```\n", + vinfo.Mitigations(osFamily)[0].Value) + } + + return fmt.Sprintf("*%4.1f (%s)* %s %s\n%s\n```\n%s\n```%s\n%s\n", maxCvss.Value.Score, severity, - cweIDs(vinfo, osFamily), + nwvec, + vinfo.PatchStatus(packs), strings.Join(vectors, "\n"), vinfo.Summaries(config.Conf.Lang, osFamily)[0].Value, + mitigation, + cweIDs(vinfo, osFamily, cweDict), ) } -func cweIDs(vinfo models.VulnInfo, osFamily string) string { +func cweIDs(vinfo models.VulnInfo, osFamily string, cweDict models.CweDict) string { links := []string{} - for _, cwe := range vinfo.CveContents.CweIDs(osFamily) { - if config.Conf.Lang == "ja" { - links = append(links, fmt.Sprintf("<%s|%s>", - cweJvnURL(cwe.Value), cwe.Value)) - } else { - links = append(links, fmt.Sprintf("<%s|%s>", - cweURL(cwe.Value), cwe.Value)) + for _, c := range vinfo.CveContents.UniqCweIDs(osFamily) { + name, url, top10Rank, top10URL := cweDict.Get(c.Value, osFamily) + line := "" + if top10Rank != "" { + line = fmt.Sprintf("<%s|[OWASP Top %s]>", + top10URL, top10Rank) } + links = append(links, fmt.Sprintf("%s <%s|%s>: %s", + line, url, c.Value, name)) } - return strings.Join(links, " / ") + return strings.Join(links, "\n") } // See testcase diff --git a/report/stdout.go b/report/stdout.go index c66d5934..8cf90e7b 100644 --- a/report/stdout.go +++ b/report/stdout.go @@ -44,9 +44,9 @@ func (w StdoutWriter) Write(rs ...models.ScanResult) error { fmt.Print("\n") } - if c.Conf.FormatShortText { + if c.Conf.FormatList { for _, r := range rs { - fmt.Println(formatShortPlainText(r)) + fmt.Println(formatList(r)) } } diff --git a/report/syslog.go b/report/syslog.go index b762cb8e..1d32924d 100644 --- a/report/syslog.go +++ b/report/syslog.go @@ -76,7 +76,7 @@ func (w SyslogWriter) encodeSyslog(result models.ScanResult) (messages []string) kvPairs = append(kvPairs, fmt.Sprintf(`packages="%s"`, pkgs)) kvPairs = append(kvPairs, fmt.Sprintf(`cve_id="%s"`, cveID)) - for _, cvss := range vinfo.Cvss2Scores() { + for _, cvss := range vinfo.Cvss2Scores(result.Family) { kvPairs = append(kvPairs, fmt.Sprintf(`cvss_score_%s_v2="%.2f"`, cvss.Type, cvss.Value.Score)) kvPairs = append(kvPairs, fmt.Sprintf(`cvss_vector_%s_v2="%s"`, cvss.Type, cvss.Value.Vector)) } @@ -86,8 +86,9 @@ func (w SyslogWriter) encodeSyslog(result models.ScanResult) (messages []string) kvPairs = append(kvPairs, fmt.Sprintf(`cvss_vector_%s_v3="%s"`, cvss.Type, cvss.Value.Vector)) } - if content, ok := vinfo.CveContents[models.NVD]; ok { - kvPairs = append(kvPairs, fmt.Sprintf(`cwe_id="%s"`, content.CweID)) + if content, ok := vinfo.CveContents[models.NvdXML]; ok { + cwes := strings.Join(content.CweIDs, ",") + kvPairs = append(kvPairs, fmt.Sprintf(`cwe_ids="%s"`, cwes)) if config.Conf.Syslog.Verbose { kvPairs = append(kvPairs, fmt.Sprintf(`source_link="%s"`, content.SourceLink)) kvPairs = append(kvPairs, fmt.Sprintf(`summary="%s"`, content.Summary)) diff --git a/report/syslog_test.go b/report/syslog_test.go index e0076c0e..40cc9fc6 100644 --- a/report/syslog_test.go +++ b/report/syslog_test.go @@ -33,10 +33,11 @@ func TestSyslogWriterEncodeSyslog(t *testing.T) { models.PackageStatus{Name: "pkg4"}, }, CveContents: models.CveContents{ - models.NVD: models.CveContent{ - Cvss2Score: 5.0, - Cvss2Vector: "AV:L/AC:L/Au:N/C:N/I:N/A:C", - CweID: "CWE-20", + models.NvdXML: models.CveContent{ + Cvss2Score: 5.0, + Cvss2Vector: "AV:L/AC:L/Au:N/C:N/I:N/A:C", + Cvss2Severity: "MEDIUM", + CweIDs: []string{"CWE-20"}, }, }, }, @@ -44,7 +45,7 @@ func TestSyslogWriterEncodeSyslog(t *testing.T) { }, expectedMessages: []string{ `scanned_at="2018-06-13 16:10:00 +0000 UTC" server_name="teste01" os_family="ubuntu" os_release="16.04" ipv4_addr="192.168.0.1,10.0.2.15" ipv6_addr="" packages="pkg1,pkg2" cve_id="CVE-2017-0001"`, - `scanned_at="2018-06-13 16:10:00 +0000 UTC" server_name="teste01" os_family="ubuntu" os_release="16.04" ipv4_addr="192.168.0.1,10.0.2.15" ipv6_addr="" packages="pkg3,pkg4" cve_id="CVE-2017-0002" cvss_score_nvd_v2="5.00" cvss_vector_nvd_v2="AV:L/AC:L/Au:N/C:N/I:N/A:C" cwe_id="CWE-20"`, + `scanned_at="2018-06-13 16:10:00 +0000 UTC" server_name="teste01" os_family="ubuntu" os_release="16.04" ipv4_addr="192.168.0.1,10.0.2.15" ipv6_addr="" packages="pkg3,pkg4" cve_id="CVE-2017-0002" cvss_score_nvdxml_v2="5.00" cvss_vector_nvdxml_v2="AV:L/AC:L/Au:N/C:N/I:N/A:C" cwe_ids="CWE-20"`, }, }, { @@ -63,7 +64,7 @@ func TestSyslogWriterEncodeSyslog(t *testing.T) { models.RedHat: models.CveContent{ Cvss3Score: 5.0, Cvss3Vector: "AV:L/AC:L/Au:N/C:N/I:N/A:C", - CweID: "CWE-284", + CweIDs: []string{"CWE-284"}, Title: "RHSA-2017:0001: pkg5 security update (Important)", }, }, @@ -103,7 +104,7 @@ func TestSyslogWriterEncodeSyslog(t *testing.T) { for j, m := range messages { e := tt.expectedMessages[j] if e != m { - t.Errorf("test: %d, Messsage %d: expected %s, actual %s", i, j, e, m) + t.Errorf("test: %d, Messsage %d: \nexpected %s \nactual %s", i, j, e, m) } } } diff --git a/report/tui.go b/report/tui.go index f4498e45..2412f2b8 100644 --- a/report/tui.go +++ b/report/tui.go @@ -32,7 +32,6 @@ import ( "github.com/google/subcommands" "github.com/gosuri/uitable" "github.com/jroimartin/gocui" - log "github.com/sirupsen/logrus" ) var scanResults models.ScanResults @@ -55,7 +54,7 @@ func RunTui(results models.ScanResults) subcommands.ExitStatus { // g, err := gocui.NewGui(gocui.OutputNormal) g := gocui.NewGui() if err := g.Init(); err != nil { - log.Errorf("%s", err) + util.Log.Errorf("%s", err) return subcommands.ExitFailure } defer g.Close() @@ -63,7 +62,7 @@ func RunTui(results models.ScanResults) subcommands.ExitStatus { g.SetLayout(layout) // g.SetManagerFunc(layout) if err := keybindings(g); err != nil { - log.Errorf("%s", err) + util.Log.Errorf("%s", err) return subcommands.ExitFailure } g.SelBgColor = gocui.ColorGreen @@ -72,7 +71,7 @@ func RunTui(results models.ScanResults) subcommands.ExitStatus { if err := g.MainLoop(); err != nil { g.Close() - log.Errorf("%s", err) + util.Log.Errorf("%s", err) os.Exit(1) } return subcommands.ExitSuccess @@ -468,10 +467,7 @@ func changeHost(g *gocui.Gui, v *gocui.View) error { if err := setDetailLayout(g); err != nil { return err } - if err := setChangelogLayout(g); err != nil { - return err - } - return nil + return setChangelogLayout(g) } func redrawDetail(g *gocui.Gui) error { @@ -479,10 +475,7 @@ func redrawDetail(g *gocui.Gui) error { return err } - if err := setDetailLayout(g); err != nil { - return err - } - return nil + return setDetailLayout(g) } func redrawChangelog(g *gocui.Gui) error { @@ -490,10 +483,7 @@ func redrawChangelog(g *gocui.Gui) error { return err } - if err := setChangelogLayout(g); err != nil { - return err - } - return nil + return setChangelogLayout(g) } func getLine(g *gocui.Gui, v *gocui.View) error { @@ -545,10 +535,7 @@ func delMsg(g *gocui.Gui, v *gocui.View) error { if err := g.DeleteView("msg"); err != nil { return err } - if err := g.SetCurrentView("summary"); err != nil { - return err - } - return nil + return g.SetCurrentView("summary") } func quit(g *gocui.Gui, v *gocui.View) error { @@ -565,11 +552,7 @@ func layout(g *gocui.Gui) error { if err := setDetailLayout(g); err != nil { return err } - if err := setChangelogLayout(g); err != nil { - return err - } - - return nil + return setChangelogLayout(g) } func debug(g *gocui.Gui, str string) error { @@ -615,7 +598,7 @@ func setSummaryLayout(g *gocui.Gui) error { return err } - lines := summaryLines() + lines := summaryLines(currentScanResult) fmt.Fprintf(v, lines) v.Highlight = true @@ -625,37 +608,42 @@ func setSummaryLayout(g *gocui.Gui) error { return nil } -func summaryLines() string { +func summaryLines(r models.ScanResult) string { stable := uitable.New() stable.MaxColWidth = 1000 stable.Wrap = false - if len(currentScanResult.Errors) != 0 { + if len(r.Errors) != 0 { return "Error: Scan with --debug to view the details" } indexFormat := "" - if len(currentScanResult.ScannedCves) < 10 { + if len(r.ScannedCves) < 10 { indexFormat = "[%1d]" - } else if len(currentScanResult.ScannedCves) < 100 { + } else if len(r.ScannedCves) < 100 { indexFormat = "[%2d]" } else { indexFormat = "[%3d]" } - for i, vinfo := range vinfos { - summary := vinfo.Titles( - config.Conf.Lang, currentScanResult.Family)[0].Value - cvssScore := fmt.Sprintf("| %4.1f", - vinfo.MaxCvssScore().Value.Score) + for i, vinfo := range r.ScannedCves.ToSortedSlice() { + max := vinfo.MaxCvssScore().Value.Score + cvssScore := "| " + if 0 < max { + cvssScore = fmt.Sprintf("| %4.1f", max) + } + + packname := vinfo.AffectedPackages.FormatTuiSummary() + packname += strings.Join(vinfo.CpeURIs, ", ") var cols []string cols = []string{ fmt.Sprintf(indexFormat, i+1), vinfo.CveID, - cvssScore, - fmt.Sprintf("| %3d |", vinfo.Confidence.Score), - summary, + cvssScore + " |", + fmt.Sprintf("%8s |", vinfo.AttackVector()), + fmt.Sprintf("%7s |", vinfo.PatchStatus(r.Packages)), + packname, } icols := make([]interface{}, len(cols)) for j := range cols { @@ -695,16 +683,12 @@ func setDetailLayout(g *gocui.Gui) error { } func setChangelogLayout(g *gocui.Gui) error { - maxX, maxY := g.Size() - summaryView, err := g.View("summary") if err != nil { return err } - _, cy := summaryView.Cursor() - _, oy := summaryView.Origin() - currentVinfo = cy + oy + maxX, maxY := g.Size() if v, err := g.SetView("changelog", int(float64(maxX)*0.5), int(float64(maxY)*0.2), maxX, maxY); err != nil { if err != gocui.ErrUnknownView { return err @@ -713,17 +697,56 @@ func setChangelogLayout(g *gocui.Gui) error { return nil } - lines := []string{} + lines := []string{ + "Affected Packages, Processes", + "============================", + } + + _, cy := summaryView.Cursor() + _, oy := summaryView.Origin() + currentVinfo = cy + oy vinfo := vinfos[currentVinfo] + vinfo.AffectedPackages.Sort() + for _, affected := range vinfo.AffectedPackages { + // packages detected by OVAL may not be actually installed + if pack, ok := currentScanResult.Packages[affected.Name]; ok { + lines = append(lines, + "* "+pack.FormatVersionFromTo( + affected.NotFixedYet, affected.FixState)) + + if len(pack.AffectedProcs) != 0 { + for _, p := range pack.AffectedProcs { + lines = append(lines, fmt.Sprintf(" * PID: %s %s", p.PID, p.Name)) + } + } else { + // lines = append(lines, fmt.Sprintf(" * No affected process")) + } + } + } + sort.Strings(vinfo.CpeURIs) + for _, uri := range vinfo.CpeURIs { + lines = append(lines, "* "+uri) + } + for _, adv := range vinfo.DistroAdvisories { + lines = append(lines, "\n", + "Advisories", + "==========", + ) lines = append(lines, adv.Format()) } - for _, affected := range vinfo.AffectedPackages { - pack := currentScanResult.Packages[affected.Name] - for _, p := range currentScanResult.Packages { - if pack.Name == p.Name { - lines = append(lines, p.FormatChangelog(), "\n") + if currentScanResult.IsDeepScanMode() { + lines = append(lines, "\n", + "ChangeLogs", + "==========", + ) + for _, affected := range vinfo.AffectedPackages { + pack := currentScanResult.Packages[affected.Name] + for _, p := range currentScanResult.Packages { + if pack.Name == p.Name { + lines = append(lines, p.FormatChangelog(), "\n") + } } } } @@ -741,12 +764,13 @@ type dataForTmpl struct { CveID string Cvsses string Summary string - Confidence models.Confidence - Cwes []models.CveContentStr + Mitigation string + Confidences models.Confidences + Cwes []models.CweDictEntry Links []string References []models.Reference Packages []string - CpeNames []string + CpeURIs []string PublishedDate time.Time LastModifiedDate time.Time } @@ -767,20 +791,6 @@ func detailLines() (string, error) { } vinfo := vinfos[currentVinfo] - - packsVer := []string{} - vinfo.AffectedPackages.Sort() - for _, affected := range vinfo.AffectedPackages { - // packages detected by OVAL may not be actually installed - if pack, ok := r.Packages[affected.Name]; ok { - packsVer = append(packsVer, pack.FormatVersionFromTo(affected.NotFixedYet)) - } - } - sort.Strings(vinfo.CpeNames) - for _, name := range vinfo.CpeNames { - packsVer = append(packsVer, name) - } - links := []string{vinfo.CveContents.SourceLinks( config.Conf.Lang, r.Family, vinfo.CveID)[0].Value, vinfo.Cvss2CalcURL(), @@ -792,35 +802,57 @@ func detailLines() (string, error) { refs := []models.Reference{} for _, rr := range vinfo.CveContents.References(r.Family) { for _, ref := range rr.Value { + if ref.Source == "" { + ref.Source = "-" + } refs = append(refs, ref) } } summary := vinfo.Summaries(r.Lang, r.Family)[0] + mitigation := vinfo.Mitigations(r.Family)[0] table := uitable.New() table.MaxColWidth = maxColWidth table.Wrap = true - scores := append(vinfo.Cvss3Scores(), vinfo.Cvss2Scores()...) + scores := append(vinfo.Cvss3Scores(), vinfo.Cvss2Scores(r.Family)...) var cols []interface{} for _, score := range scores { + if score.Value.Score == 0 && score.Value.Severity == "" { + continue + } + scoreStr := "-" + if 0 < score.Value.Score { + scoreStr = fmt.Sprintf("%3.1f", score.Value.Score) + } + scoreVec := fmt.Sprintf("%s/%s", scoreStr, score.Value.Vector) cols = []interface{}{ + scoreVec, score.Value.Severity, - score.Value.Format(), score.Type, } table.AddRow(cols...) } + uniqCweIDs := vinfo.CveContents.UniqCweIDs(r.Family) + cwes := []models.CweDictEntry{} + for _, cweID := range uniqCweIDs { + if strings.HasPrefix(cweID.Value, "CWE-") { + if dict, ok := r.CweDict[strings.TrimPrefix(cweID.Value, "CWE-")]; ok { + cwes = append(cwes, dict) + } + } + } + data := dataForTmpl{ - CveID: vinfo.CveID, - Cvsses: fmt.Sprintf("%s\n", table), - Summary: fmt.Sprintf("%s (%s)", summary.Value, summary.Type), - Confidence: vinfo.Confidence, - Cwes: vinfo.CveContents.CweIDs(r.Family), - Links: util.Distinct(links), - Packages: packsVer, - References: refs, + CveID: vinfo.CveID, + Cvsses: fmt.Sprintf("%s\n", table), + Summary: fmt.Sprintf("%s (%s)", summary.Value, summary.Type), + Mitigation: fmt.Sprintf("%s (%s)", mitigation.Value, mitigation.Type), + Confidences: vinfo.Confidences, + Cwes: cwes, + Links: util.Distinct(links), + References: refs, } buf := bytes.NewBuffer(nil) // create empty buffer @@ -833,47 +865,41 @@ func detailLines() (string, error) { const mdTemplate = ` {{.CveID}} -============== +================ CVSS Scores --------------- +----------- {{.Cvsses }} - Summary --------------- +----------- {{.Summary }} +Mitigation +----------- + {{.Mitigation }} Links --------------- +----------- {{range $link := .Links -}} * {{$link}} {{end}} - CWE --------------- +----------- {{range .Cwes -}} -* {{.Value}} ({{.Type}}) +* {{.En.CweID}} [{{.En.Name}}](https://cwe.mitre.org/data/definitions/{{.En.CweID}}.html) {{end}} - -Package/CPE --------------- -{{range $pack := .Packages -}} -* {{$pack}} -{{end -}} -{{range $name := .CpeNames -}} +{{range $name := .CpeURIs -}} * {{$name}} {{end}} - Confidence --------------- - {{.Confidence }} - - +----------- +{{range $confidence := .Confidences -}} +* {{$confidence.DetectionMethod}} +{{end}} References --------------- +----------- {{range .References -}} -* [{{.Source}}]( {{.Link}} ) +* [{{.Source}}]({{.Link}}) {{end}} ` diff --git a/report/util.go b/report/util.go index dfc27ff7..954f98cb 100644 --- a/report/util.go +++ b/report/util.go @@ -18,6 +18,7 @@ along with this program. If not, see . package report import ( + "bytes" "encoding/json" "fmt" "io/ioutil" @@ -33,9 +34,10 @@ import ( "github.com/future-architect/vuls/models" "github.com/future-architect/vuls/util" "github.com/gosuri/uitable" + "github.com/olekukonko/tablewriter" ) -const maxColWidth = 80 +const maxColWidth = 100 func formatScanSummary(rs ...models.ScanResult) string { table := uitable.New() @@ -47,7 +49,7 @@ func formatScanSummary(rs ...models.ScanResult) string { cols = []interface{}{ r.FormatServerName(), fmt.Sprintf("%s%s", r.Family, r.Release), - r.Packages.FormatUpdatablePacksSummary(), + r.FormatUpdatablePacksSummary(), } } else { cols = []interface{}{ @@ -72,7 +74,8 @@ func formatOneLineSummary(rs ...models.ScanResult) string { cols = []interface{}{ r.FormatServerName(), r.ScannedCves.FormatCveSummary(), - r.Packages.FormatUpdatablePacksSummary(), + r.ScannedCves.FormatFixedStatus(r.Packages), + r.FormatUpdatablePacksSummary(), } } else { cols = []interface{}{ @@ -86,7 +89,7 @@ func formatOneLineSummary(rs ...models.ScanResult) string { return fmt.Sprintf("%s\n", table) } -func formatShortPlainText(r models.ScanResult) string { +func formatList(r models.ScanResult) string { header := r.FormatTextReportHeadedr() if len(r.Errors) != 0 { return fmt.Sprintf( @@ -99,63 +102,49 @@ func formatShortPlainText(r models.ScanResult) string { %s No CVE-IDs are found in updatable packages. %s - `, header, r.Packages.FormatUpdatablePacksSummary()) + `, header, r.FormatUpdatablePacksSummary()) } - stable := uitable.New() - stable.MaxColWidth = maxColWidth - stable.Wrap = true - for _, vuln := range r.ScannedCves.ToSortedSlice() { - summaries := vuln.Summaries(config.Conf.Lang, r.Family) - links := vuln.CveContents.SourceLinks( - config.Conf.Lang, r.Family, vuln.CveID) + data := [][]string{} + for _, vinfo := range r.ScannedCves.ToSortedSlice() { + max := vinfo.MaxCvssScore().Value.Score + // v2max := vinfo.MaxCvss2Score().Value.Score + // v3max := vinfo.MaxCvss3Score().Value.Score - vlinks := []string{} - for name, url := range vuln.VendorLinks(r.Family) { - vlinks = append(vlinks, fmt.Sprintf("%s (%s)", url, name)) - } + // packname := vinfo.AffectedPackages.FormatTuiSummary() + // packname += strings.Join(vinfo.CpeURIs, ", ") - cvsses := "" - for _, cvss := range vuln.Cvss2Scores() { - cvsses += fmt.Sprintf("%s (%s)\n", cvss.Value.Format(), cvss.Type) - } - cvsses += vuln.Cvss2CalcURL() + "\n" - for _, cvss := range vuln.Cvss3Scores() { - cvsses += fmt.Sprintf("%s (%s)\n", cvss.Value.Format(), cvss.Type) - } - if 0 < len(vuln.Cvss3Scores()) { - cvsses += vuln.Cvss3CalcURL() + "\n" - } - - maxCvss := vuln.FormatMaxCvssScore() - rightCol := fmt.Sprintf(`%s -%s ---- -%s -%s -%sConfidence: %v`, - maxCvss, - summaries[0].Value, - links[0].Value, - strings.Join(vlinks, "\n"), - cvsses, - // packsVer, - vuln.Confidence, - ) - - leftCol := fmt.Sprintf("%s", vuln.CveID) - scols := []string{leftCol, rightCol} - cols := make([]interface{}, len(scols)) - for i := range cols { - cols[i] = scols[i] - } - stable.AddRow(cols...) - stable.AddRow("") + data = append(data, []string{ + vinfo.CveID, + fmt.Sprintf("%4.1f", max), + // fmt.Sprintf("%4.1f", v2max), + // fmt.Sprintf("%4.1f", v3max), + fmt.Sprintf("%8s", vinfo.AttackVector()), + fmt.Sprintf("%7s", vinfo.PatchStatus(r.Packages)), + // packname, + fmt.Sprintf("https://nvd.nist.gov/vuln/detail/%s", vinfo.CveID), + }) } - return fmt.Sprintf("%s\n%s\n", header, stable) + + b := bytes.Buffer{} + table := tablewriter.NewWriter(&b) + table.SetHeader([]string{ + "CVE-ID", + "CVSS", + // "v3", + // "v2", + "Attack", + "Fixed", + // "Pkg", + "NVD", + }) + table.SetBorder(true) + table.AppendBulk(data) + table.Render() + return fmt.Sprintf("%s\n%s", header, b.String()) } -func formatFullPlainText(r models.ScanResult) string { +func formatFullPlainText(r models.ScanResult) (lines string) { header := r.FormatTextReportHeadedr() if len(r.Errors) != 0 { return fmt.Sprintf( @@ -168,62 +157,117 @@ func formatFullPlainText(r models.ScanResult) string { %s No CVE-IDs are found in updatable packages. %s - `, header, r.Packages.FormatUpdatablePacksSummary()) + `, header, r.FormatUpdatablePacksSummary()) } - table := uitable.New() - table.MaxColWidth = maxColWidth - table.Wrap = true + lines = header + "\n" + for _, vuln := range r.ScannedCves.ToSortedSlice() { - table.AddRow(vuln.CveID) - table.AddRow("----------------") - table.AddRow("Max Score", vuln.FormatMaxCvssScore()) - for _, cvss := range vuln.Cvss2Scores() { - table.AddRow(cvss.Type, cvss.Value.Format()) - } + data := [][]string{} + data = append(data, []string{"Max Score", vuln.FormatMaxCvssScore()}) for _, cvss := range vuln.Cvss3Scores() { - table.AddRow(cvss.Type, cvss.Value.Format()) - } - if 0 < len(vuln.Cvss2Scores()) { - table.AddRow("CVSSv2 Calc", vuln.Cvss2CalcURL()) - } - if 0 < len(vuln.Cvss3Scores()) { - table.AddRow("CVSSv3 Calc", vuln.Cvss3CalcURL()) - } - table.AddRow("Summary", vuln.Summaries( - config.Conf.Lang, r.Family)[0].Value) - - links := vuln.CveContents.SourceLinks( - config.Conf.Lang, r.Family, vuln.CveID) - table.AddRow("Source", links[0].Value) - - vlinks := vuln.VendorLinks(r.Family) - for name, url := range vlinks { - table.AddRow(name, url) + if cvssstr := cvss.Value.Format(); cvssstr != "" { + data = append(data, []string{string(cvss.Type), cvssstr}) + } } - for _, v := range vuln.CveContents.CweIDs(r.Family) { - table.AddRow(fmt.Sprintf("%s (%s)", v.Value, v.Type), cweURL(v.Value)) + for _, cvss := range vuln.Cvss2Scores(r.Family) { + if cvssstr := cvss.Value.Format(); cvssstr != "" { + data = append(data, []string{string(cvss.Type), cvssstr}) + } + } + + data = append(data, []string{"Summary", vuln.Summaries( + config.Conf.Lang, r.Family)[0].Value}) + + mitigation := vuln.Mitigations(r.Family)[0] + if mitigation.Type != models.Unknown { + data = append(data, []string{"Mitigation", mitigation.Value}) + } + + cweURLs, top10URLs := []string{}, []string{} + for _, v := range vuln.CveContents.UniqCweIDs(r.Family) { + name, url, top10Rank, top10URL := r.CweDict.Get(v.Value, r.Lang) + if top10Rank != "" { + data = append(data, []string{"CWE", + fmt.Sprintf("[OWASP Top%s] %s: %s (%s)", + top10Rank, v.Value, name, v.Type)}) + top10URLs = append(top10URLs, top10URL) + } else { + data = append(data, []string{"CWE", fmt.Sprintf("%s: %s (%s)", + v.Value, name, v.Type)}) + } + cweURLs = append(cweURLs, url) } - packsVer := []string{} vuln.AffectedPackages.Sort() for _, affected := range vuln.AffectedPackages { if pack, ok := r.Packages[affected.Name]; ok { - packsVer = append(packsVer, pack.FormatVersionFromTo(affected.NotFixedYet)) + data = append(data, []string{"Affected PKG", + pack.FormatVersionFromTo(affected.NotFixedYet, affected.FixState)}) + if len(pack.AffectedProcs) != 0 { + for _, p := range pack.AffectedProcs { + data = append(data, []string{"", + fmt.Sprintf(" - PID: %s %s", p.PID, p.Name)}) + } + } } } - sort.Strings(vuln.CpeNames) - for _, name := range vuln.CpeNames { - packsVer = append(packsVer, name) + sort.Strings(vuln.CpeURIs) + for _, name := range vuln.CpeURIs { + data = append(data, []string{"CPE", name}) } - table.AddRow("Package/CPE", strings.Join(packsVer, "\n")) - table.AddRow("Confidence", vuln.Confidence) - table.AddRow("\n") + for _, confidence := range vuln.Confidences { + data = append(data, []string{"Confidence", confidence.String()}) + } + + links := vuln.CveContents.SourceLinks( + config.Conf.Lang, r.Family, vuln.CveID) + data = append(data, []string{"Source", links[0].Value}) + + if 0 < len(vuln.Cvss2Scores(r.Family)) { + data = append(data, []string{"CVSSv2 Calc", vuln.Cvss2CalcURL()}) + } + if 0 < len(vuln.Cvss3Scores()) { + data = append(data, []string{"CVSSv3 Calc", vuln.Cvss3CalcURL()}) + } + + vlinks := vuln.VendorLinks(r.Family) + for name, url := range vlinks { + data = append(data, []string{name, url}) + } + for _, url := range cweURLs { + data = append(data, []string{"CWE", url}) + } + for _, url := range top10URLs { + data = append(data, []string{"OWASP Top10", url}) + } + + // for _, rr := range vuln.CveContents.References(r.Family) { + // for _, ref := range rr.Value { + // data = append(data, []string{ref.Source, ref.Link}) + // } + // } + + b := bytes.Buffer{} + table := tablewriter.NewWriter(&b) + table.SetColWidth(80) + table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) + table.SetHeader([]string{ + vuln.CveID, + "", + }) + table.SetBorder(true) + table.SetHeaderColor( + tablewriter.Colors{tablewriter.Normal}, + tablewriter.Colors{tablewriter.Normal}, + ) + table.AppendBulk(data) + table.Render() + lines += b.String() + "\n" } - - return fmt.Sprintf("%s\n%s", header, table) + return } func cweURL(cweID string) string { @@ -387,8 +431,8 @@ func isCveFixed(current models.VulnInfo, previous models.ScanResult) bool { func isCveInfoUpdated(cveID string, previous, current models.ScanResult) bool { cTypes := []models.CveContentType{ - models.NVD, - models.JVN, + models.NvdXML, + models.Jvn, models.NewCveContentType(current.Family), } diff --git a/report/util_test.go b/report/util_test.go index d2d3a407..56e6d155 100644 --- a/report/util_test.go +++ b/report/util_test.go @@ -42,7 +42,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0001", CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2017-0001", LastModified: time.Time{}, }, @@ -56,7 +56,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0001", CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2017-0001", LastModified: time.Time{}, }, @@ -77,7 +77,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0002", CveContents: models.NewCveContents( models.CveContent{ - Type: models.JVN, + Type: models.Jvn, CveID: "CVE-2017-0002", LastModified: old, }, @@ -91,7 +91,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0002", CveContents: models.NewCveContents( models.CveContent{ - Type: models.JVN, + Type: models.Jvn, CveID: "CVE-2017-0002", LastModified: old, }, @@ -113,7 +113,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0003", CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2017-0002", LastModified: new, }, @@ -128,7 +128,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0003", CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2017-0002", LastModified: old, }, @@ -150,7 +150,7 @@ func TestIsCveInfoUpdated(t *testing.T) { CveID: "CVE-2017-0004", CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2017-0002", LastModified: old, }, @@ -194,18 +194,18 @@ func TestDiff(t *testing.T) { CveID: "CVE-2012-6702", AffectedPackages: models.PackageStatuses{{Name: "libexpat1"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, "CVE-2014-9761": { CveID: "CVE-2014-9761", AffectedPackages: models.PackageStatuses{{Name: "libc-bin"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, }, Packages: models.Packages{}, Errors: []string{}, - Optional: [][]interface{}{}, + Optional: map[string]interface{}{}, }, }, inPrevious: models.ScanResults{ @@ -219,18 +219,18 @@ func TestDiff(t *testing.T) { CveID: "CVE-2012-6702", AffectedPackages: models.PackageStatuses{{Name: "libexpat1"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, "CVE-2014-9761": { CveID: "CVE-2014-9761", AffectedPackages: models.PackageStatuses{{Name: "libc-bin"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, }, Packages: models.Packages{}, Errors: []string{}, - Optional: [][]interface{}{}, + Optional: map[string]interface{}{}, }, }, out: models.ScanResult{ @@ -241,7 +241,7 @@ func TestDiff(t *testing.T) { Packages: models.Packages{}, ScannedCves: models.VulnInfos{}, Errors: []string{}, - Optional: [][]interface{}{}, + Optional: map[string]interface{}{}, }, }, { @@ -256,7 +256,7 @@ func TestDiff(t *testing.T) { CveID: "CVE-2016-6662", AffectedPackages: models.PackageStatuses{{Name: "mysql-libs"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, }, Packages: models.Packages{ @@ -294,7 +294,7 @@ func TestDiff(t *testing.T) { CveID: "CVE-2016-6662", AffectedPackages: models.PackageStatuses{{Name: "mysql-libs"}}, DistroAdvisories: []models.DistroAdvisory{}, - CpeNames: []string{}, + CpeURIs: []string{}, }, }, Packages: models.Packages{ @@ -356,7 +356,7 @@ func TestIsCveFixed(t *testing.T) { }, CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2016-6662", LastModified: time.Time{}, }, @@ -374,7 +374,7 @@ func TestIsCveFixed(t *testing.T) { }, CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2016-6662", LastModified: time.Time{}, }, @@ -397,7 +397,7 @@ func TestIsCveFixed(t *testing.T) { }, CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2016-6662", LastModified: time.Time{}, }, @@ -415,7 +415,7 @@ func TestIsCveFixed(t *testing.T) { }, CveContents: models.NewCveContents( models.CveContent{ - Type: models.NVD, + Type: models.NvdXML, CveID: "CVE-2016-6662", LastModified: time.Time{}, }, diff --git a/scan/alpine.go b/scan/alpine.go index ec8922a2..29a8eaad 100644 --- a/scan/alpine.go +++ b/scan/alpine.go @@ -64,7 +64,14 @@ func detectAlpine(c config.ServerInfo) (itsMe bool, os osTypeInterface) { return false, os } -func (o *alpine) checkDependencies() error { +func (o *alpine) checkScanMode() error { + if o.getServerInfo().Mode.IsOffline() { + return fmt.Errorf("Remove offline scan mode, Alpine needs internet connection") + } + return nil +} + +func (o *alpine) checkDeps() error { o.log.Infof("Dependencies... No need") return nil } @@ -83,6 +90,7 @@ func (o *alpine) apkUpdate() error { } func (o *alpine) preCure() error { + o.log.Infof("Scanning in %s", o.getServerInfo().Mode) if err := o.detectIPAddr(); err != nil { o.log.Debugf("Failed to detect IP addresses: %s", err) } @@ -140,6 +148,11 @@ func (o *alpine) scanInstalledPackages() (models.Packages, error) { return o.parseApkInfo(r.Stdout) } +func (o *alpine) parseInstalledPackages(stdout string) (models.Packages, models.SrcPackages, error) { + installedPackages, err := o.parseApkInfo(stdout) + return installedPackages, nil, err +} + func (o *alpine) parseApkInfo(stdout string) (models.Packages, error) { packs := models.Packages{} scanner := bufio.NewScanner(strings.NewReader(stdout)) diff --git a/scan/amazon.go b/scan/amazon.go new file mode 100644 index 00000000..0befbba0 --- /dev/null +++ b/scan/amazon.go @@ -0,0 +1,114 @@ +package scan + +import ( + "fmt" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" +) + +// inherit OsTypeInterface +type amazon struct { + redhatBase +} + +// NewAmazon is constructor +func newAmazon(c config.ServerInfo) *amazon { + r := &amazon{ + redhatBase{ + base: base{ + osPackages: osPackages{ + Packages: models.Packages{}, + VulnInfos: models.VulnInfos{}, + }, + }, + sudo: rootPrivAmazon{}, + }, + } + r.log = util.NewCustomLogger(c) + r.setServerInfo(c) + return r +} + +func (o *amazon) checkScanMode() error { + if o.getServerInfo().Mode.IsOffline() { + return fmt.Errorf("Remove offline scan mode, Amazon needs internet connection") + } + return nil +} + +func (o *amazon) checkDeps() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckDeps(o.depsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckDeps(o.depsFastRoot()) + } else if o.getServerInfo().Mode.IsDeep() { + return o.execCheckDeps(o.depsDeep()) + } + return fmt.Errorf("Unknown scan mode") +} + +func (o *amazon) depsFast() []string { + if o.getServerInfo().Mode.IsOffline() { + return []string{} + } + // repoquery + return []string{"yum-utils"} +} + +func (o *amazon) depsFastRoot() []string { + return []string{ + "yum-utils", + "yum-plugin-ps", + } +} + +func (o *amazon) depsDeep() []string { + return o.depsFastRoot() +} + +func (o *amazon) checkIfSudoNoPasswd() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) + } else { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) + } +} + +func (o *amazon) sudoNoPasswdCmdsFast() []cmd { + return []cmd{} +} + +func (o *amazon) sudoNoPasswdCmdsFastRoot() []cmd { + return []cmd{ + {"yum -q ps all --color=never", exitStatusZero}, + {"stat /proc/1/exe", exitStatusZero}, + {"needs-restarting", exitStatusZero}, + {"which which", exitStatusZero}, + } +} + +func (o *amazon) sudoNoPasswdCmdsDeep() []cmd { + return o.sudoNoPasswdCmdsFastRoot() +} + +type rootPrivAmazon struct{} + +func (o rootPrivAmazon) repoquery() bool { + return false +} + +func (o rootPrivAmazon) yumRepolist() bool { + return false +} + +func (o rootPrivAmazon) yumUpdateInfo() bool { + return false +} + +func (o rootPrivAmazon) yumChangelog() bool { + return false +} diff --git a/scan/base.go b/scan/base.go index 4b99e552..cbe86abf 100644 --- a/scan/base.go +++ b/scan/base.go @@ -18,6 +18,7 @@ along with this program. If not, see . package scan import ( + "bufio" "fmt" "net" "regexp" @@ -33,7 +34,6 @@ type base struct { ServerInfo config.ServerInfo Distro config.Distro Platform models.Platform - osPackages log *logrus.Entry @@ -98,7 +98,7 @@ func (l *base) runningKernel() (release, version string, err error) { } func (l *base) allContainers() (containers []config.Container, err error) { - switch l.ServerInfo.Containers.Type { + switch l.ServerInfo.ContainerType { case "", "docker": stdout, err := l.dockerPs("-a --format '{{.ID}} {{.Names}} {{.Image}}'") if err != nil { @@ -119,12 +119,12 @@ func (l *base) allContainers() (containers []config.Container, err error) { return l.parseLxcPs(stdout) default: return containers, fmt.Errorf( - "Not supported yet: %s", l.ServerInfo.Containers.Type) + "Not supported yet: %s", l.ServerInfo.ContainerType) } } func (l *base) runningContainers() (containers []config.Container, err error) { - switch l.ServerInfo.Containers.Type { + switch l.ServerInfo.ContainerType { case "", "docker": stdout, err := l.dockerPs("--format '{{.ID}} {{.Names}} {{.Image}}'") if err != nil { @@ -145,12 +145,12 @@ func (l *base) runningContainers() (containers []config.Container, err error) { return l.parseLxcPs(stdout) default: return containers, fmt.Errorf( - "Not supported yet: %s", l.ServerInfo.Containers.Type) + "Not supported yet: %s", l.ServerInfo.ContainerType) } } func (l *base) exitedContainers() (containers []config.Container, err error) { - switch l.ServerInfo.Containers.Type { + switch l.ServerInfo.ContainerType { case "", "docker": stdout, err := l.dockerPs("--filter 'status=exited' --format '{{.ID}} {{.Names}} {{.Image}}'") if err != nil { @@ -171,7 +171,7 @@ func (l *base) exitedContainers() (containers []config.Container, err error) { return l.parseLxcPs(stdout) default: return containers, fmt.Errorf( - "Not supported yet: %s", l.ServerInfo.Containers.Type) + "Not supported yet: %s", l.ServerInfo.ContainerType) } } @@ -296,6 +296,10 @@ func (l *base) parseIP(stdout string) (ipv4Addrs []string, ipv6Addrs []string) { } func (l *base) detectPlatform() { + if l.getServerInfo().Mode.IsOffline() { + l.setPlatform(models.Platform{Name: "unknown"}) + return + } ok, instanceID, err := l.detectRunningOnAws() if err != nil { l.setPlatform(models.Platform{Name: "other"}) @@ -316,7 +320,7 @@ func (l *base) detectPlatform() { func (l *base) detectRunningOnAws() (ok bool, instanceID string, err error) { if r := l.exec("type curl", noSudo); r.isSuccess() { - cmd := "curl --max-time 1 --retry 3 --noproxy 169.254.169.254 http://169.254.169.254/latest/meta-data/instance-id" + cmd := "curl --max-time 1 --noproxy 169.254.169.254 http://169.254.169.254/latest/meta-data/instance-id" r := l.exec(cmd, noSudo) if r.isSuccess() { id := strings.TrimSpace(r.Stdout) @@ -367,7 +371,7 @@ func (l *base) isAwsInstanceID(str string) bool { } func (l *base) convertToModel() models.ScanResult { - ctype := l.ServerInfo.Containers.Type + ctype := l.ServerInfo.ContainerType if l.ServerInfo.Container.ContainerID != "" && ctype == "" { ctype = "docker" } @@ -409,3 +413,62 @@ func (l *base) setErrs(errs []error) { func (l *base) getErrs() []error { return l.errs } + +const ( + systemd = "systemd" + upstart = "upstart" + sysVinit = "init" +) + +// https://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem +func (l *base) detectInitSystem() (string, error) { + var f func(string) (string, error) + f = func(cmd string) (string, error) { + r := l.exec(cmd, sudo) + if !r.isSuccess() { + return "", fmt.Errorf("Failed to stat %s: %s", cmd, r) + } + scanner := bufio.NewScanner(strings.NewReader(r.Stdout)) + scanner.Scan() + line := strings.TrimSpace(scanner.Text()) + if strings.Contains(line, "systemd") { + return systemd, nil + } else if strings.Contains(line, "upstart") { + return upstart, nil + } else if strings.Contains(line, "File: ‘/proc/1/exe’ -> ‘/sbin/init’") || + strings.Contains(line, "File: `/proc/1/exe' -> `/sbin/init'") { + return f("stat /sbin/init") + } else if line == "File: ‘/sbin/init’" || + line == "File: `/sbin/init'" { + r := l.exec("/sbin/init --version", noSudo) + if r.isSuccess() { + if strings.Contains(r.Stdout, "upstart") { + return upstart, nil + } + } + return sysVinit, nil + } + return "", fmt.Errorf("Failed to detect a init system: %s", line) + } + return f("stat /proc/1/exe") +} + +func (l *base) detectServiceName(pid string) (string, error) { + cmd := fmt.Sprintf("systemctl status --quiet --no-pager %s", pid) + r := l.exec(cmd, noSudo) + if !r.isSuccess() { + return "", fmt.Errorf("Failed to stat %s: %s", cmd, r) + } + return l.parseSystemctlStatus(r.Stdout), nil +} + +func (l *base) parseSystemctlStatus(stdout string) string { + scanner := bufio.NewScanner(strings.NewReader(stdout)) + scanner.Scan() + line := scanner.Text() + ss := strings.Fields(line) + if len(ss) < 2 || strings.HasPrefix(line, "Failed to get unit for PID") { + return "" + } + return ss[1] +} diff --git a/scan/base_test.go b/scan/base_test.go index c385116e..39cecf0b 100644 --- a/scan/base_test.go +++ b/scan/base_test.go @@ -25,7 +25,6 @@ import ( ) func TestParseDockerPs(t *testing.T) { - var test = struct { in string expected []config.Container @@ -46,7 +45,7 @@ f570ae647edc agitated_lovelace centos:latest`, }, } - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) actual, err := r.parseDockerPs(test.in) if err != nil { t.Errorf("Error occurred. in: %s, err: %s", test.in, err) @@ -60,7 +59,6 @@ f570ae647edc agitated_lovelace centos:latest`, } func TestParseLxdPs(t *testing.T) { - var test = struct { in string expected []config.Container @@ -84,7 +82,7 @@ func TestParseLxdPs(t *testing.T) { }, } - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) actual, err := r.parseLxdPs(test.in) if err != nil { t.Errorf("Error occurred. in: %s, err: %s", test.in, err) @@ -117,7 +115,7 @@ func TestParseIp(t *testing.T) { expected6: []string{"2001:db8::68"}, } - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) actual4, actual6 := r.parseIP(test.in) if !reflect.DeepEqual(test.expected4, actual4) { t.Errorf("expected %v, actual %v", test.expected4, actual4) @@ -140,7 +138,7 @@ func TestIsAwsInstanceID(t *testing.T) { {"no data", false}, } - r := newRedhat(config.ServerInfo{}) + r := newAmazon(config.ServerInfo{}) for _, tt := range tests { actual := r.isAwsInstanceID(tt.in) if tt.expected != actual { @@ -148,3 +146,35 @@ func TestIsAwsInstanceID(t *testing.T) { } } } + +func TestParseSystemctlStatus(t *testing.T) { + var tests = []struct { + in string + out string + }{ + { + in: `● NetworkManager.service - Network Manager + Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) + Active: active (running) since Wed 2018-01-10 17:15:39 JST; 2 months 10 days ago + Docs: man:NetworkManager(8) + Main PID: 437 (NetworkManager) + Memory: 424.0K + CGroup: /system.slice/NetworkManager.service + ├─437 /usr/sbin/NetworkManager --no-daemon + └─572 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens160.pid -lf /var/lib/NetworkManager/dhclient-241ed966-e1c7-4d5c-a6a0-8a6dba457277-ens160.lease -cf /var/lib/NetworkManager/dhclient-ens160.conf ens160`, + out: "NetworkManager.service", + }, + { + in: `Failed to get unit for PID 700: PID 700 does not belong to any loaded unit.`, + out: "", + }, + } + + r := newCentOS(config.ServerInfo{}) + for _, tt := range tests { + actual := r.parseSystemctlStatus(tt.in) + if tt.out != actual { + t.Errorf("expected %v, actual %v", tt.out, actual) + } + } +} diff --git a/scan/centos.go b/scan/centos.go new file mode 100644 index 00000000..c6f7395b --- /dev/null +++ b/scan/centos.go @@ -0,0 +1,120 @@ +package scan + +import ( + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" +) + +// inherit OsTypeInterface +type centos struct { + redhatBase +} + +// NewAmazon is constructor +func newCentOS(c config.ServerInfo) *centos { + r := ¢os{ + redhatBase{ + base: base{ + osPackages: osPackages{ + Packages: models.Packages{}, + VulnInfos: models.VulnInfos{}, + }, + }, + sudo: rootPrivCentos{}, + }, + } + r.log = util.NewCustomLogger(c) + r.setServerInfo(c) + return r +} + +func (o *centos) checkScanMode() error { + return nil +} + +func (o *centos) checkDeps() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckDeps(o.depsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckDeps(o.depsFastRoot()) + } else { + return o.execCheckDeps(o.depsDeep()) + } +} + +func (o *centos) depsFast() []string { + if o.getServerInfo().Mode.IsOffline() { + return []string{} + } + // repoquery + return []string{"yum-utils"} +} + +func (o *centos) depsFastRoot() []string { + return []string{ + "yum-utils", + "yum-plugin-ps", + } +} + +func (o *centos) depsDeep() []string { + return []string{ + "yum-utils", + "yum-plugin-ps", + "yum-plugin-changelog", + } +} + +func (o *centos) checkIfSudoNoPasswd() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) + } else { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) + } +} + +func (o *centos) sudoNoPasswdCmdsFast() []cmd { + return []cmd{} +} + +func (o *centos) sudoNoPasswdCmdsFastRoot() []cmd { + if o.getServerInfo().Mode.IsOffline() { + // yum ps needs internet connection + return []cmd{ + {"stat /proc/1/exe", exitStatusZero}, + {"needs-restarting", exitStatusZero}, + {"which which", exitStatusZero}, + } + } + return []cmd{ + {"yum -q ps all --color=never", exitStatusZero}, + {"stat /proc/1/exe", exitStatusZero}, + {"needs-restarting", exitStatusZero}, + {"which which", exitStatusZero}, + } +} + +func (o *centos) sudoNoPasswdCmdsDeep() []cmd { + return o.sudoNoPasswdCmdsFastRoot() +} + +type rootPrivCentos struct{} + +func (o rootPrivCentos) repoquery() bool { + return false +} + +func (o rootPrivCentos) yumRepolist() bool { + return false +} + +func (o rootPrivCentos) yumUpdateInfo() bool { + return false +} + +func (o rootPrivCentos) yumChangelog() bool { + return false +} diff --git a/scan/debian.go b/scan/debian.go index 494e97fc..d0ed2539 100644 --- a/scan/debian.go +++ b/scan/debian.go @@ -135,20 +135,47 @@ func trim(str string) string { return strings.TrimSpace(str) } +func (o *debian) checkScanMode() error { + return nil +} + func (o *debian) checkIfSudoNoPasswd() error { - if config.Conf.Deep || o.Distro.Family == config.Raspbian { - cmd := util.PrependProxyEnv("apt-get update") + if o.getServerInfo().Mode.IsFast() { + o.log.Infof("sudo ... No need") + return nil + } + + cmds := []string{ + "checkrestart", + "stat /proc/1/exe", + } + + if !o.getServerInfo().Mode.IsOffline() { + cmds = append(cmds, "apt-get update") + } + + for _, cmd := range cmds { + cmd = util.PrependProxyEnv(cmd) o.log.Infof("Checking... sudo %s", cmd) r := o.exec(cmd, sudo) if !r.isSuccess() { o.log.Errorf("sudo error on %s", r) return fmt.Errorf("Failed to sudo: %s", r) } - o.log.Infof("Sudo... Pass") - return nil } - o.log.Infof("sudo ... No need") + initName, err := o.detectInitSystem() + if initName == upstart && err == nil { + cmd := util.PrependProxyEnv("initctl status --help") + o.log.Infof("Checking... sudo %s", cmd) + r := o.exec(cmd, sudo) + if !r.isSuccess() { + o.log.Errorf("sudo error on %s", r) + return fmt.Errorf("Failed to sudo: %s", r) + } + } + + o.log.Infof("Sudo... Pass") return nil } @@ -159,43 +186,57 @@ type dep struct { additionalMsg string } -func (o *debian) checkDependencies() error { +func (o *debian) checkDeps() error { deps := []dep{} + if o.getServerInfo().Mode.IsDeep() || o.getServerInfo().Mode.IsFastRoot() { + // checkrestart + deps = append(deps, dep{ + packName: "debian-goodies", + required: true, + logFunc: o.log.Errorf, + }) + } - switch o.Distro.Family { - case config.Ubuntu, config.Raspbian: - o.log.Infof("Dependencies... No need") - return nil - - case config.Debian: + if o.Distro.Family == config.Debian { // https://askubuntu.com/a/742844 if !o.ServerInfo.IsContainer() { deps = append(deps, dep{ packName: "reboot-notifier", required: false, logFunc: o.log.Warnf, - additionalMsg: ". If you want to detect whether not rebooted after kernel update.", + additionalMsg: ". Install it if you want to detect whether not rebooted after kernel update. To install `reboot-notifier` on Debian, see https://feeding.cloud.geek.nz/posts/introducing-reboot-notifier/", }) } - if config.Conf.Deep { + // Changelogs will be fetched only in deep scan mode + if o.getServerInfo().Mode.IsDeep() { // Debian needs aptitude to get changelogs. - // Because unable to get changelogs via apt-get changelog on Debian. + // Because unable to get changelogs via `apt-get changelog` on Debian. deps = append(deps, dep{ packName: "aptitude", required: true, logFunc: o.log.Errorf, }) } - - default: - return fmt.Errorf("Not implemented yet: %s", o.Distro) } for _, dep := range deps { - cmd := "dpkg-query -W " + dep.packName - if r := o.exec(cmd, noSudo); !r.isSuccess() { - msg := fmt.Sprintf("%s is not installed", dep.packName) + cmd := fmt.Sprintf("%s %s", dpkgQuery, dep.packName) + msg := fmt.Sprintf("%s is not installed", dep.packName) + r := o.exec(cmd, noSudo) + if !r.isSuccess() { + if dep.additionalMsg != "" { + msg += dep.additionalMsg + } + dep.logFunc(msg) + if dep.required { + return fmt.Errorf(msg) + } + continue + } + + _, status, _, _, _, _ := o.parseScannedPackagesLine(r.Stdout) + if status != "ii" { if dep.additionalMsg != "" { msg += dep.additionalMsg } @@ -204,12 +245,14 @@ func (o *debian) checkDependencies() error { return fmt.Errorf(msg) } } + } o.log.Infof("Dependencies... Pass") return nil } func (o *debian) preCure() error { + o.log.Infof("Scanning in %s", o.getServerInfo().Mode) if err := o.detectIPAddr(); err != nil { o.log.Debugf("Failed to detect IP addresses: %s", err) } @@ -218,6 +261,9 @@ func (o *debian) preCure() error { } func (o *debian) postScan() error { + if o.getServerInfo().Mode.IsDeep() || o.getServerInfo().Mode.IsFastRoot() { + return o.checkrestart() + } return nil } @@ -252,11 +298,11 @@ func (o *debian) scanPackages() error { o.Packages = installed o.SrcPackages = srcPacks - if config.Conf.Offline { + if o.getServerInfo().Mode.IsOffline() { return nil } - if config.Conf.Deep || o.Distro.Family == config.Raspbian { + if o.getServerInfo().Mode.IsDeep() || o.Distro.Family == config.Raspbian { unsecures, err := o.scanUnsecurePackages(updatable) if err != nil { o.log.Errorf("Failed to scan vulnerable packages: %s", err) @@ -281,23 +327,63 @@ func (o *debian) rebootRequired() (bool, error) { } } +const dpkgQuery = `dpkg-query -W -f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n"` + func (o *debian) scanInstalledPackages() (models.Packages, models.Packages, models.SrcPackages, error) { - installed, updatable, srcPacks := models.Packages{}, models.Packages{}, models.SrcPackages{} - r := o.exec(`dpkg-query -W -f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n"`, noSudo) + updatable := models.Packages{} + r := o.exec(dpkgQuery, noSudo) if !r.isSuccess() { return nil, nil, nil, fmt.Errorf("Failed to SSH: %s", r) } + installed, srcPacks, err := o.parseInstalledPackages(r.Stdout) + if err != nil { + return nil, nil, nil, err + } + + if o.getServerInfo().Mode.IsOffline() || o.getServerInfo().Mode.IsFast() { + return installed, updatable, srcPacks, nil + } + + if err := o.aptGetUpdate(); err != nil { + return nil, nil, nil, err + } + updatableNames, err := o.getUpdatablePackNames() + if err != nil { + return nil, nil, nil, err + } + for _, name := range updatableNames { + for _, pack := range installed { + if pack.Name == name { + updatable[name] = pack + break + } + } + } + + // Fill the candidate versions of upgradable packages + err = o.fillCandidateVersion(updatable) + if err != nil { + return nil, nil, nil, fmt.Errorf("Failed to fill candidate versions. err: %s", err) + } + installed.MergeNewVersion(updatable) + + return installed, updatable, srcPacks, nil +} + +func (o *debian) parseInstalledPackages(stdout string) (models.Packages, models.SrcPackages, error) { + installed, srcPacks := models.Packages{}, models.SrcPackages{} + // e.g. // curl,ii ,7.38.0-4+deb8u2,,7.38.0-4+deb8u2 // openssh-server,ii ,1:6.7p1-5+deb8u3,openssh,1:6.7p1-5+deb8u3 // tar,ii ,1.27.1-2+b1,tar (1.27.1-2),1.27.1-2 - lines := strings.Split(r.Stdout, "\n") + lines := strings.Split(stdout, "\n") for _, line := range lines { if trimmed := strings.TrimSpace(line); len(trimmed) != 0 { name, status, version, srcName, srcVersion, err := o.parseScannedPackagesLine(trimmed) - if err != nil { - return nil, nil, nil, fmt.Errorf( + if err != nil || len(status) < 2 { + return nil, nil, fmt.Errorf( "Debian: Failed to parse package line: %s", line) } @@ -343,35 +429,7 @@ func (o *debian) scanInstalledPackages() (models.Packages, models.Packages, mode for name := range installed { delete(srcPacks, name) } - - if config.Conf.Offline { - return installed, updatable, srcPacks, nil - } - - if err := o.aptGetUpdate(); err != nil { - return nil, nil, nil, err - } - updatableNames, err := o.getUpdatablePackNames() - if err != nil { - return nil, nil, nil, err - } - for _, name := range updatableNames { - for _, pack := range installed { - if pack.Name == name { - updatable[name] = pack - break - } - } - } - - // Fill the candidate versions of upgradable packages - err = o.fillCandidateVersion(updatable) - if err != nil { - return nil, nil, nil, fmt.Errorf("Failed to fill candidate versions. err: %s", err) - } - installed.MergeNewVersion(updatable) - - return installed, updatable, srcPacks, nil + return installed, srcPacks, nil } func (o *debian) parseScannedPackagesLine(line string) (name, status, version, srcName, srcVersion string, err error) { @@ -382,7 +440,7 @@ func (o *debian) parseScannedPackagesLine(line string) (name, status, version, s if i := strings.IndexRune(name, ':'); i >= 0 { name = name[:i] } - status = ss[1] + status = strings.TrimSpace(ss[1]) version = ss[2] // remove version. ex: tar (1.27.1-2) srcName = strings.Split(ss[3], " ")[0] @@ -417,7 +475,7 @@ func (o *debian) scanUnsecurePackages(updatable models.Packages) (models.VulnInf } // Collect CVE information of upgradable packages - vulnInfos, err := o.scanVulnInfos(updatable, meta) + vulnInfos, err := o.scanChangelogs(updatable, meta) if err != nil { return nil, fmt.Errorf("Failed to scan unsecure packages. err: %s", err) } @@ -547,7 +605,7 @@ type DetectedCveID struct { Confidence models.Confidence } -func (o *debian) scanVulnInfos(updatablePacks models.Packages, meta *cache.Meta) (models.VulnInfos, error) { +func (o *debian) scanChangelogs(updatablePacks models.Packages, meta *cache.Meta) (models.VulnInfos, error) { type response struct { pack *models.Package DetectedCveIDs []DetectedCveID @@ -583,7 +641,7 @@ func (o *debian) scanVulnInfos(updatablePacks models.Packages, meta *cache.Meta) // if the changelog is not in cache or failed to get from local cache, // get the changelog of the package via internet. // After that, store it in the cache. - if cveIDs, pack, err := o.scanPackageCveIDs(p); err != nil { + if cveIDs, pack, err := o.fetchParseChangelog(p); err != nil { errChan <- err } else { resChan <- response{pack, cveIDs} @@ -639,7 +697,7 @@ func (o *debian) scanVulnInfos(updatablePacks models.Packages, meta *cache.Meta) vinfos[cveID.CveID] = models.VulnInfo{ CveID: cveID.CveID, - Confidence: cveID.Confidence, + Confidences: models.Confidences{cveID.Confidence}, AffectedPackages: affected, } } @@ -681,7 +739,7 @@ func (o *debian) getChangelogCache(meta *cache.Meta, pack models.Package) string return changelog } -func (o *debian) scanPackageCveIDs(pack models.Package) ([]DetectedCveID, *models.Package, error) { +func (o *debian) fetchParseChangelog(pack models.Package) ([]DetectedCveID, *models.Package, error) { cmd := "" switch o.Distro.Family { case config.Ubuntu, config.Raspbian: @@ -760,7 +818,7 @@ func (o *debian) getCveIDsFromChangelog( // Only logging the error. o.log.Warnf("Failed to find the version in changelog: %s-%s", name, ver) - o.log.Debugf("Changelog of : %s-%s-%s", name, ver, changelog) + o.log.Debugf("Changelog of %s-%s: %s", name, ver, changelog) // If the version is not in changelog, return entire changelog to put into cache pack := o.Packages[name] @@ -886,3 +944,145 @@ func (o *debian) parseAptCachePolicy(stdout, name string) (packCandidateVer, err } return ver, fmt.Errorf("Unknown Format: %s", stdout) } + +func (o *debian) checkrestart() error { + initName, err := o.detectInitSystem() + if err != nil { + o.log.Warn(err) + // continue scanning + } + + cmd := "LANGUAGE=en_US.UTF-8 checkrestart" + r := o.exec(cmd, sudo) + if !r.isSuccess() { + return fmt.Errorf( + "Failed to %s. status: %d, stdout: %s, stderr: %s", + cmd, r.ExitStatus, r.Stdout, r.Stderr) + } + packs, unknownServices := o.parseCheckRestart(r.Stdout) + pidService := map[string]string{} + if initName == upstart { + for _, s := range unknownServices { + cmd := "LANGUAGE=en_US.UTF-8 initctl status " + s + r := o.exec(cmd, sudo) + if !r.isSuccess() { + continue + } + if ss := strings.Fields(r.Stdout); len(ss) == 4 && ss[2] == "process" { + pidService[ss[3]] = s + } + } + } + + for i, p := range packs { + pack := o.Packages[p.Name] + pack.NeedRestartProcs = p.NeedRestartProcs + o.Packages[p.Name] = pack + + for j, proc := range p.NeedRestartProcs { + if proc.HasInit == false { + continue + } + packs[i].NeedRestartProcs[j].InitSystem = initName + if initName == systemd { + name, err := o.detectServiceName(proc.PID) + if err != nil { + o.log.Warn(err) + // continue scanning + } + packs[i].NeedRestartProcs[j].ServiceName = name + } else { + if proc.ServiceName == "" { + if ss := strings.Fields(r.Stdout); len(ss) == 4 && ss[2] == "process" { + if name, ok := pidService[ss[3]]; ok { + packs[i].NeedRestartProcs[j].ServiceName = name + } + } + } + } + } + o.Packages[p.Name] = p + } + return nil +} + +func (o *debian) parseCheckRestart(stdout string) (models.Packages, []string) { + services := []string{} + scanner := bufio.NewScanner(strings.NewReader(stdout)) + for scanner.Scan() { + line := scanner.Text() + if strings.HasPrefix(line, "service") && strings.HasSuffix(line, "restart") { + ss := strings.Fields(line) + if len(ss) != 3 { + continue + } + services = append(services, ss[1]) + } + } + + packs := models.Packages{} + packName := "" + hasInit := true + scanner = bufio.NewScanner(strings.NewReader(stdout)) + for scanner.Scan() { + line := scanner.Text() + if strings.HasSuffix(line, "do not seem to have an associated init script to restart them:") { + hasInit = false + continue + } + if strings.HasSuffix(line, ":") && len(strings.Fields(line)) == 1 { + packName = strings.TrimSuffix(line, ":") + continue + } + if strings.HasPrefix(line, "\t") { + ss := strings.Fields(line) + if len(ss) != 2 { + continue + } + + serviceName := "" + for _, s := range services { + if packName == s { + serviceName = s + } + } + if p, ok := packs[packName]; ok { + p.NeedRestartProcs = append(p.NeedRestartProcs, models.NeedRestartProcess{ + PID: ss[0], + Path: ss[1], + ServiceName: serviceName, + HasInit: hasInit, + }) + packs[packName] = p + } else { + packs[packName] = models.Package{ + Name: packName, + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: ss[0], + Path: ss[1], + ServiceName: serviceName, + HasInit: hasInit, + }, + }, + } + } + } + } + + unknownServices := []string{} + for _, s := range services { + found := false + for _, p := range packs { + for _, proc := range p.NeedRestartProcs { + if proc.ServiceName == s { + found = true + } + } + } + if !found { + unknownServices = append(unknownServices, s) + } + } + return packs, unknownServices +} diff --git a/scan/debian_test.go b/scan/debian_test.go index 7e1f19fc..0170b6d1 100644 --- a/scan/debian_test.go +++ b/scan/debian_test.go @@ -587,3 +587,139 @@ func TestParseAptCachePolicy(t *testing.T) { } } } + +func TestParseCheckRestart(t *testing.T) { + r := newDebian(config.ServerInfo{}) + r.Distro = config.Distro{Family: "debian"} + var tests = []struct { + in string + out models.Packages + unknownServices []string + }{ + { + in: `Found 27 processes using old versions of upgraded files +(19 distinct programs) +(15 distinct packages) + +Of these, 14 seem to contain systemd service definitions or init scripts which can be used to restart them. +The following packages seem to have definitions that could be used +to restart their services: +varnish: + 3490 /usr/sbin/varnishd + 3704 /usr/sbin/varnishd +memcached: + 3636 /usr/bin/memcached +openssh-server: + 1252 /usr/sbin/sshd + 1184 /usr/sbin/sshd +accountsservice: + 462 /usr/lib/accountsservice/accounts-daemon + +These are the systemd services: +systemctl restart accounts-daemon.service + +These are the initd scripts: +service varnish restart +service memcached restart +service ssh restart + +These processes (1) do not seem to have an associated init script to restart them: +util-linux: + 3650 /sbin/agetty + 3648 /sbin/agetty`, + out: models.NewPackages( + models.Package{ + Name: "varnish", + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: "3490", + Path: "/usr/sbin/varnishd", + ServiceName: "varnish", + HasInit: true, + }, + { + PID: "3704", + Path: "/usr/sbin/varnishd", + ServiceName: "varnish", + HasInit: true, + }, + }, + }, + models.Package{ + Name: "memcached", + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: "3636", + Path: "/usr/bin/memcached", + ServiceName: "memcached", + HasInit: true, + }, + }, + }, + models.Package{ + Name: "openssh-server", + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: "1252", + Path: "/usr/sbin/sshd", + ServiceName: "", + HasInit: true, + }, + { + PID: "1184", + Path: "/usr/sbin/sshd", + ServiceName: "", + HasInit: true, + }, + }, + }, + models.Package{ + Name: "accountsservice", + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: "462", + Path: "/usr/lib/accountsservice/accounts-daemon", + ServiceName: "", + HasInit: true, + }, + }, + }, + models.Package{ + Name: "util-linux", + NeedRestartProcs: []models.NeedRestartProcess{ + { + PID: "3650", + Path: "/sbin/agetty", + HasInit: false, + }, + { + PID: "3648", + Path: "/sbin/agetty", + HasInit: false, + }, + }, + }, + ), + unknownServices: []string{"ssh"}, + }, + { + in: `Found 0 processes using old versions of upgraded files`, + out: models.Packages{}, + unknownServices: []string{}, + }, + } + + for _, tt := range tests { + packages, services := r.parseCheckRestart(tt.in) + for name, ePack := range tt.out { + if !reflect.DeepEqual(ePack, packages[name]) { + e := pp.Sprintf("%v", ePack) + a := pp.Sprintf("%v", packages[name]) + t.Errorf("expected %s, actual %s", e, a) + } + } + if !reflect.DeepEqual(tt.unknownServices, services) { + t.Errorf("expected %s, actual %s", tt.unknownServices, services) + } + } +} diff --git a/scan/executil.go b/scan/executil.go index 254bb131..969d4684 100644 --- a/scan/executil.go +++ b/scan/executil.go @@ -370,7 +370,7 @@ func decorateCmd(c conf.ServerInfo, cmd string, sudo bool) string { // } if c.IsContainer() { - switch c.Containers.Type { + switch c.ContainerType { case "", "docker": cmd = fmt.Sprintf(`docker exec --user 0 %s %s -c '%s'`, c.Container.ContainerID, dockerShell(c.Distro.Family), cmd) diff --git a/scan/executil_test.go b/scan/executil_test.go index 50fd3661..2eb9c1eb 100644 --- a/scan/executil_test.go +++ b/scan/executil_test.go @@ -69,9 +69,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo false docker { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "docker"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "docker", }, cmd: "ls", sudo: false, @@ -80,9 +80,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo true docker { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "docker"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "docker", }, cmd: "ls", sudo: true, @@ -91,9 +91,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo false, docker { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "docker"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "docker", }, cmd: "ls", sudo: false, @@ -102,9 +102,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true, docker { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "docker"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "docker", }, cmd: "ls", sudo: true, @@ -113,9 +113,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true, docker { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "docker"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "docker", }, cmd: "ls | grep hoge", sudo: true, @@ -125,9 +125,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo false lxd { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxd"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxd", }, cmd: "ls", sudo: false, @@ -136,9 +136,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo true lxd { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxd"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxd", }, cmd: "ls", sudo: true, @@ -147,9 +147,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo false, lxd { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxd"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxd", }, cmd: "ls", sudo: false, @@ -158,9 +158,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true, lxd { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxd"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxd", }, cmd: "ls", sudo: true, @@ -169,9 +169,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true lxd { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxd"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxd", }, cmd: "ls | grep hoge", sudo: true, @@ -181,9 +181,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo false lxc { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxc"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxc", }, cmd: "ls", sudo: false, @@ -192,9 +192,9 @@ func TestDecorateCmd(t *testing.T) { // root sudo true lxc { conf: config.ServerInfo{ - User: "root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxc"}, + User: "root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxc", }, cmd: "ls", sudo: true, @@ -203,9 +203,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo false, lxc { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxc"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxc", }, cmd: "ls", sudo: false, @@ -214,9 +214,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true, lxc { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxc"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxc", }, cmd: "ls", sudo: true, @@ -225,9 +225,9 @@ func TestDecorateCmd(t *testing.T) { // non-root sudo true lxc { conf: config.ServerInfo{ - User: "non-root", - Container: config.Container{ContainerID: "abc", Name: "def"}, - Containers: config.Containers{Type: "lxc"}, + User: "non-root", + Container: config.Container{ContainerID: "abc", Name: "def"}, + ContainerType: "lxc", }, cmd: "ls | grep hoge", sudo: true, diff --git a/scan/freebsd.go b/scan/freebsd.go index d77ec089..4267bbbb 100644 --- a/scan/freebsd.go +++ b/scan/freebsd.go @@ -67,18 +67,26 @@ func detectFreebsd(c config.ServerInfo) (itsMe bool, bsd osTypeInterface) { return false, bsd } +func (o *bsd) checkScanMode() error { + if o.getServerInfo().Mode.IsOffline() { + return fmt.Errorf("Remove offline scan mode, FreeBSD needs internet connection") + } + return nil +} + func (o *bsd) checkIfSudoNoPasswd() error { // FreeBSD doesn't need root privilege o.log.Infof("sudo ... No need") return nil } -func (o *bsd) checkDependencies() error { +func (o *bsd) checkDeps() error { o.log.Infof("Dependencies... No need") return nil } func (o *bsd) preCure() error { + o.log.Infof("Scanning in %s", o.getServerInfo().Mode) if err := o.detectIPAddr(); err != nil { o.log.Debugf("Failed to detect IP addresses: %s", err) } @@ -158,6 +166,10 @@ func (o *bsd) scanPackages() error { return nil } +func (o *bsd) parseInstalledPackages(string) (models.Packages, models.SrcPackages, error) { + return nil, nil, nil +} + func (o *bsd) rebootRequired() (bool, error) { r := o.exec("freebsd-version -k", noSudo) if !r.isSuccess() { @@ -245,7 +257,7 @@ func (o *bsd) scanUnsecurePackages() (models.VulnInfos, error) { CveID: cveID, AffectedPackages: affected, DistroAdvisories: disAdvs, - Confidence: models.PkgAuditMatch, + Confidences: models.Confidences{models.PkgAuditMatch}, } } return vinfos, nil diff --git a/scan/oracle.go b/scan/oracle.go new file mode 100644 index 00000000..3147eb08 --- /dev/null +++ b/scan/oracle.go @@ -0,0 +1,167 @@ +package scan + +import ( + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" +) + +// inherit OsTypeInterface +type oracle struct { + redhatBase +} + +// NewAmazon is constructor +func newOracle(c config.ServerInfo) *oracle { + r := &oracle{ + redhatBase{ + base: base{ + osPackages: osPackages{ + Packages: models.Packages{}, + VulnInfos: models.VulnInfos{}, + }, + }, + sudo: rootPrivOracle{}, + }, + } + r.log = util.NewCustomLogger(c) + r.setServerInfo(c) + return r +} + +func (o *oracle) checkScanMode() error { + return nil +} + +func (o *oracle) checkDeps() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckDeps(o.depsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckDeps(o.depsFastRoot()) + } else { + return o.execCheckDeps(o.depsDeep()) + } +} + +func (o *oracle) depsFast() []string { + if o.getServerInfo().Mode.IsOffline() { + return []string{} + } + // repoquery + return []string{"yum-utils"} +} + +func (o *oracle) depsFastRoot() []string { + if o.getServerInfo().Mode.IsOffline() { + //TODO + // return []string{"yum-plugin-ps"} + } + + majorVersion, _ := o.Distro.MajorVersion() + switch majorVersion { + case 5: + return []string{ + "yum-utils", + "yum-security", + } + case 6: + return []string{ + "yum-utils", + "yum-plugin-security", + //TODO + // return []string{"yum-plugin-ps"} + } + default: + return []string{ + "yum-utils", + //TODO + // return []string{"yum-plugin-ps"} + } + } +} + +func (o *oracle) depsDeep() []string { + majorVersion, _ := o.Distro.MajorVersion() + switch majorVersion { + case 5: + return []string{ + "yum-utils", + "yum-security", + "yum-changelog", + } + case 6: + return []string{ + "yum-utils", + "yum-plugin-security", + "yum-plugin-changelog", + //TODO + // return []string{"yum-plugin-ps"} + } + default: + return []string{ + "yum-utils", + "yum-plugin-changelog", + //TODO + // return []string{"yum-plugin-ps"} + } + } +} + +func (o *oracle) checkIfSudoNoPasswd() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) + } else { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) + } +} + +func (o *oracle) sudoNoPasswdCmdsFast() []cmd { + return []cmd{} +} + +func (o *oracle) sudoNoPasswdCmdsFastRoot() []cmd { + cmds := []cmd{{"needs-restarting", exitStatusZero}} + if o.getServerInfo().Mode.IsOffline() { + return cmds + } + + majorVersion, _ := o.Distro.MajorVersion() + if majorVersion < 6 { + return []cmd{ + {"yum repolist --color=never", exitStatusZero}, + {"yum list-security --security --color=never", exitStatusZero}, + {"yum info-security --color=never", exitStatusZero}, + {"repoquery -h", exitStatusZero}, + } + } + return append(cmds, + cmd{"yum repolist --color=never", exitStatusZero}, + cmd{"yum updateinfo list updates --security --color=never", exitStatusZero}, + cmd{"yum updateinfo updates --security --color=never", exitStatusZero}, + cmd{"repoquery -h", exitStatusZero}) +} + +func (o *oracle) sudoNoPasswdCmdsDeep() []cmd { + return o.sudoNoPasswdCmdsFastRoot() +} + +type rootPrivOracle struct{} + +func (o rootPrivOracle) repoquery() bool { + return true +} + +func (o rootPrivOracle) yumRepolist() bool { + return true +} + +func (o rootPrivOracle) yumUpdateInfo() bool { + return true +} + +// root privilege isn't needed +func (o rootPrivOracle) yumChangelog() bool { + return false +} diff --git a/scan/pseudo.go b/scan/pseudo.go index da3b3068..e7340a3d 100644 --- a/scan/pseudo.go +++ b/scan/pseudo.go @@ -48,11 +48,15 @@ func newPseudo(c config.ServerInfo) *pseudo { return d } +func (o *pseudo) checkScanMode() error { + return nil +} + func (o *pseudo) checkIfSudoNoPasswd() error { return nil } -func (o *pseudo) checkDependencies() error { +func (o *pseudo) checkDeps() error { return nil } @@ -68,6 +72,10 @@ func (o *pseudo) scanPackages() error { return nil } +func (o *pseudo) parseInstalledPackages(string) (models.Packages, models.SrcPackages, error) { + return nil, nil, nil +} + func (o *pseudo) detectPlatform() { o.setPlatform(models.Platform{Name: "other"}) return diff --git a/scan/redhat.go b/scan/redhatbase.go similarity index 65% rename from scan/redhat.go rename to scan/redhatbase.go index 96b41bb1..b0fbec28 100644 --- a/scan/redhat.go +++ b/scan/redhatbase.go @@ -31,34 +31,11 @@ import ( ver "github.com/knqyf263/go-rpm-version" ) -// inherit OsTypeInterface -type redhat struct { - base -} - -// NewRedhat is constructor -func newRedhat(c config.ServerInfo) *redhat { - r := &redhat{ - base: base{ - osPackages: osPackages{ - Packages: models.Packages{}, - VulnInfos: models.VulnInfos{}, - }, - }, - } - r.log = util.NewCustomLogger(c) - r.setServerInfo(c) - return r -} - // https://github.com/serverspec/specinfra/blob/master/lib/specinfra/helper/detect_os/redhat.rb -func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { - red = newRedhat(c) - +func detectRedhat(c config.ServerInfo) (bool, osTypeInterface) { if r := exec(c, "ls /etc/fedora-release", noSudo); r.isSuccess() { - red.setDistro(config.Fedora, "unknown") util.Log.Warnf("Fedora not tested yet: %s", r) - return true, red + return true, &unknown{} } if r := exec(c, "ls /etc/oracle-release", noSudo); r.isSuccess() { @@ -69,12 +46,13 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { result := re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) if len(result) != 3 { util.Log.Warnf("Failed to parse Oracle Linux version: %s", r) - return true, red + return true, newOracle(c) } + ora := newOracle(c) release := result[2] - red.setDistro(config.Oracle, release) - return true, red + ora.setDistro(config.Oracle, release) + return true, ora } } @@ -86,14 +64,15 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { result := re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) if len(result) != 3 { util.Log.Warnf("Failed to parse CentOS version: %s", r) - return true, red + return true, newCentOS(c) } release := result[2] switch strings.ToLower(result[1]) { case "centos", "centos linux": - red.setDistro(config.CentOS, release) - return true, red + cent := newCentOS(c) + cent.setDistro(config.CentOS, release) + return true, cent default: util.Log.Warnf("Failed to parse CentOS: %s", r) } @@ -110,19 +89,22 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { result := re.FindStringSubmatch(strings.TrimSpace(r.Stdout)) if len(result) != 3 { util.Log.Warnf("Failed to parse RedHat/CentOS version: %s", r) - return true, red + return true, newCentOS(c) } release := result[2] switch strings.ToLower(result[1]) { case "centos", "centos linux": - red.setDistro(config.CentOS, release) + cent := newCentOS(c) + cent.setDistro(config.CentOS, release) + return true, cent default: - red.setDistro(config.RedHat, release) + // RHEL + rhel := newRHEL(c) + rhel.setDistro(config.RedHat, release) + return true, rhel } - return true, red } - return true, red } if r := exec(c, "ls /etc/system-release", noSudo); r.isSuccess() { @@ -132,6 +114,9 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { if strings.HasPrefix(r.Stdout, "Amazon Linux release 2") { fields := strings.Fields(r.Stdout) release = fmt.Sprintf("%s %s", fields[3], fields[4]) + } else if strings.HasPrefix(r.Stdout, "Amazon Linux 2") { + fields := strings.Fields(r.Stdout) + release = strings.Join(fields[2:], " ") } else { fields := strings.Fields(r.Stdout) if len(fields) == 5 { @@ -139,57 +124,40 @@ func detectRedhat(c config.ServerInfo) (itsMe bool, red osTypeInterface) { } } } - red.setDistro(family, release) - return true, red + amazon := newAmazon(c) + amazon.setDistro(family, release) + return true, amazon } util.Log.Debugf("Not RedHat like Linux. servername: %s", c.ServerName) - return false, red + return false, &unknown{} } -func (o *redhat) checkIfSudoNoPasswd() error { - if !config.Conf.Deep || !o.sudo() { - o.log.Infof("sudo ... No need") - return nil - } +// inherit OsTypeInterface +type redhatBase struct { + base + sudo rootPriv +} - type cmd struct { - cmd string - expectedStatusCodes []int - } - var cmds []cmd - var zero = []int{0} +type rootPriv interface { + repoquery() bool + yumRepolist() bool + yumUpdateInfo() bool + yumChangelog() bool +} - switch o.Distro.Family { - case config.RedHat, config.Oracle: - majorVersion, err := o.Distro.MajorVersion() - if err != nil { - return fmt.Errorf("Not implemented yet: %s, err: %s", o.Distro, err) - } +type cmd struct { + cmd string + expectedStatusCodes []int +} - if majorVersion < 6 { - cmds = []cmd{ - {"yum --color=never repolist", zero}, - {"yum --color=never list-security --security", zero}, - {"yum --color=never info-security", zero}, - } - } else { - cmds = []cmd{ - {"yum --color=never repolist", zero}, - {"yum --color=never --security updateinfo list updates", zero}, - {"yum --color=never --security updateinfo updates", zero}, - } - } - - if o.Distro.Family == config.RedHat { - cmds = append(cmds, cmd{"repoquery -h", zero}) - } - } +var exitStatusZero = []int{0} +func (o *redhatBase) execCheckIfSudoNoPasswd(cmds []cmd) error { for _, c := range cmds { cmd := util.PrependProxyEnv(c.cmd) o.log.Infof("Checking... sudo %s", cmd) - r := o.exec(util.PrependProxyEnv(cmd), o.sudo()) + r := o.exec(util.PrependProxyEnv(cmd), sudo) if !r.isSuccess(c.expectedStatusCodes...) { o.log.Errorf("Check sudo or proxy settings: %s", r) return fmt.Errorf("Failed to sudo: %s", r) @@ -199,63 +167,7 @@ func (o *redhat) checkIfSudoNoPasswd() error { return nil } -// - Fast offline scan mode -// Amazon ... yum-utils -// -// - Fast scan mode -// All ... yum-utils -// -// - Deep scan mode -// CentOS 6,7 ... yum-utils, yum-plugin-changelog -// RHEL 5 (U1-) ... yum-utils, yum-security, yum-changelog -// RHEL 6 ... yum-utils, yum-security, yum-plugin-changelog -// RHEL 7 ... yum-utils, yum-plugin-changelog -// Amazon ... yum-utils -func (o *redhat) checkDependencies() error { - majorVersion, err := o.Distro.MajorVersion() - if err != nil { - msg := fmt.Sprintf("Not implemented yet: %s, err: %s", o.Distro, err) - o.log.Errorf(msg) - return fmt.Errorf(msg) - } - - if o.Distro.Family == config.CentOS { - if majorVersion < 6 { - msg := fmt.Sprintf("CentOS %s is not supported", o.Distro.Release) - o.log.Errorf(msg) - return fmt.Errorf(msg) - } - } - - packNames := []string{} - if config.Conf.Fast { - // Online fast scan needs yum-utils to issue repoquery cmd - packNames = append(packNames, "yum-utils") - } else if config.Conf.Offline { - switch o.Distro.Family { - case config.Amazon: - // Offline scan doesn't support Amazon Linux - packNames = append(packNames, "yum-utils") - } - } else { - // Deep Scan - switch o.Distro.Family { - case config.CentOS, config.Amazon: - packNames = append(packNames, "yum-utils", "yum-plugin-changelog") - case config.RedHat, config.Oracle: - switch majorVersion { - case 5: - packNames = append(packNames, "yum-utils", "yum-security", "yum-changelog") - case 6: - packNames = append(packNames, "yum-utils", "yum-plugin-security", "yum-plugin-changelog") - default: - packNames = append(packNames, "yum-utils", "yum-plugin-changelog") - } - default: - return fmt.Errorf("Not implemented yet: %s", o.Distro) - } - } - +func (o *redhatBase) execCheckDeps(packNames []string) error { for _, name := range packNames { cmd := "rpm -q " + name if r := o.exec(cmd, noSudo); !r.isSuccess() { @@ -268,7 +180,7 @@ func (o *redhat) checkDependencies() error { return nil } -func (o *redhat) preCure() error { +func (o *redhatBase) preCure() error { if err := o.detectIPAddr(); err != nil { o.log.Debugf("Failed to detect IP addresses: %s", err) } @@ -276,16 +188,27 @@ func (o *redhat) preCure() error { return nil } -func (o *redhat) postScan() error { +func (o *redhatBase) postScan() error { + if o.isExecYumPS() { + if err := o.yumPS(); err != nil { + return fmt.Errorf("Failed to execute yum-ps: %s", err) + } + } + if o.isExecNeedsRestarting() { + if err := o.needsRestarting(); err != nil { + return fmt.Errorf("Failed to execute need-restarting: %s", err) + } + } return nil } -func (o *redhat) detectIPAddr() (err error) { +func (o *redhatBase) detectIPAddr() (err error) { + o.log.Infof("Scanning in %s", o.getServerInfo().Mode) o.ServerInfo.IPv4Addrs, o.ServerInfo.IPv6Addrs, err = o.ip() return err } -func (o *redhat) scanPackages() error { +func (o *redhatBase) scanPackages() error { installed, err := o.scanInstalledPackages() if err != nil { o.log.Errorf("Failed to scan installed packages: %s", err) @@ -299,7 +222,7 @@ func (o *redhat) scanPackages() error { } o.Kernel.RebootRequired = rebootRequired - if config.Conf.Offline { + if o.getServerInfo().Mode.IsOffline() { switch o.Distro.Family { case config.Amazon: // nop @@ -307,6 +230,11 @@ func (o *redhat) scanPackages() error { o.Packages = installed return nil } + } else if o.Distro.Family == config.RedHat { + if o.getServerInfo().Mode.IsFast() { + o.Packages = installed + return nil + } } updatable, err := o.scanUpdatablePackages() @@ -326,7 +254,7 @@ func (o *redhat) scanPackages() error { return nil } -func (o *redhat) rebootRequired() (bool, error) { +func (o *redhatBase) rebootRequired() (bool, error) { r := o.exec("rpm -q --last kernel", noSudo) scanner := bufio.NewScanner(strings.NewReader(r.Stdout)) if !r.isSuccess(0, 1) { @@ -340,7 +268,7 @@ func (o *redhat) rebootRequired() (bool, error) { return running != lastInstalledKernelVer, nil } -func (o *redhat) scanInstalledPackages() (models.Packages, error) { +func (o *redhatBase) scanInstalledPackages() (models.Packages, error) { release, version, err := o.runningKernel() if err != nil { return nil, err @@ -350,19 +278,28 @@ func (o *redhat) scanInstalledPackages() (models.Packages, error) { Version: version, } - installed := models.Packages{} r := o.exec(rpmQa(o.Distro), noSudo) if !r.isSuccess() { return nil, fmt.Errorf("Scan packages failed: %s", r) } + installed, _, err := o.parseInstalledPackages(r.Stdout) + if err != nil { + return nil, err + } + return installed, nil +} + +func (o *redhatBase) parseInstalledPackages(stdout string) (models.Packages, models.SrcPackages, error) { + installed := models.Packages{} + latestKernelRelease := ver.NewVersion("") // openssl 0 1.0.1e 30.el6.11 x86_64 - lines := strings.Split(r.Stdout, "\n") + lines := strings.Split(stdout, "\n") for _, line := range lines { if trimed := strings.TrimSpace(line); len(trimed) != 0 { pack, err := o.parseInstalledPackagesLine(line) if err != nil { - return nil, err + return nil, nil, err } // Kernel package may be isntalled multiple versions. @@ -370,19 +307,28 @@ func (o *redhat) scanInstalledPackages() (models.Packages, error) { // pay attention only to the running kernel isKernel, running := isRunningKernel(pack, o.Distro.Family, o.Kernel) if isKernel { - if !running { + if o.Kernel.Release == "" { + // When the running kernel release is unknown, + // use the latest release among the installed release + kernelRelease := ver.NewVersion(fmt.Sprintf("%s-%s", pack.Version, pack.Release)) + if kernelRelease.LessThan(latestKernelRelease) { + continue + } + latestKernelRelease = kernelRelease + } else if !running { o.log.Debugf("Not a running kernel. pack: %#v, kernel: %#v", pack, o.Kernel) continue + } else { + o.log.Debugf("Found a running kernel. pack: %#v, kernel: %#v", pack, o.Kernel) } - o.log.Debugf("Found a running kernel. pack: %#v, kernel: %#v", pack, o.Kernel) } installed[pack.Name] = pack } } - return installed, nil + return installed, nil, nil } -func (o *redhat) parseInstalledPackagesLine(line string) (models.Package, error) { +func (o *redhatBase) parseInstalledPackagesLine(line string) (models.Package, error) { fields := strings.Fields(line) if len(fields) != 5 { return models.Package{}, @@ -404,13 +350,13 @@ func (o *redhat) parseInstalledPackagesLine(line string) (models.Package, error) }, nil } -func (o *redhat) scanUpdatablePackages() (models.Packages, error) { +func (o *redhatBase) scanUpdatablePackages() (models.Packages, error) { cmd := `repoquery --all --pkgnarrow=updates --qf="%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{REPO}"` for _, repo := range o.getServerInfo().Enablerepo { cmd += " --enablerepo=" + repo } - r := o.exec(util.PrependProxyEnv(cmd), o.sudo()) + r := o.exec(util.PrependProxyEnv(cmd), o.sudo.repoquery()) if !r.isSuccess() { return nil, fmt.Errorf("Failed to SSH: %s", r) } @@ -420,7 +366,7 @@ func (o *redhat) scanUpdatablePackages() (models.Packages, error) { } // parseUpdatablePacksLines parse the stdout of repoquery to get package name, candidate version -func (o *redhat) parseUpdatablePacksLines(stdout string) (models.Packages, error) { +func (o *redhatBase) parseUpdatablePacksLines(stdout string) (models.Packages, error) { updatable := models.Packages{} lines := strings.Split(stdout, "\n") for _, line := range lines { @@ -444,7 +390,7 @@ func (o *redhat) parseUpdatablePacksLines(stdout string) (models.Packages, error return updatable, nil } -func (o *redhat) parseUpdatablePacksLine(line string) (models.Package, error) { +func (o *redhatBase) parseUpdatablePacksLine(line string) (models.Package, error) { fields := strings.Fields(line) if len(fields) < 5 { return models.Package{}, fmt.Errorf("Unknown format: %s, fields: %s", line, fields) @@ -469,25 +415,109 @@ func (o *redhat) parseUpdatablePacksLine(line string) (models.Package, error) { return p, nil } -func (o *redhat) scanUnsecurePackages(updatable models.Packages) (models.VulnInfos, error) { - if config.Conf.Deep && o.Distro.Family != config.Amazon { - //TODO Cache changelogs to bolt +func (o *redhatBase) isExecScanUsingYum() bool { + if o.getServerInfo().Mode.IsOffline() { + return false + } + if o.Distro.Family == config.CentOS { + // CentOS doesn't have security channel + return false + } + if o.getServerInfo().Mode.IsFastRoot() || o.getServerInfo().Mode.IsDeep() { + return true + } + return true +} + +func (o *redhatBase) isExecFillChangelogs() bool { + if o.getServerInfo().Mode.IsOffline() { + return false + } + // Amazon linux has no changelos for updates + return o.getServerInfo().Mode.IsDeep() && + o.Distro.Family != config.Amazon +} + +func (o *redhatBase) isExecScanChangelogs() bool { + if o.getServerInfo().Mode.IsOffline() || + o.getServerInfo().Mode.IsFast() || + o.getServerInfo().Mode.IsFastRoot() { + return false + } + return true +} + +func (o *redhatBase) isExecYumPS() bool { + // RedHat has no yum-ps + switch o.Distro.Family { + case config.RedHat, + config.OpenSUSE, + config.OpenSUSELeap, + config.SUSEEnterpriseServer, + config.SUSEEnterpriseDesktop, + config.SUSEOpenstackCloud: + return false + } + + // yum ps needs internet connection + if o.getServerInfo().Mode.IsOffline() || o.getServerInfo().Mode.IsFast() { + return false + } + return true +} + +func (o *redhatBase) isExecNeedsRestarting() bool { + switch o.Distro.Family { + case config.OpenSUSE, + config.OpenSUSELeap, + config.SUSEEnterpriseServer, + config.SUSEEnterpriseDesktop, + config.SUSEOpenstackCloud: + // TODO zypper ps + // https://github.com/future-architect/vuls/issues/696 + return false + case config.RedHat, config.CentOS, config.Oracle: + majorVersion, err := o.Distro.MajorVersion() + if err != nil || majorVersion < 6 { + o.log.Errorf("Not implemented yet: %s, err: %s", o.Distro, err) + return false + } + + if o.getServerInfo().Mode.IsOffline() { + return false + } else if o.getServerInfo().Mode.IsFastRoot() || + o.getServerInfo().Mode.IsDeep() { + return true + } + return false + } + + if o.getServerInfo().Mode.IsFast() { + return false + } + return true +} + +func (o *redhatBase) scanUnsecurePackages(updatable models.Packages) (models.VulnInfos, error) { + if o.isExecFillChangelogs() { if err := o.fillChangelogs(updatable); err != nil { return nil, err } } - if o.Distro.Family != config.CentOS { - // Amazon, RHEL, Oracle Linux has yum updateinfo as default - // yum updateinfo can collenct vendor advisory information. - return o.scanCveIDsByCommands(updatable) + if o.isExecScanUsingYum() { + return o.scanUsingYum(updatable) } // Parse chnagelog because CentOS does not have security channel... - return o.scanCveIDsInChangelog(updatable) + if o.isExecScanChangelogs() { + return o.scanChangelogs(updatable) + } + + return models.VulnInfos{}, nil } -func (o *redhat) fillChangelogs(updatables models.Packages) error { +func (o *redhatBase) fillChangelogs(updatables models.Packages) error { names := []string{} for name := range updatables { names = append(names, name) @@ -516,7 +546,7 @@ func (o *redhat) fillChangelogs(updatables models.Packages) error { return nil } -func (o *redhat) getAvailableChangelogs(packNames []string) (map[string]string, error) { +func (o *redhatBase) getAvailableChangelogs(packNames []string) (map[string]string, error) { yumopts := "" if 0 < len(o.getServerInfo().Enablerepo) { yumopts = " --enablerepo=" + strings.Join(o.getServerInfo().Enablerepo, ",") @@ -527,10 +557,10 @@ func (o *redhat) getAvailableChangelogs(packNames []string) (map[string]string, if o.hasYumColorOption() { yumopts += " --color=never" } - cmd := `yum changelog all %s updates %s | grep -A 1000000 "==================== Updated Packages ===================="` + cmd := `yum changelog all updates %s %s | grep -A 1000000 "==================== Updated Packages ===================="` cmd = fmt.Sprintf(cmd, yumopts, strings.Join(packNames, " ")) - r := o.exec(util.PrependProxyEnv(cmd), o.sudo()) + r := o.exec(util.PrependProxyEnv(cmd), o.sudo.yumChangelog()) if !r.isSuccess(0, 1) { return nil, fmt.Errorf("Failed to SSH: %s", r) } @@ -539,7 +569,7 @@ func (o *redhat) getAvailableChangelogs(packNames []string) (map[string]string, } // Divide available change logs of all updatable packages into each package's changelog -func (o *redhat) divideChangelogsIntoEachPackages(stdout string) map[string]string { +func (o *redhatBase) divideChangelogsIntoEachPackages(stdout string) map[string]string { changelogs := make(map[string]string) scanner := bufio.NewScanner(strings.NewReader(stdout)) @@ -580,7 +610,7 @@ func (o *redhat) divideChangelogsIntoEachPackages(stdout string) map[string]stri return changelogs } -func (o *redhat) fillDiffChangelogs(packNames []string) error { +func (o *redhatBase) fillDiffChangelogs(packNames []string) error { changelogs, err := o.getAvailableChangelogs(packNames) if err != nil { return err @@ -593,19 +623,16 @@ func (o *redhat) fillDiffChangelogs(packNames []string) error { if index := strings.Index(p.NewVersion, ":"); 0 < index { epoch := p.NewVersion[0:index] ver := p.NewVersion[index+1 : len(p.NewVersion)] - epochNameVerRel = fmt.Sprintf("%s:%s-%s", - epoch, p.Name, ver) + epochNameVerRel = fmt.Sprintf("%s:%s-%s", epoch, p.Name, ver) } else { - epochNameVerRel = fmt.Sprintf("%s-%s", - p.Name, p.NewVersion) + epochNameVerRel = fmt.Sprintf("%s-%s", p.Name, p.NewVersion) } return strings.HasPrefix(s, epochNameVerRel) }) if found { - diff, err := o.getDiffChangelog(pack, changelogs[s]) var detectionMethod string - + diff, err := o.getDiffChangelog(pack, changelogs[s]) if err == nil { detectionMethod = models.ChangelogExactMatchStr } else { @@ -650,7 +677,7 @@ func (o *redhat) fillDiffChangelogs(packNames []string) error { return nil } -func (o *redhat) getDiffChangelog(pack models.Package, availableChangelog string) (string, error) { +func (o *redhatBase) getDiffChangelog(pack models.Package, availableChangelog string) (string, error) { installedVer := ver.NewVersion(fmt.Sprintf("%s-%s", pack.Version, pack.Release)) scanner := bufio.NewScanner(strings.NewReader(availableChangelog)) diff := []string{} @@ -702,7 +729,7 @@ func (o *redhat) getDiffChangelog(pack models.Package, availableChangelog string return strings.TrimSpace(strings.Join(diff, "\n")), nil } -func (o *redhat) scanCveIDsInChangelog(updatable models.Packages) (models.VulnInfos, error) { +func (o *redhatBase) scanChangelogs(updatable models.Packages) (models.VulnInfos, error) { packCveIDs := make(map[string][]string) for name := range updatable { cveIDs := []string{} @@ -739,7 +766,7 @@ func (o *redhat) scanCveIDsInChangelog(updatable models.Packages) (models.VulnIn vinfos[cid] = models.VulnInfo{ CveID: cid, AffectedPackages: models.PackageStatuses{{Name: name}}, - Confidence: models.ChangelogExactMatch, + Confidences: models.Confidences{models.ChangelogExactMatch}, } } } @@ -754,7 +781,7 @@ type distroAdvisoryCveIDs struct { // Scaning unsecure packages using yum-plugin-security. // Amazon, RHEL, Oracle Linux -func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInfos, error) { +func (o *redhatBase) scanUsingYum(updatable models.Packages) (models.VulnInfos, error) { if o.Distro.Family == config.CentOS { // CentOS has no security channel. return nil, fmt.Errorf( @@ -769,8 +796,8 @@ func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInf var cmd string if (o.Distro.Family == config.RedHat || o.Distro.Family == config.Oracle) && major > 5 { - cmd = "yum --color=never repolist" - r := o.exec(util.PrependProxyEnv(cmd), o.sudo()) + cmd = "yum repolist --color=never" + r := o.exec(util.PrependProxyEnv(cmd), o.sudo.yumRepolist()) if !r.isSuccess() { return nil, fmt.Errorf("Failed to SSH: %s", r) } @@ -782,9 +809,9 @@ func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInf cmd += " --color=never" } } else { - cmd = "yum --color=never --security updateinfo list updates" + cmd = "yum updateinfo list updates --security --color=never" } - r := o.exec(util.PrependProxyEnv(cmd), o.sudo()) + r := o.exec(util.PrependProxyEnv(cmd), o.sudo.yumUpdateInfo()) if !r.isSuccess() { return nil, fmt.Errorf("Failed to SSH: %s", r) } @@ -812,9 +839,9 @@ func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInf cmd += " --color=never" } } else { - cmd = "yum --color=never --security updateinfo updates" + cmd = "yum updateinfo updates --security --color=never" } - r = o.exec(util.PrependProxyEnv(cmd), o.sudo()) + r = o.exec(util.PrependProxyEnv(cmd), o.sudo.yumUpdateInfo()) if !r.isSuccess() { return nil, fmt.Errorf("Failed to SSH: %s", r) } @@ -848,7 +875,7 @@ func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInf CveID: cveID, DistroAdvisories: []models.DistroAdvisory{advIDCveIDs.DistroAdvisory}, AffectedPackages: affected, - Confidence: models.YumUpdateSecurityMatch, + Confidences: models.Confidences{models.YumUpdateSecurityMatch}, } } vinfos[cveID] = vinfo @@ -859,7 +886,7 @@ func (o *redhat) scanCveIDsByCommands(updatable models.Packages) (models.VulnInf var horizontalRulePattern = regexp.MustCompile(`^=+$`) -func (o *redhat) parseYumUpdateinfo(stdout string) (result []distroAdvisoryCveIDs, err error) { +func (o *redhatBase) parseYumUpdateinfo(stdout string) (result []distroAdvisoryCveIDs, err error) { sectionState := Outside lines := strings.Split(stdout, "\n") lines = append(lines, "=============") @@ -905,7 +932,7 @@ func (o *redhat) parseYumUpdateinfo(stdout string) (result []distroAdvisoryCveID case config.CentOS: // CentOS has no security channel. return result, fmt.Errorf( - "yum updateinfo is not suppported on CentOS") + "yum updateinfo is not suppported on CentOS") case config.RedHat, config.Amazon, config.Oracle: // nop } @@ -981,7 +1008,7 @@ const ( Content = iota ) -func (o *redhat) changeSectionState(state int) (newState int) { +func (o *redhatBase) changeSectionState(state int) (newState int) { switch state { case Outside, Content: newState = Header @@ -991,19 +1018,19 @@ func (o *redhat) changeSectionState(state int) (newState int) { return newState } -func (o *redhat) isCvesHeaderLine(line string) bool { +func (o *redhatBase) isCvesHeaderLine(line string) bool { return strings.Contains(line, "CVEs : ") } var yumCveIDPattern = regexp.MustCompile(`(CVE-\d{4}-\d{4,})`) -func (o *redhat) parseYumUpdateinfoLineToGetCveIDs(line string) []string { +func (o *redhatBase) parseYumUpdateinfoLineToGetCveIDs(line string) []string { return yumCveIDPattern.FindAllString(line, -1) } var yumAdvisoryIDPattern = regexp.MustCompile(`^ *Update ID : (.*)$`) -func (o *redhat) parseYumUpdateinfoToGetAdvisoryID(line string) (advisoryID string, found bool) { +func (o *redhatBase) parseYumUpdateinfoToGetAdvisoryID(line string) (advisoryID string, found bool) { result := yumAdvisoryIDPattern.FindStringSubmatch(line) if len(result) != 2 { return "", false @@ -1013,17 +1040,17 @@ func (o *redhat) parseYumUpdateinfoToGetAdvisoryID(line string) (advisoryID stri var yumIssuedPattern = regexp.MustCompile(`^\s*Issued : (\d{4}-\d{2}-\d{2})`) -func (o *redhat) parseYumUpdateinfoLineToGetIssued(line string) (date time.Time, found bool) { +func (o *redhatBase) parseYumUpdateinfoLineToGetIssued(line string) (date time.Time, found bool) { return o.parseYumUpdateinfoLineToGetDate(line, yumIssuedPattern) } var yumUpdatedPattern = regexp.MustCompile(`^\s*Updated : (\d{4}-\d{2}-\d{2})`) -func (o *redhat) parseYumUpdateinfoLineToGetUpdated(line string) (date time.Time, found bool) { +func (o *redhatBase) parseYumUpdateinfoLineToGetUpdated(line string) (date time.Time, found bool) { return o.parseYumUpdateinfoLineToGetDate(line, yumUpdatedPattern) } -func (o *redhat) parseYumUpdateinfoLineToGetDate(line string, regexpPattern *regexp.Regexp) (date time.Time, found bool) { +func (o *redhatBase) parseYumUpdateinfoLineToGetDate(line string, regexpPattern *regexp.Regexp) (date time.Time, found bool) { result := regexpPattern.FindStringSubmatch(line) if len(result) != 2 { return date, false @@ -1037,13 +1064,13 @@ func (o *redhat) parseYumUpdateinfoLineToGetDate(line string, regexpPattern *reg var yumDescriptionPattern = regexp.MustCompile(`^\s*Description : `) -func (o *redhat) isDescriptionLine(line string) bool { +func (o *redhatBase) isDescriptionLine(line string) bool { return yumDescriptionPattern.MatchString(line) } var yumSeverityPattern = regexp.MustCompile(`^ *Severity : (.*)$`) -func (o *redhat) parseYumUpdateinfoToGetSeverity(line string) (severity string, found bool) { +func (o *redhatBase) parseYumUpdateinfoToGetSeverity(line string) (severity string, found bool) { result := yumSeverityPattern.FindStringSubmatch(line) if len(result) != 2 { return "", false @@ -1066,7 +1093,7 @@ func (list advisoryIDPacksList) find(advisoryID string) (advisoryIDPacks, bool) } return advisoryIDPacks{}, false } -func (o *redhat) extractPackNameVerRel(nameVerRel string) (name, ver, rel string) { +func (o *redhatBase) extractPackNameVerRel(nameVerRel string) (name, ver, rel string) { fields := strings.Split(nameVerRel, ".") archTrimed := strings.Join(fields[0:len(fields)-1], ".") @@ -1078,7 +1105,7 @@ func (o *redhat) extractPackNameVerRel(nameVerRel string) (name, ver, rel string } // parseYumUpdateinfoListAvailable collect AdvisorID(RHSA, ALAS, ELSA), packages -func (o *redhat) parseYumUpdateinfoListAvailable(stdout string) (advisoryIDPacksList, error) { +func (o *redhatBase) parseYumUpdateinfoListAvailable(stdout string) (advisoryIDPacksList, error) { result := []advisoryIDPacks{} lines := strings.Split(stdout, "\n") for _, line := range lines { @@ -1120,21 +1147,201 @@ func (o *redhat) parseYumUpdateinfoListAvailable(stdout string) (advisoryIDPacks return result, nil } -func (o *redhat) clone() osTypeInterface { - return o -} - -func (o *redhat) sudo() bool { - switch o.Distro.Family { - case config.Amazon, config.CentOS: - return false - default: - // RHEL, Oracle - return config.Conf.Deep +func (o *redhatBase) yumPS() error { + cmd := "LANGUAGE=en_US.UTF-8 yum info yum" + r := o.exec(util.PrependProxyEnv(cmd), noSudo) + if !r.isSuccess() { + return fmt.Errorf("Failed to SSH: %s", r) } + if !o.checkYumPsInstalled(r.Stdout) { + switch o.Distro.Family { + case config.RedHat, config.Oracle: + return nil + default: + return fmt.Errorf("yum-plugin-ps is not installed") + } + } + + cmd = "LANGUAGE=en_US.UTF-8 yum -q ps all --color=never" + r = o.exec(util.PrependProxyEnv(cmd), sudo) + if !r.isSuccess() { + return fmt.Errorf("Failed to SSH: %s", r) + } + packs := o.parseYumPS(r.Stdout) + for name, pack := range packs { + p := o.Packages[name] + p.AffectedProcs = pack.AffectedProcs + o.Packages[name] = p + } + return nil } -func (o *redhat) hasYumColorOption() bool { +func (o *redhatBase) checkYumPsInstalled(stdout string) bool { + scanner := bufio.NewScanner(strings.NewReader(stdout)) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if strings.HasPrefix(line, "Loaded plugins: ") { + if strings.Contains(line, " ps,") || strings.HasSuffix(line, " ps") { + return true + } + return false + } + } + return false +} + +func (o *redhatBase) parseYumPS(stdout string) models.Packages { + packs := models.Packages{} + scanner := bufio.NewScanner(strings.NewReader(stdout)) + isPackageLine, needToParseProcline := false, false + currentPackName := "" + for scanner.Scan() { + line := scanner.Text() + fields := strings.Fields(line) + if len(fields) == 0 || + len(fields) == 1 && fields[0] == "ps" || + len(fields) == 6 && fields[0] == "pid" { + continue + } + + isPackageLine = !strings.HasPrefix(line, " ") + if isPackageLine { + if 1 < len(fields) && fields[1] == "Upgrade" { + needToParseProcline = true + + // Search o.Packages to divide into name, version, release + name, pack, found := o.Packages.FindOne(func(p models.Package) bool { + var epochNameVerRel string + if index := strings.Index(p.Version, ":"); 0 < index { + epoch := p.Version[0:index] + ver := p.Version[index+1 : len(p.Version)] + epochNameVerRel = fmt.Sprintf("%s:%s-%s-%s.%s", + epoch, p.Name, ver, p.Release, p.Arch) + } else { + epochNameVerRel = fmt.Sprintf("%s-%s-%s.%s", + p.Name, p.Version, p.Release, p.Arch) + } + return strings.HasPrefix(fields[0], epochNameVerRel) + }) + if !found { + o.log.Errorf("`yum ps` package is not found: %s", line) + continue + } + packs[name] = pack + currentPackName = name + } else { + needToParseProcline = false + } + } else if needToParseProcline { + if 6 < len(fields) { + proc := models.AffectedProcess{ + PID: fields[0], + Name: fields[1], + } + pack := packs[currentPackName] + pack.AffectedProcs = append(pack.AffectedProcs, proc) + packs[currentPackName] = pack + } else { + o.log.Errorf("`yum ps` Unknown Format: %s", line) + continue + } + } + } + return packs +} + +func (o *redhatBase) needsRestarting() error { + initName, err := o.detectInitSystem() + if err != nil { + o.log.Warn(err) + // continue scanning + } + + cmd := "LANGUAGE=en_US.UTF-8 needs-restarting" + r := o.exec(cmd, sudo) + if !r.isSuccess() { + return fmt.Errorf("Failed to SSH: %s", r) + } + procs := o.parseNeedsRestarting(r.Stdout) + for _, proc := range procs { + fqpn, err := o.procPathToFQPN(proc.Path) + if err != nil { + o.log.Warnf("Failed to detect a package name of need restarting process from the command path: %s, %s", + proc.Path, err) + continue + } + pack, err := o.Packages.FindByFQPN(fqpn) + if err != nil { + return err + } + if initName == systemd { + name, err := o.detectServiceName(proc.PID) + if err != nil { + o.log.Warn(err) + // continue scanning + } + proc.ServiceName = name + proc.InitSystem = systemd + } + pack.NeedRestartProcs = append(pack.NeedRestartProcs, proc) + o.Packages[pack.Name] = *pack + } + return nil +} + +func (o *redhatBase) parseNeedsRestarting(stdout string) (procs []models.NeedRestartProcess) { + scanner := bufio.NewScanner(strings.NewReader(stdout)) + for scanner.Scan() { + line := scanner.Text() + line = strings.Replace(line, "\x00", " ", -1) // for CentOS6.9 + ss := strings.Split(line, " : ") + if len(ss) < 2 { + continue + } + // https://unix.stackexchange.com/a/419375 + if ss[0] == "1" { + continue + } + + path := ss[1] + if !strings.HasPrefix(path, "/") { + path = strings.Fields(path)[0] + // [ec2-user@ip-172-31-11-139 ~]$ sudo needs-restarting + // 2024 : auditd + // [ec2-user@ip-172-31-11-139 ~]$ type -p auditd + // /sbin/auditd + cmd := fmt.Sprintf("LANGUAGE=en_US.UTF-8 which %s", path) + r := o.exec(cmd, sudo) + if !r.isSuccess() { + o.log.Warnf("Failed to exec which %s: %s", path, r) + continue + } + path = strings.TrimSpace(r.Stdout) + } + + procs = append(procs, models.NeedRestartProcess{ + PID: ss[0], + Path: path, + HasInit: true, + }) + } + return +} + +// procPathToFQPN returns Fully-Qualified-Package-Name from the command +func (o *redhatBase) procPathToFQPN(execCommand string) (string, error) { + execCommand = strings.Replace(execCommand, "\x00", " ", -1) // for CentOS6.9 + path := strings.Fields(execCommand)[0] + cmd := `LANGUAGE=en_US.UTF-8 rpm -qf --queryformat "%{NAME}-%{EPOCH}:%{VERSION}-%{RELEASE}.%{ARCH}\n" ` + path + r := o.exec(cmd, noSudo) + if !r.isSuccess() { + return "", fmt.Errorf("Failed to SSH: %s", r) + } + fqpn := strings.TrimSpace(r.Stdout) + return strings.Replace(fqpn, "-(none):", "-", -1), nil +} + +func (o *redhatBase) hasYumColorOption() bool { cmd := "yum --help | grep color" r := o.exec(util.PrependProxyEnv(cmd), noSudo) return len(r.Stdout) > 0 diff --git a/scan/redhat_test.go b/scan/redhatbase_test.go similarity index 74% rename from scan/redhat_test.go rename to scan/redhatbase_test.go index 03545ff9..7d1401f2 100644 --- a/scan/redhat_test.go +++ b/scan/redhatbase_test.go @@ -32,9 +32,90 @@ import ( // return t // } -func TestParseScanedPackagesLineRedhat(t *testing.T) { +func TestParseInstalledPackagesLinesRedhat(t *testing.T) { + r := newRHEL(config.ServerInfo{}) + r.Distro = config.Distro{Family: config.RedHat} - r := newRedhat(config.ServerInfo{}) + var packagetests = []struct { + in string + kernel models.Kernel + packages models.Packages + }{ + { + in: `openssl 0 1.0.1e 30.el6.11 x86_64 + Percona-Server-shared-56 1 5.6.19 rel67.0.el6 x84_64 + kernel 0 2.6.32 696.20.1.el6 x86_64 + kernel 0 2.6.32 696.20.3.el6 x86_64 + kernel 0 2.6.32 695.20.3.el6 x86_64`, + kernel: models.Kernel{}, + packages: models.Packages{ + "openssl": models.Package{ + Name: "openssl", + Version: "1.0.1e", + Release: "30.el6.11", + }, + "Percona-Server-shared-56": models.Package{ + Name: "Percona-Server-shared-56", + Version: "1:5.6.19", + Release: "rel67.0.el6", + }, + "kernel": models.Package{ + Name: "kernel", + Version: "2.6.32", + Release: "696.20.3.el6", + }, + }, + }, + { + in: `openssl 0 1.0.1e 30.el6.11 x86_64 + Percona-Server-shared-56 1 5.6.19 rel67.0.el6 x84_64 + kernel 0 2.6.32 696.20.1.el6 x86_64 + kernel 0 2.6.32 696.20.3.el6 x86_64 + kernel 0 2.6.32 695.20.3.el6 x86_64`, + kernel: models.Kernel{Release: "2.6.32-695.20.3.el6.x86_64"}, + packages: models.Packages{ + "openssl": models.Package{ + Name: "openssl", + Version: "1.0.1e", + Release: "30.el6.11", + }, + "Percona-Server-shared-56": models.Package{ + Name: "Percona-Server-shared-56", + Version: "1:5.6.19", + Release: "rel67.0.el6", + }, + "kernel": models.Package{ + Name: "kernel", + Version: "2.6.32", + Release: "695.20.3.el6", + }, + }, + }, + } + + for _, tt := range packagetests { + r.Kernel = tt.kernel + packages, _, err := r.parseInstalledPackages(tt.in) + if err != nil { + t.Errorf("Unexpected error: %s", err) + } + for name, expectedPack := range tt.packages { + pack := packages[name] + if pack.Name != expectedPack.Name { + t.Errorf("name: expected %s, actual %s", expectedPack.Name, pack.Name) + } + if pack.Version != expectedPack.Version { + t.Errorf("version: expected %s, actual %s", expectedPack.Version, pack.Version) + } + if pack.Release != expectedPack.Release { + t.Errorf("release: expected %s, actual %s", expectedPack.Release, pack.Release) + } + } + } + +} +func TestParseScanedPackagesLineRedhat(t *testing.T) { + r := newRHEL(config.ServerInfo{}) var packagetests = []struct { in string @@ -74,7 +155,7 @@ func TestParseScanedPackagesLineRedhat(t *testing.T) { } func TestChangeSectionState(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { oldState int newState int @@ -92,7 +173,7 @@ func TestChangeSectionState(t *testing.T) { } func TestParseYumUpdateinfoLineToGetCveIDs(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string out []string @@ -122,7 +203,7 @@ func TestParseYumUpdateinfoLineToGetCveIDs(t *testing.T) { } func TestParseYumUpdateinfoToGetAdvisoryID(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string out string @@ -160,7 +241,7 @@ func TestParseYumUpdateinfoLineToGetIssued(t *testing.T) { date, _ := time.Parse("2006-01-02", "2015-12-15") - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string out time.Time @@ -195,10 +276,9 @@ func TestParseYumUpdateinfoLineToGetIssued(t *testing.T) { } func TestParseYumUpdateinfoLineToGetUpdated(t *testing.T) { - date, _ := time.Parse("2006-01-02", "2015-12-15") - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string out time.Time @@ -234,7 +314,7 @@ func TestParseYumUpdateinfoLineToGetUpdated(t *testing.T) { } func TestIsDescriptionLine(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string found bool @@ -262,7 +342,7 @@ func TestIsDescriptionLine(t *testing.T) { } func TestParseYumUpdateinfoToGetSeverity(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) var tests = []struct { in string out string @@ -337,7 +417,7 @@ Description : kernel-uek ` issued, _ := time.Parse("2006-01-02", "2017-02-15") - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) r.Distro = config.Distro{Family: "oraclelinux"} var tests = []struct { @@ -458,7 +538,7 @@ Description : The sudo packages contain the sudo utility which allows system issued, _ := time.Parse("2006-01-02", "2015-09-03") updated, _ := time.Parse("2006-01-02", "2015-09-04") - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) r.Distro = config.Distro{Family: "redhat"} var tests = []struct { @@ -532,8 +612,7 @@ Description : The sudo packages contain the sudo utility which allows system } func TestParseYumUpdateinfoAmazon(t *testing.T) { - - r := newRedhat(config.ServerInfo{}) + r := newAmazon(config.ServerInfo{}) r.Distro = config.Distro{Family: "redhat"} issued, _ := time.Parse("2006-01-02", "2015-12-15") @@ -617,7 +696,7 @@ Description : Package updates are available for Amazon Linux AMI that fix the } func TestParseYumCheckUpdateLine(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newCentOS(config.ServerInfo{}) r.Distro = config.Distro{Family: "centos"} var tests = []struct { in string @@ -658,7 +737,7 @@ func TestParseYumCheckUpdateLine(t *testing.T) { } func TestParseYumCheckUpdateLines(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newCentOS(config.ServerInfo{}) r.Distro = config.Distro{Family: "centos"} stdout := `audit-libs 0 2.3.7 5.el6 base bash 0 4.1.2 33.el6_7.1 updates @@ -739,7 +818,7 @@ pytalloc 0 2.0.7 2.el6 @CentOS 6.5/6.5` } func TestParseYumCheckUpdateLinesAmazon(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newAmazon(config.ServerInfo{}) r.Distro = config.Distro{Family: "amazon"} stdout := `bind-libs 32 9.8.2 0.37.rc1.45.amzn1 amzn-main java-1.7.0-openjdk 0 1.7.0.95 2.6.4.0.65.amzn1 amzn-main @@ -795,7 +874,7 @@ if-not-architecture 0 100 200 amzn-main` } func TestParseYumUpdateinfoListAvailable(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) rhelStdout := `RHSA-2015:2315 Moderate/Sec. NetworkManager-1:1.0.6-27.el7.x86_64 RHSA-2015:2315 Moderate/Sec. NetworkManager-config-server-1:1.0.6-27.el7.x86_64 RHSA-2015:1705 Important/Sec. bind-libs-lite-32:9.9.4-18.el7_1.5.x86_64 @@ -859,7 +938,7 @@ updateinfo list done` } func TestExtractPackNameVerRel(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newAmazon(config.ServerInfo{}) var tests = []struct { in string out []string @@ -894,7 +973,7 @@ func TestExtractPackNameVerRel(t *testing.T) { } func TestGetDiffChangelog(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newCentOS(config.ServerInfo{}) type in struct { pack models.Package changelog string @@ -1245,7 +1324,7 @@ func TestGetDiffChangelog(t *testing.T) { } func TestDivideChangelogsIntoEachPackages(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newRHEL(config.ServerInfo{}) type in struct { pack models.Package changelog string @@ -1297,3 +1376,389 @@ func TestDivideChangelogsIntoEachPackages(t *testing.T) { } } + +func TestCheckYumPsInstalled(t *testing.T) { + r := newCentOS(config.ServerInfo{}) + var tests = []struct { + in string + out bool + }{ + { + in: `Loaded plugins: changelog, fastestmirror, ps, remove-with-leaves, show-leaves +Loading mirror speeds from cached hostfile + * base: ftp.tsukuba.wide.ad.jp + * extras: ftp.tsukuba.wide.ad.jp + * updates: ftp.tsukuba.wide.ad.jp +Installed Packages +Name : yum +Arch : noarch +Version : 3.4.3 +Release : 150.el7.centos +Size : 5.5 M +Repo : installed +From repo : anaconda +Summary : RPM package installer/updater/manager +URL : http://yum.baseurl.org/ +License : GPLv2+ +Description : Yum is a utility that can check for and automatically download and + : install updated RPM packages. Dependencies are obtained and downloaded + : automatically, prompting the user for permission as necessary. + +Available Packages +Name : yum +Arch : noarch +Version : 3.4.3 +Release : 154.el7.centos.1 +Size : 1.2 M +Repo : updates/7/x86_64 +Summary : RPM package installer/updater/manager +URL : http://yum.baseurl.org/ +License : GPLv2+ +Description : Yum is a utility that can check for and automatically download and + : install updated RPM packages. Dependencies are obtained and downloaded + : automatically, prompting the user for permission as necessary.`, + out: true, + }, + { + in: `Failed to set locale, defaulting to C +Loaded plugins: amazon-id, rhui-lb, search-disabled-repos +Installed Packages +Name : yum +Arch : noarch +Version : 3.4.3 +Release : 154.el7 +Size : 5.5 M +Repo : installed +From repo : rhui-REGION-rhel-server-releases +Summary : RPM package installer/updater/manager +URL : http://yum.baseurl.org/ +License : GPLv2+ +Description : Yum is a utility that can check for and automatically download and + : install updated RPM packages. Dependencies are obtained and downloaded + : automatically, prompting the user for permission as necessary.`, + out: false, + }, + } + + for _, tt := range tests { + ok := r.checkYumPsInstalled(tt.in) + if ok != tt.out { + t.Errorf("expected: %v\nactual: %v", tt.out, ok) + } + } +} + +func TestParseYumPS(t *testing.T) { + r := newCentOS(config.ServerInfo{}) + r.Distro = config.Distro{Family: "centos"} + r.Packages = models.NewPackages( + models.Package{ + Name: "python", + Version: "2.7.5", + Release: "34.el7", + Arch: "x86_64", + }, + models.Package{ + Name: "util-linux", + Version: "2.23.2", + Release: "26.el7", + Arch: "x86_64", + }, + models.Package{ + Name: "wpa_supplicant", + Version: "1:2.0", + Release: "17.el7_1", + Arch: "x86_64", + }, + models.Package{ + Name: "yum", + Version: "3.4.3", + Release: "150.el7.centos", + Arch: "noarch", + }, + ) + + var tests = []struct { + in string + out models.Packages + }{ + { + ` pid proc CPU RSS State uptime +python-2.7.5-34.el7.x86_64 Upgrade 2.7.5-48.el7.x86_64 + 741 tuned 1:54 16 MB Sleeping: 14 day(s) 21:52:32 + 38755 yum 0:00 42 MB Running: 00:00 +util-linux-2.23.2-26.el7.x86_64 Upgrade 2.23.2-33.el7_3.2.x86_64 + 626 agetty 0:00 848 kB Sleeping: 14 day(s) 21:52:37 + 628 agetty 0:00 848 kB Sleeping: 14 day(s) 21:52:37 +1:wpa_supplicant-2.0-17.el7_1.x86_64 Upgrade 1:2.0-21.el7_3.x86_64 + 638 wpa_supplicant 0:00 2.6 MB Sleeping: 14 day(s) 21:52:37 +yum-3.4.3-150.el7.centos.noarch + 38755 yum 0:00 42 MB Running: 00:00 +ps + `, + models.NewPackages( + models.Package{ + Name: "python", + Version: "2.7.5", + Release: "34.el7", + Arch: "x86_64", + // NewVersion: "2.7.5-", + // NewRelease: "48.el7.x86_64", + AffectedProcs: []models.AffectedProcess{ + { + PID: "741", + Name: "tuned", + }, + { + PID: "38755", + Name: "yum", + }, + }, + }, + models.Package{ + Name: "util-linux", + Version: "2.23.2", + Release: "26.el7", + Arch: "x86_64", + // NewVersion: "2.7.5", + // NewRelease: "48.el7.x86_64", + AffectedProcs: []models.AffectedProcess{ + { + PID: "626", + Name: "agetty", + }, + { + PID: "628", + Name: "agetty", + }, + }, + }, + models.Package{ + Name: "wpa_supplicant", + Version: "1:2.0", + Release: "17.el7_1", + Arch: "x86_64", + // NewVersion: "1:2.0", + // NewRelease: "21.el7_3.x86_64", + AffectedProcs: []models.AffectedProcess{ + { + PID: "638", + Name: "wpa_supplicant", + }, + }, + }, + ), + }, + { + ` pid proc CPU RSS State uptime +acpid-2.0.19-6.7.amzn1.x86_64 + 2388 acpid 0:00 1.4 MB Sleeping: 21:08 +at-3.1.10-48.15.amzn1.x86_64 + 2546 atd 0:00 164 kB Sleeping: 21:06 +cronie-anacron-1.4.4-15.8.amzn1.x86_64 + 2637 anacron 0:00 1.5 MB Sleeping: 13:14 +12:dhclient-4.1.1-51.P1.26.amzn1.x86_64 + 2061 dhclient 0:00 1.4 MB Sleeping: 21:10 + 2193 dhclient 0:00 2.1 MB Sleeping: 21:08 +mingetty-1.08-5.9.amzn1.x86_64 + 2572 mingetty 0:00 1.4 MB Sleeping: 21:06 + 2575 mingetty 0:00 1.4 MB Sleeping: 21:06 + 2578 mingetty 0:00 1.5 MB Sleeping: 21:06 + 2580 mingetty 0:00 1.4 MB Sleeping: 21:06 + 2582 mingetty 0:00 1.4 MB Sleeping: 21:06 + 2584 mingetty 0:00 1.4 MB Sleeping: 21:06 +openssh-server-6.6.1p1-33.66.amzn1.x86_64 + 2481 sshd 0:00 2.6 MB Sleeping: 21:07 +python27-2.7.12-2.120.amzn1.x86_64 + 2649 yum 0:00 35 MB Running: 00:01 +rsyslog-5.8.10-9.26.amzn1.x86_64 + 2261 rsyslogd 0:00 2.6 MB Sleeping: 21:08 +udev-173-4.13.amzn1.x86_64 + 1528 udevd 0:00 2.5 MB Sleeping: 21:12 + 1652 udevd 0:00 2.1 MB Sleeping: 21:12 + 1653 udevd 0:00 2.0 MB Sleeping: 21:12 +upstart-0.6.5-13.3.13.amzn1.x86_64 + 1 init 0:00 2.5 MB Sleeping: 21:13 +util-linux-2.23.2-33.28.amzn1.x86_64 + 2569 agetty 0:00 1.6 MB Sleeping: 21:06 +yum-3.4.3-150.70.amzn1.noarch + 2649 yum 0:00 35 MB Running: 00:01 +`, + models.Packages{}, + }, + } + + for _, tt := range tests { + packages := r.parseYumPS(tt.in) + for name, ePack := range tt.out { + if !reflect.DeepEqual(ePack, packages[name]) { + e := pp.Sprintf("%v", ePack) + a := pp.Sprintf("%v", packages[name]) + t.Errorf("expected %s, actual %s", e, a) + } + } + } +} + +func TestParseNeedsRestarting(t *testing.T) { + r := newCentOS(config.ServerInfo{}) + r.Distro = config.Distro{Family: "centos"} + + var tests = []struct { + in string + out []models.NeedRestartProcess + }{ + { + `1 : /usr/lib/systemd/systemd --switched-root --system --deserialize 21 +437 : /usr/sbin/NetworkManager --no-daemon`, + []models.NeedRestartProcess{ + { + PID: "437", + Path: "/usr/sbin/NetworkManager --no-daemon", + HasInit: true, + }, + }, + }, + } + + for _, tt := range tests { + procs := r.parseNeedsRestarting(tt.in) + if !reflect.DeepEqual(tt.out, procs) { + t.Errorf("expected %#v, actual %#v", tt.out, procs) + } + } +} + +func TestIsExecScanUsingYum(t *testing.T) { + r := newRHEL(config.ServerInfo{}) + var tests = []struct { + modes []byte + family string + out bool + }{ + { + modes: []byte{config.Offline}, + out: false, + }, + { + modes: []byte{}, + family: config.CentOS, + out: false, + }, + { + family: config.Amazon, + modes: []byte{config.FastRoot}, + out: true, + }, + { + family: config.Amazon, + modes: []byte{config.Deep}, + out: true, + }, + } + + for i, tt := range tests { + r.Distro.Family = tt.family + mode := config.ScanMode{} + for _, m := range tt.modes { + mode.Set(m) + } + + si := r.getServerInfo() + si.Mode = mode + r.setServerInfo(si) + + out := r.isExecScanUsingYum() + if out != tt.out { + t.Errorf("[%d] expected %#v, actual %#v", i, tt.out, out) + } + } +} + +func TestIsExecFillChangelogs(t *testing.T) { + r := newRHEL(config.ServerInfo{}) + var tests = []struct { + modes []byte + family string + out bool + }{ + { + modes: []byte{config.Offline}, + out: false, + }, + { + modes: []byte{config.Deep}, + family: config.CentOS, + out: true, + }, + { + family: config.Amazon, + modes: []byte{config.Deep}, + out: false, + }, + { + modes: []byte{config.Deep}, + family: config.RedHat, + out: true, + }, + } + + for i, tt := range tests { + r.Distro.Family = tt.family + mode := config.ScanMode{} + for _, m := range tt.modes { + mode.Set(m) + } + + si := r.getServerInfo() + si.Mode = mode + r.setServerInfo(si) + out := r.isExecFillChangelogs() + if out != tt.out { + t.Errorf("[%d] expected %#v, actual %#v", i, tt.out, out) + } + } +} + +func TestIsScanChangelogs(t *testing.T) { + r := newCentOS(config.ServerInfo{}) + var tests = []struct { + modes []byte + family string + out bool + }{ + { + modes: []byte{config.Offline}, + out: false, + }, + { + modes: []byte{config.Fast}, + out: false, + }, + { + modes: []byte{config.FastRoot}, + out: false, + }, + { + modes: []byte{config.Deep}, + family: config.RedHat, + out: true, + }, + } + + for i, tt := range tests { + r.Distro.Family = tt.family + mode := config.ScanMode{} + for _, m := range tt.modes { + mode.Set(m) + } + + si := r.getServerInfo() + si.Mode = mode + r.setServerInfo(si) + out := r.isExecScanChangelogs() + if out != tt.out { + t.Errorf("[%d] expected %#v, actual %#v", i, tt.out, out) + } + } +} diff --git a/scan/rhel.go b/scan/rhel.go new file mode 100644 index 00000000..70f311af --- /dev/null +++ b/scan/rhel.go @@ -0,0 +1,159 @@ +package scan + +import ( + "fmt" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/util" +) + +// inherit OsTypeInterface +type rhel struct { + redhatBase +} + +// NewRHEL is constructor +func newRHEL(c config.ServerInfo) *rhel { + r := &rhel{ + redhatBase{ + base: base{ + osPackages: osPackages{ + Packages: models.Packages{}, + VulnInfos: models.VulnInfos{}, + }, + }, + sudo: rootPrivRHEL{}, + }, + } + r.log = util.NewCustomLogger(c) + r.setServerInfo(c) + return r +} + +func (o *rhel) checkScanMode() error { + return nil +} + +func (o *rhel) checkDeps() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckDeps(o.depsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckDeps(o.depsFastRoot()) + } else if o.getServerInfo().Mode.IsDeep() { + return o.execCheckDeps(o.depsDeep()) + } + return fmt.Errorf("Unknown scan mode") +} + +func (o *rhel) depsFast() []string { + return []string{} +} + +func (o *rhel) depsFastRoot() []string { + if o.getServerInfo().Mode.IsOffline() { + return []string{} + } + + majorVersion, _ := o.Distro.MajorVersion() + switch majorVersion { + case 5: + return []string{ + "yum-utils", + "yum-security", + } + case 6: + return []string{ + "yum-utils", + "yum-plugin-security", + } + default: + return []string{ + "yum-utils", + } + } +} + +func (o *rhel) depsDeep() []string { + majorVersion, _ := o.Distro.MajorVersion() + switch majorVersion { + case 5: + return []string{ + "yum-utils", + "yum-security", + "yum-changelog", + } + case 6: + return []string{ + "yum-utils", + "yum-plugin-security", + "yum-plugin-changelog", + } + default: + return []string{ + "yum-utils", + "yum-plugin-changelog", + } + } +} + +func (o *rhel) checkIfSudoNoPasswd() error { + if o.getServerInfo().Mode.IsFast() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFast()) + } else if o.getServerInfo().Mode.IsFastRoot() { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsFastRoot()) + } else { + return o.execCheckIfSudoNoPasswd(o.sudoNoPasswdCmdsDeep()) + } +} + +func (o *rhel) sudoNoPasswdCmdsFast() []cmd { + return []cmd{} +} + +func (o *rhel) sudoNoPasswdCmdsFastRoot() []cmd { + if o.getServerInfo().Mode.IsOffline() { + return []cmd{} + } + + majorVersion, _ := o.Distro.MajorVersion() + if majorVersion < 6 { + return []cmd{ + // {"needs-restarting", exitStatusZero}, + {"yum repolist --color=never", exitStatusZero}, + {"yum list-security --security --color=never", exitStatusZero}, + {"yum info-security --color=never", exitStatusZero}, + {"repoquery -h", exitStatusZero}, + } + } + return []cmd{ + {"yum repolist --color=never", exitStatusZero}, + {"yum updateinfo list updates --security --color=never", exitStatusZero}, + {"yum updateinfo updates --security --color=never ", exitStatusZero}, + {"repoquery -h", exitStatusZero}, + {"needs-restarting", exitStatusZero}, + } +} + +func (o *rhel) sudoNoPasswdCmdsDeep() []cmd { + return append(o.sudoNoPasswdCmdsFastRoot(), + cmd{"yum changelog all updates --color=never", exitStatusZero}) +} + +type rootPrivRHEL struct{} + +func (o rootPrivRHEL) repoquery() bool { + return true +} + +func (o rootPrivRHEL) yumRepolist() bool { + return true +} + +func (o rootPrivRHEL) yumUpdateInfo() bool { + return true +} + +func (o rootPrivRHEL) yumChangelog() bool { + return true +} diff --git a/scan/serverapi.go b/scan/serverapi.go index c596630f..80267d78 100644 --- a/scan/serverapi.go +++ b/scan/serverapi.go @@ -18,7 +18,9 @@ along with this program. If not, see . package scan import ( + "errors" "fmt" + "net/http" "os" "path/filepath" "time" @@ -30,6 +32,13 @@ import ( "github.com/future-architect/vuls/util" ) +var ( + errOSFamilyHeader = errors.New("X-Vuls-OS-Family header is required") + errOSReleaseHeader = errors.New("X-Vuls-OS-Release header is required") + errKernelVersionHeader = errors.New("X-Vuls-Kernel-Version header is required") + errServerNameHeader = errors.New("X-Vuls-Server-Name header is required") +) + var servers, errServers []osTypeInterface // Base Interface of redhat, debian, freebsd @@ -41,7 +50,8 @@ type osTypeInterface interface { detectPlatform() getPlatform() models.Platform - checkDependencies() error + checkScanMode() error + checkDeps() error checkIfSudoNoPasswd() error preCure() error @@ -49,6 +59,8 @@ type osTypeInterface interface { scanPackages() error convertToModel() models.ScanResult + parseInstalledPackages(string) (models.Packages, models.SrcPackages, error) + runningContainers() ([]config.Container, error) exitedContainers() ([]config.Container, error) allContainers() ([]config.Container, error) @@ -119,7 +131,11 @@ func detectOS(c config.ServerInfo) (osType osTypeInterface) { } // PrintSSHableServerNames print SSH-able servernames -func PrintSSHableServerNames() { +func PrintSSHableServerNames() bool { + if len(servers) == 0 { + util.Log.Error("No scannable servers") + return false + } util.Log.Info("Scannable servers are below...") for _, s := range servers { if s.getServerInfo().IsContainer() { @@ -132,6 +148,7 @@ func PrintSSHableServerNames() { } } fmt.Printf("\n") + return true } // InitServers detect the kind of OS distribution of target servers @@ -273,7 +290,7 @@ func detectContainerOSes(timeoutSec int) (actives, inactives []osTypeInterface) func detectContainerOSesOnServer(containerHost osTypeInterface) (oses []osTypeInterface) { containerHostInfo := containerHost.getServerInfo() - if len(containerHostInfo.Containers.Includes) == 0 { + if len(containerHostInfo.ContainersIncluded) == 0 { return } @@ -285,11 +302,10 @@ func detectContainerOSesOnServer(containerHost osTypeInterface) (oses []osTypeIn return append(oses, containerHost) } - if containerHostInfo.Containers.Includes[0] == "${running}" { + if containerHostInfo.ContainersIncluded[0] == "${running}" { for _, containerInfo := range running { - found := false - for _, ex := range containerHost.getServerInfo().Containers.Excludes { + for _, ex := range containerHost.getServerInfo().ContainersExcluded { if containerInfo.Name == ex || containerInfo.ContainerID == ex { found = true } @@ -319,7 +335,7 @@ func detectContainerOSesOnServer(containerHost osTypeInterface) (oses []osTypeIn } var exited, unknown []string - for _, container := range containerHostInfo.Containers.Includes { + for _, container := range containerHostInfo.ContainersIncluded { found := false for _, c := range running { if c.ContainerID == container || c.Name == container { @@ -355,10 +371,21 @@ func detectContainerOSesOnServer(containerHost osTypeInterface) (oses []osTypeIn return oses } +// CheckScanModes checks scan mode +func CheckScanModes() error { + for _, s := range servers { + if err := s.checkScanMode(); err != nil { + return fmt.Errorf("servers.%s.scanMode err: %s", + s.getServerInfo().GetServerName(), err) + } + } + return nil +} + // CheckDependencies checks dependencies are installed on target servers. func CheckDependencies(timeoutSec int) { parallelExec(func(o osTypeInterface) error { - return o.checkDependencies() + return o.checkDeps() }, timeoutSec) return } @@ -420,15 +447,92 @@ func Scan(timeoutSec int) error { util.Log.Info("Scanning vulnerable OS packages...") scannedAt := time.Now() - dir, err := ensureResultDir(scannedAt) + dir, err := EnsureResultDir(scannedAt) if err != nil { return err } - if err := scanVulns(dir, scannedAt, timeoutSec); err != nil { - return err + return scanVulns(dir, scannedAt, timeoutSec) +} + +// ViaHTTP scans servers by HTTP header and body +func ViaHTTP(header http.Header, body string) (models.ScanResult, error) { + family := header.Get("X-Vuls-OS-Family") + if family == "" { + return models.ScanResult{}, errOSFamilyHeader } - return nil + release := header.Get("X-Vuls-OS-Release") + if release == "" { + return models.ScanResult{}, errOSReleaseHeader + } + + kernelRelease := header.Get("X-Vuls-Kernel-Release") + if kernelRelease == "" { + util.Log.Warn("If X-Vuls-Kernel-Release is not specified, there is a possibility of false detection") + } + + kernelVersion := header.Get("X-Vuls-Kernel-Version") + if family == config.Debian && kernelVersion == "" { + return models.ScanResult{}, errKernelVersionHeader + } + + serverName := header.Get("X-Vuls-Server-Name") + if config.Conf.ToLocalFile && serverName == "" { + return models.ScanResult{}, errServerNameHeader + } + + distro := config.Distro{ + Family: family, + Release: release, + } + + kernel := models.Kernel{ + Release: kernelRelease, + Version: kernelVersion, + } + base := base{ + Distro: distro, + osPackages: osPackages{ + Kernel: kernel, + }, + log: util.Log, + } + + var osType osTypeInterface + switch family { + case config.Debian, config.Ubuntu: + osType = &debian{base: base} + case config.RedHat: + osType = &rhel{ + redhatBase: redhatBase{base: base}, + } + case config.CentOS: + osType = ¢os{ + redhatBase: redhatBase{base: base}, + } + default: + return models.ScanResult{}, fmt.Errorf("Server mode for %s is not implemented yet", family) + } + + installedPackages, srcPackages, err := osType.parseInstalledPackages(body) + if err != nil { + return models.ScanResult{}, err + } + + result := models.ScanResult{ + ServerName: serverName, + Family: family, + Release: release, + RunningKernel: models.Kernel{ + Release: kernelRelease, + Version: kernelVersion, + }, + Packages: installedPackages, + SrcPackages: srcPackages, + ScannedCves: models.VulnInfos{}, + } + + return result, nil } func setupChangelogCache() error { @@ -440,7 +544,7 @@ func setupChangelogCache() error { break case config.Ubuntu, config.Debian: //TODO changelopg cache for RedHat, Oracle, Amazon, CentOS is not implemented yet. - if config.Conf.Deep { + if s.getServerInfo().Mode.IsDeep() { needToSetupCache = true } break @@ -466,9 +570,13 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error { return o.postScan() }, timeoutSec) + hostname, _ := os.Hostname() for _, s := range append(servers, errServers...) { r := s.convertToModel() r.ScannedAt = scannedAt + r.ScannedVersion = config.Version + r.ScannedRevision = config.Revision + r.ScannedBy = hostname r.Config.Scan = config.Conf results = append(results, r) } @@ -487,7 +595,8 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error { return nil } -func ensureResultDir(scannedAt time.Time) (currentDir string, err error) { +// EnsureResultDir ensures the directory for scan results +func EnsureResultDir(scannedAt time.Time) (currentDir string, err error) { jsonDirName := scannedAt.Format(time.RFC3339) resultsDir := config.Conf.ResultsDir diff --git a/scan/serverapi_test.go b/scan/serverapi_test.go index 040485ba..b2e35075 100644 --- a/scan/serverapi_test.go +++ b/scan/serverapi_test.go @@ -1 +1,138 @@ package scan + +import ( + "net/http" + "testing" + + "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" +) + +func TestViaHTTP(t *testing.T) { + r := newRHEL(config.ServerInfo{}) + r.Distro = config.Distro{Family: config.RedHat} + + var tests = []struct { + header map[string]string + body string + packages models.Packages + expectedResult models.ScanResult + wantErr error + }{ + { + header: map[string]string{ + "X-Vuls-OS-Release": "6.9", + "X-Vuls-Kernel-Release": "2.6.32-695.20.3.el6.x86_64", + }, + wantErr: errOSFamilyHeader, + }, + { + header: map[string]string{ + "X-Vuls-OS-Family": "redhat", + "X-Vuls-Kernel-Release": "2.6.32-695.20.3.el6.x86_64", + }, + wantErr: errOSReleaseHeader, + }, + { + header: map[string]string{ + "X-Vuls-OS-Family": "debian", + "X-Vuls-OS-Release": "8", + "X-Vuls-Kernel-Release": "2.6.32-695.20.3.el6.x86_64", + }, + wantErr: errKernelVersionHeader, + }, + { + header: map[string]string{ + "X-Vuls-OS-Family": "centos", + "X-Vuls-OS-Release": "6.9", + "X-Vuls-Kernel-Release": "2.6.32-695.20.3.el6.x86_64", + }, + body: `openssl 0 1.0.1e 30.el6.11 x86_64 + Percona-Server-shared-56 1 5.6.19 rel67.0.el6 x84_64 + kernel 0 2.6.32 696.20.1.el6 x86_64 + kernel 0 2.6.32 696.20.3.el6 x86_64 + kernel 0 2.6.32 695.20.3.el6 x86_64`, + expectedResult: models.ScanResult{ + Family: "centos", + Release: "6.9", + RunningKernel: models.Kernel{ + Release: "2.6.32-695.20.3.el6.x86_64", + }, + Packages: models.Packages{ + "openssl": models.Package{ + Name: "openssl", + Version: "1.0.1e", + Release: "30.el6.11", + }, + "Percona-Server-shared-56": models.Package{ + Name: "Percona-Server-shared-56", + Version: "1:5.6.19", + Release: "rel67.0.el6", + }, + "kernel": models.Package{ + Name: "kernel", + Version: "2.6.32", + Release: "695.20.3.el6", + }, + }, + }, + }, + { + header: map[string]string{ + "X-Vuls-OS-Family": "debian", + "X-Vuls-OS-Release": "8.10", + "X-Vuls-Kernel-Release": "3.16.0-4-amd64", + "X-Vuls-Kernel-Version": "3.16.51-2", + }, + body: "", + expectedResult: models.ScanResult{ + Family: "debian", + Release: "8.10", + RunningKernel: models.Kernel{ + Release: "3.16.0-4-amd64", + Version: "3.16.51-2", + }, + }, + }, + } + + for _, tt := range tests { + header := http.Header{} + for k, v := range tt.header { + header.Set(k, v) + } + + result, err := ViaHTTP(header, tt.body) + if err != tt.wantErr { + t.Errorf("error: expected %s, actual: %s", tt.wantErr, err) + } + + if result.Family != tt.expectedResult.Family { + t.Errorf("os family: expected %s, actual %s", tt.expectedResult.Family, result.Family) + } + if result.Release != tt.expectedResult.Release { + t.Errorf("os release: expected %s, actual %s", tt.expectedResult.Release, result.Release) + } + if result.RunningKernel.Release != tt.expectedResult.RunningKernel.Release { + t.Errorf("kernel release: expected %s, actual %s", + tt.expectedResult.RunningKernel.Release, result.RunningKernel.Release) + } + if result.RunningKernel.Version != tt.expectedResult.RunningKernel.Version { + t.Errorf("kernel version: expected %s, actual %s", + tt.expectedResult.RunningKernel.Version, result.RunningKernel.Version) + } + + for name, expectedPack := range tt.expectedResult.Packages { + pack := result.Packages[name] + if pack.Name != expectedPack.Name { + t.Errorf("name: expected %s, actual %s", expectedPack.Name, pack.Name) + } + if pack.Version != expectedPack.Version { + t.Errorf("version: expected %s, actual %s", expectedPack.Version, pack.Version) + } + if pack.Release != expectedPack.Release { + t.Errorf("release: expected %s, actual %s", expectedPack.Release, pack.Release) + } + } + } +} diff --git a/scan/suse.go b/scan/suse.go index b4939554..69f89ad9 100644 --- a/scan/suse.go +++ b/scan/suse.go @@ -13,13 +13,13 @@ import ( // inherit OsTypeInterface type suse struct { - redhat + redhatBase } // NewRedhat is constructor func newSUSE(c config.ServerInfo) *suse { r := &suse{ - redhat: redhat{ + redhatBase: redhatBase{ base: base{ osPackages: osPackages{ Packages: models.Packages{}, @@ -98,7 +98,11 @@ func (o *suse) parseOSRelease(content string) (name string, ver string) { return name, result[1] } -func (o *suse) checkDependencies() error { +func (o *suse) checkScanMode() error { + return nil +} + +func (o *suse) checkDeps() error { o.log.Infof("Dependencies... No need") return nil } @@ -122,6 +126,10 @@ func (o *suse) scanPackages() error { return err } o.Kernel.RebootRequired = rebootRequired + if o.getServerInfo().Mode.IsOffline() { + o.Packages = installed + return nil + } updatable, err := o.scanUpdatablePackages() if err != nil { @@ -135,20 +143,20 @@ func (o *suse) scanPackages() error { } func (o *suse) rebootRequired() (bool, error) { - r := o.exec("rpm -q --last kernel-default | head -n1", noSudo) + r := o.exec("rpm -q --last kernel-default", noSudo) if !r.isSuccess() { - return false, fmt.Errorf("Failed to detect the last installed kernel : %v", r) + o.log.Warnf("Failed to detect the last installed kernel : %v", r) + // continue scanning + return false, nil } stdout := strings.Fields(r.Stdout)[0] return !strings.Contains(stdout, strings.TrimSuffix(o.Kernel.Release, "-default")), nil } func (o *suse) scanUpdatablePackages() (models.Packages, error) { - cmd := "" - if v, _ := o.Distro.MajorVersion(); v < 12 { - cmd = "zypper -q lu" - } else { - cmd = "zypper --no-color -q lu" + cmd := "zypper -q lu" + if o.hasZypperColorOption() { + cmd = "zypper -q --no-color lu" } r := o.exec(cmd, noSudo) if !r.isSuccess() { @@ -188,3 +196,9 @@ func (o *suse) parseZypperLUOneLine(line string) (*models.Package, error) { Arch: fs[10], }, nil } + +func (o *suse) hasZypperColorOption() bool { + cmd := "zypper --help | grep color" + r := o.exec(util.PrependProxyEnv(cmd), noSudo) + return len(r.Stdout) > 0 +} diff --git a/scan/unknownDistro.go b/scan/unknownDistro.go index 46f74e16..0744fab1 100644 --- a/scan/unknownDistro.go +++ b/scan/unknownDistro.go @@ -17,16 +17,22 @@ along with this program. If not, see . package scan +import "github.com/future-architect/vuls/models" + // inherit OsTypeInterface type unknown struct { base } +func (o *unknown) checkScanMode() error { + return nil +} + func (o *unknown) checkIfSudoNoPasswd() error { return nil } -func (o *unknown) checkDependencies() error { +func (o *unknown) checkDeps() error { return nil } @@ -41,3 +47,7 @@ func (o *unknown) postScan() error { func (o *unknown) scanPackages() error { return nil } + +func (o *unknown) parseInstalledPackages(string) (models.Packages, models.SrcPackages, error) { + return nil, nil, nil +} diff --git a/scan/utils_test.go b/scan/utils_test.go index 8982b3d5..fc469078 100644 --- a/scan/utils_test.go +++ b/scan/utils_test.go @@ -70,7 +70,7 @@ func TestIsRunningKernelSUSE(t *testing.T) { } func TestIsRunningKernelRedHatLikeLinux(t *testing.T) { - r := newRedhat(config.ServerInfo{}) + r := newAmazon(config.ServerInfo{}) r.Distro = config.Distro{Family: config.Amazon} kernel := models.Kernel{ diff --git a/server/server.go b/server/server.go new file mode 100644 index 00000000..996156a2 --- /dev/null +++ b/server/server.go @@ -0,0 +1,106 @@ +/* Vuls - Vulnerability Scanner +Copyright (C) 2016 Future Architect, Inc. Japan. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package server + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "mime" + "net/http" + "time" + + c "github.com/future-architect/vuls/config" + "github.com/future-architect/vuls/models" + "github.com/future-architect/vuls/report" + "github.com/future-architect/vuls/scan" + "github.com/future-architect/vuls/util" +) + +// VulsHandler is used for vuls server mode +type VulsHandler struct { + DBclient report.DBClient +} + +func (h VulsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + var err error + result := models.ScanResult{ScannedCves: models.VulnInfos{}} + + contentType := r.Header.Get("Content-Type") + mediatype, _, err := mime.ParseMediaType(contentType) + if err != nil { + util.Log.Error(err) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + if mediatype == "application/json" { + if err = json.NewDecoder(r.Body).Decode(&result); err != nil { + util.Log.Error(err) + http.Error(w, "Invalid JSON", http.StatusBadRequest) + return + } + } else if mediatype == "text/plain" { + buf := new(bytes.Buffer) + io.Copy(buf, r.Body) + if result, err = scan.ViaHTTP(r.Header, buf.String()); err != nil { + util.Log.Error(err) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + } else { + util.Log.Error(mediatype) + http.Error(w, fmt.Sprintf("Invalid Content-Type: %s", contentType), http.StatusUnsupportedMediaType) + return + } + + if err := report.FillCveInfo(h.DBclient, &result, []string{}); err != nil { + util.Log.Error(err) + http.Error(w, err.Error(), http.StatusServiceUnavailable) + return + } + + // report + reports := []report.ResultWriter{ + report.HTTPResponseWriter{Writer: w}, + } + if c.Conf.ToLocalFile { + scannedAt := result.ScannedAt + if scannedAt.IsZero() { + scannedAt = time.Now().Truncate(1 * time.Hour) + } + dir, err := scan.EnsureResultDir(scannedAt) + if err != nil { + util.Log.Errorf("Failed to ensure the result directory: %s", err) + http.Error(w, err.Error(), http.StatusServiceUnavailable) + return + } + + reports = append(reports, report.LocalFileWriter{ + CurrentDir: dir, + }) + } + + for _, w := range reports { + if err := w.Write(result); err != nil { + util.Log.Errorf("Failed to report: %s", err) + return + } + } +} diff --git a/util/logutil.go b/util/logutil.go index 2fb7cdb3..e9b4d7b0 100644 --- a/util/logutil.go +++ b/util/logutil.go @@ -18,6 +18,7 @@ along with this program. If not, see . package util import ( + "io/ioutil" "os" "path/filepath" "runtime" @@ -32,6 +33,13 @@ import ( // Log for localhsot var Log *logrus.Entry +func init() { + log := logrus.New() + log.Out = ioutil.Discard + fields := logrus.Fields{"prefix": ""} + Log = log.WithFields(fields) +} + // NewCustomLogger creates logrus func NewCustomLogger(c config.ServerInfo) *logrus.Entry { log := logrus.New() @@ -50,7 +58,7 @@ func NewCustomLogger(c config.ServerInfo) *logrus.Entry { if _, err := os.Stat(logDir); os.IsNotExist(err) { if err := os.Mkdir(logDir, 0700); err != nil { - log.Errorf("Failed to create log directory: %s", err) + log.Errorf("Failed to create log directory. path: %s, err: %s", logDir, err) } } diff --git a/util/util.go b/util/util.go index 2427e51a..cdf80fd5 100644 --- a/util/util.go +++ b/util/util.go @@ -34,7 +34,7 @@ func GenWorkers(num int) chan<- func() { defer func() { if p := recover(); p != nil { log := NewCustomLogger(config.ServerInfo{}) - log.Debugf("Panic: %s", p) + log.Errorf("run time panic: %v", p) } }() for f := range tasks { @@ -70,7 +70,7 @@ func URLPathJoin(baseURL string, paths ...string) (string, error) { if err != nil { return "", err } - url.Path += strings.Join(trimedPaths, "/") + url.Path += "/" + strings.Join(trimedPaths, "/") return url.String(), nil }