TryHackMe-Learn_Linux_Walkthrough

Krishna Vaibhav
12 min readJul 9, 2020

--

Room : Learn Linux

https://www.tryhackme.com/room/zthlinux
Link to the room on TryHackMe: — https://www.tryhackme.com/room/zthlinux

[Task 1] Intro:

This room has a natural flow to it; however, if you are experienced in Linux, and just want a refresher on a specific topic, you can jump around as need be.

Q1] No Answer Needed

[Task 2] Methodology:

After careful consideration, I’ve deemed the best way to go about this is to introduce various concepts in sections, with each section being more complex and requiring knowledge from the previous section. To better enable the transition between section, I’ve split each section into different users in the VM; when you finish a section you’ll have to complete a challenge and then you’ll be able to move onto the next section.

Q1] No Answer Needed

[Task 3] [Section 1: SSH] — Intro:

SSH is the act of remotely accessing a machine. SSH allows you to run commands interactively on the remote machine. This is done through the use of a program on the target machine, which allows the ssh client to interface with the target host.

Q1] No Answer Needed

[Task 4] [Section 1: SSH] — Putty and ssh:

The download for putty can be found here, once you download it go through the install process. Once you’ve installed it, open it and you should see this screen

Q1] No Answer Needed

[Task 5] [Section 2: Running Commands] — Basic Command Execution:

Now that you’ve logged into the server, you’re gonna wanna do things, and everything that can be done over SSH is done by running commands. To start out, we’ll take a look at some of the basic commands, and the first command will be echo. Type echo hello, and press enter and you'll see your input echoed back at you.

Q1] No Answer Needed

[Task 6] [Section 2: Running Commands] — Manual Pages and Flags:

Most of the commands you’ll learn about have a lot of options that are not immediately known at first glance, these options are known as flags, and have the format <command> <flag> <input>. These flags can be learned about using the man command. The man command has the format man <command>. Therefore, to learn about flags for the echo command, we would type man echo. Typing that shows us a nicely formatted document

Q1]How would you output hello without a newline

Ans: echo -n hello

[Task 7] [Section 3: Basic File Operations] — ls:

ls is a command that lists information about every file/directory in the directory. Just running the ls command outputs the name of every file in the directory.

Q1]What flag outputs all entries

Ans: -a

Q2]What flag outputs things in a “long list” format

Ans: -l

[Task 8] [Section 3: Basic File Operations] — cat:

cat short for concatenate, does exactly that, it outputs the contents of files to the console. For example, given a file called a.txt which contains the data “hello”, cat a.txt would output hello.

Q1]What flag numbers all output lines?

Ans: -n

[Task 9] [Section 3: Basic File Operations] — touch

touch is a pretty simple command, it creates files. Given the command touch b.txt, b.txt would be created.

Q1] No Answer Needed

[Task 10] [Section 3: Basic File Operations] — Running A Binary

Occasionally there will be times when you want to run downloaded or user created programs. This is done by providing the full path to the binary, for example say you download a binary that outputs noot, providing the full path to that binary will execute it.

Q1]How would you run a binary called hello using the directory shortcut . ?

Ans: ./home

Q2]How would you run a binary called hello in your home directory using the shortcut ~ ?

Ans: ~/home

Q3]How would you run a binary called hello in the previous directory using the shortcut .. ?

Ans: ../home

[Task 11] Binary — Shiba1

Now that you’ve learned basic file operations, you can solve the first challenge! This challenge is pretty simple, create a file called noot.txt.

Q1]What’s the password for shiba2

Ans: ********

[Task 12] su

Now that we have our next user password, it seems like a good time to cover su. su is a command that allows you to change the user, without logging out and logging back in again. For example if you wanted to switch to shiba2 while you’re the user shiba1, you would type su shiba2 . You would then be prompted for a password and if you entered shiba2's password you would then become shiba2

Q1]How do you specify which shell is used when you login?

Ans: -s

[Task 13] [Section 4 — Linux Operators]: Intro

This section will cover the operators most commonly used to interact with programs. The operators that will be covered in this section are “>, >>, &, &&, and $” Over the following tasks you will come to learn what each of these operators do.

Q1] No Answer Needed

[Task 14] [Section 4: Linux Operators]: “>”

> is the operator for output redirection. Meaning that you can redirect the output of any command to a file. For example if I were to run echo hello > file, then instead of outputting hello to the console, it would save that output to a file called file.

Q1]How would you output twenty to a file called test

Ans: echo twenty > test

[Task 15] [Section 4: Linux Operators]: “>>”

>> does mainly the same thing as >, with one key difference. >> appends the output of a command to a file, instead of erasing it.

Q1] No Answer Needed

[Task 16] [Section 4: Linux Operators]: “&&”

&& means as you might expect “and”. Meaning && allows you to execute a second command after the first one has executed successfully. Meaning ls && echo hello will work fine, but dljahfrsdkjlhfsdhjklfsdhkljfh && echo hello will fail.

Q1] No Answer Needed

[Task 17] [Section 4: Linux Operators]: “&”

Much unlike &&, & has nothing to do with and at all(try saying that 10 times fast). & is a background operator, meaning say you run a command that takes 10 seconds to run, normally you wouldn’t be able to run commands during that period; however, with & that command will still execute and you’ll be able to run other commands.

Q1] No Answer Needed

[Task 18] [Section 4: Linux Operators]: “$”

The $ is an unusually special operator, as it is used to denote environment variables. These are variables set by the computer(you can set them yourself but we’ll get into that) that are used to affect different processes and how they work. Meaning that if you edit these variables you can change how certain processes work on your computer. For example your current user is always stored in an environment variable called $USER. You can view these variables with the echo command.

Q1]How would you set nootnoot equal to 1111

Ans: export nootnoot=1111

Q2]What is the value of the home environment variable

Ans: /home/shiba2

[Task 19] [Section 4: Linux Operators]: “|”

Continuing with the trend of very special operators, we have the pipe. The pipe is unique because while operators like >> allow you to store the output of a command, the | operator allows you to take the output of a command and use it as input for a second command.

For example, I can use catto get the output of a file, and pipe that into grep to search for a specific string(Note: We will learn more about grep later, but for now just know that it's a command used to find specific strings in an input).

Q1] No Answer Needed

[Task 20] [Section 4: Linux Operators] — “;”

The ; operator works a lot like &&, however it does not require the first command to execute successfully. This means that you can do dkhsgffgsafgfasdgfasfghkgdsgfs; ls and you would still see the output of ls.

Q1] No Answer Needed

[Task 21] Binary — shiba2

This challenge is pretty simple. The binary is checking to see if the environment variable “test1234” exists, and if it’s set equal to the current $USER environment variable.

Q1]What is shiba3’s password

Ans: **************

[Task 22] [Section 5 — Advanced File Operations]: Intro

Much like windows, files have a lot of complexity to them. Multiple different parameters have to be modified to allow certain users to read to files, write to files, and execute certain files. This section will cover modifying these parameters.

Q1] No Answer Needed

[Task 23] [Section 5 — Advanced File Operators]: A bit of background.

These attributes are(in order) the file permissions, owner of the file, and group that the file is in.

The next few tasks will go over the command to modify these attributes.

Q1] No Answer Needed

[Task 24] [Section 5: Advanced File Operations]: chmod

chmod allows you to set the different permissions for a file, and control who can read it. The syntax of this command is typically chmod <permissions> <file>.

Q1]What permissions mean the user can read the file, the group can read and write to the file, and no one else can read, write or execute the file?

Ans: 460

Q2]What permissions mean the user can read, write, and execute the file, the group can read, write, and execute the file, and everyone else can read, write, and execute the file.

Ans: 777

[Task 25] [Section 5: Advanced File Operations] — chown

These attributes are the user, and group attributes resepectively. Recall that we can edit the permissions for these attributes, so it stands to reason that we can also change these attributes. That is done using the chown command, which allows us to change the user and group for any file. The syntax for this command is chown user:group file. For example if we wanted to change the owner of file to shiba2 as well as the group to shiba2, we could usechown shiba2:shiba2 file.

Q1]How would you change the owner of file to paradox

Ans: chown paradox file

Q2]What about the owner and the group of file to paradox

Ans: chown paradox:paradox file

Q3]What flag allows you to operate on every file in the directory at once?

Ans: -R

[Task 26] [Section 5: Advanced File Operations] — rm

Let’s take a break from all the permissions and math, and look at something that can completely destroy your whole Linux system if used carelessly! rm as you might have guessed means remove, and that’s exactly what it does.

Q1]What flag deletes every file in a directory

Ans: -r

Q2]How do you suppress all warning prompts

Ans: -f

[Task 27] [Section 5: Advanced File Operations] — mv

mv allows you to move files from one place to another. The syntax for the command is mv <file> <destination>. so if I wanted to move a file to my home directory I could type mv file ~.

Q1]How would you move file to /tmp

Ans: mv file /tmp

[Task 28] [Section 5: Advanced File Operations] — cp

cp does mainly the same thing as mv, except instead of moving the file it duplicates(copies) it. The syntax is also the same as mv, meaning the syntax is cp <file> <destination> .

Q1] No Answer Needed

[Task 29] [Section 5: Advanced file Operations] — cd && mkdir

In windows there are folders. Folders allow you to store multiple files in a single group, which makes them easier to organize and access. Linux has the exact same thing, except their called directories.

Linux allows you to change the location of the current directory through the use of the cd command. The syntax of the cd command is this, cd <directory>.

Q1]Using relative paths, how would you cd to your home directory.

Ans: cd ~

Q1]Using absolute paths how would you make a directory called test in /tmp

Ans: mkdir /tmp/test

[Task 30] [Section 5: Advanced File Operations] ln

ln is a weird one, because it has two different main uses. One of those is what’s known as “hard linking”, which completely duplicates the file, and links the duplicate to the original copy. Meaning What ever is done to the created link, is also done to the original file. The ln syntax is ln source destination.

Q1]How would I link /home/test/testfile to /tmp/test

Ans: ln /home/test/testfile /tmp/test

[Task 31] [Section 5 — Advanced File Operations]: find

The true power of this command though comes from the parameters you can provide it. You can use find dir -user , to list every file owned by a specific user; you can use find dir -group to list every file owned by a specific group. The sheer customizability of the command is it's most powerful feature.

Q1]How do you find files that have specific permissions?

Ans: -perm

Q2]How would you find all the files in /home

Ans: find /home

Q3]How would you find all the files owned by paradox on the whole system

Ans: find / -user paradox

[Task 32] [Section 5: Advanced File Operations] — grep

I can say without reservation that grep is one of the most useful commands to learn. It allows you find data inside of data. When working with large files, or a large output, it is arguably the best way to narrow the output down to better find what your looking for. The syntax of the command is grep <string> <file> however file is optional if you're using piping.

Note: You can search multiple files at the same time, meaning you can theoretically do grep <string> <file> <file2>

Q1]What flag lists line numbers for every string found?

Ans: -n

Q2]How would I search for the string boop in the file aaaa in the directory /tmp

Ans: grep boop /tmp/aaaa

[Task 33] Binary — Shiba3

We’ve been through a lot in this section, and the challenge for this binary will reflect that. The first step is actually finding the binary, I’m not heartless though, so I’ll give you the name of the binary. The name of the binary is shiba4.

The actual binary will check for two things, it will be checking that there’s a directory called test in your home directory, how you create that is up to you. It will also be checking that inside the directory there’s a file called test1234.

[Task 34] [Section 6: Miscellaneous]: Intro

Even though we’ve gone over how the Linux operating system works, and some of it’s most useful features and commands, there are some useful commands and concepts that haven’t been covered in previous sections. So this section is dedicated to all those miscellaneous commands and concepts that are useful to know.

Q1] No Answer Needed

[Task 35] [Section 6: Miscellaneous]: sudo

Throughout this room you might have seen me mention the root user. The root user is the equivalent of the administrator user on Windows, and like Windows certain commands, and certain things you download from the internet will require admin permissions.

Q1]How do you specify which user you want to run a command as.

Ans: -u

Q2]How would I run whoami as user jen?

Ans: sudo -u jen whoami

Q3]How do you list your current sudo privileges(what commands you can run, who you can run them as etc.)

Ans: -l

[Task 36] [Section 6: Miscellaneous]: Adding users and groups

You know about how to modify permissions for users and groups, therefore it’s helpful to know how to create them. Luckily Linux provides a nice helpful way to do this, with adduserand addgroup. The syntax for both of these commands are adduser username and addgroup groupname.

Q1]How would I add the user test to the group test

Ans: sudo usermod -a -G test test

Task 37] [Section 6: Miscellaneous]: nano

Up until this point you may have seen me only using >> to add content to a file. Luckily that’s not the only way to do things, nano is a terminal based text editor. The syntax for nano is nano <file you want to write to>. For example typing nano test will take you to this screen.

Q1] No Answer Needed

[Task 38] [Section 6: Miscellaneous]: Basic shell scripting

Linux provides us a way to run commands one after another without using any special operators. This is done by storing the commands you want to run in a file with a .sh extension

Q1] No Answer Needed

[Task 39] [Section 6: Miscellaneous]: Important Files and Directories

Q1] No Answer Needed

[Task 40] [Section 6 — Miscellaneous]: Installing packages(apt)

This is a bit hard to make a task on because depending on the Linux OS you install, this information may be entirely worthless. Therefore, I have deemed it best to show how to install packages using the most popular package manager, that being apt. A package is essentially a program, you can think of it like an exe file on windows. To install packages you need root permissions, as each package will likely modify some system critical directories such as /usr. The syntax to install packages is apt install package.

Q1] No Answer Needed

[Task 41] [Section 6: Miscellaneous]: Processes

Every binary you execute on linux, is a process while it’s run. A process is just another word for a running program. A list of user created processes can be viewed with the ps command

Q1] No Answer Needed

[Task 42] Fin ~

We’ve been through a lot, but we’re finally at the end. I hope everyone of you enjoyed this room and learned something :)

Q1] No Answer Needed

[Task 43] Bonus Challenge — The True Ending

I’m not gonna leave you without one final little parting gift. This is a penetration site, and it wouldn’t feel right if I didn’t hide a flag. There’s one flag on this machine and it’s in /root/root.txt, everything you need to get there is in this room, So I leave you with this. Good luck and have fun! :)

Q1]Finish this room off! What is the root.txt flag

Ans: ********************************

--

--