| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id$ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# remote::sysmon Brik |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
package Metabrik::Remote::Sysmon; |
|
7
|
1
|
|
|
1
|
|
770
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
28
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use base qw(Metabrik::Remote::Winexe Metabrik::Client::Smbclient); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1198
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
|
13
|
|
|
|
|
|
|
return { |
|
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
|
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
|
16
|
|
|
|
|
|
|
author => 'GomoR ', |
|
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
|
18
|
|
|
|
|
|
|
attributes => { |
|
19
|
|
|
|
|
|
|
datadir => [ qw(datadir) ], |
|
20
|
|
|
|
|
|
|
host => [ qw(host) ], # Inherited |
|
21
|
|
|
|
|
|
|
user => [ qw(username) ], # Inherited |
|
22
|
|
|
|
|
|
|
password => [ qw(password) ], # Inherited |
|
23
|
|
|
|
|
|
|
remote_path => [ qw(path) ], # Inherited |
|
24
|
|
|
|
|
|
|
domain => [ qw(domain) ], # Inherited |
|
25
|
|
|
|
|
|
|
sysmon_exe => [ qw(version) ], |
|
26
|
|
|
|
|
|
|
conf_file => [ qw(file) ], |
|
27
|
|
|
|
|
|
|
}, |
|
28
|
|
|
|
|
|
|
attributes_default => { |
|
29
|
|
|
|
|
|
|
sysmon_exe => 'Sysmon64.exe', |
|
30
|
|
|
|
|
|
|
conf_file => 'sysmon.xml', |
|
31
|
|
|
|
|
|
|
}, |
|
32
|
|
|
|
|
|
|
commands => { |
|
33
|
|
|
|
|
|
|
update => [ ], |
|
34
|
|
|
|
|
|
|
get_sysmon_exe => [ ], |
|
35
|
|
|
|
|
|
|
deploy => [ qw(host|OPTIONAL user|OPTIONAL password|OPTIONAL) ], |
|
36
|
|
|
|
|
|
|
undeploy => [ ], |
|
37
|
|
|
|
|
|
|
redeploy => [ ], |
|
38
|
|
|
|
|
|
|
generate_conf => [ ], |
|
39
|
|
|
|
|
|
|
update_conf => [ ], |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
require_modules => { |
|
42
|
|
|
|
|
|
|
'Metabrik::Client::Www' => [ ], |
|
43
|
|
|
|
|
|
|
'Metabrik::File::Compress' => [ ], |
|
44
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
|
45
|
|
|
|
|
|
|
}, |
|
46
|
|
|
|
|
|
|
require_binaries => { |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
optional_binaries => { |
|
49
|
|
|
|
|
|
|
}, |
|
50
|
|
|
|
|
|
|
need_packages => { |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
}; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub update { |
|
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
my $cw = Metabrik::Client::Www->new_from_brik_init($self) or return; |
|
61
|
0
|
|
|
|
|
|
$cw->user_agent("Metabrik-Remote-Sysmon-mirror/1.00"); |
|
62
|
0
|
|
|
|
|
|
$cw->datadir($datadir); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
my $fc = Metabrik::File::Compress->new_from_brik_init($self) or return; |
|
65
|
0
|
|
|
|
|
|
$fc->datadir($datadir); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $input = 'Sysmon.zip'; |
|
68
|
0
|
|
|
|
|
|
my $files = $cw->mirror('https://download.sysinternals.com/files/'.$input); |
|
69
|
0
|
0
|
|
|
|
|
if (! defined($files)) { |
|
70
|
0
|
|
|
|
|
|
return $self->log->errpr("update: mirror fail"); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my @updated = (); |
|
74
|
0
|
|
|
|
|
|
for my $this (@$files) { |
|
75
|
0
|
0
|
|
|
|
|
my $this_files = $fc->unzip($this, $datadir) or return; |
|
76
|
0
|
|
|
|
|
|
push @updated, @$this_files; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return \@updated; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_sysmon_exe { |
|
83
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
86
|
0
|
|
|
|
|
|
my $sysmon_exe = $self->sysmon_exe; |
|
87
|
0
|
|
|
|
|
|
my $full_path = "$datadir/$sysmon_exe"; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if (-f $full_path) { |
|
90
|
0
|
|
|
|
|
|
return $full_path; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $self->log->error("get_sysmon_exe: file not found, call update Command"); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub generate_conf { |
|
97
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
|
my ($conf_file) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
|
101
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('generate_conf', $conf_file) or return; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
104
|
0
|
|
|
|
|
|
$conf_file = "$datadir/$conf_file"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $conf =<
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
SHA1 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
EOF |
|
130
|
|
|
|
|
|
|
; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
|
133
|
0
|
|
|
|
|
|
$ft->append(0); |
|
134
|
0
|
|
|
|
|
|
$ft->overwrite(1); |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
$ft->write($conf, $conf_file) or return; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return $conf_file; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub deploy { |
|
142
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
143
|
0
|
|
|
|
|
|
my ($host, $user, $password) = @_; |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
0
|
|
|
|
$host ||= $self->host; |
|
146
|
0
|
|
0
|
|
|
|
$user ||= $self->user; |
|
147
|
0
|
|
0
|
|
|
|
$password ||= $self->password; |
|
148
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('host', $host) or return; |
|
149
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('user', $user) or return; |
|
150
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('password', $password) or return; |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $sysmon_exe = $self->sysmon_exe; |
|
153
|
0
|
|
|
|
|
|
my $remote_path = $self->remote_path; |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
my $full_path = $self->get_sysmon_exe or return; |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
$self->log->verbose("deploy: uploaded file [$full_path] to remote_path[$remote_path]"); |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
$self->upload($full_path) or return; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $cmd = "\"cmd.exe /c $remote_path\\$sysmon_exe -i -accepteula -n\""; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return $self->execute($cmd); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub undeploy { |
|
167
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
168
|
0
|
|
|
|
|
|
my ($host, $user, $password) = @_; |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
0
|
|
|
|
$host ||= $self->host; |
|
171
|
0
|
|
0
|
|
|
|
$user ||= $self->user; |
|
172
|
0
|
|
0
|
|
|
|
$password ||= $self->password; |
|
173
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('host', $host) or return; |
|
174
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('user', $user) or return; |
|
175
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('password', $password) or return; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $sysmon_exe = $self->sysmon_exe; |
|
178
|
0
|
|
|
|
|
|
my $remote_path = $self->remote_path; |
|
179
|
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$self->log->verbose("undeploy: from remote_path[$remote_path] ". |
|
181
|
|
|
|
|
|
|
"sysmon_exe[$sysmon_exe]"); |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $cmd = "\"cmd.exe /c $remote_path\\$sysmon_exe -u\""; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
return $self->execute($cmd); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub update_conf { |
|
189
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
190
|
0
|
|
|
|
|
|
my ($conf_file) = @_; |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
|
193
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('update_conf', $conf_file) or return; |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
196
|
0
|
|
|
|
|
|
my $base_conf_file = $conf_file; |
|
197
|
0
|
|
|
|
|
|
$conf_file = "$datadir/$conf_file"; |
|
198
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('update_conf', $conf_file) or return; |
|
199
|
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $sysmon_exe = $self->sysmon_exe; |
|
201
|
0
|
|
|
|
|
|
my $remote_path = $self->remote_path; |
|
202
|
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
my $full_path = $self->get_sysmon_exe or return; |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$self->log->verbose("update_conf: uploaded file [$conf_file] ". |
|
206
|
|
|
|
|
|
|
"to remote_path[$remote_path]"); |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
0
|
|
|
|
|
$self->upload($conf_file) or return; |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my $cmd = "\"cmd.exe /c $remote_path\\$sysmon_exe -c $remote_path\\$base_conf_file\""; |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return $self->execute($cmd); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub redeploy { |
|
216
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
217
|
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
$self->undeploy; |
|
219
|
0
|
|
|
|
|
|
return $self->deploy; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
1; |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
__END__ |