Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make updater optional & add configurable listing #67

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func main() {
log.Fatal("main: failed to parse options: %v", err)
}

wg.Add(2)
// go yaraUpdate(&wg)
go runner.ScheduleYaraHunterUpdater(opts, &wg)
// go yaraResults(&wg)
if *opts.EnableUpdater {
wg.Add(1)
go runner.ScheduleYaraHunterUpdater(opts, &wg)
}
wg.Add(1)
go runner.StartYaraHunter(opts, config, &wg)
wg.Wait()
}
4 changes: 4 additions & 0 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Options struct {
FailOnHighCount *int
FailOnMediumCount *int
FailOnLowCount *int
RulesListingUrl *string
EnableUpdater *bool
}

func ParseOptions() (*Options, error) {
Expand Down Expand Up @@ -67,6 +69,8 @@ func ParseOptions() (*Options, error) {
FailOnHighCount: flag.Int("fail-on-high-count", -1, "Exit with status 1 if number of high malwares found is >= this value (Default: -1)"),
FailOnMediumCount: flag.Int("fail-on-medium-count", -1, "Exit with status 1 if number of medium malwares found is >= this value (Default: -1)"),
FailOnLowCount: flag.Int("fail-on-low-count", -1, "Exit with status 1 if number of low malwares found is >= this value (Default: -1)"),
RulesListingUrl: flag.String("rules-listing-url", "https://threat-intel.deepfence.io/yara-rules/listing.json", "Deepfence threat intel yara rules listing (Default: threat-intel.deepfence.io/yara-rules/listing.json)"),
EnableUpdater: flag.Bool("enable-updater", true, "Enable rules updater (Default: true)"),
}
flag.Parse()
return options, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/runner/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ func ScheduleYaraHunterUpdater(opts *config.Options, newwg *sync.WaitGroup) {
// emits, we print `tock`
for t := range ticker.C {
fmt.Println("Invoked at ", t)
err := StartYaraHunterUpdater(*opts.RulesPath, *opts.ConfigPath)
err := StartYaraHunterUpdater(*opts.RulesPath, *opts.ConfigPath, *opts.RulesListingUrl)
if err != nil {
log.Fatal("main: failed to serve: %v", err)
}
}
}
}

func StartYaraHunterUpdater(rulesPath string, configPath string) error {
func StartYaraHunterUpdater(rulesPath, configPath, rulesListingUrl string) error {
err, yaraRuleUpdater := NewYaraRuleUpdater(rulesPath)
if err != nil {
log.Errorf("main: failed to serve: %v", err)
return err
}
_, err = utils.DownloadFile("https://threat-intel.deepfence.io/yara-rules/listing.json", configPath)
_, err = utils.DownloadFile(rulesListingUrl, configPath)
if err != nil {
log.Errorf("main: failed to serve: %v", err)
return err
Expand Down