TryHackMe: Linux Fundamentals 1 –  Walkthrough

September 6, 2023
Posted in TryHackMe
September 6, 2023 Jasper
Hi! It is time to look at the first part of the Linux Fundamentals series on TryHackMe. Linux is the most fundamental skill for pentesters. Learn Linux, and you will become more efficient at everything. Let’s look at this room!

I am making these walkthroughs to keep myself motivated to learn cyber security, and ensure that I remember the knowledge gained by THMs rooms. Join me on learning cyber security. I will try and explain concepts as I go, to differentiate myself from other walkthroughs.

Room URL: https://tryhackme.com/room/linuxfundamentalspart1


Part 1 (Introduction)

Not much to say here but let’s move on to part 2 🙂

Questions

Let’s get started!

Answer: No answer needed


Part 2 (Background on Linux)

Linux is an operating system, much like Windows and OS X. Linux however is much more lightweight. Linux is the umbrella term of different variants of Operation Systems built upon UNIX, which is an operating system itself. Since UNIX is open source, there a a plethora of different versions of Linux.

Two of the most common ones are Ubuntu and Debian, since these two are so extensible. Ubuntu for example, can be used as server or all full-fledged desktop.

Questions

Research: What year was the first release of a Linux operating system?

Linux began in 1991 as a personal project by Finnish student Linus Torvalds.

Answer: 1991


Part 3 (Interacting With Your First Linux Machine)

Not much to do be here besides starting up the Ubuntu machine on TryHackMe.

Questions

I’ve deployed my first Linux machine!

Answer: No answer needed.

Part 4 (Running Your First few Commands)

Since Linux is so lightweight, it is more normal to have program without a GUI (Graphic User Interface). In this case we use the terminal to interact with these programs. The terminal is purely text-based, and will probably be quite intimidating at first. But you will soon learn that it has a great efficiency and speed to it as you become comfortable!

Let’s get started with two of the msot useful commands:

  • echo: Output any text that we provide
  • whoami: Find out what user we’re currently logged in as!

Using echo:

tryhackme@linux1:~$ echo "Hello Friend!"

Using whoami to find out the username of who we’re logged in as:

tryhackme@linux1:~$ whoami

Questions

If we wanted to output the text “TryHackMe”, what would our command be?

We can simply use the echo command in the terminal, which outputs the text argument to the terminal.

Running echo

Answer: echo TryHackMe

What is the username of who you’re logged in as on your deployed Linux machine?

Here we can use the whoami command, which returns the following answer:

Running whoami

Answer: tryhackme


Part 5 (Interacting with the Filesystem)

In this room we will learn about the following commands:

  • ls — Lists files in current directory
  • cd — Changing our current directory
  • cat — Outputting contents of file
  • pwd — Printing path to current directory

Listing Files in Our Current Directory (ls)

Use “ls” to to list the contents of the current directory:

tryhackme@linux1:~$ ls
'Important Files' 'My Documents' Notes Pictures

Pro tip: You can list the contents of a directory without having to navigate to it by using ls and the name of the directory. I.e. ls Pictures

Changing Our Current Directory (cd)

Now that we know what folders exist, we need to use the “cd” command (short for change directory) to change to that directory. Say if I wanted to open the “Pictures” directory – I’d do “cd Pictures“.

Outputting the Contents of a File (cat)

You can read the contents in a file by using a command called “cat”. “Cat” is short for concatenating and is a great way for us to output the contents of files.

tryhackme@linux1:~/Documents$ ls
todo.txt
tryhackme@linux1:~/Documents$ cat todo.txt
Here's something important for me to do later!

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

It’s easy to lose track of where we are on the filesystem exactly, which is why there exists the command”pwd“. This stands for print working directory. Using “pwd” to list the full path of the current directory:

tryhackme@linux1:~/Documents$ pwd
/home/ubuntu/Documents
tryhackme@linux1:~/Documents$

Questions

On the Linux machine that you deploy, how many folders are there?

Listing folder

Answer: 4

Which directory contains a file?

Finding the note.txt in a directory

Answer: folder4

What is the contents of this file?

Answer: Hello World

Use the cd command to navigate to this file and find out the new current working directory. What is the path?

Printing the working directory

Answer: /home/tryhackme/folder4


Task 6 (Searching for files)

It’s time to learn two new commands:

  • find — Finds a specific file within every folder of our current directory.
  • grep — Find a specific term within a file.

Using “find” to find a file with the name of “passwords.txt”

tryhackme@linux1:~$ find -name passwords.txt
./folder1/passwords.txt
tryhackme@linux1:~$

“Find” has managed to find the file. But let’s say that we don’t know the name of the file, or want to search for every file that has an extension such as “.txt”.
We can simply use what’s known as a wildcard (*) to search for anything that has .txt at the end. In our case, we want to find every .txt file that’s in our current directory.

Using “find” to find any file with the extension of “.txt”

tryhackme@linux1:~$ find -name *.txt
./folder1/passwords.txt
./Documents/todo.txt
tryhackme@linux1:~$

Using Grep

Another great utility that is a great one to learn about is the use of grep. The grep command allows us to search the contents of files for specific values that we are looking for.

We can use grep to search the entire contents of this file for any entries of the value that we are searching for. Going with the example of a web server’s access log, we want to see everything that the IP address “81.143.211.90” has visited:

tryhackme@linux1:~$ grep "81.143.211.90" access.log
81.143.211.90 - - [25/Mar/2021:11:17 + 0000] "GET / HTTP/1.1" 200 417 "-" "Mozilla/5.0 (Linux; Android 7.0; Moto G(4))"
tryhackme@linux1:~$

Questions

Use grep on “access.log” to find the flag that has a prefix of “THM”. What is the flag?

Since we are interested in files starting with THM, we can use a wildcard after THM, to find every entry starting with THM.

grep THM* access.log
Finding the THM entry in the access log

Answer: THM{ACCESS}


Task 7 (Introduction to Shell Operators)

In this final task we will learn about the following operators:

  • & — Runs command in the background of your terminal
  • && — Combines multiple commands together in one line
  • > — Takes the output from one command and direct it elsewhere
  • >> — Same as above but appends output instead of replacing it

Operator “&”

This operator allows us to execute commands in the background. For example, let’s say we want to copy a large file. This will obviously take quite a long time and will leave us unable to do anything else until the file successfully copies. The “&” shell operator allows us to execute a command and have it run in the background (such as this file copy) allowing us to do other things!

Operator “&&”

Although it looks similar to the previous operator, it does nothing similar.
We can use “&&” to make a list of commands to run for example command1 && command2. However, it’s worth noting that command2 will only run if command1 was successful.

Operator “>”

This operator is what’s known as an output redirector. What this essentially means is that we take the output from a command we run and send that output to somewhere else.

Using the > Operator:

tryhackme@linux1:~$ echo hey > welcome

Using cat to output the “welcome” file:

tryhackme@linux1:~$ cat welcome
hey

Operator “>>”

This operator is also an output redirector like in the previous operator (>) we discussed. However, what makes this operator different is that rather than overwriting any contents within a file, for example, it instead just puts the output at the end.

Using the >> Operator:

tryhackme@linux1:~$ echo hello >> welcome

Using cat to output the “welcome” file:

tryhackme@linux1:~$ cat welcome
hey
hello

Questions

If we wanted to run a command in the background, what operator would we want to use?

Answer: &

If I wanted to replace the contents of a file named “passwords” with the word “password123”, what would my command be?

Answer: echo password123 > passwords

Now if I wanted to add “tryhackme” to this file named “passwords” but also keep “passwords123”, what would my command be

Answer: echo tryhackme >> passwords

Now use the deployed Linux machine to put these into practice

Answer: No answer needed


Task 8 (Conclusion)

We are done! Awesome. I hope you picked up some Linux skills on the way. Thanks for reading!


Like my articles?

You are welcome to give my article a clap or two 🙂
I would be so grateful if you support me by buying me a cup of coffee:

I learned a lot through HackTheBox’s Academy. If you want to sign up, you can get extra cubes, and support me in the process, if you use the following link: