Setting up Lab Environment for AWS Pen-Testing

Mohammad Mohsin
7 min readApr 21, 2021
AWS Pen-Testing

Hi Folks,

This is Fourth Blog from AWS Pen-Testing Series of Blogs. In my Previous Blogs I have shown “Creating and Connecting to AWS Linux and Windows Instances” So if you are not aware of that kindly navigate to following URL’s.

In this Blog, I will focus on Setting up Lab Environment for AWS Pen-Testing. I will explain following things in this Blog,

  1. Installing Buggy apps(SQL Injection Demo Project) for Pen-testing on Windows Instance.
  2. Installing Buggy apps(DVWA) for Pen-testing on Linux Instance.

I am using following Instances on AWS, which I have already covered “How to create and connect with them in earlier Blogs”.

  1. Kali Linux (Ubuntu) Instance.
  2. Windows Server 2012 R2 Base.

So without wasting more time in theoretical explanation, Let’s start.

  1. Installing Buggy apps (SQL INJECTION Demo Project) on AWS Windows Instance:

Step 1: As shown below, I have connected to windows server 2012 R2 Base.

Connected to AWS Windows Instance

Step 2: Navigate to https://www.apachefriends.org/download.html to download XAMPP for Windows. XAMPP is package which comes with inbuilt My-SQL and Apache and many more useful packages.

Download XAMPP for Windows

Step 3: Click on Save button to save installer file.

Save File
Saved Installer File

Step 4: Now, go through simple installation Setup to install XAMPP.

Installation Steps for XAMPP
Installation Steps for XAMPP
Installation Steps for XAMPP

Step 5: Navigate to C:\xampp → htdocs folder and delete all existing folders and files and create new folder _bak as shown below.

Creating _bak Folder

Step 6: Download SQL Injection Demo which is Buggy App from below link.

Once downloaded copy the content of zip file into C:\xampp → htdocs folder. our htdocs folder will look like,

htdocs Folder Structure

Step 7: Start Apache and MySQL server from XAMPP Control Panel by running Control Panel.exe file.

Start Apache and MySQL Web Servers

Step 8: Once completed, the next step is to create a database for the application and import the data into it. To achieve this, you need to access the phpMyAdmin interface, which is accessible at http://127.0.0.1/phpmyadmin. Once here, select the New option.

Creating Database

Step 9: Create new database sqli as shown below:

Creating Database

Step 10: Click on import button and browse to database.sql file from htdocs folder to import existing database tables and click on GO button.

Creating Database
Creating Database

Step 11: Now, if we browse to http://127.0.0.1 in our browser, we will be able to access the vulnerable website running SQL Injection Demo:

Successfully Running SQL Injection Demo Project

As Shown above, We are successfully able to deploy vulnerable website on AWS windows instance and connect to it. Now we will see how to deploy buggy apps on AWS Linux instance.

2. Installing Buggy apps (DVWA) on AWS Linux Instance:

This time we will try to deploy some other buggy apps on Linux instance like Damn Vulnerable Buggy App (DVWA) rather than SQL INJECTION DEMO PROJECT.

I have already shown in my previous blogs creating and connecting to Linux Instances on AWS. So lets connect to our AWS instance and install following dependent modules.

  1. Apache Web Server (Useful in Linux to Host Websites)
  2. My-SQL (Database to Store Data for hosted website).
  3. PHP (Technology Module)
  4. PHPMyAdmin (Technology Module)

Prior to that we need to Modify Security Group On our AWS Linux instance and add inbound rule which enabled PORT 80 because by default apache web server runs on PORT 80. Let’s see how to add custom rules to Security Groups.

Step 1: Select your ubuntu linux instance from list of instances on AWS. Click on Security Group.

Enabling Port 80 from Security Group

Step 2: Click on Edit inbound rule.

Enabling Port 80 from Security Group

Step 3: Click on Add rule.

Enabling Port 80 from Security Group

Step 4: Add HTTP PORT 80 to the inbound rule and click on Save.

Enabling Port 80 from Security Group

Notice you will get success message if rules added successfully.

Enabling Port 80 from Security Group

Now next thing is connect to the ubuntu instance and install our dependent modules along with apache web server.

  1. Installing Apache Web Server on ubuntu instance:

Command: apt install apache2

Installing Apache Web Server

Testing Apache Web Server Running or not:

Now to validate that Apache is running on our Ubuntu server, we access the IP of the instance in a browser so that we will get default web page of apache web server.

Accessing Apache Default Web Page

2. Installing and configuring MySQL database:

Command: apt install mysql-server

Installing mysql-server

It will prompt to set password for MySQL root user. you can set by entering credentials twice.

Installing mysql-server
Installing mysql-server

You can set new username and password on MySQL database using below commands:

Commands:

i) mysql -u root -p
ii) GRANT ALL PRIVILEGES ON *.* TO ‘spitfire’@’%’ IDENTIFIED BY ‘Admin@123’ WITH GRANT OPTION;
iii) flush privileges;
iv) exit

Setting up DVWA for Pen-test

3. Installing PHP Module:

Command: apt install php

Installing PHP Module

4. Installing PHPMyAdmin:

Command: apt install phpmyadmin

installing phpmyadmin

Now we have successfully installed all the dependency module. Lets setup DVWA Lab for Pen-testing.

To host website or webpages locally, we basically navigate to directory /var/www/html so that web pages will be accessible on localhost from this directory while running apache web server and MySQL server. run the following commands to setup DVWA.

Commands:

i) cd /var/www/html (Root directory for localhost website)
ii) git clone https://github.com/ethicalhack3r/DVWA (Downloading Website Resources)

OR

git clone https://github.com/digininja/DVWA
iii) cd /dvwa/config
iv) mv config.inc.php.dist config.inc.php

Setting up DVWA for Pen-test

v)vim config.php

click i for INSERT MODE.

vi)Add below credentials to the file and click ESC then :wq on keyboard to SAVE Changes and Close config.php File.

Setting up DVWA for Pen-test

Now after all the installation don’t forget to reboot your Linux ubuntu AWS instance or else changes will not be done. Once rebooted navigate to your AWS linux instance URL from web browser.

Setting up DVWA for Pen-test

In your case URL may be different because Public IPV4 DNS address is differ for every instance on AWS. in my case it is

http://ec2-65-2-125-40.ap-south-1.compute.amazonaws.com/DVWA/setup.php

Click on Create/Reset Database button and it will redirect to login.php page as shown below:

Setting up DVWA for Pen-test

I hope this blog will be helpful for pen-testers. Please provide your valuable feedback and suggestions.

In my next blog, I will explain following things,

  1. Installing Vulnerable Services on Linux Instance.
  2. Establishing connection between EC2 Instances (Linux and Windows).

Thanks Readers!

--

--

Mohammad Mohsin

Director - OLF Infotech Pvt. Ltd. Ethical Hacker, Vulnerability Assessment and Penetration Tester, Bug Hunter, Security Researcher, Optimistic, Philanthropist.