-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerServerMethodsPatcher.cs
289 lines (236 loc) · 8.37 KB
/
PlayerServerMethodsPatcher.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using CompressString;
using HarmonyLib;
using NetworkMessages;
using Util;
using Newtonsoft.Json;
using UnityEngine;
namespace GHPluginCoreLib
{
class PlayerServerMethodsPatcher
{
public static bool PrepareCommandServerRpc_PrefixPatch(string pathCurrentFolder, byte[] zipComandoCompleto, string propActiveUser, string prevConnIp, int numBounces, int terminalPID, int parentPID, bool shellFtp, PlayerServerMethods __instance)
{
// Original implementation code
int num = (parentPID > 0) ? parentPID : terminalPID;
bool flag = false;
Computer.Procesos proceso = __instance.pc.GetProceso(num);
string text;
if (num == -10)
{
text = __instance.pc.GetID();
}
else
{
if (proceso == null)
{
__instance.CloseConnection(terminalPID, XmlGlobal.GetTexto("ERROR_UNKPROC", false, false), false);
return false;
}
text = proceso.GetRemoteNetID();
flag = proceso.isProtected;
}
string[] array;
try
{
array = JsonConvert.DeserializeObject<string[]>(StringCompressor.Unzip(zipComandoCompleto));
}
catch
{
__instance.CloseConnection(terminalPID, "Unknown error: invalid command.", false);
return false;
}
if (!Networking.IsNetworkActive(__instance.player.GetComputer().GetPublicIP()) && !__instance.player.GetComputer().GetID().Equals(text))
{
__instance.CloseConnection(terminalPID, "Error: No internet connection", false);
return false;
}
Computer remoteComputer = RedGlobal.Singleton.GetRemoteComputer(text, false, true, "", -1);
if (remoteComputer == null)
{
__instance.CloseConnection(terminalPID, "Error: device not found.", false);
return false;
}
if (shellFtp)
{
__instance.RunFtpCommand(array, pathCurrentFolder, propActiveUser, remoteComputer, terminalPID, prevConnIp, numBounces);
return false;
}
List<string> list = new List<string>();
list.Add(pathCurrentFolder);
list.Add("/bin");
list.Add("/usr/bin");
List<string> list2 = list;
FileSystem fileSystem = remoteComputer.GetFileSystem();
string activeUser = __instance.userConnections.GetActiveUser(remoteComputer.GetID(), propActiveUser);
Computer.User user = remoteComputer.GetUser(activeUser);
FileSystem.Archivo archivo = null;
for (int i = 0; i < list2.Count; i++)
{
if (fileSystem.GetCarpeta(list2[i], null) != null)
{
archivo = fileSystem.GetArchivo(list2[i] + "/" + array[0]);
if (archivo != null)
{
if (!archivo.IsBinario())
{
__instance.CloseConnection(terminalPID, archivo.nombre + " is not a binary file.", false);
return false;
}
if (archivo.IsTypeFile(FileSystem.Fichero.TypeFile.Script))
{
if (num == -10 || terminalPID == -10 || !proceso.isTerminal)
{
__instance.CloseConnection(terminalPID, "Error: script is not attached to any existing terminal", false);
return false;
}
if (Enumerable.Contains<string>(new string[]
{
"dsession",
"kernel_task",
"xorg",
"ssh_enc"
}, array[0].ToLower()))
{
__instance.CloseConnection(terminalPID, "Error: " + array[0] + " is a reserved process name", false);
return false;
}
__instance.RunScript(remoteComputer, array, archivo.GetRuta(true), pathCurrentFolder, propActiveUser, terminalPID, prevConnIp, numBounces);
return false;
}
else
{
try
{
if (archivo.GetNombreProceso().Equals("cd"))
{
__instance.CdTerminal(array, pathCurrentFolder, remoteComputer, activeUser, terminalPID);
return false;
}
if (!archivo.IsEjecutable())
{
__instance.CloseConnection(terminalPID, archivo.nombre + " is not an executable file.", false);
return false;
}
/*
TODO: Fix bug causing exception to be thrown when the
TienePermisoEjecucion method is called as seen below.
*/
/*
if (!archivo.TienePermisoEjecucion(user))
{
__instance.CloseConnection(terminalPID, "Can't launch program. Permission denied.", false);
ModCore.instance.LogInfo("Can't launch program. Permission denied.");
return false;
}
*/
}
catch(Exception exception)
{
GHPluginCore.instance.logger.LogInfo("Exception occurred.");
GHPluginCore.instance.logger.LogInfo("Exception message: " + exception.Message);
GHPluginCore.instance.logger.LogInfo("Exception stack trace:");
GHPluginCore.instance.logger.LogInfo(exception.StackTrace);
}
break;
}
}
}
}
if (archivo == null)
{
__instance.CloseConnection(terminalPID, string.Join(" ", array) + ": command not found", false);
return false;
}
byte[] value = null;
int value2 = -1;
string comando = archivo.GetComando();
if (comando.Contains(".exe"))
{
if (flag)
{
__instance.CloseConnection(terminalPID, "Error: Desktop GUI is not running.", false);
return false;
}
if ((remoteComputer.IsRouter() || remoteComputer.IsCctv()) && !PlayerUtils.IsAllowedCommand(comando))
{
__instance.CloseConnection(terminalPID, "Error: this program can only be run on computers.", false);
return false;
}
if (comando.Equals("Chat.exe") && !__instance.pc.GetID().Equals(remoteComputer.GetID()))
{
__instance.CloseConnection(terminalPID, "Error: this program can not be executed remotely", false);
return false;
}
value2 = __instance.StartProgram(remoteComputer, archivo, activeUser, true, terminalPID, comando, out value);
}
byte[] value3 = StringCompressor.Zip(JsonConvert.SerializeObject(archivo));
MessageClient messageClient = new MessageClient(IdClient.SendCommandClientRpc);
messageClient.AddInt(terminalPID);
messageClient.AddByte(value3);
messageClient.AddString(archivo.GetRuta(false));
messageClient.AddInt(value2);
messageClient.AddByte(value);
__instance.player.SendData(messageClient);
return false;
}
public static void UserLogin_PostfixPatch(ulong steamID, bool forceDeletePlayer, PlayerServerMethods __instance)
{
GHPluginCore.instance.logger.LogInfo("Initiating GreyOSProgram filesystem registration procedure...");
Computer.User playerUser = null;
foreach(Computer.User user in __instance.pc.users)
{
if (user.nombreUsuario != "guest" && user.nombreUsuario != "root")
{
playerUser = user;
break;
}
}
foreach (GreyOSProgram registeredGreyOSProgram in GHPluginCore.instance.greyOSProgramManager.registeredGreyOSPrograms)
{
GHPluginCore.instance.logger.LogInfo("Registration started for GreyOSProgram with name: " + registeredGreyOSProgram.programName);
try
{
FileSystem.Archivo greyOSProgramFile = new FileSystem.Archivo();
greyOSProgramFile.SetNombre(
registeredGreyOSProgram.programName.Replace(" ", "") + ".exe"
);
greyOSProgramFile.SetComando(
"/usr/bin/" + registeredGreyOSProgram.programName.Replace(" ", "") + ".exe"
);
greyOSProgramFile.isProtected = false;
greyOSProgramFile.permisos = new FileSystem.Permisos("-rwxr-xr-x");
greyOSProgramFile.allowImport = false;
greyOSProgramFile.isBinario = true;
greyOSProgramFile.isEditedOtherPlayer = false;
greyOSProgramFile.precio = 0;
if (playerUser != null)
{
greyOSProgramFile.owner = playerUser.nombreUsuario;
greyOSProgramFile.group = playerUser.nombreUsuario;
}
else
{
greyOSProgramFile.owner = "";
greyOSProgramFile.group = "";
}
__instance.pc.GetFileSystem().AddFileRef(
greyOSProgramFile,
"/usr/bin"
);
registeredGreyOSProgram.associatedFile = greyOSProgramFile;
}
catch (Exception exception)
{
GHPluginCore.instance.logger.LogInfo("Exception occurred while attempting to register GreyOSProgram: " + exception.Message);
GHPluginCore.instance.logger.LogInfo("Exception stack trace:");
GHPluginCore.instance.logger.LogInfo(exception.StackTrace);
}
GHPluginCore.instance.logger.LogInfo("Registered GreyOSProgram with name: " + registeredGreyOSProgram.programName + " to filesystem successfully.");
}
GHPluginCore.instance.logger.LogInfo("GreyOSProgram filesystem registration procedure completed successfully.");
}
}
}