Skip to content

Commit 9865eab

Browse files
sadayuki-matsunokotakanbe
authored andcommitted
Display exploit codes information for each detected CVE-IDs (future-architect#729)
* add exploit * bug fix while loading config in TUI, display in format-full-text * fix readme
1 parent 678e72a commit 9865eab

16 files changed

+568
-24
lines changed

Gopkg.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Vuls uses Multiple vulnerability databases
6767
- [Debian Security Bug Tracker](https://security-tracker.debian.org/tracker/)
6868
- Commands(yum, zypper, pkg-audit)
6969
- RHSA/ALAS/ELSA/FreeBSD-SA
70+
- [Exploit Database](https://www.exploit-db.com/)
7071
- Changelog
7172

7273
## Fast scan and Deep scan

commands/discover.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,27 @@ func (p *DiscoverCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface
9191
func printConfigToml(ips []string) (err error) {
9292
const tomlTemplate = `
9393
94-
# TODO Doc Link
94+
# https://vuls.io/docs/en/usage-settings.html
9595
[cveDict]
9696
type = "sqlite3"
9797
sqlite3Path = "/path/to/cve.sqlite3"
9898
#url = ""
9999
100-
# TODO Doc Link
101100
[ovalDict]
102101
type = "sqlite3"
103102
sqlite3Path = "/path/to/oval.sqlite3"
104103
#url = ""
105104
106-
# TODO Doc Link
107105
[gost]
108106
type = "sqlite3"
109107
sqlite3Path = "/path/to/gost.sqlite3"
110108
#url = ""
111109
110+
[exploit]
111+
type = "sqlite3"
112+
sqlite3Path = "/path/to/go-exploitdb.sqlite3"
113+
#url = ""
114+
112115
# https://vuls.io/docs/en/usage-settings.html#slack-section
113116
#[slack]
114117
#hookURL = "https://hooks.slack.com/services/abc123/defghijklmnopqrstuvwxyz"

commands/report.go

+32-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525

2626
c "github.com/future-architect/vuls/config"
27+
"github.com/future-architect/vuls/exploit"
2728
"github.com/future-architect/vuls/gost"
2829
"github.com/future-architect/vuls/models"
2930
"github.com/future-architect/vuls/oval"
@@ -36,11 +37,12 @@ import (
3637

3738
// ReportCmd is subcommand for reporting
3839
type ReportCmd struct {
39-
configPath string
40-
cveDict c.GoCveDictConf
41-
ovalDict c.GovalDictConf
42-
gostConf c.GostConf
43-
httpConf c.HTTPConf
40+
configPath string
41+
cveDict c.GoCveDictConf
42+
ovalDict c.GovalDictConf
43+
gostConf c.GostConf
44+
exploitConf c.ExploitConf
45+
httpConf c.HTTPConf
4446
}
4547

4648
// Name return subcommand name
@@ -93,6 +95,9 @@ func (*ReportCmd) Usage() string {
9395
[-gostdb-type=sqlite3|mysql|redis]
9496
[-gostdb-sqlite3-path=/path/to/gost.sqlite3]
9597
[-gostdb-url=http://127.0.0.1:1325 or DB connection string]
98+
[-exploitdb-type=sqlite3|mysql|redis]
99+
[-exploitdb-sqlite3-path=/path/to/exploitdb.sqlite3]
100+
[-exploitdb-url=http://127.0.0.1:1325 or DB connection string]
96101
[-http="http://vuls-report-server"]
97102
98103
[RFC3339 datetime format under results dir]
@@ -183,6 +188,12 @@ func (p *ReportCmd) SetFlags(f *flag.FlagSet) {
183188
f.StringVar(&p.gostConf.URL, "gostdb-url", "",
184189
"http://gost.com:1325 or DB connection string")
185190

191+
f.StringVar(&p.exploitConf.Type, "exploitdb-type", "",
192+
"DB type of exploit (sqlite3, mysql, postgres or redis)")
193+
f.StringVar(&p.exploitConf.SQLite3Path, "exploitdb-sqlite3-path", "", "/path/to/sqlite3")
194+
f.StringVar(&p.exploitConf.URL, "exploitdb-url", "",
195+
"http://exploit.com:1326 or DB connection string")
196+
186197
f.StringVar(&p.httpConf.URL, "http", "", "-to-http http://vuls-report")
187198

188199
}
@@ -200,6 +211,7 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
200211
c.Conf.CveDict.Overwrite(p.cveDict)
201212
c.Conf.OvalDict.Overwrite(p.ovalDict)
202213
c.Conf.Gost.Overwrite(p.gostConf)
214+
c.Conf.Exploit.Overwrite(p.exploitConf)
203215
c.Conf.HTTP.Overwrite(p.httpConf)
204216

205217
var dir string
@@ -378,10 +390,25 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
378390
util.Log.Infof("gost: %s", c.Conf.Gost.SQLite3Path)
379391
}
380392
}
393+
394+
if c.Conf.Exploit.URL != "" {
395+
util.Log.Infof("exploit: %s", c.Conf.Exploit.URL)
396+
err := exploit.CheckHTTPHealth()
397+
if err != nil {
398+
util.Log.Errorf("exploit HTTP server is not running. err: %s", err)
399+
util.Log.Errorf("Run exploit as server mode before reporting or run with -exploitdb-sqlite3-path option instead of -exploitdb-url")
400+
return subcommands.ExitFailure
401+
}
402+
} else {
403+
if c.Conf.Exploit.Type == "sqlite3" {
404+
util.Log.Infof("exploit: %s", c.Conf.Exploit.SQLite3Path)
405+
}
406+
}
381407
dbclient, locked, err := report.NewDBClient(report.DBClientConf{
382408
CveDictCnf: c.Conf.CveDict,
383409
OvalDictCnf: c.Conf.OvalDict,
384410
GostCnf: c.Conf.Gost,
411+
ExploitCnf: c.Conf.Exploit,
385412
DebugSQL: c.Conf.DebugSQL,
386413
})
387414
if locked {

commands/tui.go

+77-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import (
2424
"path/filepath"
2525

2626
c "github.com/future-architect/vuls/config"
27+
"github.com/future-architect/vuls/exploit"
28+
"github.com/future-architect/vuls/gost"
2729
"github.com/future-architect/vuls/models"
30+
"github.com/future-architect/vuls/oval"
2831
"github.com/future-architect/vuls/report"
2932
"github.com/future-architect/vuls/util"
3033
"github.com/google/subcommands"
@@ -33,10 +36,11 @@ import (
3336

3437
// TuiCmd is Subcommand of host discovery mode
3538
type TuiCmd struct {
36-
configPath string
37-
cvelDict c.GoCveDictConf
38-
ovalDict c.GovalDictConf
39-
gostConf c.GostConf
39+
configPath string
40+
cvelDict c.GoCveDictConf
41+
ovalDict c.GovalDictConf
42+
gostConf c.GostConf
43+
exploitConf c.ExploitConf
4044
}
4145

4246
// Name return subcommand name
@@ -124,6 +128,13 @@ func (p *TuiCmd) SetFlags(f *flag.FlagSet) {
124128
f.StringVar(&p.gostConf.SQLite3Path, "gostdb-path", "", "/path/to/sqlite3")
125129
f.StringVar(&p.gostConf.URL, "gostdb-url", "",
126130
"http://gost.com:1325 or DB connection string")
131+
132+
f.StringVar(&p.exploitConf.Type, "exploitdb-type", "",
133+
"DB type of exploit (sqlite3, mysql, postgres or redis)")
134+
f.StringVar(&p.exploitConf.SQLite3Path, "exploitdb-sqlite3-path", "", "/path/to/sqlite3")
135+
f.StringVar(&p.exploitConf.URL, "exploitdb-url", "",
136+
"http://exploit.com:1326 or DB connection string")
137+
127138
}
128139

129140
// Execute execute
@@ -142,11 +153,7 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s
142153
c.Conf.CveDict.Overwrite(p.cvelDict)
143154
c.Conf.OvalDict.Overwrite(p.ovalDict)
144155
c.Conf.Gost.Overwrite(p.gostConf)
145-
146-
util.Log.Info("Validating config...")
147-
if !c.Conf.ValidateOnTui() {
148-
return subcommands.ExitUsageError
149-
}
156+
c.Conf.Exploit.Overwrite(p.exploitConf)
150157

151158
var dir string
152159
var err error
@@ -159,17 +166,78 @@ func (p *TuiCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) s
159166
util.Log.Errorf("Failed to read from JSON: %s", err)
160167
return subcommands.ExitFailure
161168
}
169+
170+
util.Log.Info("Validating config...")
171+
if !c.Conf.ValidateOnTui() {
172+
return subcommands.ExitUsageError
173+
}
174+
162175
var res models.ScanResults
163176
if res, err = report.LoadScanResults(dir); err != nil {
164177
util.Log.Error(err)
165178
return subcommands.ExitFailure
166179
}
167180
util.Log.Infof("Loaded: %s", dir)
168181

182+
if err := report.CveClient.CheckHealth(); err != nil {
183+
util.Log.Errorf("CVE HTTP server is not running. err: %s", err)
184+
util.Log.Errorf("Run go-cve-dictionary as server mode before reporting or run with -cvedb-sqlite3-path option instead of -cvedb-url")
185+
return subcommands.ExitFailure
186+
}
187+
if c.Conf.CveDict.URL != "" {
188+
util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.URL)
189+
} else {
190+
if c.Conf.CveDict.Type == "sqlite3" {
191+
util.Log.Infof("cve-dictionary: %s", c.Conf.CveDict.SQLite3Path)
192+
}
193+
}
194+
195+
if c.Conf.OvalDict.URL != "" {
196+
util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.URL)
197+
err := oval.Base{}.CheckHTTPHealth()
198+
if err != nil {
199+
util.Log.Errorf("OVAL HTTP server is not running. err: %s", err)
200+
util.Log.Errorf("Run goval-dictionary as server mode before reporting or run with -ovaldb-sqlite3-path option instead of -ovaldb-url")
201+
return subcommands.ExitFailure
202+
}
203+
} else {
204+
if c.Conf.OvalDict.Type == "sqlite3" {
205+
util.Log.Infof("oval-dictionary: %s", c.Conf.OvalDict.SQLite3Path)
206+
}
207+
}
208+
209+
if c.Conf.Gost.URL != "" {
210+
util.Log.Infof("gost: %s", c.Conf.Gost.URL)
211+
err := gost.Base{}.CheckHTTPHealth()
212+
if err != nil {
213+
util.Log.Errorf("gost HTTP server is not running. err: %s", err)
214+
util.Log.Errorf("Run gost as server mode before reporting or run with -gostdb-sqlite3-path option instead of -gostdb-url")
215+
return subcommands.ExitFailure
216+
}
217+
} else {
218+
if c.Conf.Gost.Type == "sqlite3" {
219+
util.Log.Infof("gost: %s", c.Conf.Gost.SQLite3Path)
220+
}
221+
}
222+
223+
if c.Conf.Exploit.URL != "" {
224+
util.Log.Infof("exploit: %s", c.Conf.Exploit.URL)
225+
err := exploit.CheckHTTPHealth()
226+
if err != nil {
227+
util.Log.Errorf("exploit HTTP server is not running. err: %s", err)
228+
util.Log.Errorf("Run exploit as server mode before reporting or run with -exploitdb-sqlite3-path option instead of -exploitdb-url")
229+
return subcommands.ExitFailure
230+
}
231+
} else {
232+
if c.Conf.Exploit.Type == "sqlite3" {
233+
util.Log.Infof("exploit: %s", c.Conf.Exploit.SQLite3Path)
234+
}
235+
}
169236
dbclient, locked, err := report.NewDBClient(report.DBClientConf{
170237
CveDictCnf: c.Conf.CveDict,
171238
OvalDictCnf: c.Conf.OvalDict,
172239
GostCnf: c.Conf.Gost,
240+
ExploitCnf: c.Conf.Exploit,
173241
DebugSQL: c.Conf.DebugSQL,
174242
})
175243
if locked {

config/config.go

+54
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type Config struct {
122122
CveDict GoCveDictConf `json:"cveDict"`
123123
OvalDict GovalDictConf `json:"ovalDict"`
124124
Gost GostConf `json:"gost"`
125+
Exploit ExploitConf `json:"exploit"`
125126

126127
Slack SlackConf `json:"-"`
127128
EMail SMTPConf `json:"-"`
@@ -889,6 +890,59 @@ func (cnf *GostConf) Overwrite(cmdOpt GostConf) {
889890
cnf.setDefault()
890891
}
891892

893+
// ExploitConf is exploit config
894+
type ExploitConf struct {
895+
// DB type for exploit dictionary (sqlite3, mysql, postgres or redis)
896+
Type string
897+
898+
// http://exploit-dictionary.com:1324 or DB connection string
899+
URL string `json:"-"`
900+
901+
// /path/to/exploit.sqlite3
902+
SQLite3Path string `json:"-"`
903+
}
904+
905+
func (cnf *ExploitConf) setDefault() {
906+
if cnf.Type == "" {
907+
cnf.Type = "sqlite3"
908+
}
909+
if cnf.URL == "" && cnf.SQLite3Path == "" {
910+
wd, _ := os.Getwd()
911+
cnf.SQLite3Path = filepath.Join(wd, "go-exploitdb.sqlite3")
912+
}
913+
}
914+
915+
const exploitDBType = "EXPLOITDB_TYPE"
916+
const exploitDBURL = "EXPLOITDB_URL"
917+
const exploitDBPATH = "EXPLOITDB_SQLITE3_PATH"
918+
919+
// Overwrite set options with the following priority.
920+
// 1. Command line option
921+
// 2. Environment variable
922+
// 3. config.toml
923+
func (cnf *ExploitConf) Overwrite(cmdOpt ExploitConf) {
924+
if os.Getenv(exploitDBType) != "" {
925+
cnf.Type = os.Getenv(exploitDBType)
926+
}
927+
if os.Getenv(exploitDBURL) != "" {
928+
cnf.URL = os.Getenv(exploitDBURL)
929+
}
930+
if os.Getenv(exploitDBPATH) != "" {
931+
cnf.SQLite3Path = os.Getenv(exploitDBPATH)
932+
}
933+
934+
if cmdOpt.Type != "" {
935+
cnf.Type = cmdOpt.Type
936+
}
937+
if cmdOpt.URL != "" {
938+
cnf.URL = cmdOpt.URL
939+
}
940+
if cmdOpt.SQLite3Path != "" {
941+
cnf.SQLite3Path = cmdOpt.SQLite3Path
942+
}
943+
cnf.setDefault()
944+
}
945+
892946
// AWS is aws config
893947
type AWS struct {
894948
// AWS profile to use

config/tomlloader.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error {
5151
Conf.CveDict = conf.CveDict
5252
Conf.OvalDict = conf.OvalDict
5353
Conf.Gost = conf.Gost
54+
Conf.Exploit = conf.Exploit
5455

5556
d := conf.Default
5657
Conf.Default = d

0 commit comments

Comments
 (0)