Skip to content

Commit 7f8768d

Browse files
committed
Add flags for specifying the time range of retrohunt jobs.
1 parent 4bb04c8 commit 7f8768d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

cmd/retrohunt.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ This command receives a file containing YARA rules and starts a retrohunt job wi
153153

154154
// NewRetrohuntStartCmd returns a new instance of the 'start' command.
155155
func NewRetrohuntStartCmd() *cobra.Command {
156-
return &cobra.Command{
156+
cmd := &cobra.Command{
157157
Use: "start [file]",
158158
Short: "Start a retrohunt job",
159159
Long: retrohuntStartCmdHelp,
@@ -180,6 +180,32 @@ func NewRetrohuntStartCmd() *cobra.Command {
180180

181181
obj.Attributes["rules"] = string(rules)
182182

183+
before := viper.GetString("before")
184+
after := viper.GetString("after")
185+
186+
var timeRange map[string]int64
187+
188+
if before != "" || after != "" {
189+
timeRange = make(map[string]int64)
190+
obj.Attributes["time_range"] = timeRange
191+
}
192+
193+
if after != "" {
194+
if t, err := time.Parse("2006-01-02", after); err == nil {
195+
timeRange["start"] = t.Unix()
196+
} else {
197+
return err
198+
}
199+
}
200+
201+
if before != "" {
202+
if t, err := time.Parse("2006-01-02", before); err == nil {
203+
timeRange["end"] = t.Unix()
204+
} else {
205+
return err
206+
}
207+
}
208+
183209
err = client.CreateObject(vt.URL("intelligence/retrohunt_jobs"), obj)
184210
if err != nil {
185211
return err
@@ -189,6 +215,16 @@ func NewRetrohuntStartCmd() *cobra.Command {
189215
return nil
190216
},
191217
}
218+
219+
cmd.Flags().String(
220+
"before", "",
221+
"scan files sent to VirusTotal before the given date (format: YYYY-MM-DD)")
222+
223+
cmd.Flags().String(
224+
"after", "",
225+
"scan files sent to VirusTotal after the given date (format: YYYY-MM-DD)")
226+
227+
return cmd
192228
}
193229

194230
// NewRetrohuntAbortCmd returns a new instance of the 'abort' command.

0 commit comments

Comments
 (0)