☕
Writeups
TryHackMeHackTheBoxReferralsDonateLinkedIn
  • Writeups
  • TryHackme
    • 2025
      • Security Footage
      • Ledger
      • Moebius
      • Mayhem
      • Robots
      • Billing
      • Crypto Failures
      • Rabbit Store
      • Decryptify
      • You Got Mail
      • Smol
      • Light
      • Lo-Fi
      • Silver Platter
    • 2024
      • Advent of Cyber '24 Side Quest
        • T1: Operation Tiny Frostbite
        • T2: Yin and Yang
        • T3: Escaping the Blizzard
        • T4: Krampus Festival
        • T5: An Avalanche of Web Apps
      • The Sticker Shop
      • Lookup
      • Mouse Trap
      • Hack Back
      • SeeTwo
      • Whiterose
      • Rabbit Hole
      • Mountaineer
      • Extracted
      • Backtrack
      • Brains
      • Pyrat
      • K2
        • Base Camp
        • Middle Camp
        • The Summit
      • The London Bridge
      • Cheese CTF
      • Breakme
      • CERTain Doom
      • TryPwnMe One
      • Hammer
      • U.A. High School
      • IronShade
      • Block
      • Injectics
      • DX2: Hell's Kitchen
      • New York Flankees
      • NanoCherryCTF
      • Publisher
      • W1seGuy
      • mKingdom
      • Airplane
      • Include
      • CyberLens
      • Profiles
      • Whats Your Name?
      • Capture Returns
      • TryHack3M
        • TryHack3M: Burg3r Bytes
        • TryHack3M: Bricks Heist
        • TryHack3M: Sch3Ma D3Mon
        • TryHack3M: Subscribe
      • Creative
      • Bypass
      • Clocky
      • El Bandito
      • Hack Smarter Security
      • Summit
      • Chrome
      • Exfilibur
      • Breaking RSA
      • Kitty
      • Reset
      • Umbrella
      • WhyHackMe
      • Dodge
    • 2023
      • Advent of Cyber '23 Side Quest
        • The Return of the Yeti
        • Snowy ARMageddon
        • Frosteau Busy with Vim
        • The Bandit Surfer
      • Stealth
      • AVenger
      • Dreaming
      • DockMagic
      • Hijack
      • Bandit
      • Compiled
      • Super Secret TIp
      • Athena
      • Mother's Secret
      • Expose
      • Lesson learned?
      • Grep
      • Crylo
      • Forgotten Implant
      • Red
    • Obscure
    • Capture
    • Prioritise
    • Weasel
    • Valley
    • Race Conditions
    • Intranet
    • Flip
    • Cat Pictures 2
    • Red Team Capstone Challenge
      • OSINT
      • Perimeter Breach
      • Initial Compromise of Active Directory
      • Full Compromise of CORP Domain
      • Full Compromise of Parent Domain
      • Full Compromise of BANK Domain
      • Compromise of SWIFT and Payment Transfer
  • HackTheBox
    • 2025
      • Certified
    • 2024
      • BoardLight
      • Crafty
      • Devvortex
      • Surveillance
      • Codify
      • Manager
      • Drive
      • Zipping
    • 2023
      • Topology
Powered by GitBook
On this page
  • Recon
  • Shell As www-data
  • Shell As think
  • Shell As root

Was this helpful?

  1. TryHackme
  2. 2024

Publisher

Test your enumeration skills on this boot-to-root machine. -by josemlwdf

PreviousNanoCherryCTFNextW1seGuy

Last updated 10 months ago

Was this helpful?

The following post by 0xb0b is licensed under


Recon

We start with a Nmap scan and find only two open ports. Port 22 with SSH and port 80 with an Apache web server.

Before we manually enumerate the pages on port 80, we start a directory scan using Gobuster. Here we discover the directory spip, which could be interesting later.

We do not discover anything on the index page for the time being.

But in the spip directory, we discover a blog that was created using SPIP. SPIP is a free, open-source content management system (CMS) designed for managing web-based publications and facilitating collaborative work.

Looking through the source, we find version 4.2.0 in use. We may have our entry point here.

Shell As www-data

After a little research on SPIP 4.2.0, we find an exploit that allows RCE without authentication.

Unfortunately, the manual exploit was unsuccessful. Before we start tinkering around, let's try the Metasploit framework. Here we also find an RCE for SPIP disclosed around the same time as the exploit on exploitdb - this might be the same.

After we have set the necessary parameters and run the exploit, with a little more patience, we get a meterpreter session.

In the session, we can spawn a shell, and we are the user www-data. This user is allowed to enter the home directory of the user think and read the files there, so we get the first flag.

Shell As think

In the home directory of the user think we find a private ssh key. We copy this and adjust the rights.

After we have set the permissions, we can use the key to log in to the machine via ssh as user think. At first glance, we now have a more stable shell. But something is strange; we can't write in the home directory, and otherwise, like /tmp is not writable. The /opt directory is not readable; we are probably a bit more limited than expected.

Shell As root

When enumerating, we find the said custom binary, which has a SUID bit set, so that when executed, it's in the context of the owner root.

We can already get a quick overview with strings or cat to the binary. This will only execute a script in /opt/run_container.sh. The special thing here is that bash -p is used for this, so the script is also executed in the context of root rights.

/opt should actually be readable; another mechanism must apply here.

In fact, we can read the script in /opt, but cannot find an entry point for command or parameter injection.

As mentioned in the short description, we will probably have to get around our current shell restriction. It would then be conceivable to rewrite run_container.sh.

Attempts to escalate privileges using a custom binary are hindered by restricted access to critical system files and directories, necessitating a deeper exploration into the system's security profile to ultimately exploit a loophole that enables the execution of an unconfined bash shell and achieve privilege escalation.

Possible restrictions can arise via AppArmor. We find some rules for the shell ash. Here we see the deny rules for /opt/, among others, which prohibit us from reading and writing there.

Furthermore all programs run in /usr/bin and /usr/sbin are restriced by the rules /usr/bin/** mrix and /usr/sbin/** mrix, since they inherit this ruleset. To bypass this restriction, we need to run a bash application outside of /usr/bin or /usr/sbin.

The AppArmor profile has a flaw, there is a deny rule for /dev/shm/ and /dev/tmp. They are not complete like the rule for /tmp for example. Due to the lack of the wildcard /** we can still write to /dev/shm and /var/tmp.

In /etc/passwd we see that our user is using the ash shell.

We copy /bin/bash to /var/tmp and run it. We can now access /opt.

Fortunately, we are allowed to write on run_container.sh.

We write a small script that copies the /bin/bash into /var/tmp and sets the SUID bit this time. Because the script is executed in the root context as mentioned at the beginning, the owner also remains root and can thus we are able to obtain a root shell.

After running the bAsh binary inside /var/tmp with the tag -p we gain a root shell and find the final flag in /root/root.txt.

CC BY 4.0
PublisherTryHackMe
SPIP v4.2.0 - Remote Code Execution (Unauthenticated)Exploit Database
Logo
Logo