Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit e14431a

Browse files
committed
refactor: update variable usage, PHP and Nginx versions
1 parent 4f61eac commit e14431a

File tree

4 files changed

+66
-79
lines changed

4 files changed

+66
-79
lines changed

Dockerfile

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# DoD: Installing Nginx with Docker
2-
FROM nginx:1.25.2-bookworm
1+
# step: installing Nginx with Docker
2+
FROM nginx:1.25.4-bookworm
33
EXPOSE 80
44
EXPOSE 22
55

6-
# DoD: Deploying DVWA on Nginx
6+
WORKDIR /ndvwa
7+
8+
# step: deploying DVWA on Nginx
79
# copy config files into container
810
COPY configs/dvwa.conf /etc/nginx/sites-available/default
911
COPY configs/nginx.conf /etc/nginx/nginx.conf
10-
COPY configs/dbsetup.sql /dbsetup.sql
12+
COPY configs/dbsetup.sql ${WORKDIR}/dbsetup.sql
13+
COPY entrypoint.sh /ndvwa/entrypoint.sh
1114
# install basic packages
1215
RUN apt-get update && \
1316
apt-get install -y \
@@ -25,29 +28,27 @@ RUN apt-get update && \
2528
openssh-server \
2629
openssh-client \
2730
sshpass \
28-
knockd
31+
knockd && \
32+
apt-get autoremove -y
2933
# install a specific version of PHP
3034
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg && \
3135
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list && \
32-
apt update && \
33-
apt -y install php7.4-fpm php7.4-mysqli
36+
apt-get update && \
37+
apt-get install -y php8.3-fpm php8.3-mysqli
3438
# run configurations
35-
RUN mkdir -p /etc/nginx/sites-available && \
36-
mkdir -p /etc/nginx/sites-enabled && \
37-
mkdir -p /var/www/html && \
39+
RUN mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled /var/www/html && \
3840
# prepare DVWA files
3941
git clone --depth 1 https://github.com/digininja/DVWA.git /var/www/html/dvwa && \
4042
chmod 777 -R /var/www/html/dvwa && \
4143
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default && \
4244
# create PHP config
43-
cd /var/www/html/dvwa && \
44-
cp config/config.inc.php.dist config/config.inc.php && \
45+
cp /var/www/html/dvwa/config/config.inc.php.dist /var/www/html/dvwa/config/config.inc.php && \
4546
# setup database
4647
service mariadb start && \
47-
mysql -u root < /dbsetup.sql && \
48+
mysql -u root < ${WORKDIR}/dbsetup.sql && \
4849
# firewall setting for nginx
4950
ufw allow 80,443/tcp
5051

51-
# setup entrypoint (technically CMD)
52-
COPY entrypoint.sh /entrypoint.sh
53-
CMD [ "bash", "/entrypoint.sh" ]
52+
# setup entrypoint CMD
53+
COPY entrypoint.sh ${WORKDIR}/entrypoint.sh
54+
CMD [ "bash", "/ndvwa/entrypoint.sh" ]

README.md

+28-45
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,49 @@
11
# nDVWA
22

3-
nDVWA is a compact Dockerized solution for deploying DVWA with nginx.
3+
nDVWA is a compact Dockerized solution for deploying DVWA with Nginx.
44

55
Everything is kept in a single container: nginx is pulled as a base image, and DVWA is downloaded directly from it's official git repository.
66

77
Additionally, this application offers a few extra SSH configurations between the Docker container and it's host machine.
88

99
The SSH connection with port knocking protection is established using internal Docker network (which is evident by `docker0` interface and `172.17.0.1` default host address usage in the codebase). You can opt-out of these configurations via a prompt when starting up the container.
1010

11-
This app was a part of an academic study and had a DoD (Definition-of-Done). The details are presented below.
11+
This app consist of several key steps. The details are presented below.
1212

1313
## Contents
1414

1515
- [nDVWA](#ndvwa)
1616
- [Contents](#contents)
17-
- [**Disclaimer**](#disclaimer)
18-
- [DoD](#dod)
19-
- [Installing Nginx with Docker](#installing-nginx-with-docker)
20-
- [Deploying DVWA on Nginx](#deploying-dvwa-on-nginx)
21-
- [(optional) Establishing Reverse Tunneling to SSH](#optional-establishing-reverse-tunneling-to-ssh)
22-
- [(optional) Protecting SSH from Nmap Scanning](#optional-protecting-ssh-from-nmap-scanning)
17+
- [**Important**](#important)
18+
- [Key Steps](#key-steps)
2319
- [How To Use](#how-to-use)
2420
- [1. Build (or download) the Docker image](#1-build-or-download-the-docker-image)
2521
- [2. Create a Docker container](#2-create-a-docker-container)
26-
- [3. Check deployed DVWA via web-browser](#3-check-deployed-dvwa-via-web-browser)
22+
- [3. Check the deployed DVWA instance via web-browser](#3-check-the-deployed-dvwa-instance-via-web-browser)
2723
- [4. Follow the prompts in Docker container](#4-follow-the-prompts-in-docker-container)
2824

29-
## **Disclaimer**
25+
## **Important**
3026

31-
If you wish to execute **all** of the steps (including SSH configurations), please take into consideration that it might permanently alternate iptables rules on your machine.
27+
> [!IMPORTANT]
28+
> **\- DISCLAIMER \-**
29+
>
30+
>If you wish to execute **all** of the steps (including SSH configurations), please take into consideration that it might permanently alternate iptables rules on your machine.
31+
>
32+
>Once the SSH configurations are complete, the app flushes `DOCKER` and `INPUT` chains in iptables.
33+
>
34+
>Unless you know what you are doing or able to fix your iptables in case of any issue, it is recommended to run this app in a virtual machine (or any other environment that is not someone's primary workspace).
3235
33-
Once the SSH configurations are completed, the app flushes `DOCKER` and `INPUT` chains in iptables.
36+
> [!NOTE]
37+
> And just in case, run a `sudo iptables -L > ~/default_iptables.txt` before launching the app. That way you'll have a reference to restore your iptables rules if required.
3438
35-
Unless you know what you are doing or able to fix your iptables in case of any issue, it is recommended to run this app in a virtual machine.
39+
## Key Steps
3640

37-
Tip: And just in case, run a `sudo iptables -L > ~/default_iptables.txt` before launching the app. That way you'll have a reference to restore your iptables rules if required.
41+
The whole function of the app can be broken down into the following steps:
3842

39-
## DoD
40-
41-
### Installing Nginx with Docker
42-
43-
1. install Docker on your system;
44-
2. pull the Nginx Docker image;
45-
3. create a Docker container using the Nginx image;
46-
4. configure the necessary ports for Nginx to operate.
47-
48-
### Deploying DVWA on Nginx
49-
50-
1. download the Damn Vulnerable Web Application (DVWA) package;
51-
2. configure Nginx to serve the DVWA files;
52-
3. verify the successful deployment of DVWA by accessing it through a web browser.
53-
54-
### (optional) Establishing Reverse Tunneling to SSH
55-
56-
1. configure the SSH server to allow reverse tunneling;
57-
2. set up the reverse tunnel by initiating an SSH connection from the Docker container to the SSH server;
58-
3. verify the reverse tunnel connection by accessing the SSH server from the Docker container.
59-
60-
### (optional) Protecting SSH from Nmap Scanning
61-
62-
1. install Nmap for scanning purposes;
63-
2. implement port knocking or port scanning detection mechanisms to prevent unauthorized access attempts;
64-
3. test the implemented measures using Nmap to ensure SSH protection against scanning.
43+
1. installing Nginx with Docker;
44+
2. deploying DVWA on Nginx;
45+
3. establishing reverse tunneling to SSH (optional);
46+
4. protecting SSH from Nmap scanning with port knocking protection (optional).
6547

6648
## How To Use
6749

@@ -73,7 +55,7 @@ In the root of the directory, run:
7355
docker build . -t ndvwa
7456
```
7557

76-
Alternatively, you can download a pre-built image from repository's registry:
58+
Alternatively, you can download a pre-built image from the repository's registry:
7759

7860
```sh
7961
docker pull ghcr.io/seppzer0/ndvwa
@@ -87,7 +69,7 @@ To create a container, run:
8769
docker run --rm -it -p 80:80 ndvwa
8870
```
8971

90-
### 3. Check deployed DVWA via web-browser
72+
### 3. Check the deployed DVWA instance via web-browser
9173

9274
Using a web-browser, enter `0.0.0.0:80` URL.<br>
9375
When asked for credentials for the first time, use `dvwa` for both login and password.<br>
@@ -97,9 +79,10 @@ Then, using UI, create a new database. When asked for credentials again, use `ad
9779

9880
Once the container is launched, you will be prompted whether to proceed with SSH configurations or just directly jump into Bash shell.
9981

100-
Keep in mind that in order to establish an SSH connection between a container and a host machine, you need to setup an SSH server on the host machine first.<br>
82+
Keep in mind that in order to establish an SSH connection between a container and a host machine, you need to setup an SSH server on the host machine first.
83+
10184
On a Debian-based machine:
10285

103-
- install `openssh-server` package (use `sudo apt install openssh-server`);
86+
- install `openssh-server` package;
10487
- append `GatewayPorts yes` and `AllowTcpForwarding yes` lines into `/etc/ssh/sshd_config` file;
105-
- restart ssh service with `sudo service ssh restart`.
88+
- restart ssh service.

configs/dvwa.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ server {
1515
# this is for the PHP part of DVWA to work properly
1616
fastcgi_split_path_info ^(.+\.php)(/.+)$;
1717
try_files $uri =404;
18-
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
18+
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
1919
fastcgi_index index.php;
2020
fastcgi_param SCRIPT_FILENAME $request_filename;
2121
include fastcgi_params;

entrypoint.sh

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
#!/bin/bash
22

3+
IP="172.17.0.1"
4+
5+
36
# start services
47
service mariadb start
5-
service php7.4-fpm start
8+
service php8.3-fpm start
69
service nginx start
710
sleep 1
811

912
# prompt to either proceed with SSH configurations or jump into shell
1013
printf "\n\n"
1114
read -p "[ ? ] Proceed with SSH configurations? [yes/no] " yn
12-
case $yn in
13-
yes )
14-
# DoD: Establishing Reverse Tunneling to SSH
15+
case $yn in
16+
yes )
17+
# step: establishing reverse tunneling to SSH
1518
printf "\n\n== Establishing Reverse Tunneling to SSH ==\n"
1619
# ask for host's credentials, which will be required for sudo operations
1720
printf "\n[ * ] Please enter the following information from you host environment.\n"
1821
read -p " - Username: " USER
1922
read -s -p " - Password: " PASS
2023
printf "\n"
21-
# setup containers SSH keys and connection to the SSH server
24+
# setup container's SSH keys and connection to the SSH server (host environment)
2225
printf "\n[ * ] Setting up SSH keys.\n\n"
2326
ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/id_rsa
24-
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $USER@172.17.0.1
27+
sshpass -p ${PASS} ssh-copy-id -o StrictHostKeyChecking=no ${USER}@${IP}
2528
printf "\n[ * ] Configuring reverse tunneling.\n\n"
26-
ssh -f -N -R 2222:localhost:22 $USER@172.17.0.1
29+
ssh -f -N -R 2222:localhost:22 ${USER}@${IP}
2730
printf "[ * ] Opening SSH connection. When ready, \"exit\" it to proceed with port knocking protection setup.\n\n"
28-
ssh -p 22 $USER@172.17.0.1
31+
ssh -p 22 ${USER}@${IP}
2932

30-
# DoD: Protecting SSH from Nmap Scanning (port knocking protection)
33+
# step: protecting SSH from Nmap scanning with port knocking protection
3134
printf "\n\n== Protecting SSH from Nmap Scanning ==\n"
3235
printf "\n[ * ] Please enter the following information from you host environment.\n"
3336
read -p " - Full path to this repository: " RPATH
3437
printf "\n"
3538
printf "\n[ * ] Checking that SSH port is currently open using NMAP.\n\n"
36-
nmap -p 22 172.17.0.1
39+
nmap -p 22 ${IP}
3740
printf "\n[ * ] Configuring knockd service on the host machine (via SSH).\n\n"
38-
ssh -p 22 $USER@172.17.0.1 -t "cd $RPATH && echo $PASS | sudo -S bash knockd_setup.sh"
41+
ssh -p 22 ${USER}@${IP} -t "cd ${RPATH} && echo ${PASS} | sudo -S bash knockd_setup.sh"
3942
sleep 1
4043
printf "\n[ * ] Attemting to scan the SSH port and connect to the SSH server with knockd service running.\n\n"
41-
nmap -p 22 172.17.0.1
42-
ssh -p 22 $USER@172.17.0.1
44+
nmap -p 22 ${IP}
45+
ssh -p 22 ${USER}@${IP}
4346
printf "\n[ * ] Executing magic knock-knock sequence and actually connecting to the SSH server. When ready, \"exit\" it to proceed.\n\n"
44-
knock -v 172.17.0.1 20001 20002 20003 -d 500
45-
ssh -p 22 $USER@172.17.0.1
47+
knock -v ${IP} 20001 20002 20003 -d 500
48+
ssh -p 22 ${USER}@${IP}
4649
printf "\n[ * ] Restoring iptables rules on the host machine.\n\n"
47-
knock -v 172.17.0.1 20001 20002 20003 -d 500
48-
ssh -p 22 $USER@172.17.0.1 -t "echo $PASS | sudo -S iptables -F DOCKER && sudo -S iptables -F INPUT && sudo -S service knockd stop"
50+
knock -v ${IP} 20001 20002 20003 -d 500
51+
ssh -p 22 ${USER}@${IP} -t "echo ${PASS} | sudo -S iptables -F DOCKER && sudo -S iptables -F INPUT && sudo -S service knockd stop"
4952
;;
5053
no )
5154
printf "[ * ] Jumping directly into Bash shell..\n\n";;

0 commit comments

Comments
 (0)