2021-09-14 13:58:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-10-28 15:12:21 +00:00
|
|
|
"context"
|
2021-11-22 14:13:26 +00:00
|
|
|
"errors"
|
2021-09-14 13:58:35 +00:00
|
|
|
"os"
|
|
|
|
|
2023-02-24 18:18:25 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/vulnerabilities/macoffice"
|
2022-10-28 15:12:21 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/vulnerabilities/msrc"
|
2022-10-04 11:04:48 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/vulnerabilities/nvd"
|
2022-06-08 01:09:47 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/vulnerabilities/oval"
|
2023-11-21 18:30:07 +00:00
|
|
|
klog "github.com/go-kit/log"
|
2021-09-14 13:58:35 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func vulnerabilityDataStreamCommand() *cli.Command {
|
|
|
|
var dir string
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "vulnerability-data-stream",
|
|
|
|
Usage: "Download the vulnerability data stream",
|
|
|
|
UsageText: `
|
|
|
|
fleetctl vulnerability-data-stream [options]
|
|
|
|
|
|
|
|
Downloads (if needed) the data streams that can be used by the Fleet server to process software for vulnerabilities.
|
|
|
|
`,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "dir",
|
|
|
|
EnvVars: []string{"DIR"},
|
|
|
|
Value: "",
|
|
|
|
Destination: &dir,
|
|
|
|
Usage: "Directory to place the data streams in",
|
|
|
|
},
|
|
|
|
configFlag(),
|
|
|
|
contextFlag(),
|
|
|
|
debugFlag(),
|
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
if dir == "" {
|
|
|
|
return errors.New("No directory provided")
|
|
|
|
}
|
|
|
|
err := os.MkdirAll(dir, 0o700)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log(c, "[-] Downloading CPE database...")
|
2023-01-03 17:56:11 +00:00
|
|
|
err = nvd.DownloadCPEDBFromGithub(dir, "")
|
2022-09-01 16:02:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
|
|
|
log(c, "[-] Downloading CPE translations...")
|
2023-01-03 17:56:11 +00:00
|
|
|
err = nvd.DownloadCPETranslationsFromGithub(dir, "")
|
2021-09-14 13:58:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
2022-06-01 16:06:57 +00:00
|
|
|
log(c, "[-] Downloading NVD CVE feed...")
|
2023-11-21 18:30:07 +00:00
|
|
|
err = nvd.DownloadNVDCVEFeed(dir, "", false, klog.NewNopLogger())
|
2022-06-01 16:06:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
|
|
|
log(c, "[-] Downloading EPSS feed...")
|
2023-01-03 17:56:11 +00:00
|
|
|
err = nvd.DownloadEPSSFeed(dir)
|
2022-06-01 16:06:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
|
|
|
log(c, "[-] Downloading CISA known exploits feed...")
|
2023-01-03 17:56:11 +00:00
|
|
|
err = nvd.DownloadCISAKnownExploitsFeed(dir)
|
2021-09-14 13:58:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-06-08 01:09:47 +00:00
|
|
|
log(c, " Done\n")
|
2022-09-01 16:02:07 +00:00
|
|
|
|
2022-06-08 01:09:47 +00:00
|
|
|
log(c, "[-] Downloading Oval definitions...")
|
2023-01-03 17:56:11 +00:00
|
|
|
err = oval.Sync(dir, nil)
|
2022-06-08 01:09:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-09-14 13:58:35 +00:00
|
|
|
log(c, " Done\n")
|
|
|
|
|
2022-10-28 15:12:21 +00:00
|
|
|
log(c, "[-] Downloading MSRC artifacts...")
|
|
|
|
ctx := context.Background()
|
2023-01-03 17:56:11 +00:00
|
|
|
err = msrc.SyncFromGithub(ctx, dir, nil)
|
2022-10-28 15:12:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
2023-02-24 18:18:25 +00:00
|
|
|
log(c, "[-] Downloading MacOffice release notes...")
|
|
|
|
err = macoffice.SyncFromGithub(ctx, dir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log(c, " Done\n")
|
|
|
|
|
2021-09-14 13:58:35 +00:00
|
|
|
log(c, "[+] Data streams successfully downloaded!\n")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|