Tag: penetration testing

  • DVWA Hacking Tutorial

    DVWA Hacking Tutorial

    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!

    DVWA Hacking Tutorial: SQL Injection

    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
    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)
    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.

    XSS alert with cookie
    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!

  • How to Install DVWA in Ubuntu

    How to Install DVWA in Ubuntu

    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:

    sudo apt update && sudo apt upgrade -y 
    sudo apt -y install apache2 mariadb-server php php-mysqli php-gd libapache2-mod-php
    How to Install DVWA in Ubuntu - Install 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';
    Create the Database

    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.

    cd /var/www/html
    sudo git clone https://github.com/digininja/DVWA.git .
    sudo chown -R www-data:www-data /var/www/html/*
    Download DVWA

    Next we will need to configure the application. This is as simple as copying the example configuration file, and changing the database connection parameters.

    cp /var/www/html/config/config.inc.php.dist /var/www/html/config/config.inc.php

    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.

    Configure DVWA

    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!

    Setup DVWA

    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!

    How to Install DVWA in Ubuntu
  • Install Kali Linux in VirtualBox on Mac

    Install Kali Linux in VirtualBox on Mac

    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.

    Let’s get right to it!

    Download Kali Linux for VirtualBox

    Start by downloading the appropriate image from the Offensive Security VM download page.

    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 VirtualBox
    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 screen
    VirtualBox appliance import screen
    Select the Kali Linux virtual appliance file
    Select 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
    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 agreement
    Kali Linux GPL v3 license agreement
    Kali Linux VirtualBox import
    Kali 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
    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
    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 Linux
    Install VirtualBox Guest Additions in Kali Linux
    Insert Guest Additions
    Insert Guest Additions
    Copy VBoxLinuxAddtions.run to Desktop
    Copy VBoxLinuxAddtions.run to Desktop
    Open terminal, install as root
    Open terminal, install as root
    VirtualBox Guest Additions installed in Kali Linux
    VirtualBox 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
    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
    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
    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.

    How to learn penetration testing with Kali Linux

    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.

    We hope you enjoyed today’s tutorial on installing Kali Linux in VirtualBox. If you have any questions or feedback please leave us a comment below!

  • Understanding the Cyber Kill Chain in the Cloud

    The cyber kill chain defines the lifecycle of a cyber attack and identifies various phases during a system intrusion. Although there are numerous interpretations of the cyber kill chain, the most basic form consists of seven stages. In this post I describe these seven stages of the cyber kill chain and how it applies in the cloud. 

    Although some interpretations may use slightly different names for the various stages, the overall concept remains the same. 

    The basic seven stages of the cyber kill chain are: 

    • Recon
    • Weaponize
    • Deliver
    • Exploit
    • Install
    • Callback
    • Persist

    I will now elaborate on each of these stages and how they apply in a cloud environment.

    Recon

    During the reconnaissance or information gathering phase, threat actors collect as much information about the intended target as possible. This data often comes from external sources allowing the attacker to avoid contact with the target until absolutely necessary. 

    A motivated attacker will leave no stone unturned when searching for information about a target.

    Attackers use a wealth of intelligence gathering techniques and sometimes may spend months gathering information about a target. Careful analysis and application of this information can allow attackers to carefully tailor an attack with a higher probability of succeeding. 

    Anonymous Recon with OSINT

    Open-Source Intelligence (OSINT) is the act of collecting information from publicly available sources. For instance, an attacker may crawl an organization’s Facebook page to identify potential employees. When an attacker collects information from publicly available sources they gain information about a target without needing to interact with them directly.

    See my Open Source Intelligence Primer for a more in-depth look at the reconnaissance phase.

    The less direct contact between the attacker and the target the less chance of being detected. For this reason, attackers will avoid contact with their target through any direct means until it is time to strike.

    Public registry databases such as WHOIS provide a wealth of information about targets including IP addresses, phone numbers, technical contacts and email addresses. Armed with this information, attackers can launch very convincing spear phishing attacks during the delivery phase.

    Attackers may also scour social media sites such as Facebook, LinkedIn and Twitter. Doing so may reveal further information about employees, their schedules, and their habits. 

    Social Engineering with Social Media

    Employees are often less conscious of the security implications of posting to social media and other cloud services.

    It is not entirely uncommon for a system administrator to inadvertently leak sensitive information when using public cloud services. In fact, a North Carolina State University (NCSU) study of public Github repositories revealed leaked credentials in over 100,000 Github repositories.

    With a list of viable emails and usernames in hand, an attacker will then search for matching online accounts. This may reveal passwords available in a recent data breach. Unfortunately many users re-use passwords across many services, and are often slow to change their passwords after a breach. 

    The explosion of cloud computing has vastly increased the amount of information available to an attacker. Simply collecting all of this information serves little use to an attacker. An attacker must now analyze and weaponize the collected information. From there an attacker can develop a strategy for exploiting any discovered weaknesses.

    In the following section I describe how an attacker prepares to strike by weaponizing the information they have collected thus far.

    Weaponize

    After performing thorough reconnaissance of a target, an attacker will have a pretty good idea of where and how to strike.

    In the weaponize phase an attacker builds their ‘cyber weapons’ and prepares to strike the target. If the attack involves deploying malware it will need to be hosted somewhere. Similarly, if the attack involves phishing emails, then the attacker will need to craft the email bodies.

    This phase may use information gathered during the reconnaissance phase to develop attacks specific to a target.

    Cybercriminals automate too…

    One of the greatest benefits of cloud computing is the ease of automation. Of course cybercriminals take advantage of the benefits of automation as well. Automation allows for quickly provisioning infrastructure. This significantly reduces the time between the reconnaissance phase, and the actual strike.

    Creation of phishing pages, malware hosts, and command and control infrastructure can all be accomplished in a matter of minutes using common automation tools such as Puppet, Chef, or Ansible.

    Attackers also use generic cloud resources to host their command and control infrastructure greatly increasing resilience against take downs.

    One recent example I have encountered in the wild is the use of Azure Pages for hosting phishing sites. Hosting phishing pages on a trusted cloud provider such as Azure has the added benefit of providing a trusted domain. Traditional firewalls will typically not catch this kind of traffic.

    After an attacker has finished setting up their infrastructure they will deliver their intended payload.

    Deliver

    This is where the attack begins in earnest. During the delivery phase the attacker delivers the malicious payload to the intended victim. This delivery can take the form of a phishing email, a watering hole attack, a supply chain attack, or even a dropped USB drive.

    With almost everything in the cloud these days it seems obvious that malicious payloads and phishing pages are served from the cloud as well. 

    This can take the form of a cloud hosted download server, or a publicly available file-sharing site. Attackers have used popular services such as Pastebin, Github, or even Pinterest and Instagram to deliver their payloads. 

    Trusted services, the Trojan horses of the Internet

    Using common services such as Google Drive also helps bypass the ‘human firewall’. Users are much more likely to trust a link directing them to a known site with a valid certificate.

    Luckily many users are smart enough not to click links directing them to a random domain. However, are those same users as wary of clicking links that lead them to a document in Google Drive?

    Attackers constantly refine their delivery techniques. The vast number of different delivery methods grows every day and evolves quickly to take advantage of new weaknesses.

    Exploit

    After the malicious payload has been delivered it must exploit the system before it becomes active. While an exploit may attack a system vulnerability, an attacker may also attempt to exploit the user. For example, a downloaded Word document may entice the user to activate macros to view the full document.

    During the exploit phase the attacker will exploit any vulnerabilities found during the reconnaissance phase. Due to the number of unpatched systems in the wild it is not uncommon for an attacker to have a number of previously disclosed vulnerabilities to draw from.

    Occasionally an attacker will take advantage of a previously unknown vulnerability with a zero-day exploit. 

    Other attacks may make use of browser vulnerabilities with drive-by sites which contain malicious Javascript code. Simply browsing to a malicious website may trigger such an exploit. 

    Accelerating expansion of cloud computing provides an increasing attack surface with numerous attacks targeting unprotected credentials, weak passwords, and poorly configured or default systems. 

    Install

    Once the initial exploit has taken place the attacker will begin to install their malicious payload. The installation phase usually consists of a series of installations. For example, the initial exploit may download a reconnaissance tool to gather further system information. Depending on the information returned the attacker may then deploy a more specific malicious payload such as a key logger, banking trojan, or crypto miner. 

    Callback

    Cybercriminals do not simply want to exploit systems for the fun of it, well most of them anyways. Instead most cybercriminals want to exploit systems for personal gain. In order to extract information that can be exploited for financial or other gain, the malicious payload must send this information back to the attackers.

    This transfer of data occurs during the callback phase. The callback phase is how attackers control their new asset. This connection can be used to extract information, add the compromised host to a botnet, or attack other systems on the network. 

    Public Cloud Callback

    In their ongoing struggle to evade detection, attackers use commonly available public services to mask their command and control activities. For instance, the Twittor project relay’s commands using the Twitter API.

    Similarly, the Gcat project executes commands through Google’s Gmail. By using popular public services, malicious traffic is more likely to bypass firewalls, and has the added benefit of blending in with regular traffic.

    The use of public services also provides resilience for the attackers infrastructure. Continuing with the Twitter example, all malicious traffic gets routed through Twitter’s servers. This makes investigations much more difficult as the traffic cannot be easily traced back to the attackers system.

    Persist

    Most attackers will not simply pack up and go home once they have penetrated a network. In the final phase of the cyber kill chain attackers will use whatever foothold they have gained and implement some form of persistence mechanism for long time personal gain.

    The longer an attack remains undetected, the longer an attacker can exploit their target.

    Once a foothold has been established in a victim network attackers can begin to further exploit the target. This may involve extracting valuable information, defacing websites, launching a denial-of-service attack, or moving laterally throughout the organizations network. 

    Lateral movement happens very quickly in a cloud environment. With many cloud administrators focusing on perimeter security, private networks within a cloud usually operate with very open permissions. Once a system in this network has been compromised it is very easy for an attacker to compromise other systems in the network.

    Attackers use the cyber kill chain…so should you!

    In this post I have elaborated on the various stages of the cyber kill chain, and how these stages apply in a cloud environment. When keeping systems secure it helps to take on the attacker’s mindset and understand their goals and techniques. The cyber kill chain describes the series of steps that an attacker may follow. When implementing security for a system it always helps to use a defense in depth approach.

    Some form of security can be applied to each phase of the cyber kill chain. For example, limiting leakage of sensitive information to public resources will limit the amount of information available during reconnaissance. Keeping systems patched will make it harder for attackers to weaponize and develop exploits. An effective spam filter will help mitigate delivery of phishing emails. Similarly, installing an effective personal anti malware software can prevent the initial exploit from even occurring, and an effective firewall can prevent a successful callback from reaching the attacker.

    I hope this post has increased your understanding of the cyber kill chain in the cloud. If you have any questions, please leave a comment below and I will leave you an answer!