async def connect_to_agent(): actions = [{ 'id': "1", "tool": "ping", "output": { "live": False, "address": None, }, 'parameters': { "target": "peer0.org1.example.com", "interval": "1", "duration": "3", }, 'schedule': { "from": 0, "until": 14, "duration": 0, "interval": 2, "repeat": 1 }, }] inst_dict = { "id": "100", "actions": actions, } channel = Channel("192.168.0.13", 8910) stub = AgentStub(channel) instruction = json_format.ParseDict(inst_dict, Instruction()) reply = await stub.Probe(instruction) print("DONE connect_to_agent reply =", reply) channel.close()
async def call_monitor_event(self, scenario): monitor_events = scenario.get("eventsv2").get("monitor") # extract all the actions from monitor_events to # construct the Instruction message monitor_actions = [] for ev in monitor_events: for action in ev.get("actions"): monitor_actions.append(action) instr_dict = {"id": scenario.get("id"), "actions": monitor_actions} ip, port = self.scenario.entrypoint.get("umbra-monitor").split(':') channel = Channel(ip, int(port)) stub = MonitorStub(channel) instruction = json_format.ParseDict(instr_dict, Instruction()) reply = await stub.Listen(instruction) channel.close()
async def call_agent_event(self, scenario): agent_events = scenario.get("eventsv2").get("agent") # '[0]' because we assume only single agent exist, thus all # events should have the same "agent_name" agent_name = agent_events[0].get("agent_name") # extract all the actions from agent_events to # construct the Instruction message agent_actions = [] for ev in agent_events: for action in ev.get("actions"): agent_actions.append(action) instr_dict = {"id": scenario.get("id"), "actions": agent_actions} ip, port = self.agent_plugin[agent_name].split(':') channel = Channel(ip, int(port)) stub = AgentStub(channel) instruction = json_format.ParseDict(instr_dict, Instruction()) reply = await stub.Probe(instruction) channel.close()
def test_tools(self): actions = [ { 'id': "1", "tool": "ping", "output": { "live": False, "address": None, }, 'parameters': { "target": "127.0.0.1", "interval": "1", "duration": "3", }, 'schedule': { "from": 0, "until": 14, "duration": 0, "interval": 2, "repeat": 2 }, }, # { # 'id': "2", # "tool": "iperf3", # "output": { # "live": False, # "address": None, # }, # 'parameters': { # 'port': "9030", # 'duration': "3", # 'client': "True", # 'server': '127.0.0.1', # }, # 'schedule': {} # }, # { # 'id': "3", # "tool": "tcpreplay", # "output": { # "live": False, # "address": None, # }, # 'parameters': { # 'interface': 'lo', # 'duration': "5", # 'folder': "/tmp/", # 'pcap': 'wlp82s0.pcap', # }, # 'schedule': {} # }, ] inst_dict = { "id": "100", "actions": actions, } tools = Tools() instruction = json_format.ParseDict(inst_dict, Instruction()) instruction_dict = json_format.MessageToDict( instruction, preserving_proto_field_name=True) snapshot_dict = asyncio.run(tools.handle(instruction_dict)) snapshot = json_format.ParseDict(snapshot_dict, Snapshot()) print(snapshot)
def test_tools(self): actions = [ { 'id': "1", "tool": "process", "output": { "live": False, "address": None, }, 'parameters': { "pid": "2322", "interval": "1", "duration": "3", }, 'schedule': {} }, { 'id': "2", "tool": "container", "output": { "live": False, "address": None, }, 'parameters': { "target": "teste", "interval": "1", "duration": "3", }, 'schedule': {} }, # { # 'id': "3", # "tool": "host", # "output": { # "live": False, # "address": None, # }, # 'parameters': { # "interval": "1", # "duration": "3", # }, # 'schedule': {} # }, { 'id': "4", "tool": "tcpdump", "output": { "live": False, "address": None, }, 'parameters': { "interface": "wlp82s0", "pcap": "wlp82s0.pcap" }, 'schedule': { "duration": 3, } }, ] inst_dict = { "id": "100", "actions": actions, } # tools = Tools() # out = asyncio.run(tools.handle(inst_dict)) # print(out) tools = Tools() instruction = json_format.ParseDict(inst_dict, Instruction()) instruction_dict = json_format.MessageToDict(instruction, preserving_proto_field_name=True) snapshot_dict = asyncio.run(tools.handle(instruction_dict)) snapshot = json_format.ParseDict(snapshot_dict, Snapshot()) print(snapshot)
async def connect_to_monitor(): actions = [ # { # "id": "1", # "tool": "host", # "output": { # "live": False, # "address": None, # }, # "parameters": { # "interval": "1", # "duration": "3", # }, # 'schedule': { # "from": 1, # "until": 0, # "duration": 0, # "interval": 0, # "repeat": 0 # }, # }, # { # 'id': "1", # "tool": "process", # "output": { # "live": False, # "address": None, # }, # 'parameters': { # "pid": "2322", # "interval": "1", # "duration": "3", # }, # 'schedule': { # "from": 1, # "until": 0, # "duration": 0, # "interval": 0, # "repeat": 0 # }, # }, { 'id': "2", "tool": "container", "output": { "live": False, "address": None, }, # Launch a container with name first # $ docker run -t -d --rm --name testmon ubuntu:18.04 'parameters': { "target": "testmon", "interval": "1", "duration": "5", }, 'schedule': { "from": 1, "until": 0, "duration": 0, "interval": 0, "repeat": 0 }, }, # { # 'id': "4", # "tool": "tcpdump", # "output": { # "live": False, # "address": None, # }, # 'parameters': { # "interface": "any", # "pcap": "/home/banoris/tmp/any.pcap", # }, # 'schedule': { # "duration": 3, # } # }, ] inst_dict = { "id": "100", "actions": actions, } channel = Channel("127.0.0.1", 8900) stub = MonitorStub(channel) instruction = json_format.ParseDict(inst_dict, Instruction()) reply = await stub.Listen(instruction) print("DONE reply=", reply) channel.close()