10.09.2016 Views

Hacking_and_Penetration_Testing_with_Low_Power_Devices

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

wireless traffic to <strong>and</strong> from the development server might also reveal project names<br />

provided any of the developers are connecting wirelessly to the server.<br />

Given the likely proximity of the Dalek to the development server, this drone can<br />

be used for some specialized wireless sniffing. The following script will sniff <strong>and</strong> capture<br />

only packets to <strong>and</strong> from a specific IP or MAC address. It could easily be modified<br />

to parse through the packets <strong>and</strong> notify you if something interesting is detected.<br />

#!/usr/bin/env python<br />

# simple script to capture wireless packets<br />

# bound for or from a specific address <strong>with</strong> scapy<br />

# As presented in the book<br />

# <strong>Hacking</strong> <strong>and</strong> <strong>Penetration</strong> <strong>Testing</strong> With <strong>Low</strong> <strong>Power</strong> <strong>Devices</strong><br />

# by Dr. Phil Polstra<br />

from scapy.all import *<br />

import optparse<br />

# create a pktcap file<br />

pktcap ¼ PcapWriter(’devserver.pcap’, append¼True, sync¼True)<br />

ipaddr ¼ None<br />

macaddr ¼ None<br />

# define a function to be called <strong>with</strong> each received packet<br />

def packet_h<strong>and</strong>ler(pkt) :<br />

if ipaddr !¼ None :<br />

if (pkt.getlayer(IP).dst ¼¼ ipaddr) j\<br />

(pkt.getlayer(IP).src ¼¼ ipaddr):<br />

pktcap.write(pkt)<br />

return<br />

if macaddr !¼ None :<br />

if (pkt.getlayer(Ether).dst ¼¼ macaddr) j\<br />

(pkt.getlayer(Ether).src ¼¼ macaddr):<br />

pktcap.write(pkt)<br />

def main() :<br />

# parse comm<strong>and</strong> line options<br />

parser ¼ optparse.OptionParser(’usage %prog -i \<br />

-m ’)<br />

parser.add_option(’-i’, dest¼’ipaddr’, type¼’string’,\<br />

help¼’target IP address’)<br />

parser.add_option(’-m’, dest¼’macaddr’, type¼’string’,\<br />

help¼’target MAC address’)<br />

(options, args) ¼ parser.parse_args()<br />

ipaddr ¼ options.ipaddr<br />

macaddr ¼ options.macaddr

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

Saved successfully!

Ooh no, something went wrong!