Linux Fundamentals 1 | TryHackMe Walkthrough
Get started with Linux in an infosec environment with hands-on challenges.
If you're getting started in your InfoSec journey or are new to Linux, this introductory Linux room on TryHackMe is a great place to start.
Deploy box, clicking green deploy button. Follow the VPN tutorial in VM/ terminal or use AttackBox. ssh into the box IP address.
Use the ssh program to connect to the remote machine using the account Shiba1.
Basics and help
The first section covers basics, using Linux, echo, and man pages.
echo -n hello
Using echo as the command, we set the -n flag so that there is no newline and type the text we want the command to return, in this case, 'hello'.
Section 3 asks about flag outputs. we can use the man pages as discussed in task 4 to help us with this. We already know the command we need is ls, so let's check the man page for ls using man ls.
When searching the man page for ls, were presented with an alphabetical list of flags available. Reading the short description for each we can see one option -a / --all. The description isn't entirely helpful, stating it shows files beginning with ..
In Linux, it's possible to hide many files from normal searches by adding '.' to the beginning of the file name. These files are known as hidden files or dotfiles.
Sidenote: whenever you run this search you will always find two files at the beginning of the output: '.' and '..'. These files are special files, '.' refers to the current working directory, and '..' refers to one directory up. One command not discussed in this course is 'cd', meaning change directory. The command is used to change your location in the file structure, taking one argument: which directory to change to. using 'cd ..' will move you to one position up in the file system. As you use the command-line more and more this concept will become second nature.
Using the same technique let's look through the man pages. A method of speeding up our hunt is using the search function in less, by typing '/' then out query, for example '/long'. Then scroll and keep an eye peeled for any highlighted entries.
Eventually, we come across -l, long listing. This option prints the same information as ls, in a table format with some extra details, such as the permissions, owner, group owner, execute permissions, file size, and more.
touch the cat
cat is used to view the output of a given file. The command is incredibly useful and you will find yourself using it often. The only downside, however, is the command will output the entire contents of a file. It's useful for short files like a shopping list, but not so for an essay. Two alternative commands to cat are head and tail, which output the first and last 10 lines of a file respectively.
Using the —help flag on cat, try to identify the correct flag. Only one option listed mentions outputting line numbers, -n.
touch is used to create new files. Give it a try like the demo on tryhackme.
Running a binary
Just like what we discussed above, the . and .. refer to different locations within the file structure. Another path, ~ , can be used to describe our home directory ( for example /home/shiba1 ).
Use the chart to help you discover the answer to each question, considering that to execute a binary you must always have <path>/binary_name. For example, to execute a binary named demo in your current directory (ie you can see it with ls) would be ./demo.
another great way to check is to consider how you can see the binary. For example, if you just use ls (the same as ls .) then use ./binary, if you used ls .. the use ls ../binary and if it is in your home directory (ls ~) then use ~/binary.
Challenge - Shiba1
Try using the skills above to solve the challenge.
First, we need to create a file with a certain name. To create files we use the touch function. verify the file has been created correctly with ls.
Next, we need to run the binary. Consider where the binary (named shiba1) is. It should be in our current directory, meaning we would see its output in the previous command as noot.txt shiba1. Execute the binary using the ./ method.
Once the binary is executed we will see a string printed to the terminal. Make note of this as it is the password we will need in the next step.
Switching users is performed using the su command. su will let you switch user whilst maintaining your previous shell. simply run su and the username of the account you want to log in to.
Once prompted, enter the password we discovered in the previous step.
To solve the question, we need to use the man pages for the su command. Use what you learned above, running man su and looking for an option that mentions the shell options. If you're stuck consider the search function '/'.