Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a5b42c2
Remove CentOS post-processing
Jun 8, 2022
62ad2b4
Moved OVAL test data to upper directory
Jun 8, 2022
53b2811
Use t.TempDir()
Jun 8, 2022
ca32887
Renamed VulnerabilitySource constants
Jun 8, 2022
99e7bce
Renamed DeleteVulnerabilitiesByCPECVE -> DeleteSoftwareVulnerabilities
Jun 8, 2022
0b6a4e7
Oval definitions for rhel based systems only use the major version as…
Jun 8, 2022
f8c920a
Added OVAL input types for RHEL
juan-fdz-hawa Jun 8, 2022
8173688
WIP: Parse rhel OVAl defs
juan-fdz-hawa Jun 8, 2022
c501925
Added missing tests for mappers
juan-fdz-hawa Jun 9, 2022
5102127
Fill in parseRhelXML
juan-fdz-hawa Jun 9, 2022
b816a41
Parse OVAL definitions for RHEL
juan-fdz-hawa Jun 9, 2022
b4ddce2
Added missing tests for parser
juan-fdz-hawa Jun 9, 2022
f624765
Added rpm_verify_object and rpm_verify_state to parser
juan-fdz-hawa Jun 10, 2022
924f813
WIP: Extend analyzer to use OS tests results
juan-fdz-hawa Jun 12, 2022
b78ba66
Added implementation for object_state_string.go
juan-fdz-hawa Jun 13, 2022
93019fa
Propagate errors from state objects
juan-fdz-hawa Jun 13, 2022
e25ac6e
Implemented ObjectStateSimpleValue
juan-fdz-hawa Jun 13, 2022
93f9cc7
Implemented #EvalSoftware on ObjectInfoState, which evaluates the pas…
juan-fdz-hawa Jun 13, 2022
48915d8
Implement EvalOSVersion
juan-fdz-hawa Jun 13, 2022
0693dbe
Wire up RpmVerifyFileTest and RpmInfoTest
juan-fdz-hawa Jun 13, 2022
72cb655
Only allow Name and Version as state props for RpmVerifyFile
juan-fdz-hawa Jun 13, 2022
bbc4d08
Use vulnerability/testdata when populating vuln software in osquery-perf
juan-fdz-hawa Jun 14, 2022
b4988fb
Extracted partial for ubuntu hosts
juan-fdz-hawa Jun 14, 2022
c662aae
Added software inventory for CentOS and RedHat
juan-fdz-hawa Jun 14, 2022
5251dc6
Don't match cpe->cves for rhel platforms
juan-fdz-hawa Jun 14, 2022
577a965
Added missing info to the rpm verify file tests, fixed misc bugs
juan-fdz-hawa Jun 15, 2022
5fdb54f
Added CVEs, if vals is empty return identity when evaluating operator…
juan-fdz-hawa Jun 15, 2022
0eb8c1f
Added RHEL OVAL defs to test data
juan-fdz-hawa Jun 15, 2022
96311f8
Added integration tests for RHEL
juan-fdz-hawa Jun 15, 2022
cfb670c
Merge branch 'main' into 6096-use-oval-to-detect-centosred-hat-vulner…
juan-fdz-hawa Jun 15, 2022
e62c2ef
Fixed broken test and linter errors
juan-fdz-hawa Jun 15, 2022
6976224
Fixed linter issues
juan-fdz-hawa Jun 16, 2022
9a23042
Added missing test
juan-fdz-hawa Jun 16, 2022
589e238
Added changes file
juan-fdz-hawa Jun 16, 2022
84c0792
Fixed linter error
juan-fdz-hawa Jun 16, 2022
38e6d95
Added support for Amazon Linux 2
juan-fdz-hawa Jun 20, 2022
894b12f
Merge branch 'main' into 6096-use-oval-to-detect-centosred-hat-vulner…
juan-fdz-hawa Jun 20, 2022
0b7461f
Add amzn to list of supported distros
juan-fdz-hawa Jun 21, 2022
39bf547
Merge branch 'main' into 6096-use-oval-to-detect-centosred-hat-vulner…
juan-fdz-hawa Jun 23, 2022
84373c3
Added RHEL benchmark
juan-fdz-hawa Jun 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/feature-6096-rhel-oval
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Use OVAL definitions to scan RHEL based hosts for vulnerable software
29 changes: 1 addition & 28 deletions cmd/cpe/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"compress/gzip"
"database/sql"
"flag"
"fmt"
"io"
Expand All @@ -13,7 +12,6 @@ import (

"github.com/facebookincubator/nvdtools/cpedict"
"github.com/fleetdm/fleet/v4/server/vulnerabilities"
"github.com/fleetdm/fleet/v4/server/vulnerabilities/vuln_centos"
)

func panicif(err error) {
Expand All @@ -23,24 +21,14 @@ func panicif(err error) {
}

func main() {
var (
runCentOS bool
verbose bool
)
flag.BoolVar(&runCentOS, "centos", true, "Sets whether to run the CentOS sqlite generation")
var verbose bool
flag.BoolVar(&verbose, "verbose", false, "Sets verbose mode")
flag.Parse()

dbPath := cpe()

fmt.Printf("Sqlite file %s size: %.2f MB\n", dbPath, getSizeMB(dbPath))

// The CentOS repository data is added to the CPE database.
if runCentOS {
centos(dbPath, verbose)
fmt.Printf("Sqlite file %s size with CentOS data: %.2f MB\n", dbPath, getSizeMB(dbPath))
}

fmt.Println("Compressing DB...")
compressedPath, err := compress(dbPath)
panicif(err)
Expand Down Expand Up @@ -113,21 +101,6 @@ func compress(path string) (string, error) {
return compressedPath, nil
}

func centos(dbPath string, verbose bool) {
fmt.Println("Starting CentOS sqlite generation...")

db, err := sql.Open("sqlite3", dbPath)
panicif(err)
defer db.Close()

pkgs, err := vuln_centos.ParseCentOSRepository(vuln_centos.WithVerbose(verbose))
panicif(err)

fmt.Printf("Storing CVE info for %d CentOS packages...\n", len(pkgs))
err = vuln_centos.GenCentOSSqlite(db, pkgs)
panicif(err)
}

func getSanitizedEtag(resp *http.Response) string {
etag := resp.Header.Get("Etag")
etag = strings.TrimPrefix(strings.TrimSuffix(etag, `"`), `"`)
Expand Down
9 changes: 0 additions & 9 deletions cmd/fleet/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,6 @@ func cronVulnerabilities(
errHandler(ctx, logger, "calculating hosts count per software", err)
}

// It's important vulnerabilities.PostProcess runs after ds.SyncHostsSoftware
// because it cleans up any software that's not installed on the fleet (e.g. hosts removal,
// or software being uninstalled on hosts).
if !vulnDisabled {
if err := vulnerabilities.PostProcess(ctx, ds, vulnPath, logger, config); err != nil {
errHandler(ctx, logger, "post processing CVEs", err)
}
}

level.Debug(logger).Log("loop", "done")
}
}
Expand Down
51 changes: 49 additions & 2 deletions cmd/osquery-perf/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package main

import (
"bytes"
"compress/bzip2"
"crypto/tls"
"embed"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -412,16 +415,55 @@ func (a *agent) HostUsersMacOS() []fleet.HostUser {
return users
}

func extract(src, dst string) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

srcF, err := os.Open(src)
if err != nil {
panic(err)
}
defer srcF.Close()

dstF, err := os.Create(dst)
if err != nil {
panic(err)
}
defer dstF.Close()

r := bzip2.NewReader(srcF)
// ignoring "G110: Potential DoS vulnerability via decompression bomb", as this is test code.
_, err = io.Copy(dstF, r) //nolint:gosec
if err != nil {
panic(err)
}
}

func loadUbuntuSoftware(ver string) []fleet.Software {
var r []fleet.Software
srcPath := filepath.Join(
"..",
"..",
"server",
"vulnerabilities",
"testdata",
"ubuntu",
"software",
fmt.Sprintf("ubuntu_%s-software.json.bz2", ver),
)

tmpDir, err := ioutil.TempDir("", "osquery-perf")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpDir)
dstPath := filepath.Join(tmpDir, fmt.Sprintf("%s-software.json", ver))

extract(srcPath, dstPath)

type softwareJSON struct {
Name string `json:"name"`
Version string `json:"version"`
}

var software []softwareJSON
contents, err := ioutil.ReadFile(fmt.Sprintf("ubuntu_%s-vulnerable_software.json", ver))
contents, err := ioutil.ReadFile(dstPath)
if err != nil {
log.Printf("reading vuln software for ubuntu %s: %s\n", ver, err)
return nil
Expand All @@ -433,6 +475,7 @@ func loadUbuntuSoftware(ver string) []fleet.Software {
return nil
}

var r []fleet.Software
for _, fi := range software {
r = append(r, fleet.Software{
Name: fi.Name,
Expand Down Expand Up @@ -742,6 +785,7 @@ func main() {
"mac10.14.6.tmpl",

// Uncomment this to add ubuntu hosts with vulnerable software
// "partial_ubuntu.tmpl",
// "ubuntu_16.04.tmpl",
// "ubuntu_18.04.tmpl",
// "ubuntu_20.04.tmpl",
Expand Down Expand Up @@ -773,6 +817,9 @@ func main() {

for i := 0; i < *hostCount; i++ {
tmpl := tmpls[i%len(tmpls)]
if strings.HasPrefix(tmpl.Name(), "partial") {
continue
}
a := newAgent(i+1, *serverURL, *enrollSecret, tmpl, *configInterval, *queryInterval,
softwareEntityCount{
entityCount: entityCount{
Expand Down
Loading