Exemplo n.º 1
0
        public static async void SubmitAgentCommand(string agentId, string module, string command, string data = "")
        {
            var cmdRequest = new AgentCommandRequest
            {
                AgentId = agentId,
                Module  = module,
                Command = command,
                Data    = data
            };

            var apiRequest = new RestRequest($"/api/Agents/command", Method.POST);

            apiRequest.AddParameter("application/json", JsonConvert.SerializeObject(cmdRequest), ParameterType.RequestBody);
            await REST.Client.ExecuteAsync(apiRequest);
        }
Exemplo n.º 2
0
        public void SendAgentCommand(AgentCommandRequest request, string user)
        {
            var agent = ConnectedAgents.FirstOrDefault(a => a.Metadata.AgentID.Equals(request.AgentId, StringComparison.OrdinalIgnoreCase));

            if (agent != null)
            {
                while (true)
                {
                    if (!string.IsNullOrEmpty(agent.Metadata.ParentAgentID))
                    {
                        var parentAgent = agent.Metadata.ParentAgentID;
                        agent = ConnectedAgents.FirstOrDefault(a => a.Metadata.AgentID.Equals(parentAgent, StringComparison.OrdinalIgnoreCase));
                        if (string.IsNullOrEmpty(agent.Metadata.ParentAgentID))
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                agent.QueuedCommands.Enqueue(new AgentMessage
                {
                    IdempotencyKey = Guid.NewGuid().ToString(),
                    Metadata       = new AgentMetadata(),
                    Data           = new C2Data {
                        AgentID = request.AgentId, Module = request.Module, Command = request.Command, Data = Encoding.UTF8.GetBytes(request.Data)
                    }
                });

                OnAgentEvent?.Invoke(this, new AgentEvent(request.AgentId, AgentEventType.CommandRequest, request.Command));
                Log.Logger.Information("AGENT {Event} {AgentID} {Command} {Nick}", AgentEventType.CommandRequest.ToString(), request.AgentId, request.Command, user);
            }
        }
Exemplo n.º 3
0
        public void SendAgentCommand([FromBody] AgentCommandRequest request)
        {
            var user = HttpContext.User.Identity.Name;

            Program.ServerController.AgentController.SendAgentCommand(request, user);
        }