[docs]classTuoniAgent:""" A class that encapsulates the data and functionality of a connected agent. Attributes: guid (GUID): A unique identifier (GUID) assigned to the agent. first_registration_time (str): The time, in string format, when the agent first connected. last_callback_time (str): The time, in string format, of the agent's most recent connection. metadata (dict): A dictionary containing metadata about the agent. active (bool): A boolean flag indicating whether the agent is currently active. recentListeners (list): A list of listeners that the agent uses to maintain its connection. availableCommands (dict): A dictionary of commands that the agent is capable of executing. """def__init__(self,conf,c2):""" Constructor. Attributes: conf (dict): Data from server. c2 (TuoniC2): Related server object. """self.c2=c2self._load_conf(conf)def_load_conf(self,conf):self.guid=conf["guid"]self.first_registration_time=conf["firstRegistrationTime"]self.last_callback_time=conf["lastCallbackTime"]self.metadata=conf["metadata"]self.active=conf["active"]self.recentListeners=conf["recentListeners"]self._fill_available_commands(conf["availableCommandTemplates"])
[docs]defget_commands(self):""" Retrieves a list of all commands associated with the agent. Returns: list[TuoniCommand]: List of commands sent to the agent. """ifself.guidisNone:raiseExceptionTuoniDeleted("")commands_data=self.c2.request_get(f"/api/v1/agents/{self.guid}/commands")commands=[]forcommand_nrincommands_data:command_data=commands_data[command_nr]command_obj=TuoniCommand(command_data,self.c2)commands.append(command_obj)returncommands
[docs]defdelete(self):""" Deletes agent (actually makes it inactive but close enough). """ifself.guidisNone:raiseExceptionTuoniDeleted("")self.c2.request_put(f"/api/v1/agents/{self.guid}/inactive")self.listener_id=None
[docs]defsetCustomProperties(self,name,value):""" Adds or updates a property in the agents customProperties metadata. Parameters: name (str): The name (key) of the property to add or update. value (Any): The value to assign to the given name. Behavior: - If the property with the given name exists, its value will be updated. - If it does not exist, a new name/value pair will be added. - If value is None the name/value pair will be deleted. Example: myAgent.setCustomProperties("notes", "Domain Controller") """self.metadata['customProperties'][name]=valueself.c2.request_put(f"/api/v1/agents/{self.guid}/metadata",self.metadata)