forked from 0x101-Cyber-Security/NetLock-RMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
141 lines (119 loc) · 5.58 KB
/
Copy pathProgram.cs
File metadata and controls
141 lines (119 loc) · 5.58 KB
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
using _x101.HWID_System;
using Global.Helper;
using NetLock_RMM_Agent_Comm;
using System.Net;
using Global.Encryption;
using Microsoft.Extensions.Hosting;
Console.WriteLine("Starting NetLock RMM Comm Agent");
var builder = Host.CreateApplicationBuilder(args);
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in assembly.GetTypes())
{
if (typeof(FileSystemWatcher).IsAssignableFrom(type) || type.Name.Contains("FileSystemWatcher"))
{
Console.WriteLine($"Gefunden in: {assembly.FullName}, Typ: {type.FullName}");
}
}
}
// Write version to disk
await File.WriteAllTextAsync(Application_Paths.netlock_comm_agent_version_txt, String_Encryption.Encrypt(Application_Settings.version, Application_Settings.NetLock_Local_Encryption_Key));
// Check if debug mode
if (Logging.Check_Debug_Mode()) // debug_mode
{
Console.WriteLine("Debug mode enabled");
Global.Configuration.Agent.debug_mode = true;
}
else
Console.WriteLine("Debug mode disabled");
// Thats dev stuff
//Global.Configuration.Agent.debug_mode = true;
// Read server_config.json
if (Convert.ToBoolean(Global.Initialization.Server_Config.Ssl())) // ssl
{
Global.Configuration.Agent.ssl = true;
Global.Configuration.Agent.http_https = "https://";
}
else
{
Global.Configuration.Agent.ssl = false;
Global.Configuration.Agent.http_https = "http://";
}
Global.Configuration.Agent.package_guid = Global.Initialization.Server_Config.Package_Guid();
Global.Configuration.Agent.communication_servers = Global.Initialization.Server_Config.Communication_Servers();
Global.Configuration.Agent.remote_servers = Global.Initialization.Server_Config.Remote_Servers();
Global.Configuration.Agent.update_servers = Global.Initialization.Server_Config.Update_Servers();
Global.Configuration.Agent.trust_servers = Global.Initialization.Server_Config.Trust_Servers();
Global.Configuration.Agent.file_servers = Global.Initialization.Server_Config.File_Servers();
Global.Configuration.Agent.relay_servers = Global.Initialization.Server_Config.Relay_Servers();
Global.Configuration.Agent.tenant_guid = Global.Initialization.Server_Config.Tenant_Guid();
Global.Configuration.Agent.location_guid = Global.Initialization.Server_Config.Location_Guid();
Global.Configuration.Agent.language = Global.Initialization.Server_Config.Language();
Global.Configuration.Agent.device_name = Environment.MachineName;
// Output platform config
Console.WriteLine($"Device Name: {Global.Configuration.Agent.device_name}");
Console.WriteLine($"Communication Servers: {Global.Configuration.Agent.communication_servers}");
Console.WriteLine($"Remote Servers: {Global.Configuration.Agent.remote_servers}");
Console.WriteLine($"Update Servers: {Global.Configuration.Agent.update_servers}");
Console.WriteLine($"Trust Servers: {Global.Configuration.Agent.trust_servers}");
Console.WriteLine($"File Servers: {Global.Configuration.Agent.file_servers}");
Console.WriteLine($"Relay Servers: {Global.Configuration.Agent.relay_servers}");
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Detecting platform...");
if (OperatingSystem.IsWindows())
{
Console.WriteLine("Windows platform detected");
Logging.Debug("Program.cs", "Startup", "Windows platform detected");
Global.Configuration.Agent.platform = "Windows";
}
else if (OperatingSystem.IsLinux())
{
Console.WriteLine("Linux platform detected");
Logging.Debug("Program.cs", "Startup", "Linux platform detected");
Global.Configuration.Agent.platform = "Linux";
}
else if (OperatingSystem.IsMacOS())
{
Console.WriteLine("MacOS platform detected");
Logging.Debug("Program.cs", "Startup", "MacOS platform detected");
Global.Configuration.Agent.platform = "MacOS";
}
builder.Services.AddHostedService<Device_Worker>();
// Get access key
Device_Worker.access_key = Global.Initialization.Server_Config.Access_Key();
Global.Configuration.Agent.hwid = ENGINE.HW_UID; // init after access key, because the linux & macos hwid generation is based on the access key
Device_Worker.authorized = Global.Initialization.Server_Config.Authorized();
Global.Initialization.Health.CleanTempScripts();
Global.Initialization.Health.Check_Directories();
Global.Initialization.Health.Check_Firewall();
Global.Initialization.Health.Check_Databases();
Global.Offline_Mode.Handler.Policy();
Global.Initialization.Health.Setup_Events_Virtual_Datatable();
Global.Initialization.Health.User_Processes();
// Check if platform is Windows
if (OperatingSystem.IsWindows())
{
Console.WriteLine("Starting Windows Worker");
Logging.Debug("Program.cs", "Startup", "Starting Windows Worker");
builder.Services.AddHostedService<Windows_Worker>();
builder.Services.AddWindowsService();
}
else if (OperatingSystem.IsLinux())
{
builder.Services.AddSystemd();
// Currently disabled because there are no linux only native functions implemented
/*Console.WriteLine("Starting Linux Worker");
Logging.Debug("Program.cs", "Startup", "Starting Linux Worker");
builder.Services.AddHostedService<Linux_Worker>();*/
}
else if (OperatingSystem.IsMacOS())
{
// Currently disabled because there are no macos only native functions implemented
/* Console.WriteLine("Starting MacOS Worker");
Logging.Debug("Program.cs", "Startup", "Starting MacOS Worker");
builder.Services.AddHostedService<MacOS_Worker>();*/
}
Console.WriteLine("Starting Host");
Logging.Debug("Program.cs", "Startup", "Starting Host");
var host = builder.Build();
host.Run();