Search

Introduction to Docker and How Docker can be used as Pentesting?

Introduction to Docker and How Docker can be used as Pentesting?

Introduction to Docker?

Docker is an open-source platform for building and running applications in a container that acts as a lightweight virtual machine.

Terminologies

Docker Container: Containers are designed to run isolated from other processes so they only take up the resources they require. This means that containers don’t interfere with each other or the host operating system, nor do they consume memory, processor time, or disk space beyond what is needed by the application.

Docker Hub:  Docker hub is a cloud-based registry for users to create, store, manage, test,  and distribute its images.

Docker Images: It is image serves as a template for creating containers. To create its images, one can use the build command. It’s images are much faster to build compared to virtual machines and require a lot less space.

Docker Registry: It stores all of its images. Users can have a local registry on their machine or use a public registry like It’s Hub.

Difference between Docker and Virtual Machine

  1. Docker is a service offering platform that uses the host OS Kernel rather than a standard virtual machine, which requires OS installation for each virtual machine. 
  2. The containers of its contain all of the dependencies and libraries that an application or service requires to execute, removing the need to manually install them.
  3. Docker containers are substantially more efficient than virtual machines since they use the host operating system.
  4. As there are fewer layers to virtualize, its more efficient in terms of installation and configuration time, and resource utilization.
  5. Unlike Virtual Machine, Its containers do not have separate operating systems. So, porting its container is easy as compared to the virtual machine.
  6. The virtual machine does not share an operating system. The host kernel is also highly isolated in a virtual machine. While Docker containers share a host kernel. As a result, virtual machines are more secure than Containers.

Installing the Docker

We can install it directly using the package manager or scripts. Following is the command to install docker using aptitude package manager:

$ sudo apt-get install docker.io

After installing it , we can check the version of it using the following command:

$ docker –version

Now, we should enable the docker service which can be done by the following command:

$ sudo systemctl enable docker

After enabling the service, we must start it’s service in order to work with it:

$ sudo systemctl start docker

Now, we can start working with it.

Basic Commands

  • docker version – It shows a version of it’s client, API, engine, containerd, runc, docker-init
  • docker info – We will get more information about it’s settings
  • docker pull registry:5000/alpine –  It will download the image
  • docker inspect  – We will get the information of the container
  • docker network ls – It will list network information
  • docker exec –it  /bin/sh – Get a shell inside a container
  • docker commit  registry:5000/name-container – Update container
  • docker export -o alpine.tar  – This will export the container as a tar file
  • docker save -o ubuntu.tar  – It will export an image
  • docker ps -a – This will list currently running and stopped containers
  • docker stop  – It is used to stop running container
  • docker rm  – It will remove container ID
  • docker image ls – This will list all the docker images
  • docker rmi  – This will remove the image
  • docker system prune -a –This will remove all networks not used by at least one container, all stopped containers, and all images without at least one container associated to them

How Docker can be used as Pentesting?

Now, we know how it images and it’s containers work. We can also get started by downloading the images and running it as a container with it. We can use Kali’s pre-built pentesting OS images. As we have discussed above, the its hub has a lot of alternative dockerized images. We can use these alternative dockerized images for pen-testing and learning purposes.

We may use the pre-set it pull command on it is repository page to pull an image from it’s hub, which will download the image to our host for deployment.

By using the following command, we can pull the official Kali Linux Docker image:

$ docker pull kali Linux/kali-linux-docker

After pulling the Kali Linux Docker image, we can check whether the image has been saved by going to our local it’s images or not using the following command:

$ docker images

This will show all of our downloaded images, which can be used right away. It also provides vital information about the image, such as the repository name, image ID, and size of the image.

The following commands are used to create a container from an image:

$ docker run -it –rm kali Linux/kali-linux-docker /bin/bash

Where -it  #Interactive Terminal

-d  #Detached mode that will run the container in the background

–rm  #It will delete the container after it has been put in an excited state.

This command will start a Kali Linux container with a bash interactive terminal.

We’ll be logged in to the Kali docker container with bash interactive terminal after running the run command. We can now use the Kali repository in order to install the different pen-testing tools that we require as the Kali image does not have any pre-installed tools.

One of the drawbacks of using Kali’s pen-testing images is that they assume it can only be used to run a single tool or toolkit, while it may be utilized to achieve a far more comprehensive experience.

This is why we have to construct our own it’s image, which would include all of the necessary and vital tools for penetration testing.

Book A Free Demo Class

    Social Media
    Facebook
    Twitter
    WhatsApp
    LinkedIn