Skip to content

Commit c9a08a9

Browse files
committed
Add multiple PHP versions
1 parent 225c86c commit c9a08a9

File tree

8 files changed

+257
-34
lines changed

8 files changed

+257
-34
lines changed

.env-example

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
# PHP VERSION
2+
# -----------
3+
# Uncomment one of the PHP versions you want to use for DVWA
4+
#PHP_VERSION=5.6
5+
#PHP_VERSION=7.0
6+
#PHP_VERSION=7.1
7+
PHP_VERSION=7.2
8+
#PHP_VERSION=7.3
9+
#PHP_VERSION=7.4
10+
#PHP_VERSION=8.0
11+
12+
13+
LISTEN_PORT=8000
114
# Local Listen Port
215
# -----------------
316
LISTEN_PORT=8000
417

518

619
# ReCAPTCHA settings
720
# ------------------
8-
# Used for the 'Insecure CAPTCHA' module
9-
# You'll need to generate your own keys at: https://www.google.com/recaptcha/admin
21+
# Used for the 'Insecure CAPTCHA' module
22+
# You'll need to generate your own keys at: https://www.google.com/recaptcha/admin
1023
RECAPTCHA_PRIV_KEY=
1124
RECAPTCHA_PUB_KEY=
1225

.github/workflows/test.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
3+
# -------------------------------------------------------------------------------------------------
4+
# Job Name
5+
# -------------------------------------------------------------------------------------------------
6+
name: Linux
7+
8+
9+
# -------------------------------------------------------------------------------------------------
10+
# When to run
11+
# -------------------------------------------------------------------------------------------------
12+
on:
13+
# Runs on Pull Requests
14+
pull_request:
15+
16+
# Runs on master Branch and Tags
17+
push:
18+
branches:
19+
- master
20+
tags:
21+
- '[0-9]+.[0-9]+*'
22+
23+
24+
# -------------------------------------------------------------------------------------------------
25+
# What to run
26+
# -------------------------------------------------------------------------------------------------
27+
jobs:
28+
smoke_linux:
29+
30+
runs-on: ubuntu-latest
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
php:
36+
- "5.6"
37+
- "7.0"
38+
- "7.1"
39+
- "7.2"
40+
- "7.3"
41+
- "7.4"
42+
- "8.0"
43+
44+
name: "[PHP ${{ matrix.php }}]"
45+
steps:
46+
47+
# ------------------------------------------------------------
48+
# Checkout repository
49+
# ------------------------------------------------------------
50+
- name: Checkout repository
51+
uses: actions/checkout@v1
52+
53+
- name: Show environment
54+
shell: bash
55+
run: |
56+
env
57+
58+
- name: Show network
59+
shell: bash
60+
run: |
61+
netstat -an || true
62+
ss -tlun || true
63+
64+
- name: Show Docker version
65+
shell: bash
66+
run: |
67+
docker version
68+
69+
# ------------------------------------------------------------
70+
# Setup
71+
# ------------------------------------------------------------
72+
- name: Configure
73+
shell: bash
74+
run: |
75+
cp .env-example .env
76+
echo "PHP_VERSION=${PHP}" >> .env
77+
env:
78+
PHP: ${{ matrix.php }}
79+
80+
# ------------------------------------------------------------
81+
# Build & Run
82+
# ------------------------------------------------------------
83+
- name: Build
84+
shell: bash
85+
run: |
86+
retry() {
87+
for n in $(seq ${RETRIES}); do
88+
echo "[${n}/${RETRIES}] ${*}";
89+
if eval "${*}"; then
90+
echo "[SUCC] ${n}/${RETRIES}";
91+
return 0;
92+
fi;
93+
sleep 2;
94+
echo "[FAIL] ${n}/${RETRIES}";
95+
done;
96+
return 1;
97+
}
98+
retry make build
99+
env:
100+
RETRIES: 20
101+
102+
- name: Run
103+
shell: bash
104+
run: |
105+
retry() {
106+
for n in $(seq ${RETRIES}); do
107+
echo "[${n}/${RETRIES}] ${*}";
108+
if eval "${*}"; then
109+
echo "[SUCC] ${n}/${RETRIES}";
110+
return 0;
111+
fi;
112+
sleep 2;
113+
echo "[FAIL] ${n}/${RETRIES}";
114+
done;
115+
return 1;
116+
}
117+
retry make start
118+
env:
119+
RETRIES: 20
120+
121+
# ------------------------------------------------------------
122+
# Wait
123+
# ------------------------------------------------------------
124+
- name: Wait
125+
shell: bash
126+
run: |
127+
sleep 10
128+
129+
# ------------------------------------------------------------
130+
# Test
131+
# ------------------------------------------------------------
132+
- name: Test
133+
shell: bash
134+
run: |
135+
SUCCESS=0
136+
for i in $(seq 60); do
137+
printf "."
138+
if [ "$(curl -sS -o /dev/null -w '%{http_code}' http://localhost:8000/login.php)" = "200" ]; then
139+
SUCCESS=1;
140+
break;
141+
fi
142+
sleep 1;
143+
done
144+
if [ "${SUCCESS}" != "1" ]; then
145+
printf "\\nFAILED"
146+
false
147+
else
148+
printf "\\nSUCCESS"
149+
fi

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ start: .env
2020

2121
stop:
2222
@echo "Stopping DVWA"
23-
docker-compose stop
23+
docker-compose down
2424

2525
logs:
2626
docker-compose logs -f dvwa_web

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
**[Sec Tools](#lock-cytopia-sec-tools)** |
1212
**[License](#page_facing_up-license)**
1313

14+
[![Linux](https://github.com/cytopia/docker-dvwa/actions/workflows/test.yml/badge.svg)](https://github.com/cytopia/docker-dvwa/actions/workflows/test.yml)
15+
16+
1417
DVWA has an official Docker image available at [Dockerhub](https://hub.docker.com/r/vulnerables/web-dvwa/), however by the time of writing this image did not receive any updates for 2 years.
1518

1619
If you prefer an always up-to-date version, use the here provided Docker Compose setup. The image will always be built locally against the latest master branch of the [DVWA](https://github.com/digininja/DVWA) repository.
@@ -58,7 +61,8 @@ This setup allows you to configure a few settings via the `.env` file.
5861

5962
| Variable | Default | Settings |
6063
|----------------------|---------|----------|
61-
| `LISTEN_PORT ` | `8000` | Local port for the web server to listen on |
64+
| `PHP_VERSION` | `7.2` | PHP version to run DVWA (`5.6`, `7.0`, `7.1`, `7.2`, `7.3`, `7.4` or `8.0`) |
65+
| `LISTEN_PORT` | `8000` | Local port for the web server to listen on |
6266
| `RECAPTCHA_PRIV_KEY` | | Required to make the captcha module work. (See [FAQ](#bulb-faq) section below) |
6367
| `RECAPTCHA_PUB_KEY` | | Required to make the captcha module work. (See [FAQ](#bulb-faq) section below) |
6468
| `PHP_DISPLAY_ERRORS` | `0` | Set to `1` to display PHP errors (if you want a really easy mode) |

docker-compose.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22
version: '2.3'
33

44
services:
5+
56
dvwa_web:
6-
build: ./docker/
7+
build:
8+
context: ./docker/
9+
args:
10+
PHP_VERSION: ${PHP_VERSION:-7.2}
11+
image: cytopia/dvwa:${PHP_VERSION:-7.2}
712
restart: unless-stopped
813
ports:
914
- "${LISTEN_PORT:-8000}:80"
1015
networks:
11-
- app-net
16+
- dvwa-net
1217
environment:
1318
- RECAPTCHA_PRIV_KEY=${RECAPTCHA_PRIV_KEY:-}
1419
- RECAPTCHA_PUB_KEY=${RECAPTCHA_PUB_KEY:-}
1520
- SECURITY_LEVEL=${SECURITY_LEVEL:-medium}
1621
- PHPIDS_ENABLED=${PHPIDS_ENABLED:-0}
1722
- PHPIDS_VERBOSE=${PHPIDS_VERBOSE:-0}
1823
- PHP_DISPLAY_ERRORS=${PHP_DISPLAY_ERRORS:-0}
24+
- MYSQL_HOSTNAME=dvwa_db
25+
- MYSQL_DATABASE=dvwa
26+
- MYSQL_USERNAME=dvwa
27+
- MYSQL_PASSWORD=p@ssw0rd
28+
1929
dvwa_db:
2030
image: mysql:5.6
2131
hostname: dvwa_db
@@ -28,10 +38,10 @@ services:
2838
MYSQL_PASSWORD: p@ssw0rd
2939
restart: unless-stopped
3040
networks:
31-
- app-net
41+
- dvwa-net
3242

3343
networks:
34-
app-net:
44+
dvwa-net:
3545
driver: bridge
3646

3747
volumes:

docker/Dockerfile

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
FROM php:7.2-apache as builder
1+
ARG PHP_VERSION
2+
FROM php:${PHP_VERSION}-apache as builder
23

34
# Get DVWA
45
RUN set -eux \
5-
&& apt update \
6-
&& apt install -y \
6+
&& apt-get update \
7+
&& apt-get install -y \
78
git \
89
&& git clone https://github.com/digininja/DVWA /DVWA \
910
&& rm -rf /DVWA/.git \
1011
&& rm -rf /DVWA/.github \
11-
&& rm -rf /DVWA/.gitignore
12+
&& rm -rf /DVWA/.gitignore \
13+
&& rm -rf /DVWA/php.ini
1214

1315
# Get Adminer
1416
RUN set -eux \
@@ -19,27 +21,32 @@ RUN set -eux \
1921
&& curl -sS --fail -L "${URL}" > /adminer.php
2022

2123

22-
FROM php:7.2-apache
24+
ARG PHP_VERSION
25+
FROM php:${PHP_VERSION}-apache
2326

2427
# Satisfy PHP requirements
2528
RUN set -eux \
26-
&& apt update \
27-
&& apt install -y \
29+
&& apt-get update \
30+
&& apt-get install -y \
2831
libpng-dev \
2932
&& docker-php-ext-install gd \
3033
&& docker-php-ext-install mysqli \
31-
&& docker-php-ext-install pdo_mysql
34+
&& docker-php-ext-install pdo_mysql \
35+
&& apt-get clean \
36+
&& rm -rf /var/lib/apt/lists/*
3237

3338
# Satisfy Application requirements
3439
RUN set -eux \
35-
&& apt update \
36-
&& apt install -y \
40+
&& apt-get update \
41+
&& apt-get install -y \
3742
iputils-ping \
3843
ltrace \
3944
netcat \
4045
strace \
4146
sudo \
42-
telnet
47+
telnet \
48+
&& apt-get clean \
49+
&& rm -rf /var/lib/apt/lists/*
4350

4451
# Copy source
4552
COPY --from=builder /DVWA/ /var/www/html/
@@ -53,6 +60,7 @@ RUN set -eux \
5360
echo "allow_url_include = on"; \
5461
echo "allow_url_fopen = on"; \
5562
echo "error_reporting = E_ALL | E_STRICT"; \
63+
echo "magic_quotes_gpc = off"; \
5664
} > /usr/local/etc/php/conf.d/default.ini
5765

5866
# Adjust permissions

docker/config.inc.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,5 @@
1515
# If you are using MariaDB then you cannot use root, you must use create a dedicated DVWA user.
1616
# See README.md for more information on this.
1717
$_DVWA = array();
18-
$_DVWA[ 'db_server' ] = 'dvwa_db';
19-
$_DVWA[ 'db_database' ] = 'dvwa';
20-
$_DVWA[ 'db_user' ] = 'dvwa';
21-
$_DVWA[ 'db_password' ] = 'p@ssw0rd';
2218
$_DVWA[ 'db_port'] = '3306';
23-
2419
?>

0 commit comments

Comments
 (0)