Skip to content

Commit

Permalink
Don't uninstall agent after server verification fails. A server misco…
Browse files Browse the repository at this point in the history
…nfiguration could cause all agents to uninstall.
  • Loading branch information
bitbound committed Aug 8, 2020
1 parent 563051a commit 3e491fa
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions Agent/Services/AgentSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,22 @@ private void RegisterMessageHandlers()
// by emitting these events so other services can listen for them.

HubConnection.On("Chat", async (string senderName, string message, string orgName, bool disconnected, string senderConnectionID) => {
if (!IsServerVerified)
{
Logger.Write("Chat attempted before server was verified.", EventType.Warning);
return;
}
await ChatService.SendMessage(senderName, message, orgName, disconnected, senderConnectionID, HubConnection);
});
HubConnection.On("DownloadFile", async (string filePath, string senderConnectionID) =>
{
if (!IsServerVerified)
{
Logger.Write("File download attempted before server was verified.", EventType.Warning);
return;
}
filePath = filePath.Replace("\"", "");
if (!File.Exists(filePath))
{
Expand All @@ -168,14 +180,19 @@ private void RegisterMessageHandlers()
});
HubConnection.On("ChangeWindowsSession", async (string serviceID, string viewerID, int targetSessionID) =>
{
if (!IsServerVerified)
{
Logger.Write("Session change attempted before server was verified.", EventType.Warning);
return;
}
await AppLauncher.RestartScreenCaster(new List<string>() { viewerID }, serviceID, viewerID, HubConnection, targetSessionID);
});
HubConnection.On("ExecuteCommand", (async (string mode, string command, string commandID, string senderConnectionID) =>
{
if (!IsServerVerified)
{
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderConnectionID}");
Uninstaller.UninstallAgent();
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderConnectionID}", EventType.Warning);
return;
}
Expand All @@ -185,15 +202,20 @@ private void RegisterMessageHandlers()
{
if (!IsServerVerified)
{
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderUserName}");
Uninstaller.UninstallAgent();
Logger.Write($"Command attempted before server was verified. Mode: {mode}. Command: {command}. Sender: {senderUserName}", EventType.Warning);
return;
}
await CommandExecutor.ExecuteCommandFromApi(mode, requestID, command, commandID, senderUserName, HubConnection);
}));
HubConnection.On("UploadFiles", async (string transferID, List<string> fileIDs, string requesterID) =>
{
if (!IsServerVerified)
{
Logger.Write("File upload attempted before server was verified.", EventType.Warning);
return;
}
Logger.Write($"File upload started by {requesterID}.");
var sharedFilePath = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(),"RemotelySharedFiles")).FullName;
Expand Down Expand Up @@ -226,13 +248,13 @@ private void RegisterMessageHandlers()
HubConnection.On("DeployScript", async (string mode, string fileID, string commandResultID, string requesterID) => {
if (!IsServerVerified)
{
Logger.Write($"Script deploy attempted before server was verified. Mode: {mode}. File ID: {fileID}. Sender: {requesterID}");
Uninstaller.UninstallAgent();
Logger.Write($"Script deploy attempted before server was verified. Mode: {mode}. File ID: {fileID}. Sender: {requesterID}", EventType.Warning);
return;
}
await ScriptRunner.RunScript(mode, fileID, commandResultID, requesterID, HubConnection);
});

HubConnection.On("UninstallClient", () =>
{
Uninstaller.UninstallAgent();
Expand All @@ -242,8 +264,7 @@ private void RegisterMessageHandlers()
{
if (!IsServerVerified)
{
Logger.Write("Remote control attempted before server was verified.");
Uninstaller.UninstallAgent();
Logger.Write("Remote control attempted before server was verified.", EventType.Warning);
return;
}
await AppLauncher.LaunchRemoteControl(-1, requesterID, serviceID, HubConnection);
Expand All @@ -252,14 +273,18 @@ private void RegisterMessageHandlers()
{
if (!IsServerVerified)
{
Logger.Write("Remote control attempted before server was verified.");
Uninstaller.UninstallAgent();
Logger.Write("Remote control attempted before server was verified.", EventType.Warning);
return;
}
await AppLauncher.RestartScreenCaster(viewerIDs, serviceID, requesterID, HubConnection);
});
HubConnection.On("CtrlAltDel", () =>
{
if (!IsServerVerified)
{
Logger.Write("CtrlAltDel attempted before server was verified.", EventType.Warning);
return;
}
User32.SendSAS(false);
});

Expand All @@ -271,8 +296,7 @@ private void RegisterMessageHandlers()
}
else
{
Logger.Write($"Server sent an incorrect verification token. Token Sent: {verificationToken}.");
Uninstaller.UninstallAgent();
Logger.Write($"Server sent an incorrect verification token. Token Sent: {verificationToken}.", EventType.Warning);
return;
}
});
Expand Down

0 comments on commit 3e491fa

Please sign in to comment.