Code
Source: HackTheBox Difficulty: Easy OS: Linux
Enumeration & Reconnaissance
Started with the usual
autorecon, which revealed two open ports:SSH (22)
HTTP (5000)
Service Analysis
Browsing the HTTP service on port 5000, I found a Python code execution platform. Cool, right? You could register, log in, run code, and save scripts. But of course, it wasnβt that simple. The platform blocked keywords like
import,os,execute,open, and others. Any attempt to use these triggered a sassy "Use of restricted keywords is not allowed."


This ruled out:
Reverse shells via Python.
Reading sensitive files (
/etc/passwd,/etc/shadow).Writing SSH keys or executing OS commands.
After bashing my head against the keyword filter, I started looking for alternatives. I wanted to understand what we are dealing with. Since we canβt import anything, I wanted to know what we have, to know what we can do. After some research, I found:
This printed a list of loaded modules, including multiple
sqlalchemymodules, hello, database.Next, I pretended to read documentation while secretly letting an AI agent cook up code for me. The goal: enumerate the database. After some trial and error:

This revealed two tables: user and code. Okay, now let's try to get the users. After going through the same process to reach working code:
This worked and printed out the data.

Data from table user:
Data from table code:
Gaining Initial Access
We have 2 users, martin and development. The passwords were stored as MD5 hashes and were easily cracked:
development: 759b74ce43947f5f4c91aeddc3e5bad3 (development)
martin: 3de6f30c4a09c27fc71932bfc68474be (nafeelswordsmaster)

I thought we had to log in as these users and that we might find juicy information in their saved codes, but we had already enumerated the data from the code table, and nothing was there. Let's try SSH. I tried with martin and we were in already.
I searched for the local flag in martinβs home, but I couldnβt find it, so I focused on getting root first, as I usually do anyway. Get root and the flags can be retrieved later.
Privilege Escalation
I ran
sudo -land found that we can run a specific script:/usr/bin/backy.shas sudo without a password. I checked, but the file wasnβt writeable, we can read it though.This is the code found (with explanatory comments added):

So, we can get a "backup" zip archive of any directory we want, but it has to be under
/var/or/home/, and they arenβt allowing us to traverse directories as they remove../from the path.However, their check is loose, we can add
....//and it will work, as this will keep the initial.., remove the next../, and keep the last/.I battled with the other players who were trying to root the machine, who for some reason kept removing my JSON file. By editing the JSON file to be:

It worked, and I got a zip archive with the content of the root directory (including the root flag) in
martin/backups/after unzipping with:
For the local flag, it was under
home/app-production/, so I did the same just for app-production to get the local flag.
Lessons Learned
Check Loaded Modules: Even without
import,sys.modulescan reveal attack surfaces.Database Enumeration: SQLAlchemy and Flask modules can be used to list database tables and extract data, even when access seems limited.
Privilege Escalation via Sudo: Always check for misconfigured sudo permissions; a seemingly simple script can lead to root if exploited correctly.
Loose Path Validation: When sanitization is not strict, creative bypasses (like using
....//) can allow directory traversal, making it possible to extract sensitive archives.
Last updated