mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-08 22:00:46 -08:00
* chore(app): change dir * feat(rpc): add a proto file and auto-generated files * chore(dep): add dependencies * fix(app): fix import path * fix(integration): fix import path * fix(protoc): use enum for severity * chore(Makefile): add fmt andd protoc * chore(clang): add .clang-format * refactor: split functions for client/server (#296) * refactor(db): split db.Download * refactor(standalone): create a different package * refactor(vulnerability): split FillAndFilter * fix(protoc): use enum for severity * chore(Makefile): add fmt andd protoc * chore(clang): add .clang-format * fix(db): remove an unused variable * fix(db): expose the github client as an argument of constructor * refactor(vulnerability): add the detail message * feat(rpc): add rpc client (#302) * fix(protoc): use enum for severity * chore(Makefile): add fmt andd protoc * chore(clang): add .clang-format * feat(rpc): convert types * feat(rpc): add rpc client * token: Refactor to handle bad headers being set Signed-off-by: Simarpreet Singh <simar@linux.com> * feat(rpc): add rpc server (#303) * feat(rpc): add rpc server * feat(utils): add CopyFile * feat(server/config): add config struct * feat(detector): add detector * feat(scanner): delegate procedures to detector * fix(scanner): fix the interface * test(mock): add mocks * test(rpc/server): add tests * test(rpc/ospkg/server): add tests * tets(os/detector): add tests * refactor(library): move directories * chore(dependency): add google/wire * refactor(library): introduce google/wire * refactor(ospkg/detector): move directory * feat(rpc): add eosl * refactor(ospkg): introduce google/wire * refactor(wire): bind an interface * refactor(client): use wire.Struct * chore(Makefile): fix wire * test(server): add AssertExpectations * test(server): add AssertExpectations * refactor(server): remove debug log * refactor(error): add more context messages * test(server): fix error message * refactor(test): create a constructor of mock * refactor(config): remove an unused variable * test(config): add an assertion to test the config struct * feat(client/server): add sub commands (#304) * feat(rpc): add rpc server * feat(utils): add CopyFile * feat(server/config): add config struct * feat(detector): add detector * feat(scanner): delegate procedures to detector * fix(scanner): fix the interface * feat(client/server): add sub commands * merge(server3) * test(scan): remove an unused mock * refactor(client): generate the constructor by wire * fix(cli): change the default port * fix(server): use auto-generated constructor * feat(ospkg): return eosl * test(integration): add integration tests for client/server (#306) * fix(server): remove unnecessary options * test(integration): add integration tests for client/server * fix(server): wrap an error * fix(server): change the update interval * fix(server): display the error detail * test(config): add an assertion to test the config struct * fix(client): returns an error when failing to initizlie a logger * test(ospkg/server): add eosl * Squashed commit of the following: * test(server): refactor and add tests (#307) * test(github): create a mock * test(db): create a mock * test(server): add tests for DB hot update * chore(db): add a log message * refactor(db): introduce google/wire * refactor(rpc): move directory * refactor(injector): fix import name * refactor(import): remove new lines * fix(server): display the error detail * fix(server): change the update interval * fix(server): wrap an error * test(integration): add integration tests for client/server * fix(server): remove unnecessary options * refactor(server): return an error when failing to initialize a logger * refactor(server): remove unused error * fix(client/server): fix default port * chore(README): add client/server * chore(README): update
95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
package oracle
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
|
|
oracleoval "github.com/aquasecurity/trivy-db/pkg/vulnsrc/oracle-oval"
|
|
version "github.com/knqyf263/go-rpm-version"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/aquasecurity/fanal/analyzer"
|
|
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
|
|
"github.com/aquasecurity/trivy/pkg/log"
|
|
"github.com/aquasecurity/trivy/pkg/scanner/utils"
|
|
"github.com/aquasecurity/trivy/pkg/types"
|
|
|
|
"k8s.io/utils/clock"
|
|
)
|
|
|
|
var (
|
|
eolDates = map[string]time.Time{
|
|
// Source:
|
|
// https://www.oracle.com/a/ocom/docs/elsp-lifetime-069338.pdf
|
|
// https://community.oracle.com/docs/DOC-917964
|
|
"3": time.Date(2011, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"4": time.Date(2013, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"5": time.Date(2017, 12, 31, 23, 59, 59, 0, time.UTC),
|
|
"6": time.Date(2021, 3, 21, 23, 59, 59, 0, time.UTC),
|
|
"7": time.Date(2024, 7, 23, 23, 59, 59, 0, time.UTC),
|
|
"8": time.Date(2029, 7, 18, 23, 59, 59, 0, time.UTC),
|
|
}
|
|
)
|
|
|
|
type Scanner struct {
|
|
vs dbTypes.VulnSrc
|
|
clock clock.Clock
|
|
}
|
|
|
|
func NewScanner() *Scanner {
|
|
return &Scanner{
|
|
vs: oracleoval.NewVulnSrc(),
|
|
clock: clock.RealClock{},
|
|
}
|
|
}
|
|
|
|
func (s *Scanner) Detect(osVer string, pkgs []analyzer.Package) ([]types.DetectedVulnerability, error) {
|
|
log.Logger.Info("Detecting Oracle Linux vulnerabilities...")
|
|
|
|
if strings.Count(osVer, ".") > 0 {
|
|
osVer = osVer[:strings.Index(osVer, ".")]
|
|
}
|
|
|
|
log.Logger.Debugf("Oracle Linux: os version: %s", osVer)
|
|
log.Logger.Debugf("Oracle Linux: the number of packages: %d", len(pkgs))
|
|
|
|
var vulns []types.DetectedVulnerability
|
|
for _, pkg := range pkgs {
|
|
advisories, err := s.vs.Get(osVer, pkg.SrcName)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("failed to get Oracle Linux advisory: %w", err)
|
|
}
|
|
|
|
installed := utils.FormatVersion(pkg)
|
|
installedVersion := version.NewVersion(installed)
|
|
for _, adv := range advisories {
|
|
fixedVersion := version.NewVersion(adv.FixedVersion)
|
|
vuln := types.DetectedVulnerability{
|
|
VulnerabilityID: adv.VulnerabilityID,
|
|
PkgName: pkg.Name,
|
|
InstalledVersion: installed,
|
|
}
|
|
if installedVersion.LessThan(fixedVersion) {
|
|
vuln.FixedVersion = adv.FixedVersion
|
|
vulns = append(vulns, vuln)
|
|
}
|
|
}
|
|
}
|
|
return vulns, nil
|
|
}
|
|
|
|
func (s *Scanner) IsSupportedVersion(osFamily, osVer string) bool {
|
|
if strings.Count(osVer, ".") > 0 {
|
|
osVer = osVer[:strings.Index(osVer, ".")]
|
|
}
|
|
|
|
eol, ok := eolDates[osVer]
|
|
if !ok {
|
|
log.Logger.Warnf("This OS version is not on the EOL list: %s %s", osFamily, osVer)
|
|
return false
|
|
}
|
|
|
|
return s.clock.Now().Before(eol)
|
|
}
|