forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflows.go
99 lines (88 loc) · 2.9 KB
/
flows.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package api
import (
context "golang.org/x/net/context"
"www.velocidex.com/golang/velociraptor/acls"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/api/tables"
artifacts_proto "www.velocidex.com/golang/velociraptor/artifacts/proto"
"www.velocidex.com/golang/velociraptor/json"
vjson "www.velocidex.com/golang/velociraptor/json"
"www.velocidex.com/golang/velociraptor/services"
)
func (self *ApiServer) GetClientFlows(
ctx context.Context,
in *api_proto.GetTableRequest) (*api_proto.GetTableResponse, error) {
users := services.GetUserManager()
user_record, org_config_obj, err := users.GetUserFromContext(ctx)
if err != nil {
return nil, Status(self.verbose, err)
}
user_name := user_record.Name
permissions := acls.READ_RESULTS
perm, err := services.CheckAccess(org_config_obj, user_name, permissions)
if !perm || err != nil {
return nil, PermissionDenied(err,
"User is not allowed to view flows.")
}
launcher, err := services.GetLauncher(org_config_obj)
if err != nil {
return nil, Status(self.verbose, err)
}
// If no sort column is specified, sort by flow id so later flows
// are on top. Flow Ids have times encoded in them so they sort
// chronologically.
if in.SortColumn == "" {
in.SortColumn = "FlowId"
in.SortDirection = true
}
options, err := tables.GetTableOptions(in)
if err != nil {
return nil, Status(self.verbose, err)
}
flows, err := launcher.GetFlows(ctx, org_config_obj, in.ClientId, options,
int64(in.StartRow), int64(in.Rows))
if err != nil {
return nil, Status(self.verbose, err)
}
result := &api_proto.GetTableResponse{
TotalRows: int64(flows.Total),
Columns: []string{
"State", "FlowId", "Artifacts", "Created", "Last Active", "Creator",
"Mb", "Rows", "_Flow", "_Urgent", "_ArtifactsWithResults",
},
ColumnTypes: []*artifacts_proto.ColumnType{{
Name: "Created",
Type: "timestamp",
}, {
Name: "Last Active",
Type: "timestamp",
}, {
Name: "Mb",
Type: "mb",
}, {
Name: "Rows",
Type: "number",
}},
}
// Convert the items into a table format
for _, flow := range flows.Items {
if flow.Request == nil {
continue
}
row_data := []string{
flow.State.String(),
flow.SessionId,
json.AnyToString(flow.Request.Artifacts, vjson.DefaultEncOpts()),
json.AnyToString(flow.CreateTime, vjson.DefaultEncOpts()),
json.AnyToString(flow.ActiveTime, vjson.DefaultEncOpts()),
json.AnyToString(flow.Request.Creator, vjson.DefaultEncOpts()),
json.AnyToString(flow.TotalUploadedBytes, vjson.DefaultEncOpts()),
json.AnyToString(flow.TotalCollectedRows, vjson.DefaultEncOpts()),
json.MustMarshalProtobufString(flow, vjson.DefaultEncOpts()),
json.AnyToString(flow.Request.Urgent, vjson.DefaultEncOpts()),
json.AnyToString(flow.ArtifactsWithResults, vjson.DefaultEncOpts()),
}
result.Rows = append(result.Rows, &api_proto.Row{Cell: row_data})
}
return result, nil
}