Scripting for the noob Hacker,(BASH Basics)
Scripting for the noob Hacker,(BASH Basics)
Any self-respecting hacker must be able to script. For that matter, any self-respecting Linux administrator must be able to script.
With the arrival of the Windows PowerShell, Windows administrators are increasingly required to script as well perform automated tasks and be more efficient.
As a hacker, we often need to automate the use of multiple commands, sometimes from multiple tools.
To become an elite hacker, you not only need to have advanced shell scripting skills, but also the ability to script in one of the widely-used scripting languages such as Ruby (Metasploit exploits are written in Ruby), Python (many hacking tools are Python scripts), or Perl (Perl is the best text manipulation scripting language).
This is the first of a new series I'm starting in scripting.
We will start with basic shell scripting, move to advanced shell scripting, and then to each of these scripting languages developing hacking tools as we go.
Our ultimate goal will be to develop enough scripting skills to be able to develop our own exploits.
Types of Shells:
A shell is an interface between the user and the operating system. This enables us to run commands, programs, manipulate files, etc.
There are a number of different shells available for Linux. These include the Korn shell, the Z shell, the C shell, and the Bourne again shell (or BASH).
As the BASH shell is available on nearly all Linux and UNIX distributions (including Mac OS X, BackTrack, and Kali), we will be using the BASH shell, exclusively.
BASH Basics:
To create a shell script, we need to start with a text editor.
You can use any of the text editors in Linux including vi, vim, emacs, gedit, kate, etc., but I will be using kwrite here in these tutorials.
Using a different editor should not make any difference in your script.
For our first script, we will start with a simple script that returns a message to the screen that says 'Hello, spyboy!'.
We start by entering the shebang or #!. This tells the operating system that whatever follows the shebang is the interpreter we want to use for our script.
We then follow the shebang with /bin/bash indicating that we want the operating system to use the BASH shell interpreter.
#! /bin/bash
Next, we enter echo, a command in Linux that tells the system to simply repeat or echo back to our monitor (stdout) what follows.
In this case, we want the system to echo back to us Hello spyboy!.
Note that the text or message we want to echo back is in double quotation marks.
echo 'Hello spyboy'
Set Execute Permissions:
When we create a file, it's not necessarily executable, not even by us, the owner.
Let's look at the permissions on our new file, by typing ls -l in our directory.
To give the owner, the group, and all execute permissions, we type:
chmod 755 spyboy
Now when we do a long listing (ls -l) on the file, we can see that we have execute permissions.
Run Hellospyboy:
To run our simple script, we simply type:
./Hellospyboy
The ./ before the file name tells the system that we want to execute this script in the current directory.
_________________________
Related Posts
Subscribe Our Newsletter
0 Comments to "Scripting for the noob Hacker,(BASH Basics)"
Post a Comment