WordPress Pentest Lab Setup in Multiple Ways


WordPress Pentest Lab Setup in Multiple Ways

In this post, we will demonstrate how to set-up our own Vulnerable WordPress CMS for penetration testing on Ubuntu 20.04, Docker and Windows using XAMPP server.  

Table of Content

·         For Ubuntu 20.04
·         For Docker in Ubuntu 20.04
·         For XAMP server in Windows
WordPress Setup in Ubuntu 20.04
In order to configure Wordpress in your Ubuntu platform, there are some prerequisites before we install the CMS.
Prerequisites for wordPress
Apache
Database (MySQL/Mariadb)
PHP

Install Apache
To Start HTTP service with the help of Apache thus, using privilege account (as root) execute the following command in the terminal.
apt install apache2


Install MySQL
For run WordPress, you will also need a database server. The database server is where WordPress content is saved. So, we are going choose MariaDB-server as the required database for Wordpress and execute the following command
apt install mariadb-server mariadb-client


Next, execute the following commands to protect remote root login for the database server.
mysql_secure_installation
Then respond to questions asked after the command has been executed.
§  Enter current password for root (enter for none): press the Enter
§  Set root password? [Y/n]: Y
§  New password: Enter password
§  Re-enter new password: Repeat password
§  Remove anonymous users? [Y/n]: Y
§  Disallow root login remotely? [Y/n]: Y
§  Remove test database and access to it? [Y/n]:  Y
§  Reload privilege tables now? [Y/n]:  Y




Install php
And at last install the php php-mysql  and run the following command to install these application.
apt install php php-mysql



Create Database for WordPress



To access the mysql, enter the following command
mysql –u root –p
CREATE DATABASE wordpress;
CREATE USER ‘wp_user’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit;




WordPress Installation & Configuration
Now, its time to download and install the WordpPress on our localhost, with the help of wget we have fetched the compressed file of wordpress setup and extract the folder inside /var/www/html directory.
cd /var/www/html
wget http://www.wordpress.org/latest.tar.gz
tar –xvf latest.tar.gz



Then run the given command to change ownership of ‘wordpress’ directory as well permission for upload directory.
chown -R www-data:www-data wordpress/
chmod -R 755  wordpress/
mkdir  wordpress/wp-content/uploads
chmod -R  www-data:www-data wordpress/wp-content/uploads


Now, till here we are done with installation, to configure WordPress we need to access the application over web browser on localhost by executing following.
http://localhost/wordpress/
This will open the setup file and ask to choose your preferred language. I select English and then press the continue Tab.

Read the given content and press Let’s go to continue the activity.


To continue the activity, we need to enter the required details that will help the application to connect with database, thus it should be the same information that we have entered above at the time of database was created for WordPress.


And if your above given detail is correct, you get the Installation page as we have here.


Now after that, it will ask you enter details for your Website which you want to host using WordPress CMS as shown in the below and then finally click on install Tab.
Note: The User and Password asked before the installation is referred to your Database information, and the username and password asked after installed is referred to your application (CMS).


And once it is done, you get application login page where you have to enter credential to access the dashboard of your CMS.

You get the dashboard where you can write your content that to be posted on the website.


Open the wp-config.php file in wordpress directory and paste the following lines in it to access the website page.
define(‘ WP_SITEURL ‘, ‘http://’ .S_SERVER[‘HTTP_HOST’].’/wordpress’);
define(‘ WP_HOME ‘, ‘http://’ .S_SERVER[‘HTTP_HOST’].’/wordpress’);



And Finally, it is over here, and your WordPress is completely ready to go😊.


Install WordPress using Docker

Install WordPress through will release your effort of installing prerequisites for WordPress setup. I very easy and quick technique to configured WordPress. All you need to have some basic knowledge of Docker and its functionalities.
To install wordpress using docker, first we will update the Ubuntu repository and then install the latest version of docker.io. Let’s start the installation of docker packages with the apt command as below:

apt install docker.io


Docker Compose is used to run multiple containers as a single service. Let’s begin the installation of docker-compose with the help of apt by entering following command.
apt install docker-compose


After installing the composer for the Docker, we must create a directory by the name of wordpress.
After creating the directory, we will create a .yml file that will contain the service definitions for your setup.
mkdir wordpress
cd wordpress/
nano docker-compose.yml


Now Paste the following text in the .yml and the configuration.
version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}



Now the docker image in detach mode using following command
docker–compose up -d




After the doing all the configuration step-by-step, now access the localhost on port 8000 that will be hosting your WordPress Docker image and configure your WordPress site as done in previous section.


You get the dashboard where you can write your content that to be posted on the website. But here we need to make some changes inside the setting so that the wordpress after installation it will work properly. Thus, enter your localhost ip address with port number on which your docker image is running.


And Finally, it is over here, and your WordPress is completely ready to go but over port 8000 as shown here 😊.



Install Wordpress on Windows Platform

Installation of WordPress is also very easy as compared to ubuntu, because to fulfil the prerequisites of LAMP Server we can use XAMPP that will completed the all required dependency like apache and MySQL for the  WordPress.

Now download the extract the zip file of WordPress inside the /htdocs folder in /xampp folder in C-Drive.

Now open the PHPMYADMIN in web browser by accessing /localhost/phpMyAdmin and create the database for Wordpress to stored its data.


Now in order to configure wordpress, explore the /localhost/wordpress/ and then enter the detail for database.
Note: By Default, XAMPP DB_User is root and DB_Pass is empty
So as per XMAPP database configuration we entered following details in the given record.

Now again repeat the same step as done in above section.



You get the dashboard where you can write your content that to be posted on the website.


To make it vulnerable WordPress platform in order to perform penetration testing I install some vulnerable plugin as highlighted in the image.
To know how we can go do WordPress Penetration testing read this article.


CyberSploit: 1 Vulnhub Walkthrough


Today we are going to solve another boot2root challenge called "CyberSploit: 1".  It's available at Vulnhub for penetration testing. This is an easy level lab.  The credit for making this lab goes to cybersploit1. Let's get started and learn how to successfully break it down.Level: Easy

Since these labs are available on the Vulnhub website. Let's download the lab file from here.

Penetration Testing Methodology
Reconnaissance
·         Netdiscover
·         Nmap
Enumeration
·         Gobuster
Exploiting
·         Basic Cryptography
·         CyberChef
Privilege Escalation
·         Local Privilege Escalation ‘Overlays’
·         Capture the flag

Walkthrough

Reconnaissance

As always we identify the host's IP with the "Netdiscover" tool:

$ netdiscover



So, let's start by listing all the TCP ports with nmap.
$ nmap –sV -sC -p- 192.168.10.190



To work more comfortably, I'll put the IP address in /etc/hosts.


Enumeration

We access the web service and review the source code. We find the SSH user name.



It's time to fuzzing! We used Gobuster and found several files. We examined the robots.txt and found a base64 text.


Exploiting
We use curl and add "base64 -d" to the command to decode the message in plain text. We get the first flag, the flag is the user's password "itsskv".




We access with the obtained credentials and read the file "flag2.txt". Inside, we find a new code, this time it's "binary code".



We use the online tool "Cyberchef" and we get the second flag.




Privilege Escalation (root)

The root is quite simple (as the creator of the machine said it was easy level). The machine has a kernel vulnerable to "overlayfs: Local Privilege Escalation".

We download the exploit, compile it on the victim machine and run it.
We get a root prompt and read our flag.


Author: David Utón is Penetration Tester and security auditor for Web applications, perimeter networks, internal and industrial corporate infrastructures, and wireless networks
Contacted on LinkedIn and Twitter.

Sunset: decoy Vulnhub Walkthrough


Today we are going to solve another boot2root challenge called "Sunset: decoy".  It's available at Vulnhub for penetration testing. This is an easy to intermediate level lab.

The credit for making this lab goes to whitecr0wz. Let's start and learn how to break it down successfully.

Level: Easy/Intermediate

Since these labs are available on the Vulnhub website. Let's download the lab file from here.

Penetration Testing Methodology
Reconnaissance
·         Netdiscover
·         Nmap
Enumeration
·         Web server backup
Exploiting
·         Zip2john & John The Ripper
Privilege Escalation
·         Pspy64
·         Chrontab abuse and chkrootkit vulnerability
Capture the flag

Walkthrough

Reconnaissance

As always we identify the host's IP with the "Netdiscover" tool:




To work more comfortably, I'll put the IP address in /etc/hosts.



So, let's start by listing all the TCP ports with nmap.
$ nmap –sV -sC -p- 192.168.10.186



Enumeration

We access the web service and download the file "save.zip".



We tried to unzip the file, but it's password protected.


For this mission we will use "zip2john" which will help us to extract the hash from the .zip file and later we will attack it with "John The Ripper" and the dictionary "rockyou.txt".

We will obtain the password "manuel" and use it to decompress the file, this time with success.
  



Exploiting

In the content of the .zip, we found a backup of several system files. We read the "shadow" file, copy the two hashes into a file called "users.hash" and crack this one with John The Ripper and the "rockyou.txt" dictionary.



We connect through the SSH service, this time we will add -t "bash --noprofile" to escape from the restricted bash.
In there, we will read the user flag.




Privilege Escalation (root)
We listed the files and found a binary called "honeypot.decoy". We run it, use option 5 and see a warning that it will run in a minute.



It is time to run pspy64, we check that a binary is running as root every 60 seconds.



We looked for information about the version of this binary and found an exploit that allows to scale privileges as root.



Simply create a file called "update" and insert a reverse shell. We will give it execution permissions and wait 60 seconds with a netcat listening on port 4444 in our Kali.



After some time, we will have a session as root and we will be able to read the flag.



Author: David Utón is Penetration Tester and security auditor for Web applications, perimeter networks, internal and industrial corporate infrastructures, and wireless networks
Contacted on LinkedIn and Twitter.