10.09.2016 Views

Hacking_and_Penetration_Testing_with_Low_Power_Devices

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

176 CHAPTER 7 Building an army of devices<br />

self.xbee.send(’at’, frame_id¼’A’, comm<strong>and</strong>¼’MY’)<br />

resp ¼ self.xbee.wait_read_frame()<br />

while (resp[’parameter’] ¼¼ ’\xff\xfe’):<br />

sleep(1)<br />

self.xbee.send(’at’, frame_id¼’A’, comm<strong>and</strong>¼’MY’)<br />

resp ¼ self.xbee.wait_read_frame()<br />

# initial beacon to the controller<br />

self.sendAnnounce("By your comm<strong>and</strong>-drone is awaiting orders")<br />

# These variables are for transfering files<br />

rc_size ¼ 0<br />

rc_bytes ¼ 0<br />

rc_packet_num ¼ 0<br />

rc_name ¼ ""<br />

rc_file ¼ None<br />

sdl_path ¼ "./"<br />

while True:<br />

try:<br />

# get a comm<strong>and</strong> from the controller<br />

cmd ¼ self.xbee.wait_read_frame()<br />

if (cmd[’rf_data’].find(’c:’) ¼¼ 0): # sanity check this\<br />

should be the start of a comm<strong>and</strong><br />

self.sendToController("---Process started----\n")<br />

proc ¼ subprocess.Popen(cmd[’rf_data’][2:],\<br />

stdout¼subprocess.PIPE, stderr¼subprocess.PIPE,\<br />

shell¼True, bufsize¼4096)<br />

signal.alarm(3600) # nothing should take an hour to\<br />

run this will reset a drone if it all goes bad<br />

rc ¼ proc.wait() # this call blocks until the process\<br />

completes<br />

signal.alarm(0) # process succeeded so reset the timer<br />

if (rc ¼¼ 0): #returned successfully<br />

resp ¼ ""<br />

for line in iter(proc.stdout.readline, ’’):<br />

resp +¼ line<br />

resp +¼ "---------Process completed\<br />

successfully------\n"<br />

self.sendToController(resp)<br />

else:<br />

self.sendToController("+++++++Process errored\<br />

out++++++++\n")<br />

elif (cmd[’rf_data’].find("ft:") ¼¼ 0): # comm<strong>and</strong>\<br />

console is attempting to transfer a file<br />

rc_size ¼ int(cmd[’rf_data’].split(’:’)[2])<br />

rc_bytes ¼ 0<br />

rc_packet_num ¼ 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!