From 5ac7656475f10d72b70240cc5e61da0738f9d1f6 Mon Sep 17 00:00:00 2001 From: checkymander Date: Tue, 14 Jan 2025 11:32:36 -0500 Subject: [PATCH] update unit tests --- .../Agent.Tests/AgentTests/TaskingTests.cs | 15 +--- .../Agent.Tests/TestClasses/TestProfile.cs | 71 +++++++++++-------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/AgentTests/TaskingTests.cs b/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/AgentTests/TaskingTests.cs index cf8b237b8..6fc0841c1 100644 --- a/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/AgentTests/TaskingTests.cs +++ b/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/AgentTests/TaskingTests.cs @@ -80,7 +80,7 @@ public async Task TestGetTaskingMultiple() AthenaCore _agent = new AthenaCore(_profile, _taskManager, _logger, _config, _tokenManager, new List() { _agentMod }); TestProfile prof = (TestProfile)_profile.First(); - Task.Run(_agent.Start); + await _agent.Start(); _profile.First().SetTaskingReceived += (sender, args) => taskingReceived.Set(); ((TestTaskManager)_taskManager).WaitForNumberOfJobs(3); @@ -109,18 +109,5 @@ public async Task TestGetTaskingNoTasks() { _profile.First().StopBeacon(); Assert.IsTrue(((TestTaskManager)_taskManager).jobs.Count == 0); } - [TestMethod] - public async Task TestGetTaskingNullTasks() - { - ManualResetEvent taskingReceived = new ManualResetEvent(false); - IEnumerable _profile = new List() { new TestProfile(true) }; - _profile.First().SetTaskingReceived += (sender, args) => taskingReceived.Set(); - TestProfile prof = (TestProfile)_profile.First(); - AthenaCore _agent = new AthenaCore(_profile, _taskManager, _logger, _config, _tokenManager, new List() { _agentMod }); - Task.Run(_agent.Start); - prof.taskingSent.WaitOne(1000); - _profile.First().StopBeacon(); - Assert.IsTrue(((TestTaskManager)_taskManager).jobs.Count == 0); - } } } diff --git a/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/TestClasses/TestProfile.cs b/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/TestClasses/TestProfile.cs index 85b576ed2..575f2e2cd 100644 --- a/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/TestClasses/TestProfile.cs +++ b/Payload_Type/athena/athena/agent_code/Tests/Agent.Tests/TestClasses/TestProfile.cs @@ -17,38 +17,11 @@ public class TestProfile : IProfile private bool returnedTask = false; public CancellationTokenSource cts = new CancellationTokenSource(); public ManualResetEvent taskingSent = new ManualResetEvent(false); - public TestProfile() { - - checkinResponse = new CheckinResponse() - { - status = "success", - action = "checkin", - id = Guid.NewGuid().ToString(), - encryption_key = "", - decryption_key = "", - process_name = "", - }; - - getTaskingResponse = new GetTaskingResponse() - { - action = "get_tasking", - tasks = new List() - { - new ServerTask() - { - id = Guid.NewGuid().ToString(), - command = "whoami", - parameters = "", - } - }, - socks = new List(), - rpfwd = new List(), - delegates = new List(), - }; + public TestProfile() + { } public TestProfile(CheckinResponse? checkinResponse) { - Console.WriteLine(checkinResponse.status); this.checkinResponse = checkinResponse; } @@ -64,6 +37,18 @@ public TestProfile(bool nullable) public async Task Checkin(Checkin checkin) { + if (this.checkinResponse is null) + { + return new CheckinResponse() + { + status = "success", + action = "checkin", + id = Guid.NewGuid().ToString(), + encryption_key = "", + decryption_key = "", + process_name = "", + }; + } return this.checkinResponse; } @@ -74,10 +59,36 @@ public async Task StartBeacon() { if (!returnedTask) { - TaskingReceivedArgs tra = new TaskingReceivedArgs(getTaskingResponse); + TaskingReceivedArgs tra; + if (this.getTaskingResponse is null) + { + + tra = new TaskingReceivedArgs(new GetTaskingResponse() + { + action = "get_tasking", + tasks = new List() + { + new ServerTask() + { + id = Guid.NewGuid().ToString(), + command = "whoami", + parameters = "", + }, + }, + socks = new List(), + rpfwd = new List(), + delegates = new List(), + }); + } + else + { + tra = new TaskingReceivedArgs(this.getTaskingResponse); + } + SetTaskingReceived?.Invoke(this, tra); returnedTask = true; taskingSent.Set(); + return; } } isRunning = false;