public void RemoveDelegateNode(string uuid) { if (DelegateNodes.ContainsKey(uuid)) { DelegateNode node = DelegateNodes[uuid]; if (node.NodeRelay.IsActive() && !node.TemporaryUUID) { node.NodeRelay.StopAllThreads = true; while (node.NodeRelay.IsActive()) { Thread.Sleep(500); } } DelegateNodesMutex.WaitOne(); DelegateNodes.Remove(uuid); DelegateNodesMutex.ReleaseMutex(); AS.EdgeNode en = new AS.EdgeNode() { source = this.uuid, destination = node.AgentUUID, direction = 1, // from source to dest metadata = "", action = "remove", c2_profile = node.ProfileInfo.name }; if (!node.TemporaryUUID) { var response = new ApolloTaskResponse() { task_id = node.OriginatingTaskID, completed = true, user_output = $"Lost link to {node.AgentComputerName} (Agent UUID: {node.AgentUUID})", status = "error", edges = new AS.EdgeNode[] { en } }; try { Profile.SendResponse(node.OriginatingTaskID, response); } catch (Exception ex) { DebugWriteLine($"Error sending node removal message to server. Reason: {ex.Message}\n\tStackTrack: {ex.StackTrace}"); } } } }
public void AddDelegateNode(string uuid, DelegateNode dg) { if (DelegateNodes.ContainsKey(uuid)) { RemoveDelegateNode(uuid); } DelegateNodesMutex.WaitOne(); try { DelegateNodes.Add(uuid, dg); } catch { } finally { DelegateNodesMutex.ReleaseMutex(); } }