Page cover

Mastering Linux Shells : A TryHackMe Walkthrough

In this post, I delve into the Linux Shells module from TryHackMe’s Cyber Security 101 learning path. This module offers a comprehensive introduction to Linux command-line interfaces, shell scripting,

Module Overview

The module covers:

  • Understanding Shells: The interface between the user and the operating system.

  • Interacting with the Shell: Basic commands and navigation.

  • Types of Linux Shells: Exploring different shells like Bash, Zsh, and Fish.

  • Shell Scripting: Writing and executing shell scripts.

  • Practical Exercises: Hands-on tasks to apply learned concepts.

🛠️ Key Scripts from the Module

1. The Locker Script

This script simulates a bank locker authentication system, prompting the user for their username, company name, and PIN. If the provided credentials match predefined values, access is granted.

#!/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

Note: Ensure you're executing it with Bash and not sh.
  1. The Flag Hunt Script This script searches for a specific flag within system logs, demonstrating the use of grep and find commands.

Practical Exercises

The module includes exercises like:

  • The Locker Script: A script that authenticates users based on predefined credentials.

  • Flag Hunt: Searching for a specific flag within system logs.

🔗 Repository Overview

REPOSITORY

I’ve documented all the scripts and exercises from this module in my GitHub repository: THM-LinuxShells. The repository includes:

  • lockerscript.sh: The authentication script.

  • flag_hunt.sh: The script for searching flags in logs.

  • shell.sh and shell2.sh: Additional shell scripting exercises.

Conclusion The Linux Shells module is an excellent starting point for anyone looking to understand Linux command-line operations and scripting. The hands-on exercises provide practical experience, reinforcing the concepts learned.

Feel free to explore the repository and try out the scripts. Happy learning!

Last updated