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.
Refactored VQL subsystem to its own module.
- Loading branch information
Showing
16 changed files
with
229 additions
and
29 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
// These are the messages used in client actions. | ||
syntax = "proto2"; | ||
|
||
import "www.velocidex.com/golang/velociraptor/proto/semantic.proto"; | ||
|
||
package proto; | ||
|
||
message VQLCollectorArgs { | ||
optional string Query = 1 [(sem_type) = { | ||
description: "The VQL query to execute on the client.", | ||
}, default = "select * from client_info()"]; | ||
} | ||
|
||
message VQLResponse { | ||
optional string Response = 1 [(sem_type) = { | ||
description: "JSON encoded response.", | ||
}]; | ||
} |
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,49 @@ | ||
package actions | ||
|
||
import ( | ||
"www.velocidex.com/golang/velociraptor/context" | ||
"encoding/json" | ||
"www.velocidex.com/golang/vfilter" | ||
"github.com/golang/protobuf/proto" | ||
actions_proto "www.velocidex.com/golang/velociraptor/actions/proto" | ||
vql_subsystem "www.velocidex.com/golang/velociraptor/vql" | ||
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto" | ||
) | ||
|
||
type VQLClientAction struct{} | ||
func (self *VQLClientAction) Run( | ||
ctx *context.Context, | ||
msg *crypto_proto.GrrMessage) []*crypto_proto.GrrMessage { | ||
responder := NewResponder(msg) | ||
arg, pres := responder.GetArgs().(*actions_proto.VQLCollectorArgs) | ||
if !pres { | ||
return responder.RaiseError("Request should be of type VQLCollectorArgs") | ||
} | ||
|
||
if arg.Query == nil { | ||
return responder.RaiseError("Query should be specified.") | ||
} | ||
|
||
vql, err := vfilter.Parse(*arg.Query) | ||
if err != nil { | ||
responder.RaiseError(err.Error()) | ||
} | ||
|
||
scope := vql_subsystem.MakeScope() | ||
output_chan := vql.Eval(ctx, scope) | ||
result := []vfilter.Row{} | ||
for row := range output_chan { | ||
result = append(result, row) | ||
} | ||
|
||
s, err := json.MarshalIndent(result, "", " ") | ||
if err != nil { | ||
return responder.RaiseError(err.Error()) | ||
} | ||
|
||
responder.AddResponse(&actions_proto.VQLResponse{ | ||
Response: proto.String(string(s)), | ||
}) | ||
|
||
return responder.Return() | ||
} |
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,49 @@ | ||
package main | ||
|
||
import ( | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
"www.velocidex.com/golang/velociraptor/config" | ||
"www.velocidex.com/golang/velociraptor/http_comms" | ||
"www.velocidex.com/golang/velociraptor/context" | ||
"www.velocidex.com/golang/velociraptor/crypto" | ||
"www.velocidex.com/golang/velociraptor/executor" | ||
) | ||
|
||
var ( | ||
config_path = kingpin.Arg("config", "The client's config file.").Required().String() | ||
) | ||
|
||
|
||
func main() { | ||
kingpin.Parse() | ||
|
||
ctx := context.Background() | ||
config, err := config.LoadConfig(*config_path) | ||
if err != nil { | ||
kingpin.FatalIfError(err, "Unable to load config file") | ||
} | ||
ctx.Config = *config | ||
manager, err := crypto.NewClientCryptoManager( | ||
&ctx, []byte(config.Client_private_key)) | ||
if err != nil { | ||
kingpin.FatalIfError(err, "Unable to parse config file") | ||
} | ||
|
||
exe, err := executor.NewClientExecutor(&ctx) | ||
if err != nil { | ||
kingpin.FatalIfError(err, "Can not create executor.") | ||
} | ||
|
||
comm, err := http_comms.NewHTTPCommunicator( | ||
ctx, | ||
manager, | ||
exe, | ||
config.Client_server_urls, | ||
) | ||
if err != nil { | ||
kingpin.FatalIfError(err, "Can not create HTTPCommunicator.") | ||
} | ||
|
||
comm.Run() | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package velociraptor | ||
package vql | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package velociraptor | ||
package vql | ||
|
||
import ( | ||
"github.com/shirou/gopsutil/host" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package velociraptor | ||
package vql | ||
|
||
import ( | ||
"github.com/shirou/gopsutil/host" | ||
|
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