forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
123 lines (100 loc) · 3.2 KB
/
client.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Velociraptor - Hunting Evil
Copyright (C) 2019 Velocidex Innovations.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main
import (
"context"
"sync"
kingpin "gopkg.in/alecthomas/kingpin.v2"
crypto_client "www.velocidex.com/golang/velociraptor/crypto/client"
crypto_utils "www.velocidex.com/golang/velociraptor/crypto/utils"
"www.velocidex.com/golang/velociraptor/executor"
"www.velocidex.com/golang/velociraptor/http_comms"
logging "www.velocidex.com/golang/velociraptor/logging"
"www.velocidex.com/golang/velociraptor/services"
"www.velocidex.com/golang/velociraptor/utils"
)
var (
// Run the client.
client = app.Command("client", "Run the velociraptor client")
)
func RunClient(
ctx context.Context,
wg *sync.WaitGroup,
config_path *string) {
// Include the writeback in the client's configuration.
config_obj, err := makeDefaultConfigLoader().
WithRequiredClient().
WithRequiredLogging().
WithFileLoader(*config_path).
WithWriteback().LoadAndValidate()
kingpin.FatalIfError(err, "Unable to load config file")
// Make sure the config crypto is ok.
err = crypto_utils.VerifyConfig(config_obj)
if err != nil {
kingpin.FatalIfError(err, "Invalid config")
}
executor.SetTempfile(config_obj)
manager, err := crypto_client.NewClientCryptoManager(
config_obj, []byte(config_obj.Writeback.PrivateKey))
if err != nil {
kingpin.FatalIfError(err, "Unable to parse config file")
}
// Start all the services
sm := services.NewServiceManager(ctx, config_obj)
defer sm.Close()
exe, err := executor.NewClientExecutor(ctx, config_obj)
if err != nil {
kingpin.FatalIfError(err, "Can not create executor.")
}
err = executor.StartServices(sm, manager.ClientId, exe)
if err != nil {
kingpin.FatalIfError(err, "Can not start services.")
}
// Now start the communicator so we can talk with the server.
comm, err := http_comms.NewHTTPCommunicator(
config_obj,
manager,
exe,
config_obj.Client.ServerUrls,
func() { on_error(config_obj) },
utils.RealClock{},
)
kingpin.FatalIfError(err, "Can not create HTTPCommunicator.")
wg.Add(1)
go func() {
defer wg.Done()
comm.Run(ctx)
}()
wg.Add(1)
go func() {
defer wg.Done()
<-ctx.Done()
logger := logging.GetLogger(config_obj, &logging.ClientComponent)
logger.Info("<cyan>Interrupted!</> Shutting down\n")
}()
wg.Wait()
}
func init() {
command_handlers = append(command_handlers, func(command string) bool {
if command == client.FullCommand() {
wg := &sync.WaitGroup{}
ctx, cancel := install_sig_handler()
defer cancel()
RunClient(ctx, wg, config_path)
return true
}
return false
})
}