(self)
| 25 | loop.create_task(self.operation_loop()) |
| 26 | |
| 27 | async def operation_loop(self): |
| 28 | while True: |
| 29 | await self.tcp_handler.refresh() |
| 30 | for session in self.tcp_handler.sessions: |
| 31 | _, instructions = await self.contact_svc.handle_heartbeat(paw=session.paw) |
| 32 | for instruction in instructions: |
| 33 | try: |
| 34 | self.log.debug('TCP instruction: %s' % instruction.id) |
| 35 | status, _, response, agent_reported_time = await self.tcp_handler.send( |
| 36 | session.id, |
| 37 | self.decode_bytes(instruction.command), |
| 38 | timeout=instruction.timeout |
| 39 | ) |
| 40 | beacon = dict(paw=session.paw, |
| 41 | results=[dict(id=instruction.id, output=self.encode_string(response), status=status, agent_reported_time=agent_reported_time)]) |
| 42 | await self.contact_svc.handle_heartbeat(**beacon) |
| 43 | await asyncio.sleep(instruction.sleep) |
| 44 | except Exception as e: |
| 45 | self.log.debug('[-] operation exception: %s' % e) |
| 46 | await asyncio.sleep(20) |
| 47 | |
| 48 | |
| 49 | class TcpSessionHandler(BaseWorld): |
no test coverage detected