Hack Like a Pro: Linux Basics for the Aspiring Hacker, Part 9 (Managing Environmental Variables)

Aug 20, 2013 04:19 PM
Aug 20, 2013 04:34 PM
635125942532119585.jpg

Welcome back, my aspiring hackers!

One of the areas that often gives Linux newcomers problems are the environment variables. Although Windows systems have environment variables, most users, and for that matter, most administrators, never manage their environment variables. To get the most from our Linux hacking system, we need to both understand environment variables and be able to manage them for optimal performance.

635125942686871856.jpg

Environment variables are the variables that are used by our particular user environment. In most cases, this will be our BASH shell. Each user, including root, has a set of environment variables that are set at default values unless they're changed. We can change these values to make our system work more efficiently and tailor our work environment to best meet our individual needs.

Step 1: View Our Environment Variables

We can view our environment variables by typing:

  • set
635125927200724656.jpg

Notice that set lists for us all of the environment variables, user defined functions, and aliases. Also, make note that our environment variables are always UPPER CASE names such as HOME, PATH, HISTSIZE, etc.

If want to see the value inside the variable, we can type:

  • echo $HISTSIZE
635125927382620976.jpg

It's important to notice that when we want to use the value inside the variable, such as here, we need to put a $ before the variable name.

The HISTSIZE variable contains the value of the number of commands that are stored in our history file. As you can see in this screenshot, the HISTSIZE variable is set to 1000. In some cases, we may not want our commands stored in the history file, such as when we are covering our tracks, then we can set our HISTSIZE variable to zero.

  • HISTSIZE=0

When we change an environment variable, it's only for that environment. This means that once we close that terminal, any changes that we made to these variables is lost or set back to the default value. If we want the value to remain for our next terminal session and other terminal sessions, we need to export the variable. We can do this by simply typing:

  • export HISTSIZE

Step 2: Changing Our Terminal Prompt

Let's have a little fun and change the prompt in our terminal. The environment variable that contains our prompt for the first terminal is PS1. We can change it by typing:

  • PS1= "World's Best Hacker: #"
635125927753277627.jpg

Remember that our prompt will now be "World's Best Hacker" whenever we open the first terminal (PS1), but the second terminal will still be the default BackTrack command prompt. In addition, if we really like this command prompt and want to keep it, we need to export it so that each time we open this terminal, the prompt will be "World's Best Hacker."

  • export PS1

Step 3: Changing Our Path Variable

Probably the most important variable in our environment is our PATH variable. This is what controls where our shell looks for the commands we type, such as cd, ls, echo, etc. If it doesn't find the command in one of the directories in our path, it returns an error "command not found," even if it DOES exist in another directory not in our PATH.

Let's take a look at our path variable:

  • echo =$PATH
635125927861541817.jpg

Notice the directories included in our PATH. These are usually the various /bin and /sbin directories where our system variables are found. When we type ls, the system knows to look in each of these directories for the ls command.

Whenever we want to use aircrack-ng or another hacking application in this PATH variable, we have to first navigate to that directory. In the case of aircrack-ng, that would be /pentest/wireless/aircrack-ng.

Now, if we want to add our wireless hacking application to our PATH variable, we can type:

  • PATH=$PATH:/pentest/wireless/aircrack-ng
635125927965594000.jpg

Now when we want to run aircrack-ng, we don't need to navigate to the pentest/wireless/aircrack-ng directory. We now can execute aircrack-ng applications from anywhere in BackTrack!

635125928118786269.jpg

This can be a very useful technique for directories that we use often, but be careful to not add too many directories to your PATH variable as the system will have to search through every directory in the PATH to find commands and could potentially slow down your terminal and your hacking.

That's It for Now...

Stay tuned for more Linux basics for the aspiring hacker. If you haven't checked out the other guides yet, you can find them all right here. If you have any questions, make sure to comment below or start a thread in the Null Byte forum for help.

Calm penguin and screaming penguin photos via Shutterstock

Just updated your iPhone? You'll find new Apple Intelligence capabilities, sudoku puzzles, Camera Control enhancements, volume control limits, layered Voice Memo recordings, and other useful features. Find out what's new and changed on your iPhone with the iOS 18.2 update.

Comments

No Comments Exist

Be the first, drop a comment!