Day 009 #FromZeroToHacker – Linux Fundamentals: Part 1

Many servers and security tools use Linux. Let’s learn how to use the Linux operating system, a critical skill in cyber security.

It is going to be a 3 part lesson, so let’s start with the first #FromZeroToHacker lesson.

Table of contents
Introduction
What I have learnt today?
Stats
Resources

Introduction to Linux Fundamentals

For the average user, Linux is Open-Source, easy to adapt, control, and pretty reliable (ask older Windows users if their SO is reliable!). For hacking and penetration testing, Linux also offers a wide range of tools and applications (Kali Linux distro is the first one that comes to mind), and its command line or terminal interface gives us full control of our system.

What I have learnt today?

A bit of background in Linux

Where is Linux used?

Linux powers things such as:

  • The websites you visit
  • Car entertainment and control panels
  • Point of Sale (PoS) systems such as checkout tills and registers in shops
  • Critical infrastructures such as traffic light controllers or industrial sensors

Flavours of Linux

“Linux” is an umbrella term for multiple OSs that are based on UNIX (another operating system). Thanks to UNIX being open-source, we have many distribution options, each suited best for what we want.

For example, Ubuntu and Debian are commonplace distributions (or distros) of Linux as it is extensible (You can run Ubuntu as a server or as a desktop OS).

Running our first commands

One of the larger “selling” point of using Linux is how lightweight it can be. This comes with some disadvantages: for example, oftentimes there is no GUI (Graphical User Interface) or “Desktop Environment” to interact with the machine, so we need to resort to using what is called the “Terminal”.

Ubuntu Linux terminal

The terminal is purely text-based and it may seem intimidating at first, but if we start learning some basic commands, we can become quite familiar with using it.

We can do basic functions such as navigating to files and directories, displaying their contents and creating/deleting files. The commands are self-explanatory…once you learnt them, of course.

For example, echo displays a text provided by us, and whoami tell us which user are we using:

terminal echo and whoami commands

Interacting with the Filesystem

We can and we should be able to navigate the machine we are using without relying on a desktop environment, as we don’t know what OS we are going to use or if it has a GUI. Always we will find a terminal. Always.

For that, we have a series of commands such as ls to list all files and directories, cd to change the current directory, cat to concatenate text or pwd to Print the Working Directory

Listing files in our current directory (ls)

Before doing anything, we need to know the content in the actual directory. This can be done with the ls (or LiSting) command:

terminal ls command

As shown, we have an access.log file and 4 folders or directories.

Changing Our Current Directory (cd)

Now that we know there are directories, we can change our current location to one of them. Using cd (Change Directory) we can navigate our machine:

Linux cd command

Outputting the Contents of a File (cat)

Knowing that there are files is not enough: We need to view the contents of (all of) them.

cat is short for ConcATenating, and it is used to output the contents of a file. And not only text files!

Linux cat command

Finding out the full Path to our Current Working Directory (pwd)

Sometimes we lose track of where we are on a computer by just using the terminal without any GUI, that’s why we can use pwd to find what is the current directory (as pwd stands for Print Working Directory).

Linux pwd command

Searching for Files

I know you won’t believe me, but one of the redeeming features of Linux is how efficient you can be by using just the terminal.

But you can only be as efficient as you practise and learn more and more commands, and over time, essential commands will become pure muscle memory.

Using Find

The command find let us find a file:

Linux find command

Find manages to find the file, despite being in another folder. But what if we want to find ALL the text files? Let’s move to the root folder and replace ‘note’ with a wildcard (*).

Linux find command with a wildcard

Using Grep

Another utility that is important to learn about is grep. This command allows us to search too, but inside the content of files, for a specific value.

Linux grep command

An Introduction to Shell Operators

Even if that wasn’t enough, we can power up our terminal skills with operators. For example: & to run commands in the background of your terminal, && to combine multiple commands together in one line, > to redirect the output from a command elsewhere, and >> that does the same as > but appending the output rather than replacing it (so nothing is overwritten).

Operator “&”

This operator allows us to execute commands in the background. For example, if we want to copy a large file, something that would take a lot of time, blocking the terminal. By using & we can keep working!

Operator “&&”

Despite the ampersand, isn’t related to the previous command. We use && to make a list of commands to run. For example command1 && command2.

One caveat: command2 only will run if command1 was successful.

Operator “>”

This is known as the output redirector. It takes the output from a command we ran and sends the output somewhere else.

One way to use this like this:

Creating a new file on a terminal

Operator “>>”

This is also an output redirector as >. However, it just appends the text, instead of overwriting, or replacing the content, of the current file.

Creating a new file on a terminal while concatenating new text

Stats

From 238.382th to 229.009th. Getting better!

Here is also the Skill Matrix:

Skill matrix

Resources

Path: Pre Security

Linux Fundamentals

TryHackMe: Linux fundamentals part 1

Other resources

Linux

Kali Linux

List of all Linux distros

Linux major distributions