Skip to content

Commit 8e520cd

Browse files
authored
add new writeups (#2)
* Add Bandit Level 21 to Level 22 writeup * Add Bandit Level 22 to Level 23 writeup * Add TryHackMe Pre-Security Module 3 writeup
1 parent 001c268 commit 8e520cd

3 files changed

Lines changed: 262 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: "OverTheWire Bandit: Level 21 to Level 22"
3+
date: 2026-07-03 08:33:00 +0500
4+
categories: [CTF, Bandit]
5+
tags: [linux, cron, crontab, scheduled-tasks, overthewire, beginner]
6+
---
7+
8+
## The Goal
9+
10+
A program is running automatically at regular intervals via cron. Find what it does and use it to get the password for bandit22.
11+
12+
## What is Cron
13+
14+
Cron is a time-based job scheduler built into Linux. It runs commands automatically at specified times without any user interaction. You define tasks in a crontab file and cron executes them in the background on schedule.
15+
16+
## What I Did
17+
18+
Navigated to `/etc/cron.d/` where cron job configurations are stored:
19+
20+
```bash
21+
bandit21@bandit:~$ cd /etc/cron.d/
22+
bandit21@bandit:/etc/cron.d$ ls
23+
behemoth4_cleanup clean_tmp cronjob_bandit22 cronjob_bandit23 cronjob_bandit24 e2scrub_all leviathan5_cleanup manpage3_resetpw_job otw-tmp-dir
24+
```
25+
26+
Read the bandit22 cron job:
27+
28+
```bash
29+
bandit21@bandit:/etc/cron.d$ cat cronjob_bandit22
30+
@reboot bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
31+
* * * * * bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
32+
```
33+
34+
Two entries for the same script — `@reboot` runs it once when the server boots, `* * * * *` runs it every minute. The `&> /dev/null` discards all output so nothing is printed to any terminal.
35+
36+
Read the script itself:
37+
38+
```bash
39+
bandit21@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit22.sh
40+
#!/bin/bash
41+
chmod 644 /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
42+
cat /etc/bandit_pass/bandit22 > /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
43+
```
44+
45+
The script does two things every minute:
46+
1. Sets the permissions on a file in `/tmp` to `644` — world readable
47+
2. Writes bandit22's password into that file
48+
49+
Since the file is world readable, anyone can read it including bandit21:
50+
51+
```bash
52+
bandit21@bandit:/tmp$ cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
53+
RYVux2rHEm9tiXHmLFzuR7Vhx6AZQMEz
54+
```
55+
56+
## Understanding the Crontab Format
57+
58+
The five fields before the username define the schedule:
59+
60+
```
61+
* * * * * bandit22 /usr/bin/cronjob_bandit22.sh
62+
│ │ │ │ │
63+
│ │ │ │ └── day of week (0-7, 0 and 7 = Sunday)
64+
│ │ │ └──── month (1-12)
65+
│ │ └────── day of month (1-31)
66+
│ └──────── hour (0-23)
67+
└────────── minute (0-59)
68+
```
69+
70+
`*` means every value for that field. So `* * * * *` runs every minute of every hour of every day.
71+
72+
Some examples:
73+
- `0 * * * *` — every hour at minute 0
74+
- `0 9 * * *` — every day at 9am
75+
- `0 9 * * 1` — every Monday at 9am
76+
- `30 6 1 * *` — 6:30am on the 1st of every month
77+
78+
`@reboot` is a special keyword that runs the job once when the system starts, regardless of time.
79+
80+
## What I Tried That Didn't Work
81+
82+
Tried to list and navigate `/tmp` directly — permission denied. The `/tmp` directory itself was restricted so you can't browse it with `ls` or `find`. But you can still read a specific file inside it if you know the exact path and the file has read permissions. The script set `chmod 644` on the file which made it readable by everyone, so `cat /tmp/filename` worked even though listing the directory didn't.
83+
84+
## What I Learned
85+
86+
**Cron jobs run as a specific user.** The username in the crontab entry (`bandit22`) determines whose privileges the script runs with. This script runs as bandit22, which is why it can read `/etc/bandit_pass/bandit22`.
87+
88+
**`/etc/cron.d/` contains system-wide cron jobs.** Individual user cron jobs live in `/var/spool/cron/crontabs/`. The `/etc/cron.d/` directory is readable by all users — useful for reconnaissance when you have access to a system.
89+
90+
**Cron jobs writing to world-readable files is a misconfiguration.** If a privileged cron job writes sensitive data to a location other users can read, that data is exposed. This is a real-world finding in penetration tests.
91+
92+
**You don't need to list a directory to read a file in it.** If you know the exact filename and the file has read permission, `cat /path/to/file` works regardless of whether you can `ls` the directory.
93+
94+
## Commands Used
95+
96+
| Command | What it did |
97+
|---|---|
98+
| `ls /etc/cron.d/` | Found the cron job configurations |
99+
| `cat cronjob_bandit22` | Read the schedule and script path |
100+
| `cat /usr/bin/cronjob_bandit22.sh` | Read what the script actually does |
101+
| `cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv` | Read the password written by the cron job |
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "OverTheWire Bandit: Level 22 to Level 23"
3+
date: 2026-07-03 08:53:00 +0500
4+
categories: [CTF, Bandit]
5+
tags: [linux, cron, md5sum, cut, bash-scripting, overthewire, beginner]
6+
---
7+
8+
## The Goal
9+
10+
Another cron job running automatically. This time the script is more complex — it generates a filename using a hash and writes the password there. The challenge is figuring out what filename the script generates when it runs as bandit23.
11+
12+
## What I Did
13+
14+
Checked `/etc/cron.d/` and read the bandit23 cron job:
15+
16+
```bash
17+
bandit22@bandit:/etc/cron.d$ cat cronjob_bandit23
18+
@reboot bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
19+
* * * * * bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
20+
```
21+
22+
Read the script:
23+
24+
```bash
25+
bandit22@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit23.sh
26+
#!/bin/bash
27+
myname=$(whoami)
28+
mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1)
29+
echo "Copying passwordfile /etc/bandit_pass/$myname to /tmp/$mytarget"
30+
cat /etc/bandit_pass/$myname > /tmp/$mytarget
31+
```
32+
33+
The script runs as bandit23 via cron. That means `$(whoami)` returns `bandit23`. The filename is generated by hashing the string `I am user bandit23` with md5sum and cutting the output to just the hash.
34+
35+
I needed to calculate that hash myself since the script runs as bandit23 but I'm logged in as bandit22:
36+
37+
```bash
38+
bandit22@bandit:/tmp$ echo "I am user bandit23" | md5sum >> t1
39+
bandit22@bandit:/tmp$ cat t1
40+
8ca319486bfbbc3663ea0fbe81326349 -
41+
```
42+
43+
The hash is `8ca319486bfbbc3663ea0fbe81326349`. Read the file at that path:
44+
45+
```bash
46+
bandit22@bandit:/tmp$ cat 8ca319486bfbbc3663ea0fbe81326349 -
47+
gKXDTAXnIz3OBxiPjRZ2uqutUlPZrBsw
48+
```
49+
50+
## Understanding the Script
51+
52+
Breaking down the key line:
53+
54+
```bash
55+
mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1)
56+
```
57+
58+
Three commands chained with pipes:
59+
60+
**`echo I am user $myname`** — outputs the string `I am user bandit23`
61+
62+
**`md5sum`** — takes that string and produces a hash. MD5 is a cryptographic hash function — it takes any input and produces a fixed-length 32-character hex string. The same input always produces the same output, but you can't reverse it to get the original. The raw output looks like:
63+
```
64+
8ca319486bfbbc3663ea0fbe81326349 -
65+
```
66+
The ` -` at the end means md5sum was reading from stdin.
67+
68+
**`cut -d ' ' -f 1`** — splits the output by spaces and keeps only the first field. Without this, the filename would include the ` -` suffix which would be messy. `cut` strips it down to just the clean hash string.
69+
70+
The resulting hash becomes both the filename and an indirect reference to who the script ran as — you can only figure out the filename if you know it was generated from `I am user bandit23`.
71+
72+
## What I Tried That Didn't Work
73+
74+
Initially tried using `$mytarget` as a variable in my own shell — but that variable doesn't exist in my session, only inside the script when it runs as bandit23. So `cat /tmp/$mytarget` expanded to `cat /tmp/` which is a directory.
75+
76+
The fix was to manually calculate the hash value myself using the same commands the script uses, substituting `bandit23` as the username.
77+
78+
## What I Learned
79+
80+
**`$(command)` is command substitution.** Whatever is inside `$()` gets executed and its output becomes the value. So `myname=$(whoami)` stores the output of `whoami` into the variable `myname`.
81+
82+
**`cut` extracts specific fields from text.** `-d` sets the delimiter character to split on, `-f` specifies which field number to keep. It's commonly used to parse structured output where fields are separated by a consistent character like spaces, colons, or commas.
83+
84+
**MD5 is not secure for cryptography** but is still widely used for non-security purposes like generating consistent filenames from input strings, checksums for file integrity, and similar tasks. For password hashing it's completely broken — too fast to brute force and vulnerable to precomputed rainbow tables. Use bcrypt or Argon2 for passwords.
85+
86+
**Reading a script carefully lets you predict its output** without running it. The key insight here was realising the script runs as bandit23, substituting that username into the hash calculation, and computing the result manually.
87+
88+
## Commands Used
89+
90+
| Command | What it did |
91+
|---|---|
92+
| `cat /usr/bin/cronjob_bandit23.sh` | Read the script to understand what it does |
93+
| `echo "I am user bandit23" \| md5sum` | Calculated the hash the script generates when run as bandit23 |
94+
| `cat /tmp/8ca319486bfbbc3663ea0fbe81326349` | Read the password from the file the script wrote |
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "TryHackMe Pre-Security: Module 3 — Operating Systems"
3+
date: 2026-07-04 04:47:00 +0500
4+
categories: [Learning, TryHackMe]
5+
tags: [tryhackme, linux, windows, operating-systems, privilege-escalation, cli, beginner]
6+
---
7+
8+
## Overview
9+
10+
Module 3 of TryHackMe's Pre-Security path covered operating systems across five rooms — OS fundamentals, Windows basics, Linux CLI, Windows CLI, and a practical privilege escalation exercise. Most of the individual concepts weren't new to me at this point, but working through them in a structured environment filled in gaps and showed me how these pieces connect in real scenarios.
11+
12+
## Room 1 — Operating Systems Introduction
13+
14+
The first room covered what an OS actually does — managing hardware, processes, memory, and user permissions. The key distinction was between **kernel space** and **user space**:
15+
16+
- **Kernel space** — the privileged core of the OS with direct hardware access. The kernel manages everything below the surface.
17+
- **User space** — where applications run with limited permissions. If an application crashes here it doesn't bring down the whole system.
18+
19+
This distinction matters in security because most privilege escalation attacks are attempts to move from user space into kernel space — or to gain the privileges of a process running closer to the kernel than you should have.
20+
21+
## Room 2 — Windows Basics
22+
23+
Windows interface fundamentals — Task Manager, Windows Security, Defender Firewall, Windows Update. Most of this was familiar from daily use but seeing it framed through a security lens was useful. Task Manager isn't just for killing frozen apps — it's a real-time view of what's running on a system, which is one of the first places you look during incident response to identify suspicious processes.
24+
25+
Windows Defender Firewall controls what network traffic is allowed in and out. Understanding what it does conceptually is important before getting into firewall rule analysis in later modules.
26+
27+
## Room 3 — Linux CLI Basics
28+
29+
Navigating the Linux filesystem, searching for files, reading configuration files, inspecting system information. Most of this I already knew from working through OverTheWire Bandit — `ls`, `cat`, `find`, `grep` and the logic of Linux file permissions were all covered there in much more depth and with actual problem solving rather than guided exercises.
30+
31+
What Bandit teaches through challenges, this room taught through explanation. Having done Bandit first meant I already had the practical intuition and this room just gave me the formal framing around concepts I'd already applied.
32+
33+
## Room 4 — Windows CLI Basics
34+
35+
The Windows Command Prompt equivalent of the Linux CLI room — navigating files, locating hidden files, reading file contents, gathering system and network information from the terminal. The key takeaway applies to both operating systems: the command line gives you speed, precision, and the ability to automate tasks that would take many clicks in a GUI.
36+
37+
In real-world security work, you often can't rely on a GUI — remote access, restricted environments, and incident response scenarios all require CLI comfort on both Windows and Linux.
38+
39+
## Room 5 — Privilege Escalation Practical
40+
41+
The most hands-on room of the module. A complete attack chain on a Linux system:
42+
43+
1. SSH into the system as `sammie`
44+
2. Lateral movement to `johnny`
45+
3. Escalation to `root`
46+
4. Retrieve the flag from `/root/flag.txt`
47+
48+
A few things worth noting from working through this:
49+
50+
**Typos cost time.** Multiple failed `su` attempts because of `jhonny` and `jhony` instead of `johnny`. Running `whoami` and `id` first to confirm your current user context before attempting account switches prevents this — something I'll carry forward.
51+
52+
**Credentials get exposed in unexpected places.** Passwords discovered through shell history and sticky notes. In a real assessment this is one of the first places to look after gaining initial access.
53+
54+
**Privilege escalation is a chain, not a single step.** Moving from sammie → johnny → root required understanding each stage — what credentials were available, which user had access to what, and how to move progressively through the access chain.
55+
56+
## The Bigger Picture
57+
58+
What this module solidified wasn't individual commands — it was seeing how these pieces connect. Kernel space versus user space explains why privilege escalation is possible and what it means. The Linux file permission system I learned in Bandit is what makes setuid binaries and misconfigured files exploitable. The Windows security tools are the defensive layer that attackers try to bypass.
59+
60+
The concepts are no longer isolated facts. They're parts of a system I can now see working together.
61+
62+
## What's Next
63+
64+
Module 4 covers networking fundamentals — how data actually moves across networks at the protocol level. This is where the conceptual groundwork from the first three modules starts becoming directly applicable to understanding attacks.
65+
66+
---
67+
*TryHackMe username: sdenarzai786*

0 commit comments

Comments
 (0)