Pentest Lab: Local Pentesting Lab using Docker-Compose
If you are pentester or security researcher, then you will definitely spend hours in searching for vulnerable systems, and once you have found one the next step is to exploit it, but this can be very time consuming and may or may not be possible depending on the target, but if the target is in your local network you can use the pentest lab which lets you test various tools like nmap, metasploit, hydra, SQLMap, etc on a vulnerable target with just one command.
This local pentest lab leverages docker compose to spin up multiple victim services and an attacker service running Kali Linux. If you run this lab for the first time it will take some time to download all the different docker images.
./lab.sh --up --all-services
./lab.sh --overview all
ssh root@kali -o "UserKnownHostsFile /dev/null"
The lab should work out of the box if all needed dependencies are installed. At startup the lab will run a dependency check.
Start the lab
git clone https://github.com/oliverwiegers/pentest_lab
By default the lab will start all victim services and one red team service. Other services can be started and added. More information on this down on this below.
For further usage information consider reading the help message shown by ./lab.sh -h | --help.
yq (The Python version. Not yq-go.)
The lab has a build in dependency check which runs at startup. This also can be run manually ./lab.sh -C.
For ease of use a Heimdall interface was added that is exposed to localhost:7000. All services that are exposed to your local machine and can be accessed via browser are listed there. Changes that will be made to the interface are automatically saved in ./etc/heimheimdall. This directory is than turned into ./etc/heimdall.tar while stopping the lab. This tar archive will be extracted on starup. Both ./etc/heimdall.tar and ./etc/heimdall are ignored by git by default.
This lab knows the following four types of services.
The default red team service – the Kali service – is a pretty basic Kali instance. Nonetheless kali-tools-web metapackage is installed. For a web application testing lab the basic web testing tools seem to be useful. This can be changed by editing the Dockerfile from which the image is build. This is located at ./dockerfiles/kali. The kali service installs these dotfiles by default. This is also changable by tweaking the Dockerfile.
These are pretty basic. One could add more by adding dashboards via the Grafana interface. These dashboards will be lost when the grafana volume is deleted. To permanently add dashboards consult the Provisioning Docs by Grafana. Used directories for provisioning are located at ./etc/grafana/.
To change settings via Grafana interface one must login as admin. The credentials are the default ones: admin:admin. #hacktheplanet
For Loki beeing able to gather docker logs this lab installs the Loki Docker Driver as Docker plugin.
Prometheus / cAdvisor
For Prometheus beeing able to access performance metrics of the containers running in the cluster cAdvisor is used.
To add additional services a little knowledge of docker-compose.yml files is needed. The docker-compose.yml in the root of this repository is auto generated when the lab starts. This process uses the yaml files located unter ./etc/services.
Note: If a service requires some kind of installation at first usage use docker inspect <image_name> to find out where the docker image stores the data and add a volume pointing to this directory. In the example above this is:
This ensures that you don’t have to setup the service again every time you restart the lab. But if you want to reset the lab and completely start over again you can use ./lab.sh -p | --prune. This will delete all resources owned by the lab.
The reason we used static IP addresses is that the Kali box needs to have an IP address that doesn’t change to simplify SSH login. More in information in the Tips/Tricks section down below.
Red team services start at 10.5.0.5
The Kali service has 10.5.0.5.
Blue team services start at 10.5.0.50
Victim services start at 10.5.0.100
Monitoring services start at 10.5.0.200
If you add services and there is additional information that is useful for anyone running this lab you can add this information to ./etc/services_info. Content of this file will be printed as is line by line by running ./lab.sh -i.
For an easy connect to the Kali service one could add the following to $HOME/.ssh/cofig:
So instead of ssh email@example.com -o "UserKnownHostsFile /dev/null" one could run ssh kali.
For tmux users the following will attach to a tmux session automatically:
RemoteCommand tmux -L tmux new-session -As hacktheplanet