forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hunt_update() VQL function to allow stopping/starting hunt (Vel…
…ocidex#2587) Also added relaunch to hunt_add() to more easily relaunch the hunt
- Loading branch information
Showing
4 changed files
with
211 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package hunts | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Velocidex/ordereddict" | ||
"www.velocidex.com/golang/velociraptor/acls" | ||
api_proto "www.velocidex.com/golang/velociraptor/api/proto" | ||
"www.velocidex.com/golang/velociraptor/services" | ||
vql_subsystem "www.velocidex.com/golang/velociraptor/vql" | ||
"www.velocidex.com/golang/vfilter" | ||
"www.velocidex.com/golang/vfilter/arg_parser" | ||
) | ||
|
||
type UpdateHuntFunctionArg struct { | ||
HuntId string `vfilter:"required,field=hunt_id,doc=The hunt to update"` | ||
Stop bool `vfilter:"optional,field=stop,doc=Stop the hunt"` | ||
Start bool `vfilter:"optional,field=start,doc=Start the hunt"` | ||
Description string `vfilter:"optional,field=description,doc=Update hunt description"` | ||
} | ||
|
||
type UpdateHuntFunction struct{} | ||
|
||
func (self *UpdateHuntFunction) Call(ctx context.Context, | ||
scope vfilter.Scope, | ||
args *ordereddict.Dict) vfilter.Any { | ||
|
||
err := vql_subsystem.CheckAccess(scope, acls.START_HUNT) | ||
if err != nil { | ||
scope.Log("hunt_update: %v", err) | ||
return vfilter.Null{} | ||
} | ||
|
||
arg := &UpdateHuntFunctionArg{} | ||
err = arg_parser.ExtractArgsWithContext(ctx, scope, args, arg) | ||
if err != nil { | ||
scope.Log("hunt_update: %v", err) | ||
return vfilter.Null{} | ||
} | ||
|
||
config_obj, ok := vql_subsystem.GetServerConfig(scope) | ||
if !ok { | ||
scope.Log("hunt_update: GetServerConfig not found") | ||
return vfilter.Null{} | ||
} | ||
|
||
hunt_dispatcher, err := services.GetHuntDispatcher(config_obj) | ||
if err != nil { | ||
scope.Log("hunt_update: %v", err) | ||
return vfilter.Null{} | ||
} | ||
|
||
if arg.Start || arg.Stop { | ||
state := api_proto.Hunt_STOPPED | ||
if arg.Start { | ||
state = api_proto.Hunt_RUNNING | ||
} | ||
|
||
err = hunt_dispatcher.MutateHunt( | ||
ctx, config_obj, &api_proto.HuntMutation{ | ||
HuntId: arg.HuntId, | ||
State: state, | ||
}) | ||
if err != nil { | ||
scope.Log("hunt_update: %v", err) | ||
return vfilter.Null{} | ||
} | ||
} | ||
|
||
if arg.Description != "" { | ||
err = hunt_dispatcher.MutateHunt( | ||
ctx, config_obj, &api_proto.HuntMutation{ | ||
HuntId: arg.HuntId, | ||
Description: arg.Description, | ||
}) | ||
if err != nil { | ||
scope.Log("hunt_update: %v", err) | ||
return vfilter.Null{} | ||
} | ||
} | ||
|
||
return arg.HuntId | ||
} | ||
|
||
func (self UpdateHuntFunction) Info(scope vfilter.Scope, type_map *vfilter.TypeMap) *vfilter.FunctionInfo { | ||
return &vfilter.FunctionInfo{ | ||
Name: "hunt_update", | ||
Doc: "Update a hunt.", | ||
ArgType: type_map.AddType(scope, &UpdateHuntFunctionArg{}), | ||
} | ||
} | ||
|
||
func init() { | ||
vql_subsystem.RegisterFunction(&UpdateHuntFunction{}) | ||
} |