Skip to content

Commit 34a10d4

Browse files
authored
Merge pull request #550 from hoang-himself/containers
Add ability to run via containers
2 parents c4d9971 + 9ae2306 commit 34a10d4

File tree

8 files changed

+171
-23
lines changed

8 files changed

+171
-23
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/.git
2+
**/.gitignore
3+
**/.github
4+
**/Dockerfile*
5+
**/.dockerignore
6+
**/compose*

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
config/config.inc.php.bak
44
config/config.inc.php
55

6-
Dockerfile
7-
86
# Vim swap files
97
.*swp
108

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM docker.io/library/php:8-apache
2+
WORKDIR /var/www/html
3+
4+
# https://www.php.net/manual/en/image.installation.php
5+
RUN apt-get update \
6+
&& apt-get install -y zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev \
7+
&& rm -rf /var/lib/apt/lists/* \
8+
&& docker-php-ext-configure gd --with-jpeg --with-freetype \
9+
# Use pdo_sqlite instead of pdo_mysql if you want to use sqlite
10+
&& docker-php-ext-install gd mysqli pdo pdo_mysql
11+
12+
COPY --chown=www-data:www-data . .
13+
COPY --chown=www-data:www-data config/config.inc.php.dist config/config.inc.php

README.md

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,54 @@ XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows
7878

7979
This [video](https://youtu.be/Yzksa_WjnY0) walks you through the installation process for Windows but it should be similar for other OSs.
8080

81-
### Config File
81+
### Docker
8282

83-
DVWA ships with a dummy copy of its config file which you will need to copy into place and then make the appropriate changes. On Linux, assuming you are in the DVWA directory, this can be done as follows:
83+
It is possible to run DVWA with containers.
8484

85-
`cp config/config.inc.php.dist config/config.inc.php`
85+
Prerequisites: Docker and Docker Compose.
8686

87-
On Windows, this can be a bit harder if you are hiding file extensions, if you are unsure about this, this blog post explains more about it:
87+
- If you are using Docker Desktop, both of these should be already installed.
88+
- If you prefer Docker Engine on Linux, make sure to follow their [installation guide](https://docs.docker.com/engine/install/#server).
8889

89-
[How to Make Windows Show File Extensions](https://www.howtogeek.com/205086/beginner-how-to-make-windows-show-file-extensions/)
90+
**We provide support for the latest Docker release as shown above.**
91+
If you are using Linux and the Docker package that came with your package manager, it will probably work too, but support will only be best-effort.
92+
93+
Upgrading Docker from the package manager version to upstream requires that you uninstall the old versions as seen in their manuals for [Ubuntu](https://docs.docker.com/engine/install/ubuntu/#uninstall-old-versions), [Fedora](https://docs.docker.com/engine/install/fedora/#uninstall-old-versions) and others.
94+
Your Docker data (containers, images, volumes, etc.) should not be affected, but in case you do run into a problem, make sure to [tell Docker](https://www.docker.com/support) and use search engines in the mean time.
95+
96+
Then, to get started:
97+
98+
1. Run `docker version` and `docker compose version` to see if you have Docker and Docker Compose properly installed. You should be able to see the version of Docker in the output.
99+
100+
For example:
101+
102+
```text
103+
>>> docker version
104+
Client:
105+
[...]
106+
Version: 23.0.5
107+
[...]
108+
109+
Server: Docker Desktop 4.19.0 (106363)
110+
Engine:
111+
[...]
112+
Version: 23.0.5
113+
[...]
114+
115+
>>> docker compose version
116+
Docker Compose version v2.17.3
117+
```
118+
119+
If you don't see anything or get a command not found error, follow the prerequisites to setup Docker and Docker Compose.
120+
121+
2. Clone or download this repository and extract (see [Download](#download)).
122+
3. Open a terminal of your choice and change its working directory to `DVWA`.
123+
4. `docker compose up -d`.
124+
125+
DVWA is now available at `http://localhost:4280`.
126+
127+
**Notice that for running DVWA in containers, the web server is listening on port 4280 instead of the usual port of 80.**
128+
For more information on this decision, see [I want to run DVWA on a different port](#i-want-to-run-dvwa-on-a-different-port).
90129
91130
### Linux Packages
92131
@@ -108,6 +147,18 @@ apt install -y apache2 mariadb-server mariadb-client php php-mysqli php-gd libap
108147
109148
The site will work with MySQL instead of MariaDB but we strongly recommend MariaDB as it works out of the box whereas you have to make changes to get MySQL to work correctly.
110149
150+
## Configurations
151+
152+
### Config File
153+
154+
DVWA ships with a dummy copy of its config file which you will need to copy into place and then make the appropriate changes. On Linux, assuming you are in the DVWA directory, this can be done as follows:
155+
156+
`cp config/config.inc.php.dist config/config.inc.php`
157+
158+
On Windows, this can be a bit harder if you are hiding file extensions, if you are unsure about this, this blog post explains more about it:
159+
160+
[How to Make Windows Show File Extensions](https://www.howtogeek.com/205086/beginner-how-to-make-windows-show-file-extensions/)
161+
111162
### Database Setup
112163
113164
To set up the database, simply click on the `Setup DVWA` button in the main menu, then click on the `Create / Reset Database` button. This will create / reset the database for you with some data in.
@@ -182,7 +233,7 @@ Generated a pair of API keys from <https://www.google.com/recaptcha/admin/create
182233

183234
These then go in the following sections of `./config/config.inc.php`:
184235

185-
* `$_DVWA[ 'recaptcha_public_key' ]`
236+
* `$_DVWA[ 'recaptcha_public_key' ]`
186237
* `$_DVWA[ 'recaptcha_private_key' ]`
187238

188239
### Default Credentials
@@ -199,20 +250,67 @@ _Note: This will be different if you installed DVWA into a different directory._
199250

200251
- - -
201252

202-
## Docker Container
253+
## Troubleshooting
203254

204-
_This section of the readme was added by @thegrims, for support on Docker issues, please contact them or @opsxcq who is the maintainer of the Docker image and repo. Any issue tickets will probably be pointed at this and closed._
255+
These assume you are on a Debian based distro, such as Debian, Ubuntu and Kali. For other distros, follow along, but update the command where appropriate.
205256

206-
- [dockerhub page](https://hub.docker.com/r/vulnerables/web-dvwa/)
207-
`docker run --rm -it -p 80:80 vulnerables/web-dvwa`
257+
### Containers
208258

209-
Please ensure you are using aufs due to previous MySQL issues. Run `docker info` to check your storage driver. If it isn't aufs, please change it as such. There are guides for each operating system on how to do that, but they're quite different so we won't cover that here.
259+
#### I want to access the logs
210260

211-
- - -
261+
If you are using Docker Desktop, logs can be accessed from the graphical application.
262+
Some minor details may change with newer versions, but the access method should be the same.
212263

213-
## Troubleshooting
264+
![Overview of DVWA compose](./docs/graphics/docker/overview.png)
265+
![Viewing DVWA logs](docs/graphics/docker/detail.png)
214266

215-
These assume you are on a Debian based distro, such as Debian, Ubuntu and Kali. For other distros, follow along, but update the command where appropriate.
267+
Logs can also be accessed from the terminal.
268+
269+
1. Open a terminal and change its working directory to DVWA
270+
2. Show the merged logs
271+
272+
```shell
273+
docker compose logs
274+
```
275+
276+
In case you want to export the logs to a file, e.g. `dvwa.log`
277+
278+
```shell
279+
docker compose logs >dvwa.log
280+
```
281+
282+
#### I want to run DVWA on a different port
283+
284+
We don't use port 80 by default for a few reasons:
285+
286+
- Some users might already be running something on port 80.
287+
- Some users might be using a rootless container engine (like Podman), and 80 is a privileged port (< 1024). Additional configuration (e.g. setting `net.ipv4.ip_unprivileged_port_start`) is required, but you will have to research on your own.
288+
289+
You can expose DVWA on a different port by changing the port binding in the `compose.yml` file.
290+
For example, you can change
291+
292+
```yml
293+
ports:
294+
- 4280:80
295+
```
296+
297+
to
298+
299+
```yml
300+
ports:
301+
- 8806:80
302+
```
303+
304+
DVWA is now accessible at `http://localhost:8806`.
305+
306+
#### DVWA auto starts when Docker runs
307+
308+
The included [`compose.yml`](./compose.yml) file automatically runs DVWA and its database when Docker starts.
309+
310+
To disable this, you can delete or comment out the `restart: unless-stopped` lines in the [`compose.yml`](./compose.yml) file.
311+
312+
If you want to disable this behavior temporarily, you can run `docker compose stop`, or use Docker Desktop, find `dvwa` and click Stop.
313+
Additionally, you can delete the containers, or run `docker compose down`.
216314
217315
### Log files
218316

compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
volumes:
2+
dvwa:
3+
4+
5+
networks:
6+
dvwa:
7+
8+
9+
services:
10+
dvwa:
11+
build: .
12+
environment:
13+
- DB_SERVER=db
14+
depends_on:
15+
- db
16+
networks:
17+
- dvwa
18+
ports:
19+
- 4280:80
20+
restart: unless-stopped
21+
22+
db:
23+
image: docker.io/library/mariadb:10
24+
environment:
25+
- MYSQL_ROOT_PASSWORD=dvwa
26+
- MYSQL_DATABASE=dvwa
27+
- MYSQL_USER=dvwa
28+
- MYSQL_PASSWORD=p@ssw0rd
29+
volumes:
30+
- dvwa:/var/lib/mysql
31+
networks:
32+
- dvwa
33+
restart: unless-stopped

config/config.inc.php.dist

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ $DBMS = 'MySQL';
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' ] = '127.0.0.1';
18+
$_DVWA[ 'db_server' ] = getenv('DB_SERVER') ?: '127.0.0.1';
1919
$_DVWA[ 'db_database' ] = 'dvwa';
2020
$_DVWA[ 'db_user' ] = 'dvwa';
2121
$_DVWA[ 'db_password' ] = 'p@ssw0rd';
22-
$_DVWA[ 'db_port'] = '3306';
22+
$_DVWA[ 'db_port'] = '3306';
2323

2424
# ReCAPTCHA settings
2525
# Used for the 'Insecure CAPTCHA' module
@@ -42,15 +42,15 @@ $_DVWA[ 'default_locale' ] = 'en';
4242
# so this setting lets you turn off authentication.
4343
$_DVWA[ 'disable_authentication' ] = false;
4444

45-
define ("MYSQL", "mysql");
46-
define ("SQLITE", "sqlite");
45+
define ('MYSQL', 'mysql');
46+
define ('SQLITE', 'sqlite');
4747

4848
# SQLi DB Backend
4949
# Use this to switch the backend database used in the SQLi and Blind SQLi labs.
5050
# This does not affect the backend for any other services, just these two labs.
5151
# If you do not understand what this means, do not change it.
52-
$_DVWA["SQLI_DB"] = MYSQL;
53-
#$_DVWA["SQLI_DB"] = SQLITE;
54-
#$_DVWA["SQLITE_DB"] = "sqli.db";
52+
$_DVWA['SQLI_DB'] = MYSQL;
53+
#$_DVWA['SQLI_DB'] = SQLITE;
54+
#$_DVWA['SQLITE_DB'] = 'sqli.db';
5555

5656
?>

docs/graphics/docker/detail.png

160 KB
Loading

docs/graphics/docker/overview.png

71.5 KB
Loading

0 commit comments

Comments
 (0)