forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitoring.go
69 lines (56 loc) · 1.75 KB
/
monitoring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package flows
import (
artifacts "www.velocidex.com/golang/velociraptor/artifacts"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
crypto_proto "www.velocidex.com/golang/velociraptor/crypto/proto"
flows_proto "www.velocidex.com/golang/velociraptor/flows/proto"
"www.velocidex.com/golang/velociraptor/services"
utils "www.velocidex.com/golang/velociraptor/utils"
)
// Receive monitoring messages from the client.
func MonitoringProcessMessage(
config_obj *config_proto.Config,
collection_context *flows_proto.ArtifactCollectorContext,
message *crypto_proto.GrrMessage) error {
err := FailIfError(config_obj, collection_context, message)
if err != nil {
return err
}
switch message.RequestId {
case constants.TransferWellKnownFlowId:
return appendUploadDataToFile(
config_obj, collection_context, message)
}
response := message.VQLResponse
if response == nil || response.Query == nil {
return nil
}
// Deobfuscate the response if needed.
_ = artifacts.Deobfuscate(config_obj, response)
// Store the event log in the client's VFS.
if response.Query.Name != "" {
json_response := response.Response
if json_response == "" {
json_response = response.JSONLResponse
}
rows, err := utils.ParseJsonToDicts([]byte(json_response))
if err != nil {
return err
}
// Mark the client this came from. Since message.Souce
// is cryptographically trusted, this column may also
// be trusted.
for _, row := range rows {
row.Set("ClientId", message.Source)
}
journal, err := services.GetJournal()
if err != nil {
return err
}
return journal.PushRowsToArtifact(
config_obj, rows, response.Query.Name,
message.Source, message.SessionId)
}
return nil
}