> For the complete documentation index, see [llms.txt](https://kchuene.gitbook.io/data-communication-project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kchuene.gitbook.io/data-communication-project/setup/ubuntu-production-server/dvwa.md).

# DVWA

A DVWA to demonstrate detection upon compromise (or attempted compromise) of production node.

## Pull Image and Copy Configurations

**Prepare bind mounts**&#x20;

Create a folders for **Apache2 configuration**, **logs**, and **SSL/TLS certificates** like so

{% code overflow="wrap" lineNumbers="true" %}

```
sudo mkdir -p /opt/dvwa/etc/apache2/sites-available
sudo mkdir -p /opt/dvwa/log/apache2
sudo mkdir -p /opt/dvwa/etc/apache2/certs
```

{% endcode %}

Assign appropriate permissions (`-rw-r-xr-x` ) and ownership that will still enable **Wazuh Agent** to still collect the logs

{% code overflow="wrap" lineNumbers="true" %}

```
sudo chown -R root:root /opt/dvwa
sudo chmod -R 755 /opt/dvwa
```

{% endcode %}

{% hint style="info" %}
There is no **Text Editor** binaries in the image so bind mounts will be one way to manage these files, which will be necessary in later steps.
{% endhint %}

**Pull + Create and Run DVWA temporarily**

{% code overflow="wrap" lineNumbers="true" %}

```
sudo docker run --name dvwa-tmp vulnerables/web-dvwa:1.9
```

{% endcode %}

**Copy over `apache2.conf` and default sites**

{% code overflow="wrap" lineNumbers="true" %}

```
sudo docker cp dvwa-tmp:/etc/apache2/apache2.conf /opt/dvwa/etc/apache2/apache2.conf
sudo docker cp dvwa-tmp:/etc/apache2/sites-available/00-default.conf /opt/dvwa/etc/apache2/sites-available/00-default.conf
sudo docker cp dvwa-tmp:/etc/apache2/sites-available/default-ssl.conf /opt/dvwa/etc/apache2/sites-available/default-ssl.conf
```

{% endcode %}

Then take the temporary container down

{% code overflow="wrap" lineNumbers="true" %}

```
sudo docker rm -f dvwa-tmp
```

{% endcode %}

## SSL and Virtual Hosting

**Generate SSL/TLS certificate**

{% code overflow="wrap" lineNumbers="true" %}

```
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /opt/dvwa/etc/apache2/certs/dvwa.key -out /opt/dvwa/etc/apache2/certs/dvwa.cert
```

{% endcode %}

{% hint style="info" %}
Tools like **mkcert** can alternatively be used. Good for avoiding warning from the browser.
{% endhint %}

**Edit the `default-ssl.conf`**&#x20;

Edit the copied `default-ssl.conf` to include (comment out existing where applicable)

{% code overflow="wrap" lineNumbers="true" %}

```xml
<IfModule mod_ssl.c>
   ServerName dvwa.vm
   DocumentRoot /var/www/html
   
   <VirtualHost _default_:443>
      <!-- Must Match Certificate -->
      ServerName www.dvwa.vm 
      DocumentRoot /var/www/html
      
      <!-- SNIP -->
      
      SSLCertificateFile /etc/apache2/certs/dvwa.cert
      SSLCertificateKeyFile /etc/apache2/certs/dvwa.key
   </VirtualHost>
</IfModule>
```

{% endcode %}

## Compose Configuration

**Compose configuration**

{% code overflow="wrap" lineNumbers="true" %}

```yaml
services:
    dvwa:
        container_name: dvwa
        image: vulnerables/web-dvwa:1.9
        restart: always
        ports:
            - 443:443
        volumes:
            # Config and Virtual Hosting
            - /opt/dvwa/etc/apache2/apache2.conf:/etc/apache2/apache2.conf
            - /opt/dvwa/etc/apache2/sites-available/default-ssl.conf:/etc/apache2/sites-available/default-ssl.conf
            # SSL/TLS Certificates
            - /opt/dvwa/etc/apache2/certs/dvwa.key:/etc/apache2/certs/dvwa.key
            - /opt/dvwa/etc/apache2/certs/dvwa.cert:/etc/apache2/certs/dvwa.cert
            # Log Collection
            - /opt/dvwa/log/apache2/:/var/log/apache2/     
```

{% endcode %}

## Deploy

**Create + Run container**

{% code overflow="wrap" lineNumbers="true" %}

```
sudo docker compose -f dvwa-compose.yaml up -d
```

{% endcode %}

{% hint style="info" %}
**DVWA** is served via **Apache** with a **MySQL** database.
{% endhint %}

**Enable SSL/TLS, Available site and Reload config**

Enter the container

{% code overflow="wrap" lineNumbers="true" %}

```
sudo docker exec -it dvwa bash
```

{% endcode %}

enable SSL/TLS

{% code overflow="wrap" lineNumbers="true" %}

```
a2enmod ssl
```

{% endcode %}

and enable the site (also disable default HTTP site)

{% code overflow="wrap" lineNumbers="true" %}

```
a2ensite default-ssl.conf
a2dissite 000-default.conf
```

{% endcode %}

reload **Apache2** service

{% code overflow="wrap" lineNumbers="true" %}

```
service apache2 reload
```

{% endcode %}

## Local DNS Setup

Edit the local `/etc/hosts` file to include

{% code overflow="wrap" lineNumbers="true" %}

```
192.168.56.103 dvwa.vm
192.168.56.103 www.dvwa.vm
```

{% endcode %}

{% hint style="info" %}
Edit this file on clients that will be visiting the site.
{% endhint %}

## DVWA Access and DB Setup

Access the application at `https://dvwa.vm` or `https://www.dvwa.vm` and setup the **DVWA** database **Setup DVWA > Create /** **Reset Database**

Proceed to login as prompted with the default credentials `admin` (username) and `password` (password).

## Security Setting

When logged in, adjust the security level under **DVWA Security > Security Level**. This can be changed from `low` through to `impossible`.&#x20;

{% embed url="<https://hub.docker.com/r/vulnerables/web-dvwa>" %}

{% embed url="<https://httpd.apache.org/docs/trunk/logs.html>" %}

{% embed url="<https://www.youtube.com/watch?v=l9-BkbI-7vA>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kchuene.gitbook.io/data-communication-project/setup/ubuntu-production-server/dvwa.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
