Linux Shells [Cyber Security 101] Learning Path TryHackMe Writeup | Detailed Walkthrough



The Room : Linux Shells is a Part of Command Line Path from the CyberSecurity 101 Learning Path on TryHackMe
The writeups for Two of the Above rooms have already been done →
Check out my Previous Writeups on Medium of this same module path →
{{ Windows Command Line | TryHackMe Writeup }}
{{ Windows PowerShell | TryHackMe Writeup }}
Room Type
Only subscribers can deploy virtual machines in this room!
Go to your profile page to subscribe (if you have not already).
Do note : Premium Subscription is required to solve this room
Let’s Start !
Task 1 : Introduction to Linux Shells
Task 1 Question : Who is the facilitator between the user and the OS?
The facilitator between the user and the operating system (OS) is the shell.
The shell is a program that acts as an interface between the user and the OS, allowing users to interact with the system by typing commands. When you enter commands in the shell (e.g., to list files or launch applications), the shell interprets these commands and passes them to the operating system for execution. It then displays the output, if any, back to the user.
Types of shells: include Bash, PowerShell, and Zsh for command-line interfaces, and graphical shells like Windows Explorer for graphical user interfaces.

Task 2 : How To Interact With a Shell?
This rooms requires us to start the VM and login using SSH with the given Credentials →


Task 2 Question 1 : What is the default shell in most Linux distributions?
Most Linux distributions use Bash (Bourne Again Shell) as their default shell.” So, the answer is Bash.
Answer : Bash
Task 2 Question 2 : Which command utility is used to list down the contents of a directory?
To see the contents of a directory in the shell,
The commandls
is used
Answer : ls
Task 2 Question 3 : Which command utility can help you search for anything in a file?
To search within a file, the text explains the
grep
command, used to search for specific words or patterns inside a file.
Answer : grep
Task 2 Done !

Task 3 : Types of Linux Shells
Task 3 Question 1 : Which shell comes with syntax highlighting as an out-of-the-box feature?

Answer : Fish
Task 3 Question 2 : Which shell does not have auto spell correction?

Answer : Bash
Task 3 Question 3 : Which command displays all the previously executed commands of the current session?

Answer : history
Task 3 is now Completed !

Task 4 : Shell Scripting and Components
Task 4 Question 1 : What is the shebang used in a Bash script?
Every script should start with a shebang (i.e.,
#!
) followed by the interpreter.
For Bash scripts, this is#!/bin/bash
Answer : #!/bin/bash
Task 4 Question 2 : Which command gives executable permissions to a script?
To make a script executable, it says to use
chmod +x
. This command adds execute permissions to the file, allowing it to run as a script.
Answer : chmod +x
Task 4 Question 3 : Which scripting functionality helps us configure iterative tasks?
The information describes loops as a way to automate repetitive tasks by iterating over a set of commands. This functionality allows scripts to execute commands repeatedly until a condition is met.
Answer : loops
Task 4 Done !

Task 5 : The Locker Script
Task 5 Question : What would be the correct PIN to authenticate in the locker script?
First We have to create a bash file and let’s name that file
locker.sh
using nano and use the following script which is also share to us in this moduleBefore proceeding Let’s make sure that we are logged into SSH with the user credentials shared in the previous module →

Let’s now create a bash file named → locker.sh
using nano file editor
The Bash Script We are going to use →
# Defining the Interpreter
#!/bin/bash
# Defining the variables
username=""
companyname=""
pin=""
# Defining the loop
for i in {1..3}; do
# Defining the conditional statements
if [ "$i" -eq 1 ]; then
echo "Enter your Username:"
read username
elif [ "$i" -eq 2 ]; then
echo "Enter your Company name:"
read companyname
else
echo "Enter your PIN:"
read pin
fi
done
# Checking if the user entered the correct details
if [ "$username" = "John" ] && [ "$companyname" = "Tryhackme" ] && [ "$pin" = "7385" ]; then
echo "Authentication Successful. You can now access your locker, John."
else
echo "Authentication Denied!!"
fi

Now the bash file has been created using the nano editor ,
Next Step we are going to give locker.sh
file execute permissions by using the command chmod +x locker.sh

Now we are set , Let’ execute the bash script using this command → ./locker.sh
We are asked for username , companyname and pin to access the locker
Let’s try random details like →
username as abc , companyname as tesla , pin as 1234

Access is denied with the above credentials and code
After reading the script for the locker room , we found interesting details →

Let’s try using these information and see if the conditions are met →
username : John
companyname : Tryhackme
pin : 7385

Access is granted with the pin → 7385
Answer : 7385
Task 5 is now Done !

Task 6 : Practical Exercise
Task 6 Question 1 : Which file has the keyword?
Before proceeding let’s switch user to root
The password we are going to use would be the one from the earlier task →
root : user@Tryhackme

We need to change the “ ” values for the two entries → Flag & Directory


There is one more entry left → we need to add — $directory

Let’s give execute permission to the file using command →
chmod +x flag_hunt.sh
and try running the file → ./flag_hunt.sh

Flag Found in : authentication.log
Answer : authentication.log
Task 6 Question 2 : Where is the cat sleeping?
Hint to this Question is : Open the file that contains the flag.
We found our flag in authentication.log
which is in /var/log
directory
Let’s simply cat the directory /var/log
where the file authentication.log
is located →

We found the cat under the table
🤣
Answer : under the table
Task 6 in successfully completed !
