Linux Fundamentals Part 3 : TryHackMe

Task 3 Terminal Text Editors
Edit “task3” located in “tryhackme”’s home directory using Nano. What is the flag?
Ans: THM{TEXT_EDITORS}
Task 4 General/Useful Utilities
Transferring Files From Your Host — SCP (SSH)
Secure copy, or SCP, is just that — a means of securely copying files. Unlike the regular cp command, this command allows you to transfer files between two computers using the SSH protocol to provide both authentication and encryption
- Copy files & directories from your current system to a remote system
- Copy files & directories from a remote system to your current system
Serving Files From Your Host — WEB
python3 -m http.server
then we can use wget to download a file.
Download the file http://MACHINE_IP:8000/.flag.txt onto the TryHackMe AttackBox. Remember, you will need to do this in a new terminal.What are the contents?
Ans: THM{WGET_WEBSERVER}
Task 5 Processes 101
Viewing Processes:
- Processes Overview:
- Processes are running programs managed by the kernel, each with a unique Process ID (PID).
- The PID increments in the order of process initiation.
- The
ps
command provides a list of running processes with details like status, session, CPU usage, and the executed program
2. Command Examples:
ps aux
: Displays processes from all users, including system processes.top
: Provides real-time statistics about running processes, refreshing every 10 seconds.
Managing Processes:
- Sending Signals:
- Processes can be terminated using signals.
kill
command is used with the PID to terminate a process (e.g.,kill 1337
).- Signals include
SIGTERM
(allow cleanup),SIGKILL
(no cleanup), andSIGSTOP
(suspend).
How Processes Start:
- Namespaces:
- Namespaces split resources like CPU and RAM among processes, isolating them for security.
- Processes with the same namespace can interact; those in different namespaces are isolated.
2. System Init Process (PID 0):
- The process with PID 0 starts when the system boots.
- On Ubuntu, it’s often the init process (e.g., systemd), managing user processes.
3. Child Processes:
- Processes started by init (or other processes) are child processes, running independently.
Getting Processes/Services to Start on Boot:
- systemctl Command:
systemctl
interacts with systemd to manage processes.- Commands include
start
,stop
,enable
, anddisable
. - Used to control services like web servers, databases, etc.
Backgrounding and Foregrounding:
- Process States:
- Processes can run in the background or foreground.
- Background processes don’t block the terminal and allow for continued use.
2. Backgrounding Commands:
- Use the
&
operator to run a command in the background (e.g.,echo "Hi THM" &
). Ctrl + Z
pauses a process, andbg
resumes it in the background.
3. Foregrounding Commands:
- Use
fg
to bring a background process to the foreground for interaction. - Allows you to interact with a backgrounded script or command.
Understanding processes and how to manage them is crucial for system administrators, developers, and security professionals in Linux environments.
If we were to launch a process where the previous ID was “300”, what would the ID of this new process be?
Ans: 301
If we wanted to cleanly kill a process, what signal would we send it?
Ans: SIGTERM
Locate the process that is running on the deployed instance (MACHINE_IP). What flag is given?
Ans: THM{PROCESSES}
What command would we use to stop the service “myservice”?
Ans: systemctl stop myservice
What command would we use to start the same service on the boot-up of the system?
Ans: systemctl enable myservice
What command would we use to bring a previously backgrounded process back to the foreground?
Ans: fg
Task 6 Maintaining Your System: Automation
Certainly! Here’s a summary of the information about crontab and scheduling tasks in Linux:
Cron Process and Crontabs:
1. Purpose:
— Cron is a process started during boot responsible for managing scheduled tasks.
— Crontabs are special files recognized by cron to execute commands at specified intervals.
2. Crontab Structure:
— A crontab requires six specific values:
— MIN: Minute to execute at.
— HOUR: Hour to execute at.
— DOM: Day of the month to execute at.
— MON: Month of the year to execute at.
— DOW: Day of the week to execute at.
— CMD: The actual command to be executed.
4. Wildcard Usage:
— The asterisk (*) can be used as a wildcard.
— If a field doesn’t need a specific value, an asterisk is used.
5. Online Tools:
— Crontab generation can be simplified using online tools like “Crontab Generator” and “Cron Guru.”
6. Editing Crontabs:
— Crontabs can be edited using `crontab -e`.
— Select an editor (e.g., Nano) to modify the crontab file.
Understanding crontabs is essential for users who want to automate tasks on their Linux systems, such as running commands, backups, or launching specific programs at scheduled intervals. The flexibility of crontab formatting allows users to tailor the execution of tasks according to their needs.
Task 7 Maintaining Your System: Package Management
Managing Repositories (Adding and Removing):
- Using
apt
for Package Management:
apt
is part of the package management software and allows managing packages and sources.
2. Adding Repositories Manually:
- Developers may not use
add-apt-repository
and manually add repositories for software. - GPG (Gnu Privacy Guard) keys ensure the integrity of downloaded software.
Example — Adding Sublime Text Repository:
- Download the GPG key and add it to the trusted list:
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
- Create a file
sublime-text.list
in/etc/apt/sources.list.d/
with repository information. - Update apt to recognize the new entry:
apt update
- Install the trusted software:
apt install sublime-text
Removing Repositories and Software:
- Removing Repositories:
- Use
add-apt-repository --remove ppa:PPA_Name/ppa
or manually delete the repository file. - Example:
add-apt-repository --remove ppa:example/example
2. Removing Software:
- After removing the repository, use
apt remove [software-name]
to uninstall software. - Example:
apt remove sublime-text
Task 8 Maintaining Your System: Logs
services and logs are a great way in monitoring the health of your system and protecting it. Not only that, but the logs for services such as a web server contain information about every single request — allowing developers or administrators to diagnose performance issues or investigate an intruder’s activity. For example, the two types of log files below that are of interest:
- access log
- error log
What is the IP address of the user who visited the site?
Ans: 10.9.232.111
What file did they access?
Ans: catsanddogs.jpg