Sitemap

Bash Scripting

Objective

--

The objective of this task is to create a Bash script that reads the contents of a protected file and displays the result in the terminal.

Procedure

Open the TryHackMe room and connect to the target machine through SSH, following the room instructions.

Locate the files read_secret.sh and secret.txt.

Open read_secret.sh in a text editor or with a command such as cat.

Write a Bash script that reads the contents of secret.txt, stores the content in a variable, and prints the variable on the terminal.

Give the script the appropriate permission and execute it.

Submit the required screenshots showing the TryHackMe answer and the script/output.

Bash Script

The script used in the task reads secret.txt with cat, stores its contents in the variable secret, and then prints the value using echo.

Get Sourabh Jala’s stories in your inbox

Join Medium for free to get updates from this writer.

#!/bin/bash

secret=$(cat secret.txt)
echo “$secret”

Screenshot: Script Content

Press enter or click to view image in full size
Figure 1 — Bash script used to read secret.txt

Execution and Result

After creating the script, the task instructions require appropriate permission to be given to the script and then the related file to be executed. In the submitted terminal screenshot, the command output reveals the task flag.

Press enter or click to view image in full size
Figure 2 — Terminal output showing the result

Flag

Flag{you_wrote_an_script}

Conclusion

This task demonstrates a basic Bash scripting workflow: locating files, reading file content with a command, storing the output in a variable, and displaying that variable in the terminal. It also provides practical experience with executing scripts in a Linux environment.

--

--

I’m a cybersecurity enthusiast and Vulnerability Assessment and Penetration Tester focused on web application security and vulnerability assessment

See more from me