So what is it that ' Hackers ' try to do? Well I'll show you in a few commands - kinda

September 30, 2024 #Gaining Access #docker #Hacking

Disclaimer: This blog post is intended for educational purposes only. The information provided here is meant to raise awareness about security vulnerabilities and encourage the development of more secure web applications. Misuse of this information for malicious purposes is illegal and unethical!

Overview

Administrative privileges are powerful and come with significant responsibility. They allow users to perform system-level tasks and access sensitive information. In this post, we’ll explore techniques for exploiting applications with administrative privileges, specifically using Docker containers and mounting the /etc directory.

Docker is a containerization tool that allows you to create and manage isolated environments. Containers share the host system’s kernel but operate in their own user spaces. By manipulating Docker configurations, you might exploit applications with administrative privileges or gain unauthorized access to sensitive information on the host system.

Installing Docker

Install Docker: Follow the official Docker installation guide to install Docker on your host machine. (Usually it's something like using the package manager to get the package and then adding the user to the group is something most people including me do for convinience ( so you don't have to constately type sudo docker which is what we're gonna exploit today ) and starting the docker daemon / service.

Create and Run the Container to test everything:

Use the following command to create and run a Docker container with the Alpine Linux distribution and an interactive shell:

docker run --rm -it alpine sh

Mount the /etc Directory to abuse configuration / misconfiguration:

To mount the /etc directory from your host system into the container, use the -v option. For example, to mount /etc to /mnt/etc in the container:

docker run --rm -it -v /etc:/mnt/etc alpine sh

Exploring the Container

Accessing the Container's Shell: After running the container with the mounted directory, you’ll be inside the container’s shell. You can navigate to the mounted /etc directory with:

cd /mnt/etc

Viewing Host System Files:

The files from the host’s /etc directory will be accessible within the container. For example, you can list the files with:


    ls -l /mnt/etc

# Something like /etc/shadow will have all the passwords and users for example.

    cat /mnt/etc/shadow


Exploit and Explanation Privilege Escalation in Docker

Container Privileges: Containers are generally isolated from the host system. However, mounting sensitive directories like /etc can expose configuration files that may contain valuable information if the container is not properly secured.

Mounting Sensitive Directories: By mounting directories from the host system, you can access sensitive files. For instance:

docker run --rm -it -v /etc:/mnt/etc alpine sh

This mounts the host’s /etc directory into /mnt/etc in the container, allowing access to host configuration files. Which means if a hacker might can some user privilages on the server thru docker they can get admin level privilages, it would require the user ( in the linux sense - the identity the hacker stole ) to be in the docker group which people do to often, I personally do it on my personal computer. It saves you from running sudo and entering your password every time but..

Potential Misconfigurations: Docker misconfigurations or running containers with elevated privileges can lead to privilege escalation. For instance, if the Docker daemon is exposed or containers are run with excessive privileges, it could be exploited further.

Conclusion and Mitigation

Conclusion

Mounting host directories into Docker containers can expose sensitive information from the host system. In this example, mounting the /etc directory allows access to critical system configuration files. Proper Docker security configurations are essential to prevent unauthorized access and privilege escalation.

Mitigation

By following these best practices, you can better secure your Docker environments and reduce the risk of exploiting administrative privileges.

And don't worry if you're wondering well what do I do with this and how do I actually get here in the first place, those are the questions you should be asking. We will get to everything depending on the interest. Subscribe to the YouTube So send your questions and speak to you soon!