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.

56 CHAPTER 4 Filling the toolbox<br />

systems. Incidentally, the virtual terminals don’t go away after you install a desktop<br />

environment. Normally, the graphical environment is run on terminal 7 (accessible<br />

by pressing Ctrl-Alt-F7).<br />

Setting up a basic graphical desktop is easy thanks to scripts that are provided<br />

<strong>with</strong> our version of Ubuntu. Creating a graphical desktop <strong>with</strong> LXDE is as simple<br />

as running sudo /boot/tools/ubuntu/small-lxde-desktop.sh on your Beagle.<br />

This will run a shell script. You may be familiar <strong>with</strong> scripting languages such as<br />

Python. Scripting languages, especially Python <strong>and</strong> Ruby, are very popular <strong>with</strong><br />

hackers. They allow complex <strong>and</strong> mundane tasks to be automated. We will learn<br />

a little Python later in this book when we start using our hacking drones. If you<br />

want to learn more about Python, I highly recommend Vivek Ramach<strong>and</strong>ran’s SecurityTube<br />

Python Scripting Expert course (available at http://www.securitytube-train<br />

ing.com/online-courses/securitytube-python-scripting-expert/index.html or http://<br />

www.pentesteracademy.com/course?id¼1) <strong>and</strong>/or the book Violent Python by<br />

T. J. O’Connor (Syngress, 2012).<br />

One issue <strong>with</strong> scripting languages is that they require a scripting engine to be<br />

installed. Shell scripts don’t suffer from this problem, however. Shell scripts allow<br />

you to tie together a number of tools in an automated way <strong>and</strong> are essentially guaranteed<br />

to work. While they might look strange at first, it is worth the effort to learn<br />

some of the basics of shell scripting. We will walk through the LXDE installation<br />

script in order to get a better underst<strong>and</strong>ing of how to write shell scripts. We will<br />

later use this knowledge to automate the process of filling our toolbox. Classic Shell<br />

Scripting by Arnold Robbins <strong>and</strong> Nelson H. F. Beebe <strong>and</strong> Wicked Cool Shell<br />

Scripts by Dave Taylor are both good references if you want to learn more. Several<br />

online tutorials such as those found in http://www.freeos.com/guides/lsst/ <strong>and</strong> in<br />

http://www.tldp.org/LDP/abs/html/ are also available.<br />

A lot is happening in the first few lines of our script:<br />

#!/bin/sh -e<br />

board¼$(cat /proc/cpuinfo j grep "^Hardware" j awk '{print $4}')<br />

sudo apt-get update<br />

sudo apt-get -y upgrade<br />

The very first line in our script is a special comment. If the first line in any text file<br />

starts <strong>with</strong> “#!”, or pound-bang as it is normally called (apologies to British readers<br />

who think # is known as the hash sign), the shell will run whatever comm<strong>and</strong> follows<br />

the #! <strong>and</strong> pass the entire file to that comm<strong>and</strong>. This allows you to run a script written<br />

in any language directly (i.e., myScript.py not python myScript.py). Because<br />

Linux users have a large choice of available shells, our script runs a particular shell<br />

<strong>and</strong> also passes an argument. The -e option causes the script to immediately exit if<br />

any non-test comm<strong>and</strong> in the script fails.<br />

There is a lot going on in the second line of our script. This line is also a great<br />

example of the Unix philosophy of combining several small specialized tools<br />

together in order to accomplish a task. This line assigns a value to the shell variable

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

Saved successfully!

Ooh no, something went wrong!