-
Notifications
You must be signed in to change notification settings - Fork 2
/
EncaseNetworkFrameworkLib.EnScript
359 lines (322 loc) · 11.7 KB
/
EncaseNetworkFrameworkLib.EnScript
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
//===============================================
// EnCase Network Framework Library
// Written by: James Habben
// Version: 1.0
// Updated: 2014-12-1
//===============================================
class NetworkFrameworkClass {
DialogClass Dialog;
SafeClass Safe;
RoleClass Role;
int ScanMode;
uint DirectNetworkPort;
bool ServletCheckin,
GetSnapshot;
String ScriptName,
HelpText,
Username,
Rolename,
KeyfilePath,
KeyfilePassword,
NetworkName,
DirectNetworkName,
ExportPath;
NetworkFrameworkClass (const String &scriptName) :
Safe(),
DirectNetworkPort = 4445,
GetSnapshot = true,
ScriptName = scriptName
{
}
int ShowDialog () {
if (Dialog) {
return Dialog.Execute();
}
else {
Dialog = new NetworkDialogClass(this, ScriptName);
int ret = Dialog.Execute();
delete Dialog;
return ret;
}
}
void RunScan () {
PreScan();
// local scan
if (ScanMode == 2) {
SnapshotClass ss;
if (GetSnapshot) {
ss = new SnapshotClass();
LocalMachine.ReadSnapshot(ss);
}
ScanNode(LocalMachine, ss, GetDeviceList(LocalMachine));
// direct network scan
} else if (ScanMode == 1) {
ConnectionClass conn();
Console.WriteLine("Connecting to {0}", DirectNetworkName);
if (SystemClass::EnCaseDirectNode(conn, KeyfilePath, KeyfilePassword, DirectNetworkName, DirectNetworkPort)) {
Console.WriteLine(" Connected Successfully. Processing Volumes.");
SnapshotClass ss;
if (GetSnapshot) {
ss = new SnapshotClass();
conn.ReadSnapshot(ss);
}
ScanNode(conn, ss, GetDeviceList(conn));
} else {
Console.WriteLine(" Connection Failed. [{0}]", SystemClass::LastError());
}
// enterprise scan
} else {
BatchClass batch(Safe, Role, Safe.TotalConnections(), GetSnapshot ? ConnectionClass::SNAPSHOT : 0);
if (!batch.Add(ParseText(NetworkName), TRYCONNECT | (ServletCheckin ? WAITING : 0))) {
SystemClass::Message(MBOK | ICONSTOP, ScriptName, "There was a problem with the network address: " + NetworkName);
return;
}
batch.SetPriority(BatchClass::HIGH);
if (batch.Start()) {
Console.WriteLine("Scanning " + batch.TotalMachines() + " nodes using " + batch.ConnectionsUsed() + " connection(s)");
if (ServletCheckin)
Console.WriteLine(" Waiting for Servlet Check-in");
do {
ConnectionClass conn;
SnapshotClass ss(null);
String message;
String name;
BatchClass::ConnectionTypes reply = batch.GetConnection(conn, ss, name, message, 0);
if (reply == BatchClass::BATCHCONNECT) {
SystemClass::StatusMessage("Processing " + name + " | " + ScriptName);
ScanNode(conn, ss, GetDeviceList(conn));
SystemClass::StatusMessage(ScriptName);
} else if (reply == BatchClass::BATCHWAIT)
SystemClass::Sleep(500);
else if (reply == BatchClass::BATCHERROR)
Console.WriteLine("Could Not Connect To " + name + " SAFE Error Message: " + message);
else if (reply == BatchClass::BATCHFATAL) {
String err = SystemClass::LastError();
Console.WriteLine("The SAFE is not responding: " + err + ". This Enscript will terminate.");
return;
}
} while (reply != BatchClass::BATCHDONE);
}
}
PostScan();
}
virtual void PreScan () {
}
virtual void PostScan () {
}
virtual void ScanNode (ConnectionClass con, SnapshotClass snap, DeviceInfoClass devList) {
}
EntryClass GetEntryRoot (DeviceInfoClass di) {
CaseClass cc();
DeviceClass dev = di.Mount(cc);
return dev.GetRootEntry();
}
DeviceInfoClass GetDeviceList (ConnectionClass con) {
DeviceInfoClass dicoll();
dicoll.Create(con);
return dicoll;
}
NetworkClass ParseText(String t) {
NetworkClass SweepNet();
while (t) {
int end = t.Find("\n");
String line = end < 0 ? t : t.SubString(0, end);
int dash = line.Find("-");
if (dash >= 0) {
IPClass ip1(ExtractIP(line.SubString(0, dash))),
ip2(ExtractIP(line.SubString(dash+1, -1)));
if (ip1 && !ip2) {
String ipstring = ip1;
ipstring.ReplaceExtension(line.SubString(dash+1));
ip2 = ipstring;
}
if (ip1 && ip2) {
NetworkClass n(SweepNet, "IP Range", NodeClass::SELECTED);
n.SetStart(ip1);
n.SetStop(ip2);
}
else
NetworkClass n(SweepNet, line, NodeClass::SELECTED);
}
else if (line != "") {
NetworkClass n(SweepNet, line, NodeClass::SELECTED);
}
if (end >= 0)
t.Delete(0, end+1);
else
break;
}
return SweepNet;
}
String ExtractIP(const String &s) {
String ret = s;
ret.Trim(" ", String::TRIMSTART | String::TRIMEND);
return ret.IsValidIPAddress() ? ret : "";
}
}
class NetworkDialogClass : DialogClass {
NetworkFrameworkClass N;
String NetworkName;
ButtonClass Btn_Help;
RadioButtonClass Rdo_Mode;
ButtonClass Btn_SafeLogon;
StringEditClass Str_Username;
ButtonClass Btn_Role;
StringEditClass Str_Rolename;
CheckBoxClass Chk_ServletCheckin;
PathEditClass Pth_Keyfile;
StringEditClass Str_KeyfilePassword;
ButtonClass Btn_CheckPassword;
ImageWindowClass Img_PasswordCheck;
StringEditClass Str_Network;
StringEditClass Str_DirectNetwork;
UIntEditClass Unt_DirectNetworkPort;
PathEditClass Pth_ExportPath;
NetworkDialogClass (NetworkFrameworkClass n, const String &windowTitle = "Network Framework") :
super (null, windowTitle),
N = n,
Btn_Help (this, "&Help", START, START, DEFAULT, DEFAULT, 0),
Rdo_Mode (this, "Scan Run Mode", START, NEXT, DEFAULT, DEFAULT, HORIZONTAL, N.ScanMode, "Enterprise Servlet(s)\tDirect Servlet\tLocal System"),
Btn_SafeLogon (this, "Safe &Logon", START, NEXT, 70, DEFAULT, 0),
Str_Username (this, "", NEXT, SAME, 100, DEFAULT, READONLY, N.Username, 200, 0),
Btn_Role (this, "Choose &Role", START, NEXT, 70, DEFAULT, 0),
Str_Rolename (this, "", NEXT, SAME, 100, DEFAULT, READONLY, N.Rolename, 200, 0),
Chk_ServletCheckin (this, "Wait for Servlet Check-in", START, NEXT, DEFAULT, DEFAULT, 0, N.ServletCheckin),
Pth_Keyfile (this, "Private Key File for Servlet", 220, 75, 250, DEFAULT, 0, N.KeyfilePath, FILEOPEN, "Private Key File\t*.PrivateKey"),
Str_KeyfilePassword (this, "Password", 220, NEXT, 150, DEFAULT, PASSWORD, N.KeyfilePassword, 200, 0),
Btn_CheckPassword (this, "Check Password", NEXT, SAME2, DEFAULT, DEFAULT, 0),
Img_PasswordCheck (this, "", NEXT, SAME, 14, 12, 0, 0),
Str_Network (this, "Machine &IP/DNS", START, NEXT, 200, 50, 0, N.NetworkName, 200, 0),
Str_DirectNetwork (this, "Single Machine IP/DNS", 220, SAME, 200, DEFAULT, 0, N.DirectNetworkName, 100, 0),
Unt_DirectNetworkPort (this, "Port #", NEXT, SAME, 40, DEFAULT, 0, N.DirectNetworkPort, 1, 65535, 0),
Pth_ExportPath (this, "LEF Export Folder", START, 200, 300, DEFAULT, 0, N.ExportPath, 0)
{
}
virtual void Setup () {
super::Setup();
EnableClose(false);
Btn_Role.Enable(false);
Str_Network.Enable(false);
Pth_ExportPath.Enable(false);
Chk_ServletCheckin.Enable(false);
}
virtual void CheckControls () {
bool enableControls = Rdo_Mode.GetValue() == 2 ||
(Rdo_Mode.GetValue() == 0 && N.Safe.UserName() ||
(Rdo_Mode.GetValue() == 1 && Pth_Keyfile.GetText() && Str_KeyfilePassword.GetText() && Str_DirectNetwork.GetText()));
// Safe controls
Btn_SafeLogon.Enable(Rdo_Mode.GetValue() == 0);
Btn_Role.Enable(enableControls && Rdo_Mode.GetValue() == 0);
Chk_ServletCheckin.Enable(enableControls && Rdo_Mode.GetValue() == 0);
Str_Network.Enable(enableControls && Rdo_Mode.GetValue() == 0);
// Direct network controls
Pth_Keyfile.Enable(Rdo_Mode.GetValue() == 1);
Str_KeyfilePassword.Enable(Rdo_Mode.GetValue() == 1);
Str_DirectNetwork.Enable(Rdo_Mode.GetValue() == 1);
Btn_CheckPassword.Enable(Rdo_Mode.GetValue() == 1 && Str_KeyfilePassword.GetText() && Pth_Keyfile.GetText());
Unt_DirectNetworkPort.Enable(Rdo_Mode.GetValue() == 1);
Pth_ExportPath.Enable(enableControls);
EnableClose(enableControls);
}
virtual void ChildEvent(const WindowClass::EventClass &event) {
if (Btn_SafeLogon.Matches(event)) {
if (N.Safe.Logon(this) && N.Safe.UserName().Compare("keymaster") != 0) {
Str_Username.SetText(N.Safe.UserName());
N.Role = N.Safe.RoleRoot().FirstChild();
Str_Rolename.SetText(N.Role.Name());
}
if (N.Safe.UserName().Compare("keymaster") == 0)
SystemClass::Message(SystemClass::MBOK | SystemClass::ICONSTOP, "No!", "No Keymaster for you!!1!");
} else if (Rdo_Mode.Matches(event)) {
if (Rdo_Mode.GetValue() == 2) {
NetworkName = Str_Network.GetText();
Str_Network.SetText("LocalMachine");
} else {
if (Rdo_Mode.GetValue() == 1) {
Str_Network;
}
Str_Network.SetText(NetworkName);
}
} else if (Btn_Help.Matches(event)) {
SystemClass::Message(MBOK | ICONINFORMATION, N.ScriptName, N.HelpText);
} else if (Btn_Role.Matches(event)) {
RoleDialogClass diag(this, N);
if (diag.Execute() != SystemClass::CANCEL)
Str_Rolename.SetText(N.Role.Name());
} else if (Btn_CheckPassword.Matches(event)) {
SafeClass safe();
LocalFileClass lf();
if (lf.Open(Pth_Keyfile.GetText())) {
bool status = safe.ReadUserKey("asdf", lf, Str_KeyfilePassword.GetText());
if (status == true) {
ImageClass img();
img.CreateIcon(IconClass::OK);
Img_PasswordCheck.SetImage(img);
} else {
ImageClass img();
img.CreateIcon(IconClass::EXCLUDED);
Img_PasswordCheck.SetImage(img);
}
}
} else if (Str_KeyfilePassword.Matches(event)) {
ImageClass img();
img.CreateIcon(IconClass::REFRESH);
Img_PasswordCheck.SetImage(img);
}
super::ChildEvent(event);
}
virtual bool CanClose() {
LocalMachine.CreateFolder(Pth_ExportPath.GetText(), ConnectionClass::CREATEFOLDERALL);
bool retval = super::CanClose();
if (retval) {
if (!Pth_ExportPath.GetText()) {
SystemClass::Message(SystemClass::MBOK, "No Export Path", "Choose an export path.");
return false;
}
if (Pth_ExportPath.GetText().LastChar() != '\\')
Pth_ExportPath.SetText(Pth_ExportPath.GetText() + "\\");
return true;
}
return false;
}
class RoleDialogClass: DialogClass {
NetworkFrameworkClass N;
TreeEditClass Tre_Role;
RoleDialogClass (DialogClass parent, NetworkFrameworkClass n) :
DialogClass(parent, "Choose Role"),
N = n,
Tre_Role (this, "Role", START, START, 240, 130, 0, N.Safe.RoleRoot(), 0)
{
}
virtual bool CanClose() {
if (super::CanClose()) {
N.Role = RoleClass::TypeCast(Tre_Role.GetValue());
return true;
}
return false;
}
}
}
#ifdef RunLib
// Demo code only run with #define RunLib
class NetFraClass : NetworkFrameworkClass {
NetFraClass () :
super("Demo Class"),
HelpText("This is some example text to explain the usage when the user clicks the help button")
{
}
virtual void ScanNode (ConnectionClass con, SnapshotClass snap, DeviceInfoClass devList) {
Console.WriteLine("Host: {0}", con.Name());
foreach (DeviceInfoClass di in devList) {
Console.WriteLine(" {0}: {1}", di.IsPhysical() ? "Physical" : "Logical", di.Name());
}
}
}
class MainClass {
void Main() {
NetFraClass nf();
nf.ShowDialog();
nf.RunScan();
}
}
#endif