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.

144 CHAPTER 6 Input <strong>and</strong> output devices<br />

The only change is to use the env comm<strong>and</strong> execute Python instead of invoking a<br />

script.<br />

The line “from scapy.all import *” is used to load all the goodies from the Scapy<br />

networking module. Next, an empty list to store detected access points is created<br />

before any methods are defined in order to make this variable globally accessible.<br />

A h<strong>and</strong>ler function called packet_h<strong>and</strong>ler is then defined.<br />

The line “sniff(iface¼"mon0", prn¼packet_h<strong>and</strong>ler, timeout¼60)” in the main<br />

method performs a packet capture on the mon0 interface for 60 seconds. The h<strong>and</strong>ler<br />

function, packet_h<strong>and</strong>ler, is called for each received packet. The if statement “if<br />

__name__ ¼¼ ’__main__’ :” demonstrates a Python trick that allows you to write<br />

code that can be imported into other Python scripts (as we have done <strong>with</strong> the Scapy<br />

module) or to run the script directly. Note that double underscores are used before<br />

<strong>and</strong> after name <strong>and</strong> main.<br />

The results of running this script are shown in Figure 6.12. From the screenshot,<br />

we can see that our target PFE-Secure network is running on channel 6. The PFE-<br />

Guest <strong>and</strong> another uninteresting network are also detected. If you run this script<br />

<strong>and</strong> it does not work for you, you most likely forgot to run the airmon-ng start<br />

wlan0 mentioned earlier (assuming your wireless adapter is wlan0). Recall that<br />

you can list all of the network interfaces on your machine by executing the comm<strong>and</strong><br />

ifconfig -a.<br />

FIGURE 6.12<br />

Detecting wireless networks <strong>with</strong> Scapy.

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

Saved successfully!

Ooh no, something went wrong!