{"id":1183,"date":"2018-10-31T15:22:29","date_gmt":"2018-10-31T12:22:29","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1183"},"modified":"2024-03-11T19:53:18","modified_gmt":"2024-03-11T16:53:18","slug":"how-to-setup-damn-vulnerable-web-app-lab-on-ubuntu-18-04-server","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-setup-damn-vulnerable-web-app-lab-on-ubuntu-18-04-server\/","title":{"rendered":"How to Install and Configure DVWA Lab on Ubuntu 18.04 server"},"content":{"rendered":"\n<p>Hello there, today we are going to learn how to install and configure DVWA lab on Ubuntu 18.04 server.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.dvwa.co.uk\/\" target=\"_blank\" rel=\"noopener noreferrer\">DVWA<\/a> has been defined as a damn vulnerable PHP\/MySQL based web application whose main goals are to aid security professionals to test their skills and tools in a legal environment, help web developers better understand the processes of securing web applications and aid teachers or students to teach or learn web application security respectively in a class room environment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing DVWA on Ubuntu 18.04<\/h2>\n\n\n\n<p>To setup DVWA on Ubuntu 18.04 server, step through the following procedure.<\/p>\n\n\n\n<p>Update and upgrade all packages on your server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt update\napt upgrade<\/pre>\n\n\n\n<p>One the upgrade is done, we are going to install the basic components of LAMP stack i.e Apache, MySQL, and PHP. Therefore you can check our previous article on <a href=\"https:\/\/kifarunix.com\/howtos\/how-to-install-lamp-stack-apachemariadb-php-7-2-on-ubuntu-18-04-lts\/\" target=\"_blank\" rel=\"noopener noreferrer\">how to install LAMP Stack on Ubuntu 18.04<\/a>.<\/p>\n\n\n\n<p>Once you have had LAMP Stack, proceed as follows.<\/p>\n\n\n\n<p>When prompted to set MySQL password you can set it to the default password that is used by the DVWA, <strong class=\"userinput\"><code>p@ssw0rd<\/code><\/strong>. If you do set a different password, keep it as we will need it later.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Download DVWA<\/h3>\n\n\n\n<p>DVWA is available either as a package that will run on your own web server or as a Live CD. In this guide, we are going to use DVWA package.<\/p>\n\n\n\n<p>We are going to install DVWA on the Apache web root directory,<strong class=\"userinput\"><code>\/var\/www\/html<\/code><\/strong>. Therefore you have to remove the default <strong class=\"userinput\"><code>index.html<\/code> <\/strong>file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm -r \/var\/www\/html\/index.html<\/pre>\n\n\n\n<p>Once that is done, clone the latest version of the DVWA to some directory, say <strong>\/tmp<\/strong> by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git clone https:\/\/github.com\/ethicalhack3r\/DVWA \/tmp\/DVWA<\/pre>\n\n\n\n<p>The required DVWA source code files are now available under <strong>\/tmp\/DVWA<\/strong>. You need to move or copy these files to Apache default web root directory as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rsync -avP \/tmp\/DVWA\/ \/var\/www\/html\/<\/pre>\n\n\n\n<p>You can now verify that all the DVWA source code files are under the Apache Web root directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ls \/var\/www\/html\/\nabout.php     config       docs  external     hackable     index.php         login.php   phpinfo.php  README.md   security.php  vulnerabilities\nCHANGELOG.md  COPYING.txt  dvwa  favicon.ico  ids_log.php  instructions.php  logout.php  php.ini      robots.txt  setup.php<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure DVWA on Ubuntu 18.04<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Set Database connection details<\/h4>\n\n\n\n<p>Next, we are going to configure DVWA database connection details. You will notice that the DVWA configuration file named <strong class=\"userinput\"><code>\/var\/www\/html\/config\/config.inc.php.dist<\/code><\/strong>. Therefore, rename this configuration file to <strong class=\"userinput\"><code>\/var\/www\/html\/config\/config.inc.php<\/code><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp \/var\/www\/html\/config\/config.inc.php.dist \/var\/www\/html\/config\/config.inc.php<\/pre>\n\n\n\n<p>If you had set a different MySQL password, edit the configuration file, <strong class=\"userinput\"><code>\/var\/www\/html\/config\/config.inc.php<\/code><\/strong> and find the line, <strong class=\"userinput\"><code>&nbsp;<strong>$_DVWA[ 'db_password' ] = 'p@ssw0rd';<\/strong><\/code> <\/strong>and replace the <strong class=\"userinput\"><code><strong>'p@ssw0rd'<\/strong><\/code><\/strong> with your new password. For example, if you set your root password to <strong>NewP@SSw0rd<\/strong>, your configuration should look like as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/var\/www\/html\/config\/config.inc.php<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>...<\/strong>\n# If you are using MariaDB then you cannot use root, you must use create a dedicated DVWA user.\n#   See README.md for more information on this.\n$_DVWA = array();\n$_DVWA[ 'db_server' ]   = '127.0.0.1';\n$_DVWA[ 'db_database' ] = 'dvwa';\n$_DVWA[ 'db_user' ]     = 'root';\n<strong>$_DVWA[ 'db_password' ] = 'NewP@SSw0rd';<\/strong>\n<strong>...<\/strong><\/pre>\n\n\n\n<p>Note, if you are using MariaDB rather than MySQL, you can&#8217;t use the database root user and therefore you must create a new database and the database user using the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql<span class=\"pl-k\">&gt;<\/span> create database dvwa;\nmysql<span class=\"pl-k\">&gt;<\/span> <span class=\"pl-k\">grant<\/span> all <span class=\"pl-k\">on<\/span> dvwa.<span class=\"pl-k\">*<\/span> to dvwa@localhost identified by <span class=\"pl-s\"><span class=\"pl-pds\">'<\/span>STRONGP@SSW0rd<span class=\"pl-pds\">'<\/span><\/span>;\nmysql<span class=\"pl-k\">&gt;<\/span> flush privileges;\nmysql&gt; quit<\/pre>\n\n\n\n<p>Once you are done creating dvwa database user, edit the DVWA configuration and adjust the database configuration settings such that your configuration looks like;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>...<\/strong>\n$_DVWA[ 'db_server' ] = '127.0.0.1';\n$_DVWA[ 'db_database' ] = 'dvwa';\n$_DVWA[ 'db_user' ] = 'dvwa';\n$_DVWA[ 'db_password' ] = 'STRONGP@SSW0rd';\n<strong>...<\/strong><\/pre>\n\n\n\n<p>Save the configuration file and restart MySQL.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart mysql<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Configure PHP<\/h4>\n\n\n\n<p>The version PHP installed in our case here is 7.2.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">php -v\nPHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )<\/pre>\n\n\n\n<p>Now edit the file, <strong class=\"userinput\"><code><strong>\/etc\/php\/7.2\/apache2\/php.ini<\/strong><\/code><\/strong> and make the following changes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>allow_url_include = on<\/code> &#8211; Allows for Remote File Inclusions (RFI)<\/li>\n\n\n\n<li><code>allow_url_fopen = on<\/code> &#8211; Allows for Remote File Inclusions (RFI)<\/li>\n\n\n\n<li><code>safe_mode = off<\/code> &#8211; (If PHP &lt;= v5.4) Allows for SQL Injection (SQLi)<\/li>\n\n\n\n<li><code>magic_quotes_gpc = off<\/code> &#8211; (If PHP &lt;= v5.4) Allows for SQL Injection (SQLi)<\/li>\n\n\n\n<li><code>display_errors = off<\/code> &#8211; (Optional) Hides PHP warning messages to make it less verbose<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">File Permissions<\/h4>\n\n\n\n<p>Make the following folder and file writeable by the web service for File Uploads and PHPIDS respectively.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/var\/www\/html\/hackable\/uploads\/\n\/var\/www\/html\/external\/phpids\/0.6\/lib\/IDS\/tmp\/phpids_log.txt<\/pre>\n\n\n\n<p>In short, you can change the ownership of the Apache web root directory as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chown -R www-data.www-data \/var\/www\/html\/<\/pre>\n\n\n\n<p>Now locate the IP address of your server and navigate to the web browser and type the IP address of your web server on the address bar to access your DVWA. See the screenshot below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-interface.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1097\" height=\"864\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-interface.png\" alt=\"Install and Configure DVWA Lab on Ubuntu 18.04\" class=\"wp-image-1188\" title=\"Install and Configure DVWA Lab on Ubuntu 18.04 server\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-interface.png 1097w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-interface-768x605.png 768w\" sizes=\"(max-width: 1097px) 100vw, 1097px\" \/><\/a><\/figure>\n\n\n\n<p>If your are using MariaDB, then you will get the login page directly.<\/p>\n\n\n\n<p>If the web page doesn&#8217;t load, and tailing the the Apache error log, <strong># tail \/var\/log\/apache2\/error.log<\/strong>, you get the following error;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>[Tue Oct 30 23:27:28.149822 2018] [php7:error] [pid 16560] [client 192.168.43.149:40556] PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in \/var\/www\/html\/dvwa\/includes\/dvwaPage.inc.php:470\\nStack trace:\\n#0 \/var\/www\/html\/login.php(8): dvwaDatabaseConnect()\\n#1 {main}\\n thrown in \/var\/www\/html\/dvwa\/includes\/dvwaPage.inc.php on line 470<\/strong><\/pre>\n\n\n\n<p>It means you are missing the PHP mysqli package. Install the package as shown below and restart Apache;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt install php-mysqli -y\nsystemctl restart apache2<\/pre>\n\n\n\n<p>As shown in the dashboard above, there are a few issues whose status is marked in red ans therefore we need to fix them as follow;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>PHP module gd:<span class=\"failure\" style=\"color: #f50202;\"> Missing<br><\/span><\/strong>\n<ul class=\"wp-block-list\">\n<li>Fix this by install php-gd module;<\/li>\n\n\n\n<li><strong class=\"userinput\"><code><strong># apt install php-gd -y<\/strong><\/code><\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>reCAPTCHA key: <span class=\"failure\" style=\"color: #f50202;\">Missing<\/span><\/strong>\n<ul class=\"wp-block-list\">\n<li>Fix this by generating recapture values from <a href=\"https:\/\/www.google.com\/recaptcha\/intro\/v3.html\" target=\"_blank\" rel=\"noopener noreferrer\">Google service<\/a>.<\/li>\n\n\n\n<li>Once you have generated, edit the <strong class=\"userinput\"><code>\/var\/www\/html\/config\/config.inc.php<\/code><\/strong> and set the values for;\n<ul class=\"wp-block-list\">\n<li><code>$_DVWA[ 'recaptcha_public_key' ] = 'PASTE YOUR PUBLIC KEY HERE';<\/code> &amp;<\/li>\n\n\n\n<li><code>$_DVWA[ 'recaptcha_private_key' ] = 'PASTE YOUR SECRET KEY HERE';<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Once you are done with configurations, restart both Apache and MySQL<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart apache2\nsystemctl restart mysql<\/pre>\n\n\n\n<p>Go back to your web browser and reload the page and everything should be fine now.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-ui-status-green.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1116\" height=\"862\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-ui-status-green.png\" alt=\"\" class=\"wp-image-1189\" title=\"Install and Configure DVWA Lab on Ubuntu 18.04 server\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-ui-status-green.png 1116w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-web-ui-status-green-768x593.png 768w\" sizes=\"(max-width: 1116px) 100vw, 1116px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create Database for DVWA<\/h3>\n\n\n\n<p>Now, you have to create the DVWA database to ensure the success of your exercise. Click the button <strong>Create\/Reset Database<\/strong> at the bottom of your web page. You may encounter the following error;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-create-db-error.png\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"313\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-create-db-error.png\" alt=\"\" class=\"wp-image-1190\" title=\"Install and Configure DVWA Lab on Ubuntu 18.04 server\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-create-db-error.png 865w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-create-db-error-768x278.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/a><\/figure>\n\n\n\n<p>The error above is due to wrong database connection details. You can verify the same as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -u root -p<strong>NewP@SSw0rd<\/strong> -D dvwa -h 127.0.0.1\nmysql: [Warning] Using a password on the command line interface can be insecure.\nERROR 1698 (28000): <strong>Access denied for user 'root'@'localhost'<\/strong><\/pre>\n\n\n\n<p>Therefore, login to your mysql reconfigure it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -u root -p<\/pre>\n\n\n\n<p>Drop the root user;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">drop user root@localhost;<\/pre>\n\n\n\n<p>Recreate root user;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">create user root@localhost identified by '<strong>NewP@SSw0rd<\/strong>'<\/pre>\n\n\n\n<p>You may opt to use the default DVWA password, <strong class=\"userinput\"><code><strong>p@ssw0rd<\/strong><\/code><\/strong>.<\/p>\n\n\n\n<p>Run the command below to reload the database grant tables and quit DB connection.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">flush privileges;\nquit;<\/pre>\n\n\n\n<p>Restart MySQL service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart mysql<\/pre>\n\n\n\n<p>Before you can navigate back to the web UI, verify that you can now connect to the DVWA DB with the set login credentials;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -u root -p<strong>NewP@SSw0rd<\/strong> -D dvwa -h 127.0.0.1<\/pre>\n\n\n\n<p>If all is well, then it should be able to see that the database has been created on the Web UI.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-database-created.png\"><img loading=\"lazy\" decoding=\"async\" width=\"826\" height=\"508\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-database-created.png\" alt=\"\" class=\"wp-image-1192\" title=\"Install and Configure DVWA Lab on Ubuntu 18.04 server\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-database-created.png 826w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-database-created-768x472.png 768w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/a><\/figure>\n\n\n\n<p>If all is well, you will be redirected to the login page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-login-page.png\"><img loading=\"lazy\" decoding=\"async\" width=\"971\" height=\"443\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-login-page.png\" alt=\"\" class=\"wp-image-1193\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-login-page.png 971w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-login-page-768x350.png 768w\" sizes=\"(max-width: 971px) 100vw, 971px\" \/><\/a><\/figure>\n\n\n\n<p>You can now login to your DVWA server using the credentials; user <strong class=\"userinput\"><code><strong>admin<\/strong><\/code><\/strong> passord: <strong class=\"userinput\"><code><strong>password<\/strong><\/code><\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-welcome-page.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1097\" height=\"859\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-welcome-page.png\" alt=\"\" class=\"wp-image-1199\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-welcome-page.png 1097w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/10\/dvwa-welcome-page-768x601.png 768w\" sizes=\"(max-width: 1097px) 100vw, 1097px\" \/><\/a><\/figure>\n\n\n\n<p>There you go.<\/p>\n\n\n\n<p>To wrap, we have successfully learnt Install and configure DVWA lab on Ubuntu 18.04 server. You can now hunt for the vulnerabilities. We hope this article helped. Happy vulnerability hunting!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Related Guides<\/h3>\n\n\n\n<p><a title=\"How to Install Acutenix on Ubuntu 18.04\" href=\"https:\/\/kifarunix.com\/how-to-install-acutenix-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"bookmark noopener noreferrer\">How to Install Acutenix on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a title=\"Install Nessus Professional Scanner on Debian 10\" href=\"https:\/\/kifarunix.com\/install-openvas-10-gvm-on-debian-10-buster\/\" target=\"_blank\" rel=\"bookmark noopener noreferrer\">Install Nessus Professional Scanner on Debian 10<\/a><\/p>\n\n\n\n<p><a title=\"Install OpenVAS 10 (GVM) on Debian 10 Buster\" href=\"https:\/\/kifarunix.com\/install-openvas-10-gvm-on-debian-10-buster\/\" target=\"_blank\" rel=\"bookmark noopener noreferrer\">Install Nessus Professional Scanner on Debian 10<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello there, today we are going to learn how to install and configure DVWA lab on Ubuntu 18.04 server. DVWA has been defined as a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,34,150],"tags":[222,67],"class_list":["post-1183","post","type-post","status-publish","format-standard","hentry","category-howtos","category-security","category-vulnerability-scanners","tag-dvwa","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1183"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":9,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"predecessor-version":[{"id":21010,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1183\/revisions\/21010"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}