Author: SecuringNinja

  • 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
  • How to Use nmap to Find Devices on Your Network

    How to Use nmap to Find Devices on Your Network

    Today I will show you how to use nmap to find devices on your network. Knowing which devices are available on a network is the first step to both attacking and defending your systems. It is important to identify unauthorized, or ‘rogue’, devices in order to maintain a high level of network security.

    Knowing which devices are running which services is invaluable to a penetration tester as well. Identifying which hosts are available on a network is part of the reconnaissance phase of a cyber attack. If you are curious, you can learn more about the steps involved in a cyber attack.

    Now that we know why we might want to locate hosts and services available on a network, how do we actually go about doing this? A network scan uses a variety of techniques to detect and fingerprint hosts on a network. We will be using the highly popular Network Mapper, or nmap. But first, what is nmap?

    What is nmap?

    Network Mapper (nmap) is a network scanning tool that is used to detect hosts and services on a network. Nmap can also be used to identify service versions, operating systems and much more.

    Scanning tools such as nmap are used to detect hosts and services on a network.

    Is nmap safe?

    Because nmap is such a powerful tool there are a few things you should know before you install it. The software itself is safe, as in not malicious, if downloaded from the official site linked below.

    You must run the tool as root to use the advanced scanning features. This poses its own risks and you should be comfortable running commands as root.

    There is nothing to protect you from amateur mistakes. Nmap is not an exploit tool but a scanning tool so the damage is not as extreme. However some networks do not tolerate scanning activity very well so a simple scan might turn into a DDoS attack.

    Scanning is also a very noisy activity. You will be blocked if you start scanning large swathes of the Internet. This is very noticeable, don’t do it.

    Now that we have that covered, let’s get right to it!

    How to Use nmap

    First go ahead and download nmap for your specific operating system. The download is available on the nmap.org download page here: Download nmap.

    Once you have nmap downloaded and installed we can start exploring a few of the many features available.

    This article is not meant to be a comprehensive overview of all features in nmap. It is a very powerful tool with numerous options. Instead we will highlight the more common features and options of this tool so that you can begin experimenting on your own.

    Bring up your command line and pick a host on your network. If you don’t know the IP of any devices on your network you can scan 127.0.0.1, the localhost address for now. We will discover more IPs to scan in a moment.

    If you don’t have any interesting devices on your network you can also install Metasploitable in VirtualBox. This is a vulnerable VM designed for experimenting with penetration testing techniques.

    To kick off a simple scan with the defaults just run:

    nmap -sV 192.168.1.220

    Assuming the target system doesn’t block the scan you should see some scan results shortly.

    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-26 13:15 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.0076s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    53/tcp   open  domain
    80/tcp   open  http
    111/tcp  open  rpcbind
    8081/tcp open  blackice-icecap
    
    Nmap done: 1 IP address (1 host up) scanned in 0.27 seconds

    Scanning your local network

    Before we explore nmap’s extensive command line options, let us scan our local network with a quick default scan. If your household is anything like mine, chances are you have a couple of smart phones, smart TVs, lights, you name it, all connected to your Wifi. Lets see if we can detect any with our scan.

    Get your local network range

    Before we can scan our local network, we need to determine the correct IP range to scan. Most likely your home router provides a 192.168.xx.xx type address, though various models may offer a different range such as 10.x.x.x.

    Luckily it is quite easy to determine your local network range. You can check what network your computer is using with the ifconfig command on Mac and Unix systems and with the ipconfig command on Windows. This will give you details about your network adapter, including the subnet. In the screenshot below you can see that my computer has a local IP of 192.168.1.158, and a netmask of 0xffffff00. 0xffffff00 corresponds to a /24 bit mask. Your router most likely provides the same size subnet, but if you get a different netmask value, you can use a calculator such as this subnet calculator.

    ifconfig command output
    ifconfig command output on Mac

    Initiating a scan

    Now that we have our local network range, let’s get scanning. The following command instructs nmap to scan the 192.168.1.1/24 subnet (my local network). This includes the IPs from 192.168.1.1 all the way through 192.168.1.255.

    nmap -sV 192.168.1.1/24

    We are using the -sV flag to inform nmap to perform probes on any services it finds and attempt to determine the version of software running on that port. The following is the output after running the command on my local network. I’ve left some parts out as the output can get quite long if you have many devices on your network.

    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:08 EDT
    Nmap scan report for smarttv.isp.net (192.168.1.73)
    Host is up (0.0051s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE         VERSION
    7000/tcp open  rtsp            AirTunes rtspd 377.25.06
    8008/tcp open  http?
    8009/tcp open  ssl/castv2      Ninja Sphere Chromecast driver
    8443/tcp open  ssl/https-alt?
    9000/tcp open  ssl/cslistener?
    
    ...
    
    Nmap scan report for macbook.isp.net (192.168.1.158)
    Host is up (0.00054s latency).
    Not shown: 997 filtered ports
    PORT     STATE SERVICE VERSION
    22/tcp   open  ssh     OpenSSH 8.1 (protocol 2.0)
    80/tcp   open  http    Apache httpd 2.4.41 ((Unix) PHP/7.3.11)
    3306/tcp open  mysql   MySQL 8.0.19
    
    ...
    
    Nmap scan report for 192.168.1.231
    Host is up (0.029s latency).
    All 1000 scanned ports on 192.168.1.231 are closed
    
    ...
    
    Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
    Nmap done: 256 IP addresses (9 hosts up) scanned in 194.20 seconds

    From this output we can see a couple of devices with open ports on my local network. There is my laptop, hosting an Apache web server, and my Smart TV with all manner of ports open. You can also see what the output looks like when no open ports are detected on a host.

    Now that we can initiate a basic scan of our local network, let us take a look at some command line options to further refine our scan.

    Target specification

    First let us take a look at how we can define our scan range more specifically.

    For example, you can specify a list of hosts to scan from a file with -iL. Suppose we have a list of IP addresses in the file scan-hosts.txt:

    nmap -iL scan-hosts.txt
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:17 EDT
    Nmap done: 14 IP addresses (0 hosts up) scanned in 6.19 seconds

    This instructs nmap to scan the list of IPs it reads from the file. In this case it was a list of old host addresses that were no longer in use.

    The scanner also has the ability to generate a random list of hosts to scan. This is done by using the -iR flag, and then specifying the number of hosts to scan. Be careful with this option! This will include public IP addresses! The owners of these systems may not be too happy with you scanning them.

    To use this flag simply specify the number of random hosts to scan after the -iR flag.

    nmap -iR <num hosts>

    There is also the option to exclude specific hosts or ranges. This is particularly useful if you have a slow device that takes a long time to scan. This may also be used during a penetration test to avoid scanning a known honeypot for example.

    Exclude specific hosts:

    nmap --exclude <host1> <host2> ...

    Host discovery

    The first phase of an nmap scan consists of host discovery. During this phase nmap attempts to determine if there are any online hosts within the scan range. This cuts down on the scan time significantly as nmap does not try to scan any ports unless a host is online and responsive.

    List targets to scan (good for confirming scan range)

    nmap -sL 192.168.1.1/24
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 20:41 EDT
    Nmap scan report for 192.168.1.0
    Nmap scan report for 192.168.1.1
    Nmap scan report for 192.168.1.2
    Nmap scan report for 192.168.1.3
    Nmap scan report for 192.168.1.4
    Nmap scan report for 192.168.1.5
    Nmap scan report for 192.168.1.6
    Nmap scan report for 192.168.1.7
    Nmap scan report for 192.168.1.8
    Nmap scan report for 192.168.1.9
    Nmap scan report for 192.168.1.10
    
    ...
    

    Ping scan – use ICMP only, don’t scan any ports

    nmap -sn 192.168.1.1/24

    Treat all hosts as online. This is good for when hosts are not responding to ICMP but you know they are there.

    nmap -Pn 192.168.1.1/24

    Specify whether to perform DNS resolution

    Without DNS resolution

    nmap -n 192.168.1.1/24 
    Nmap scan report for 192.168.1.73
    Nmap scan report for 192.168.1.74
    Nmap scan report for 192.168.1.75
    Nmap scan report for 192.168.1.76
    Nmap scan report for 192.168.1.77

    With DNS resolution (-R is on by default):

    nmap -R 192.168.1.1/24 
    Nmap scan report for viziocastdisplay.isp.net (192.168.1.73)
    Nmap scan report for 192.168.1.74
    Nmap scan report for amazon-74b9e7c98.isp.net (192.168.1.75)
    Nmap scan report for QCA4002.isp.net (192.168.1.76)
    Nmap scan report for QCA4002.isp.net (192.168.1.77)

    Scan techniques

    Depending on the specific target being scanned, the type of scan may need to be altered. By default for example, nmap does not perform UDP scans. If you know a specific target may be running UDP services a UDP scan would be appropriate.

    The most interesting options here are the scan types, the UDP scan, and the “special scans” (-sN/sF/sX).

      -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
      -sU: UDP Scan
      -sN/sF/sX: TCP Null, FIN, and Xmas scans
      --scanflags <flags>: Customize TCP scan flags
      -sI <zombie host[:probeport]>: Idle scan
      -sY/sZ: SCTP INIT/COOKIE-ECHO scans
      -sO: IP protocol scan
      -b <FTP relay host>: FTP bounce scan

    Port specification

    When fingerprinting a server you may already have an idea of specific ports that may be open. You can specify which ports to scan with the -p flag. You can scan a common Linux web server with the following command. This command scans ports that are commonly found on web servers: FTP port 21, SSH port 22, HTTP port 80, and HTTP proxy port 8080. The command also attempts to determine versions of the running services.

    nmap -p21,22,80,8080 -sV 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:00 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.0072s latency).
    
    PORT     STATE  SERVICE    VERSION
    21/tcp   closed ftp
    22/tcp   open   ssh        OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
    80/tcp   open   http       Apache httpd 2.4.41 ((Ubuntu))
    8080/tcp closed http-proxy
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
    Nmap done: 1 IP address (1 host up) scanned in 6.43 seconds

    You can also exclude specific ports from a general scan. For example to skip scanning port 80 use:

    nmap --exclude-ports 80 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:03 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.0098s latency).
    Not shown: 996 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    53/tcp   open  domain
    111/tcp  open  rpcbind
    8081/tcp open  blackice-icecap
    
    Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds

    Service and version detection

    Of course determining if a port is open is all good and well, ideally we want to find vulnerable services. To do this we need to figure out what versions of services are running on each port. Nmap can do this for us with the -sV flag.

    nmap -sV 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:05 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.0084s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE VERSION
    22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
    53/tcp   open  domain  dnsmasq 2.80
    80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
    111/tcp  open  rpcbind 2-4 (RPC #100000)
    8081/tcp open  http    nginx
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
    Nmap done: 1 IP address (1 host up) scanned in 7.06 seconds

    As you can see, we get a bit more information about each port now. For example we can see that this server is running Apache 2.4.41. Armed with this information we could now search for vulnerabilities in that version of Apache.

    OS detection

    Just as we want to know the versions of each service running on the system, we also would like to know the specific OS version running on the system.

    Note, this option requires root privileges. To enable OS fingerprinting:

    sudo nmap -O 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:10 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.0064s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    53/tcp   open  domain
    80/tcp   open  http
    111/tcp  open  rpcbind
    8081/tcp open  blackice-icecap
    MAC Address: C8:58:C0:10:BF:17 (Intel Corporate)
    Device type: general purpose
    Running: Linux 4.X|5.X
    OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
    OS details: Linux 4.15 - 5.6
    Network Distance: 1 hop
    
    OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
    Nmap done: 1 IP address (1 host up) scanned in 2.06 seconds

    Unfortunately nmap could not determine the flavor of linux running on the system, but we do have some linux kernel information now.

    Evasion and spoofing

    Many IDS systems will detect, and often prevent, port scans as they are highly noticeable. This section outlines some of the more common options for cloaking a scan. IDS evasion is a complex topic in itself and is out of the scope of this post.

    Scan slower

    By default nmap tries to complete a scan as quickly as possible without overloading the target system. This is great for experimenting as you want to see your results quickly. However scanning a “target” system at full speed is a sure fire way to get blocked and cut your testing short.

    Here are two scans at the slowest and fastest speeds for comparison. Any value between 0 and 5 is valid for the -T parameter.

    Scan at highest speed:

    nmap -T5 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:27 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.017s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    53/tcp   open  domain
    80/tcp   open  http
    111/tcp  open  rpcbind
    8081/tcp open  blackice-icecap
    
    Nmap done: 1 IP address (1 host up) scanned in 1.32 seconds

    Scan at lowest speed. Scanning at the lowest speed though less noticeable is considerably slower! The same scan was run with -T0. I left this scan running overnight and you can see it took 11 hours to complete.

    nmap -T0 192.168.1.220
    
    Starting Nmap 7.91 ( https://nmap.org ) at 2021-06-21 21:27 EDT
    Nmap scan report for 192.168.1.220
    Host is up (0.017s latency).
    Not shown: 995 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    53/tcp   open  domain
    80/tcp   open  http
    111/tcp  open  rpcbind
    8081/tcp open  blackice-icecap
    
    Nmap done: 1 IP address (1 host up) scanned in 11:18:39

    Nmap output formats

    Running nmap in a terminal is good fun, but ideally we would like to make use of the data that nmap provides for deeper analysis or exploitation. Other security tools for example may accept a XML file for host specification.

    Lucky for us, nmap has a number of different output formats depending on how the information is to be consumed.

    -oN <file>: Output scan in normal (default)
    -oX <file>: XML,
    -oS <file>: s|<rIpt kIddi3,
    -oG <file>: and Grepable format, respectively, to the given filename.

    The Grepable format (-oG) is perfect for further parsing on the command line or in a script. Here we instruct nmap to print output in a Grepable format to stout –.

    greg@securing.ninja[~]$ nmap -n -sV -oG - 192.168.1.220
    # Nmap 7.91 scan initiated Mon Jun 21 17:37:33 2021 as: nmap -n -sV -oG - 192.168.1.220
    Host: 192.168.1.220 ()	Status: Up
    Host: 192.168.1.220 ()	Ports: 22/open/tcp//ssh//OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)/, 53/open/tcp//domain//dnsmasq 2.80/, 80/open/tcp//http//Apache httpd 2.4.41 ((Ubuntu))/, 111/open/tcp//rpcbind//2-4 (RPC #100000)/, 8081/open/tcp//http//nginx/	Ignored State: closed (995)
    # Nmap done at Mon Jun 21 17:37:40 2021 -- 1 IP address (1 host up) scanned in 7.52 seconds

    Putting it all together

    In general, nmap is very easy to use and an effective method for discovering hosts and services on a network.

    Security professionals and hobbyists alike use nmap everyday because of its powerful features. Of course we have just scratched the surface with this post but we hope you now have the skills to start scanning systems with nmap. Take some time to read more about some of the other options and flags. There is lots more to discover making nmap such a powerful tool.

  • How to Use John the Ripper

    How to Use John the Ripper

    In this article we describe how to crack password hashes with John the Ripper (JtR). It is not unheard of to come across a file containing password hashes during a penetration testing engagement. This can be a gold mine if you can crack the password hashes.

    John the Ripper is a fantastic tool for ripping apart password hashes. Check out the full documentation here. Let us first take a look at how the tool works.

    How does John the Ripper work?

    John the Ripper is a password cracking tool capable or breaking a variety of hash types. When combined with a hefty word list such as the infamous rockyou.txt, the tool can make short work of simple passwords. John the Ripper determines the hash type of the password file and then attempts to find a match for those hashes.

    This tool also highlights the importance of choosing a strong randomized password. Cracking passwords found in a word list is 10-fold faster than running an incremental brute-force attack.

    By default the tool is capable of breaking the following hashes. If you need to break a hash that is not on the list, check the Internet. Given that JtR is open-source software it is likely someone has developed an extension capable of processing your hash type.

    • UNIX crypt(3)
    • Traditional DES-based
    • bigcrypt
    • BSDI extended DES-based
    • FreeBSD MD5-based
    • OpenBSD Blowfish-based
    • Kerberos/AFS
    • Windows LM (DES-based)
    • DES-based tripcodes
    • SHA-crypt hashes

    What is John the Ripper used for?

    John the Ripper is used by security professionals to crack password hashes. During a penetration testing engagement it is not uncommon to get your hands on a file containing hashed passwords. In order to make use of these passwords the hashes must first be broken. Lets start by getting a copy installed.

    How to download John the Ripper?

    Before we jump in, you will need to download a copy of John the Ripper. If you are using Kali Linux it is likely you already have a copy installed. This is the easiest method as it keeps all of your penetration testing tools in a single place.

    Check out the tutorial to install Kali Linux in VirtualBox. Otherwise head over to the John the Ripper home page and do the install manually: download page

    JtR is open-source software so you can also head over to the Github repository and download the source yourself.

    Tutorials for using John the Ripper

    Now that we have a copy of John the Ripper downloaded and installed we can jump into some basic commands.

    You can run the following command at any time to list the built-in help:

    $ john

    Cracking Passwords

    To actually crack passwords we need to provide a file of password hashes. John the Ripper will determine the hash types before stepping through a number of cracking modes.

    The most common cracking modes that JtR uses are:

    • Single Crack: Fastest mode if a full password file is available
    • Wordlist: Attempts passwords found in word lists, works very well against simple passwords
    • Incremental: True brute-force, tries every possible combination until a match is found (or not)

    The easiest and usually fastest method is to start John the Ripper and let it automatically step through its most efficient modes. This is usually fastest unless you know the passwords in question will not be on a wordlist.

    john passwordfile

    You can also use a specific wordlist such as one downloaded from the Internet:

    john <passfile> –-wordlist=”bestwordlist.txt”

    Or specify which cracking mode to use:

    john --single <passfile>
    john --incremental <passfile>

    This will start John the Ripper in single crack or incremental mode respectively.

    What is Single Crack Mode?

    In single-crack mode the program will use the login names, “GECOS” / “Full Name” fields, and users’ home directory names as candidate passwords. It also applies heavy mangling rules for efficient processing. Information is only used against accounts that it was taken from making this mode much faster than wordlist mode. Any successfully guessed passwords are also tried against other hashes in case users are using the same passwords.

    Word Mangling Rules

    Word mangling rules are key to making JtR more efficient. If you are trying to crack complex or long passwords you will want to operate as efficiently as possible (and even then it will take a long time, or a lot of hardware!).

    Mangling rules pre process the wordlists and make optimizations to improve the cracking process.

    john --wordlist=”bestwordlist.txt” --rules <passfile>

    Viewing Output

    Hopefully at this point you’ve cracked some passwords. You can view any cracked passwords with:

    john --show <passfile>

    This will show any cracked passwords for that password file. You can also filter the list to show users with a particular id or that are in a particular group:

    john --show --users=0 <passfile>
    john --show --groups=0,1 <passfile>

    Of course you can also pipe the output to another tool such as grep for further filtering:

    john --show | grep "some user"

  • How to Create a Kali Linux Bootable Usb

    How to Create a Kali Linux Bootable Usb

    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.

    Creating a Bootable Kali USB Drive on Windows

    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.

    dd if=kali-linux-2020.1b-live-amd64.iso of=/dev/disk4 bs=4M

    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!

    dd if=kali-linux-2020.1b-live-amd64.iso of=/dev/disk6 bs=4M

    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.

  • How to Install MySQL on Mac

    How to Install MySQL on Mac

    Welcome back to another SecuringNinja tutorial. No cyber security researcher should be with out a database to practice their skills on, or just to store tons of relational data. Today we will show you how to install MySQL on a Mac. Having a local database is perfect for running websites locally, or for providing persistent storage for another application.

    In this article we cover how to:

    MySQL is very straight forward to install on a Mac. If you do not already have the Homebrew package manager for Mac you’ll need to install that first. If you would rather not install Homebrew you can also install MySQL using the DMG file available on the MySQL site.

    Installing Homebrew on Mac

    Lets start by opening up Terminal and installing Homebrew. Homebrew is a macOS package manager that makes installing packages on macOS a breeze.

    To install Homebrew on Mac run the following command:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

    Once the install is complete go ahead and run an update to test that everything is working correctly.

    brew update

    With Homebrew installed it is a simple matter to install MySQL.

    Installing MySQL on Mac with Brew

    Installing MySQL with Brew is a breeze. All it takes is:

    brew install mysql

    This will install the most recent version of the package available on Brew. As of this writing it is MySQL version 8.0. To install a different version simply append the version to the end of the package with an @ symbol. For example, to install MySQL 5.7 use:

    brew install mysql@5.7

    If you don’t want to install Homebrew you can also install MySQL with the DMG file available for download as described below.

    Installing MySQL with a DMG file

    You can also install MySQL via the DMG file on the MySQL downloads page. This will add a MySQL preference pane in System Preferences as well. You can start and stop your server from here too.

    First begin by downloading and mounting the DMG file available from the MySQL Community downloads page. Make sure you grab the appropriate DMG for your OS version.

    Download MySQL Server for Mac from the MySQL Community site.
    Download MySQL Server for Mac from the MySQL Community site.

    Mount the DMG and double click the .pkg file to begin the installation.

    Mount the DMG and double click the package to begin the installation
    Mount the DMG and double click the package to begin the installation

    Step through the installer installer and make a note of your temporary root password. You will need this for the initial connection to the server. DO NOT LOSE IT!

    The server will require that you update your password on the first login. MySQL server is now installed. To start the server use launchctl or the MySQL preference pane in System Preferences. The server uses very few resources while running in the background so there really is no need to start and stop the server each time.

    To start the server via launchctl:

     sudo launchctl load -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

    This instructs MySQL to start when the system boots up.

    You can also start and stop MySQL through the System Preferences pane. Open System Preferences and select MySQL:

    And finally, start or stop the server as needed.

    From this preference pane you can also edit the MySQL server configuration, re-initialize the database, and uninstall MySQL server entirely. We cover how to uninstall MySQL on Mac in the next section.

    Uninstalling MySQL on Mac

    If you installed MySQL via the DMG file method then uninstalling is extremely straight forward. Navigate to the MySQL preference pane in System Preferences, and click Uninstall. Thats it! MySQL has been uninstalled.

    If you however installed MySQL using the Brew method described above, then there are a couple of extra steps.

    Uninstalling MySQL on Mac with Brew

    The steps below show how to uninstall MySQL installed with Brew. Begin by finding any running MySQL processes and stopping them. Then uninstall MySQL and remove all files.

    # Stop all running mysql processes
    ps -aux | grep mysql
    kill <pid>
    
    brew remove mysql
    brew cleanup
    sudo rm /usr/local/mysql
    sudo rm -rf /usr/local/var/mysql
    sudo rm -rf /usr/local/mysql*
    sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    sudo rm -rf /Library/StartupItems/MySQLCOM
    sudo rm -rf /Library/PreferencePanes/My*
    launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    
    # Remove user files if they exist
    rm -rf ~/Library/PreferencePanes/My*
    sudo rm -rf /Library/Receipts/mysql*
    sudo rm -rf /Library/Receipts/MySQL*
    sudo rm -rf /private/var/db/receipts/*mysql*

    What to do with your new database

    Now that you’ve got a local database up and running you may want to take a look at how a SQL injection attack works. Your new database will be great for practice! If you have any issues getting your database up and running, please reach out in the comments below. We would love to assist you!

  • 7 Types of Cyber Attacks That Could Be Targeting You Right Now!

    7 Types of Cyber Attacks That Could Be Targeting You Right Now!

    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.

    1. Phishing Attack
    2. Man-in-the-middle Attack
    3. SQL Injection Attack
    4. Distributed Denial of Service (DDoS)
    5. Password Attack
    6. Cross-Site Scripting (XSS)
    7. Ransomware

    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. 

    Phishing Attack
    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.

    How does a man in the middle attack work?
    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

    1. Prefer sites that offer HTTPS (look for the lock icon in your browser)
    2. Use a VPN to send your traffic through an encrypted tunnel
    3. 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.

    Distributed denial of service attack
    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.

    We used this same method when taking over a router with brute-force. While that example was on a much smaller scale, the attack remains the same.

    What is a cross-site scripting attack?

    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. 

    Wanna Cry ransom note
    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:

    Also keep an eye out for our follow up articles where we deep-dive these types of cyber attacks in further detail!

  • 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!

  • Fast Flux DNS: What is it? How does it work?

    Fast Flux DNS: What is it? How does it work?

    Cyber criminals are using ever sneakier tactics to avoid detection of their botnets and C&C servers. One such tactic botnet masters are using is fast-flux DNS. Fast-flux DNS was originally implemented by the Storm Worm botnet masters in 2007. Since then, numerous malware variants have used fast-flux DNS to avoid detection by the authorities.

    Fast-flux DNS involves associating many IP addresses with a single fully qualified domain name (FQDN). Botnet masters rotate the IP addresses in this pool at high frequencies, sometimes as often as once every 5 minutes. Thereby creating an ever changing network of compromised hosts known as fast-flux agents. Cybercriminals use this DNS technique to obscure the true origin of malicious sites and other resources. This allows C&C infrastructure to stay online for longer periods of time.

    In a fast-flux network the command and control infrastructure is often referred to as the mothership. The mothership consists of numerous backend servers that each facilitate the operation of the botnet.

    When a compromised host attempts to communicate with the mothership, it first makes a request to a fast-flux agent. The fast-flux agent then transparently proxies the request to the mothership.

    What is a fast-flux network?

    We know that fast-flux works by rapidly changing IP addresses assigned to a domain name. Now let us take a deeper look at how this is accomplished.

    There are two types of fast flux networks:

    • Single-flux
    • Double-flux

    Single-flux networks

    Single flux DNS works by rapidly assigning multiple A or AAAA records to a domain name and constantly rotating the active IP addresses. These IP addresses belong to compromised hosts which are known as fast-flux agents.

    Each fast-flux agent acts as a reverse proxy to the command and control infrastructure. When a compromised host resolves the domain name of its C2 infrastructure, the name server sends the IP of a fast-flux agent. This keeps the mothership hidden behind a vast network of ever changing proxy servers. As such, a compromised host only ever communicates directly with a fast-flux agent, never with the C&C servers.

    In single-flux networks the authoritative name server is often hosted on bullet-proof hosting to further increase resistance against takedown. Operators of bullet proof hosting services typically reside in areas with little to no established cybersecurity laws and generally do not comply with takedown requests.

    This makes it very difficult for security researchers to identify and take down the C&C servers. Even if a fast-flux agent is identified and taken offline, another node is always ready to take its place.

    Double-flux networks

    With single-flux only the domain’s A records are changing. Double-flux networks add an additional layer of misdirection by also changing the authoritative name server records. Network masters rotate not only the A records, as with single flux, but also the NS addresses. When an infected client attempts to resolve the domain name, it first gets the IP address of the authoritative name server. This is just another fast-flux agent which forwards the DNS request on the to the C&C servers which handle the DNS resolution.

    Fast-flux provides an intricate web of misdirection making detection difficult, and take-down almost impossible.

    With an ever changing network of endpoints and name servers there is no single point of failure in the network. Shutdown a node serving requests for a malicious website, another pops up to take its place. Shutdown the name server serving DNS requests for a malicious domain, another name server steps in and starts serving requests.

    What are fast-flux networks used for?

    As you can see, fast-flux networks are quite powerful in their resilience. Botnet masters may have thousands of fast-flux agents at their disposal allowing them to create massive proxy networks.

    This resilience and protection makes fast-flux networks the tool of choice for attackers looking to serve any less than legit content. Cybercriminals use fast-flux networks for serving malicious downloads, phishing sites, illegal marketplace sites, and even worse things such as sites dealing in child pornography and sex trafficking.

    The sensitive or malicious material is stored on the mothership. The fast-flux network acts as a layer of reverse proxies disguising the true origin of the malicious files. This is what makes the fast-flux network so powerful. Authorities are only ever able to shutdown a fast-flux node, not the actual backend content. As soon as another node takes its place, the content is available again.

    How do fast-flux networks work?

    Network masters typically divide their fast flux networks into 2 or more sub-networks. The main hosting sub-network is used for directing traffic to phishing sites, or other malicious content. While the secondary C2 sub-network is used for managing and monitoring the botnet.

    Single-flux example

    Let’s take a look at a simple example of how a compromised host may contact its command and control infrastructure. In this example let’s assume that the domain name of the command and control channel of the mothership is c2.mother.ship.

    First the compromised host makes a DNS request (1) to look up the address associated with the command and control domain, c2.mother.ship.

    Single-flux network example
    Single-flux network example

    The name server returns the IP address of a fast-flux agent. The compromised host then makes a request to the fast-flux agent (2). When the fast-flux agent receives the request it transparently forwards the request on to the C2 server (3). The C2 server returns the appropriate content to the fast-flux agent. Finally, the fast-flux agent returns this content to the compromised host. The compromised host does not even know the C2 server actually exists. It only ever communicates with one of the thousands of fast-flux agents.

    Of course this is a simplified example. In a real world fast-flux network requests are often routed between multiple different fast-flux agents before finally reaching the command and control server.

    Double-flux example

    Now that we have seen single-flux in action, let us take a look at how double-flux works with another example. Once again our infected host tries to contact c2.mother.ship. In order to locate the authoritative name server, the infected host first queries the .ship TLD for the authoritative name server for the c2.mother.ship domain (1).

    Double-flux network example
    Double-flux network example

    The .ship TLD server responds with the address of a fast-flux agent as the authoritative NS. Now the infected host sends a DNS query (or more accurately, the infected host’s DNS resolver) to the fast-flux agent (2). This fast-flux agent forwards the DNS request on to the mothership for resolution (3). The mother ship sends back the IP address of a fast-flux agent active on this domain. Once the infected host receives the IP address of the fast-flux agent, it makes a request to that agent (4). That agent once again forwards the request to the mothership and responds with the content served by the mothership (5).

    Detecting fast-flux networks

    The very nature of fast-flux networks makes them difficult to investigate. It may take years for teams to finally track down the mothership and dismantle the botnet. Fast-flux networks typically span many countries meaning varying levels of regulations apply. Dealing with cross-border bureaucratic red tape slows many investigations to a crawl. This is why some botnets such as Avalanche remained operational for years before they were finally shutdown.

    Interested in how a host gets compromised in the first place? Check out my article on the cyber kill chain, the sequence of events from reconnaissance to compromise and beyond.

    We hope you’ve enjoyed taking an in-depth look at the fast-flux DNS technique. Leave us your thoughts in 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!