Ethical Hacking With Kali Linux - Made Easy
Ethical Hacking With Kali Linux - Made Easy
Made Easy
MOHAMAD MAHJOUB
Acknowledgement
This book couldn’t have happened without the involvement of many people.
First and foremost is my wonderful family that is supporting me. My amazing
mom, my brother Tarek, and my brother Ziad. Not to forget my wonderful
friends who are providing me with the emotional support while being away
from my home country. After my family and friends, there is an amazing
team of people who have helped me write this book. Hussein Baghdad, my
online friend whom I have never met till date. He and his ghost team of
designers, proofreaders, and editors are of the main reason I’m publishing
this book. I’m truly lucky to have met Hussein; having him onboard this
journey had a huge impact in making this book a reality.
This book you are about to read had no prayer of getting in front of you
without the amazing people who have helped me acquire my knowledge
throughout the year. The journey was not easy, but totally worth it from the
learning perspective. To all of these people, I am deeply grateful.
Finally, I dedicate this book, to the soul my late father; I miss you dad.
Mohamad
September 2020
Content
INTRODUCTION
The Undeniable Power of Ethical Hacking
SETUP YOUR LAB
Why Kali?
Different Installation Methods
Install KALI
Install Windows (Target machine)
Master KALI desktop environment
SETUP YOUR KALI SERVER
Get Started with Linux Commands
Explore Main Services and Install Necessary Programs
STEPS TO PLAN A SUCCESSFUL PENETRATION TEST
Threat Modeling
9+ WAYS TO ATTACK A NETWORK
Wireshark Simplified
How Does Port Scanning Work?
How Does the UDP Scanning Work?
Introducing NMAP
NMAP and ZENMAP Simplified
Understand NETBIOS and SMB Attacks
Execute Man-in-the-Middle Attacks
Perform a DNS Spoofing Attack
Identify a DNS Zone Transfer Vulnerability
Plan DOS and DDOS Attacks
All-in-one Metasploit Framework
Create Your First Trojan and Infiltrate a Target
Explore the Powerful Armitage Tool
Hide a Payload in a JPEG Image
HOW TO ATTACK MODERN WIRELESS NETWORKS?
Introduction
WPA and WPA2 Cracking
WPS Cracking
4+ WAYS TO ATTACK A WEB APPLICATION
Web Applications Attack Surface
Metasploitable VM
Discover Vulnerabilities in Websites
Control Database Server with SQLMap
Easily Hack a WordPress Site
Intercept, Analyze, and Replay Web Traffic
SIMPLE WAYS TO GAIN ACCESS
Various Password Attacks
Hashing in a Nutshell
Execute an Offline Password Attack on Linux
Execute an Offline Password Attack on Windows:
Run an Online Password Attack on Linux
Run an Online Password Attack on a Router
Crack Passwords with Rainbow Tables
Design Effective Wordlists
PROVEN SOCIAL ENGINEERING TECHNIQUES
Attack Vectors
Open-source Intelligence (OSINT):
Google Dorks Live Examples
Collect and Visualize Data with Maltego
Execute a Phishing Attack
Hack Facebook, Twitter, and Gmail Accounts
PERFORM ATTACKSON MOBILE PHONES
Mobile Attack Surface
Decrypt TLS Sessions
Reverse Engineer an Android Application
Hack an Android Phone and Download its Contacts
MAINTAIN ACCESS
Post-Exploitation Terminologies
Backdoor Tools Explained
Netcat Simplified
Install a Backdoor
Deface a Website in Few Seconds
Understand the Hidden Tear Ransomware
Bypass Firewalls by Tunneling Data and Commands over DNS
SECRET SAUCE BONUS
Wi-Fi Jamming Tool
Create a $3 Rubber Ducky Key-logger
Introduction
The Undeniable Power of Ethical Hacking
An ethical hacker, also referred to as a white hat hacker, is an information
security expert who systematically attempts to penetrate a computer system,
network, application or other computing resources on behalf of its owners,
and with their permission, to find security vulnerabilities that a malicious
hacker could potentially exploit.
The purpose of ethical hacking is to evaluate the security of and identify
vulnerabilities in systems, networks or system infrastructure. It includes
finding and attempting to exploit any vulnerability to determine whether
unauthorized access or other malicious activities are possible.
Ethical hacking entails an ongoing cycle of research and attacks against a
target or a boundary. It is a set of processes and procedures used by
penetration testers in order to circumvent the controls of a certain information
system. These controls can be categorized into technical, administrative and
operational. At the end of the day, the owner will be presented by a
professional report that shows all of these controls, the vulnerabilities in
addition to an executive summary of the engagement.
So, what is an ethical hacker?
An ethical hacker is a person who can access the system on behalf of its
owner after getting a written consent, it is very important here to obtain the
consent. The objective of ethical hacking is to make the world a safer place. It
is a real world audit in order to reveal a certain security posture.
We have different types of hackers; white-hat hackers, black-hat hackers and
the grey-hat hackers.
The white-hat hackers are the type of penetration testers that we will refer to
throughout this book, we are the good guys. A white-hat hacker will have
access to the system on behalf of its owner in order to test it and reveal the
security weaknesses it has. Meanwhile, black-hat hackers will access systems
without any consent or permission from their owner, in order to perform
some hidden agenda.
Meanwhile, the grey-hat hackers lie in between, they usually access systems
without permission, but they do not have some hidden agenda, they just do
this for their own benefit.
The name of the game is to identify vulnerabilities in systems that can be
exploited. It is important to note that the skills that you will learn should not
be leveraged to break into anything that you do not have permission to. It is
completely illegal to access systems that you do not have explicit or written
permission to, we will perform everything on our VM, virtual machines or
the systems that you actually own.
Again, I repeat, this is very important. Please do not exercise the skills that
you will learn throughout this book to attack systems you do not own.
As Kali is updated on a daily basis, the GUI and the screenshots available in
this book might for some of the applications look slightly different from the
ones in the version you are using.
The default look and feel after employing the sudo su is clear format. To
add the original format, you need to replace the content of the .bashrc file
with the content of this file on my GitHub repository, as seen below
https://github.com/redpython961/kali/blob/master/bashrc.txt
To do so, Install leafpad using sudo apt-get install leafpad , open bashrc file,
then replace its content from the content of the GitHub file, then save the file
and restart the terminal.
root@kali:/home/kali# leafpad ~/.bashrc
Install KALI
You need to go to the VMware website and install the VMware Workstation
Player from there. It is a free tool if you are using it for your personal
purpose, but if you are using it for commercial use, it has an active license
only for a few days. So, feel free to download this player and install it from
the downloads section or you can go directly to the following website
https://www.vmware.com/products/workstation-player/workstation-player-
evaluation.html.
You can as well use Oracle Virtual Box from
https://www.virtualbox.org/wiki/downloads, which will do the same job.
Once you open the VMware Workstation Player for the first time, it will be
empty since there are no virtual machines yet. What you need to do is to go to
www.offensive-security.com website or https://www.kali.org/downloads/ and
download the Kali Linux VMware image from there.
In this case, I will be downloading the 64-bit version. The downloaded image
will be in a compressed form, so you need to extract it, and then go to your
VMware Workstation Player again, press on Open a Virtual Machine link
(see below), navigate to the files extracted, locate the VMX file, and press
open.
As you will notice, the virtual machine name pops up under the home button,
you can directly press on the ‘Play virtual machine’ or you can edit the
virtual machine settings in terms of resources.
Two gigabytes of RAM are enough for the machine to run. Keep the other
default settings and press on the ‘Play’ button.
After some time, the login screen will pop up and you will have to enter the
default username which is kali and the default password, kali. Make sure you
are using the credentials relevant to the release you ae using.
After logging on for the first time, the resolution might be incorrect. For this
purpose, you can open the main menu, press on Settings, then select Display
to setup the proper resolution.
Set the memory for the virtual machine to 2,048 MB, and press ‘OK’. Now
we have the windows 10 machine up and running and we have our lab setup.
Master KALI desktop environment
Press on the main menu (see below), to find that there are more than 300
applications used for penetration testing, security auditing, forensics, etc.
These 300 applications are well spread over the categories of information
gathering, vulnerability analysis, web application analysis, database
assessment, password attacks, wireless attacks, reverse engineering, etc. It is
easy to spot an application directly under the category of attacks that you are
planning to do.
The menu item next to the main menu is the File Manager, as in Windows.
You can navigate directories just by double clicking any folder. You have the
option to open a directory as GUI or in the terminal.
Also you can see the workspaces toggle buttons. The concept of workspace is
important if you are planning to running multiple applications, so that you
can switch between them without disrupting the display.
For example, if we have an open terminal, and some other applications, the
terminal will be workspace one, we can go to workspace two and open other
applications without even closing or disrupting the initial applications open.
Itis a brilliant feature in Kali.
You can see as well the wired connection, wireless connection(s) if there is
any; virtual machines usually cannot access the internal (built-in) wireless
card. You will learn under the wireless section how to set up this, you can as
well turn off the machine, using the log out button, with the below options.
Feel free to explore the desktop environment and get familiar with it.
Setup Your KALI Server
Get Started with Linux Commands
It is important to learn a couple of Linux commands before continuing with
this book. We are not going to go deep into scripting, but shed the light on
basic Linux commands that will help us jumpstart and continue the rest of the
book.
Many of the applications have graphical interfaces, so we will be able to
make most of our penetration tests within these graphical interfaces. But
learning command line is very powerful and very helpful; I bet you will enjoy
it. Some of the commands we will use are listed below. Remember to use the
sudo command if you are using the default kali account.
passwd
ls
pwd
cd
mkdir & rmdir
locate
man & help
cat
nano
leafpad
grep
less
ifconfig
display
The best practice whenever you log in to any new machine is to change your
current password. The tool provided by Kali is passwd . Type passwd and
follow the wizard. We will enter the password in the text box and write it
again, and the new password is setup.
The next command is the ls , which means list. If you press enter, it will list
all the directories and files in your current working directory. ls has some
arguments that can help you explore more about the files you are listing.
For example: ls-l . If you want to know more about these arguments that you
can pass, you can use either Help or Manual. For the ls program, we will
type in help and you will see all the help provided with the ls program, all
the arguments and how we can use all these arguments, it is pretty much
helpful as you will see.
On top of that you can use the man command as well. Man means manual
man <space> ls , then you hit enter, it will show you the manual provided
with this command. Some of the programs provide manual and others do not
provide manual, it depends on the program that you are using.
The next command is cd or Change Directory. If you want to know your
current working directory, you can use the command pwd (Print Working
Directory).
It is important to mention that all these commands in Kali and Linux in
general are case sensitive. So if you write pwd (P uppercase), it will tell you
that the command is not found. So you should write everything in the lower
case as pwd .
We will get our current working directory, which is the root, we can list the
files, we can change using cd command, and we can go to any of the
displayed directories. For example: Music (M in uppercase).
So, if you want to go back to the original path or directory, use: cd <space>
<dot><dot> , and you are back to the directory. You can as well toggle
through the previous commands that you used, using the up arrow and down
arrow. Even if you close the terminal and open it again, you can still use the
up and down buttons for this purpose.
The next command on our list is the Make Directory. So, we will use ls
again, then go into Music folder for example and create a directory: mkdir
pop . We type ls again, and we will get the directory, I can remove this
director as well using: rmdir , or remove directory, pop, ls again.
One of the important commands cat , which helps us print the content of the
file to the terminal. For example, if we have a file on the desktop called:
demo.txt, and we want to print the content on the screen, we can use cat ,
then we have to write the name of the file. The content of the file will be
displayed as shown below.
If we want to change the content of the file, we can use another command:
nano <space> the name of the file (demo.txt), then the nano program opens
and we can simply edit the file.
We can add records at the end and then press "control x", it asks us: "Do you
want to save?" we will say "Yes". If you used nano again, you will see the
file updated.
One of the important commands that we will be using through this book is
the grep command. grep searches for a string in a file. And this is very
important when we are doing our analysis, sometimes we want to search for a
certain text within a file or within a list of returned values, this application
will help us a lot. So if I use the same file (demo.txt and search for the word
command, for example, I use grep , command and name of the file, and it
returns back the command word along with the line where this word appears.
Another command that can help us, especially when we are looking into huge
files, is the less command. So, we can choose a huge file, and we will use
less , and then we will paste the file name and then open it. So, it opens the
file, but not at once, you can sequentially go forward or backward in this file
by using the “Control F” to go forward and “Control B” to go backward.
It fetches the file bit by bit, so you will be able to view it moderately, and if
you want to quit just press Q and you are out of the file.
Another important command to use is the ifconfig , which is similar to the
ipconfig on Windows machines, it displays the current IP that we are using,
as well as the subnet mask and the default gateway.
Another useful command is locate , which is used to find files in a very
quick way. But before that, it is recommended to use the updatedb
command, which will build a local database for all the files on the system.
And then when you can use the locate command. You will be using this
database to determine the location of the file. Suppose that we are searching
for a file called "crontab", it will return the file in all the paths.
If you want to clear the screen, just use the clear command, it clears
everything, and you can still use the up and down arrows, to retrieve previous
commands.
The final command to talk about is the uname command, which shows you
the version of Kali you are working on.
The next service we will discuss is HTTP, which is mainly used to host
websites. So again, if you want to start the service, the command is:
sudo service apache2 start
And if you want to see if the service is running, we go to the same netstat
command, and instead of SSH, we type apache2 , and you will see the
service apache2 running on port 80.
We can stop the service as well by using “stop” instead of “start”. It is a
pretty straightforward task, just type the name of the service, then “start” or
“stop”.
Now we will learn how to install services that are not available by default in
the distribution, such as FTP. If we type for example:
sudo service vsftpd start
We will get an error, it is actually not installed. So how do we install it?
We use the command:
sudo apt-get install vsftpd
It will take some time to install the service. If we want to run the service as
we did before, use the command:
sudo service vsftpd start
To verify if the service is running, we use the command:
sudo netstat-antp | grep vsftpd
We will see that the FTP service is running on port 21 as shown below.
Starting and stopping services manually each time is not a practical thing to
do. There is a way that enable these services at boot time. For this purpose we
can use the following command:
sudo update-rc.dssh enable
This command will enable SSH to start automatically at boot time. We can do
the same for the rest of the protocols. If you need to disable the service, use
the command instead “disable” instead of “enable”.
Steps to Plan a Successful Penetration
Test
Planning a penetration testing exercise is the name of the game. It always
starts with the reconnaissance phase, and ends with the reporting phase.
Below is the list of some tools and techniques used in each of the phases.
Threat Modeling
Threat modeling is understanding the system we have at hand, whether it is a
mobile application, web application, or even a network, and identifying all
the possible threats it would face and assessing the threat scenarios that might
happen.
In straightforward terms, it is about finding different ways within which our
system can be attacked, and subsequently designing countermeasures to stop
these attacks. Threat modeling helps us become more proactive and strategic
in our operational and application security. The ultimate goal is to reduce the
attack surface and focus on the investment of the business itself.
It actually starts by a couple of questions, what are we working on? So, we
have to identify the assets and then what can go wrong?
After identifying the assets and attaining the architectural overview of the
system, we ask ourselves several questions, "How can the system be
attacked? what can go wrong?" We need to pinpoint those questions. After
that, what are we going to do about it? So, we start thinking about
countermeasures and the controls we will have in place, and at the end, we
need to assess our job, "Did we do a good job?"
Threat modeling springs from the trivial risk assessments model. We need to
identify threats in the first place, whether it is process, it is software, it is an
attacker, anything can be a threat. The threat can attack our systems by taking
advantage of weaknesses we have or vulnerabilities we have.
The purpose of a threat modeling is to close the gaps of vulnerabilities, to put
controls in order to close those vulnerabilities.
Different methods and techniques are used by pen testers, practitioners and
analysts to understand the variety of information security risks. Some of
those structured threat modeling techniques are Attack Trees, Stride Method,
Elevation of Privileges, T-Map, Petri net, Data Flow Diagram, Activity
Diagram and Risk Reduction Overview. One of the most famous models used
is the Stride model.
After having the architecture overview or after simplifying our process or
system and projecting it on a diagram, we start thinking about what can go
wrong? How does this web application or mobile application workflow go?
Do we care about what can go wrong with this application for, example?
Does it have financial information? How about the content? Where is the data
stored? Etc.
We spend much of time analyzing each of the steps in our architectural
overview; one of the simplest techniques that can help us is Stride. Stride is a
mnemonic for spoofing, tampering, information disclosure, repudiation,
denial of service and elevation of privilege. The technique is used for
identifying a threat in these six areas. See the detailed explanation below.
Threat Definition Property Example
Spoof identify Pretend to be Authentication Hack an email
someone else and send a
message under
the name of
the victim
Tamper data Changing data or Integrity Change the
code source code of
an application
Repudiation Deniability Non-repudiation No I did not
send this email
Information Leakage of Confidentiality PII
Disclosure sensitive information
information available on
the Internet
Denial of Non-availability Availability Web
Service of service application not
responding to
user requests
Elevation of Perform Authorization Normal user is
Privilege unauthorized able to delete
actions other accounts
This is a full round TCP connection. You might have noticed that the server
always replies with the sequence number plus one, then the client replies with
the previous sequence number plus one.
Similarly, the same routine is followed when we are terminating a
connection. The client sends the server a FIN packet, then the server replies
with a FIN/ACK packet, then the client confirms with an ACK packet and the
connection is terminated.
To demonstrate and show example from Kali machine, we will connect using
Netcat, and we will try to use the previous example of texting using the
chatting between the client and the server, then we will fetch the traffic and
analyze the traffic and see what happened.
To open Wireshark, you go to the menu under sniffing and spoofing. First of
all, you need to filter the interface that you want to capture traffic on. You
will discover that, by default, you have lots of filters and if you capture all the
traffic coming on these filters, you will end up with a huge amount of data
and information.
It is very important to understand the layout of the Wireshark, it is divided
into three main views. The most important part is the capture engine, it is
capturing the traffic based on the capture filters defined; on top you will find
the display and the display filters. (See below).
So, certain activity has been taking place between the client and the server.
Now we can go to Wireshark and stop the packet capture. We will end up
with a small capture, similar to the one shown below. All you need to do is to
right click on one of the TCP packets and follow the TCP stream, to be able
to view the data communication between Kali and the Windows machines in
clear text.
How Does Port Scanning Work?
Port scanning is the process of checking for open ports, TCP or UDP ports on
a remote machine, it is very important that you think of the traffic
implications of your scans before you perform any, as it might have possible
effects on the target machines.
We have two methods for scanning a TCP port, the first method is called
Connect and the second method is called Syn/Stealth. The first method is
purely based on the three-way TCP handshake mechanism. The Connect port
scanning involves attempting to complete a three-way handshake with the
target host on the specific port. If the handshake is totally completed, this
indicates that the port is open.
As for the Syn/Stealth scanning, it is a TCP port scanning method that
involves only sending Syn packets to various ports on the target machine
without completing the three-way TCP handshake. If the TCP port is open a
Syn Ack packet should be sent in return. And this means that the port is open
without the need to send the final packet to the target machine. It is called
stealth because with the early and primitive firewalls, this method opens half
a three-way handshake connection and often bypasses the login of the
firewall, but this is not the case anymore with the new firewalls, as your
scans will be detected.
UDP scanning is different than TCP scanning; as we know TCP is connection
oriented while UDP is stateless, so it does not have a three-way handshake
mechanism. So, scanning a UDP port is somehow different than scanning a
TCP port. It is actually important to get into these details as understanding
these basics will help us a lot going through this book.
Introducing NMAP
Many systems and network administrators find Nmap useful for tasks such as
network inventory, managing service upgrade schedules, and monitoring host
or service uptime. Before going further with exploring different options on
how to use Nmap, it is important to understand the basic options, because
will can get complex later on. Nmap is a case sensitive tool, so make sure you
type in the proper case, as shown below.
Option Name Description
-sS TCP SYN The default and quickest way to scan
scan thousands of ports. Half-open
scanning.
-sT TCP Connect The system call completes connections
Scan to open target ports rather than
performing the half-open reset that
SYN scan does.
-sU UDP Scan UDP scan works by sending a UDP
packet to every targeted port
-sN TCP Null This option sends TCP packets with
Scan none of the TCP flags set in the
packet. If the scan is returned a RST
packet it means the port is closed,
however if nothing is returned it is
either filtered or open
-sn Ping/Sweep Only send ping packet to the target, no
port scanning. This is useful if you
need to determine what hosts are in the
vicinity, but do not want to scan them
yet
-v Increase This will give your extra information
verbosity in the data outputted by nmap
-T4 Timing 0: paranoid, 1: sneaky, 2: polite, 3:
template normal, 4: aggressive, 5: insane
-sV Enumerate Actively probe open ports to try
determine what service and version
they are running
-P Port Comma separated list of ports to scan
-oG Grepable Redirect the output to a text file
output
-F Fast mode Instead of scanning as many ports as
the default scan does, the fast scan
only scans the common 100
-O Check OS nmap tries to determine the OS type
-A Check OS + Detect OS and Services
-Pn Skip Assume the host is up thus skipping
discovery the host discovery phase
--script Use script This argument takes in a comma
separated list of files, categories and
directories containing NSE scripts
The -sS option stands for the TCP syn scan, which is the quickest way to
perform a scan, as mentioned before. It is based on half opening the TCP
three-way handshake. As for the -sT option, we are telling the Nmap to use
the three-way handshake to establish a connection with the target and to
determine if the ports are open. When we are scanning ports that are based on
UDP, such as DNS, we have to use the -sU option.
Another option to perform a scan is to use the -sN option, which basically
sends TCP packet with no flag set because the SYN packet and the
SYN/ACK and the ACK packets have a flag set, like the sequence flag and
the ack flag. So, we will send a packet with null flag set or zero flag set, if the
scan returned an RST or rest packet, it means that the destination port is
closed. However, if nothing is returned, it means that the port is open or
filtered. The -sn option stands for pinging or sweeping the target, we are
pinging the target just to know if it is alive. So, if it is alive, we might take
into consideration the next step of scanning it, so it is just probing the
network without actually scanning.
The -v option is used to increase verbosity. This will give us extra
information and progress information about our scan, the -T option is a
timing template, in where 3 is the default option, and 5 is the fastest one or
paranoid, while zero is the slowest one. It can take you from a couple of
milliseconds, performing an insane scan, up to a couple of minutes
performing a paranoid scan. The -sV option is used to enumerate and
determine the services and the version of the OS that is running on the
destination host. -P stands for port, -oG is used to redirect the output to a
text file for further analysis. -O is used to check the OS type, -A is used to
detect the OS and services running, the Pn is used to skip discovery and just
pretend that the host is up and running and implement the scans, and the --
script is to inject the Nmap scripting engine which is very useful in
performing what is beyond just port scanning.
You can get the same results using a hostname instead of an IP address, for
example:
nmap www.abcd.com
If you want to scan a range of IP addresses, or a subnet you can use:
nmap<then the IP address range>
If you have a determined list of IP addresses, put them in a text file, and issue
the following command:
nmap - iL<then the name of the file>
Scanning a specific port requires the usage of the -p option as seen below.
If you want to do a fast scan, you can use the attribute F which scans the
most common used ports. It is good to mention that the default nmap
command scans thousand ports and can take some time. So if you want to
scan the most common port numbers, use the minus -F attribute. Notice that
we have the SSH port open in addition to the Netbios port, SMB ports are
open as shown at the bottom of the below example.
If you want to do an extensive scan for all the ports, issue the following
command:
nmap -p 1-65535 -T4 -A -v IP address
It will take a huge amount of time, because it is scanning almost all the
65,000 ports.
Some attributes to understand:
-p is the port numbers from one till 65535.
-T4 template is the timing template. Actually, this is an attribute that
can go from T0 to T5. T0 being the slowest type of scan, and T5 being
the fastest type of scan, we are controlling how the response of Nmap
and how fast it is in this scan. So actually, this is a timing template and
it gives the user an easy way to tune how fast Nmap performs.
-A attribute is an option that allows Nmap to make effort in identifying
the target OS, the services and the versions. It also does a trace route
and as well applies some NSE which are engine scripts in order to detect
additional information. This is a huge scan and it is actually quite noisy
as it applies to many different scans.
If you want to select the type of the scan, use the following command:
nmap -sT <the IP address>
As we mentioned earlier, we have two types of scans, the syn scan which is
the default one and the connect scan. If you want to force Nmap to use the
connect scan, you issue the attribute -sT . If you want to use the default type
of scan, use -sS attribute.
If you want to scan UDP port, you use the attribute -sU and then you need to
specify the port types or the port numbers that you are scanning.
If you want to output the result of a certain scan to a text file, use the -oG
option to find the result of the scan in the text file you specify.
There is another tool named enum4linux , used for the same purpose. The
syntax is enum4linux then -a option, and then we put the IP address. This
tool enables you to have more information than the NBTScan. The target
windows machine used in the below example is recent, so you will not be
able to find these vulnerabilities that exist in the previous SMB version. But
to give you an overview of what this tool is, you will have information about
the users created on this machine, the groups, the password policies, the
details of the password policy, the host, the UX and some share information.
This is an outstanding tool when it comes to discovering SMB vulnerability.
Under anomalous situations, Mr. Bad, a malicious user, will have access to
the network, it is very important to have access to the network, because this
attack only works this way. Mr. Bad will then send fake ARP replies saying
that his MAC address is associated to the advertised IP address. So, as you
can notice, there is no request for ARP, but Mr. Bad was able to send the
reply. This is the vulnerability in the protocol, you do not need to be
authenticated in order to send an ARP reply, and any host can just connect to
the network and send the fake ARP reply message. In this case, Mr. Nice will
cache this message that the IP is associated with the MAC address of Mr.
Bad. ARP protocol is the de facto protocol in network communication, with
such a vulnerability!
Anyone having access to the network can take advantage of this vulnerability
and route the traffic to their machine. This kind of attack has some legitimate
uses in some cases. For example, especially in server fail-over cases, some
server can take on the traffic of another server in case of a failure. But this is
not well used because it needs dedicated tools to be employed.
To execute an ARP poisoning attack, go to the Windows machine, which is
the victim's machine, and type ipconfig . The default gateway of this machine
is 192.168.211.2. In order to get the MAC address of this default gateway,
just type the command arp-a , and you will find the cached entries on this
machine. The first entry is the default gateway and the MAC address ends
with d2, as shown below. Don’t forget to invoke the sudo command.
Our aim is to change this cached entry. Now go to your Kali machine and
open a terminal, write ifconfig to get the MAC address of this machine,
which again is a malicious machine that has an illegal access to the network
of the victim.
As demonstrated in the image above, the MAC address the KALI machine
ends with 4b. A good tool to do the ARP poisoning attack is called Ettercap,
it is found under sniffing and spoofing tools. Open the application, press on
the Sniff menu and press on unified sniffing and select the interface, and then
you go to the Host menu and press on Scan for hosts. Ettercap will identify
all the hosts on the network. If you want to see the host list, just press on the
Hosts menu , and then Host list sub-menu. Select the IP address of the target
machine, in our case it ends with .129, and then press on Add to Target 1
button. Next go to the Mitm menu (can be a menu icon), and select ARP
poisoning, select the option of only poison one-way, and press OK. Now a
fake ARP reply has been sent to the target machine. To verify this, go to the
target machine and type arp -a again in the command line.
Before starting with this attack, make sure to change the UID and GID to
zero. Default configuration starts with 65, whatever number is, just make sure
that it is zero, so you can use this file.
You can see the file has lots of translations, we’re interested in these
translations, so make sure to comment microsoft.com entries for the
hostname, just make the pointer there without comment and add a star, so we
will be creating a host entry and redirect them to the local IP, as shown
below. And make sure to save the file and then close the file.
Now open the Ettercap application, and start sniffing on the interface, then go
the Hosts menu, and scan for hosts submenu. Now we will be able to
discover the hosts available on the network. Select the target machine, that
ends with .129 in our case, and press on Add to Target 1. Go to the Mitm
menu (can be a menu icon), select ARP poisoning sub-menu, tick Sniff
remote connections, and press OK.
Now go to the Plugins menu, click on Manage plugins sub-menu, click on
dns_spoof plugin to activate it. Now everything is up and running. Go the
victim's machine and try to browser any website, to be redirected to our fake
page.
The script will loop through all the name servers and get all the DNS records.
It will try the first name server, and this would result in all information
associated. Similarly, the second name server would result in all the
information of the records as well.
We will use the console command to run Metasploit, so open your terminal
and type msfconsole , and press enter. It will take some time to initiate the
database and connect to it. You will notice that the cursor has changed as we
are in the Metasploit framework now. Before going further you might have
noticed that the architecture has libraries as well. We have three main
libraries which are Rex, MSF core and MSF base.
The Rex library is the basic library for most of the attacks. It handles
operations like protocols, text transformation, sockets, etc. The MSF core is
the core library that provides basic API, and the MSF base provides like
additional or friendly API.
As of now, this framework has around 2000 exploits, 1000 plus auxiliaries,
560 payloads, and 45 encoders.
With a large number of exploits, searching becomes necessary. The easiest
way of using the search function is to issue the command search followed by
a search term. For example, type ‘search exploits’ to retrieve all the exploits
are available in the framework at the time being, the description of the
exploit, the name of the exploit, etc.
We can improve the search process by specifying the platform that we are
looking for exploits into. So, we can select Windows operating system for
example, and we will get all these exploits related to the Windows system
which are many. A better example is to narrow the search to Android to
notice that it returns the exploits that pertain to the Android platform. To
select an exploit, type in the word use, then show info to retrieve the
description of the exploit.
In the example above, we have chosen to use the exploit
payload/php/reverse_php. To setup the exploit, issue the show options
command. Notice that the argument LHOST is empty, and we need to
populate it as it is required. You can do that using the command set LHOST
and then an IP address. Type show options again, to see he populated
argument, as shown above.
Type show payloads , to view the payloads related to the current exploit.
You can now use these payload along with the exploit.
Step 5: Some of the initial post-exploitation commands you can use are:
sysinfo , to see the system info of Windows 10. You will be able to see the
computer name, the OS, the architecture, the domain or a workgroup, and the
current logged on users.
ls , to list the directories
ipconfig , to see the network configurations of the remote machine
You can as well search for any files on the compromised system. For
example, you can search for files of any type and download them to your
machine. In the below example, I will be downloading the file hobbit.txt. Use
the download command and paste the path and make sure to change the back
slash to forward slash.
You can go to a new terminal, type ls to verify that the hobbit.txt file has
been downloaded. You can do the same for any file on the compromised
machine.
One of the most important commands we can use is the shell command.
Once we use it, we will be able to acquire a Windows shell; now you can
type in all the commands you are familiar with.
One of the important features of Armitage is the Hail Mary. It is the Brute
force, in a way Armitage will try all of the relevant attacks possible on a
target. This attack is noisy, as it will consume the network a lot. It is not
recommended to try it, meanwhile it is recommended to try individual
attacks. The module pane is a file tree structure which is easy to navigate.
The command line pane or the console pane will show you the commands
that are being invoked by Armitage.
Let us create a payload, move it to the Windows machine, run the payload
from the Windows machine, and acquire a Meterpreter session from
Armitage. To do this, go to the modules pane,
payloads → windows → meterpreter, select meterpreter_reverse_tcp and
make sure to select a port that is easy to remember, for example 9090. From
the output, select exe file. Then we create an exe file, which is our payload.
Under the Kali machine, we need to create a handler to manage the incoming
connection from the compromised target. Again, double click on
meterpreter_reverse_tcp. Select multi handler and make sure you use the
same port that we used earlier.
WPS stands for Wi-Fi Protected Setup. It allows you connect to your wireless
router faster and easier. WPS only works on wireless devices that support
WPA Personal or WPA2 Personal. It doesn’t work on devices that use WEP.
Typically, if you want to connect a device to a wireless network, you must
know the SSID and the password, except it’s an unsecured Wi-Fi network.
However, you don’t need to enter any password if use WPS button.
To connect a device, such as your laptop, or smartphone, to a wireless
network with the WPS feature, press WPS button on your router. Go to your
laptop or smartphone, select and connect to your wireless network name.
Your device will automatically be connected to the wireless network, without
asking you provide any security password. This method works for all devices,
including wireless range extenders, or wireless printers. It helps you make a
quick connection between your Wi-Fi router and your device.
Why Wi-Fi Protected Setup is Insecure?
Along with this “Push To Connect” feature, you can also fill out a PIN (eight
numbers) to connect to your wireless router. All wireless routers that come
with the WPS feature always have this eight-number PIN code. It is an
automatically generated code and can’t change. If your wireless router
supports WPS, but don’t have a WPS button, the Wi-Fi connection can be
established with this PIN code.
However, rather than check all eight numbers, many wireless routers only
check first four numbers. Therefore, the WPS PIN code can be guessed with
the brute-force method. Many routers don’t have the limitation function that
defines how many times you can try. So, attackers can guess the PIN code
over and over and over again, with the help of tools.
This “Push To Connect” feature is more secure than the PIN method. The
reason is attackers only can access your wireless network by physically
getting into your home, walk to your router and then push the WPS button.
How to Disable WPS (Wi-Fi Protected Setup)?
Most wireless routers enable WPS feature by default. If you want to disable
it, access the administrator control panel of your wireless router via IP
address, Once you have accessed, locate the WPS feature and disable it.
Depending on the brand of your wireless router, the WPS function can be in
different locations.
So even if you change the common phrase and WPA, you can still run some
applications in Kali to recover the password in a means of seconds, not even
minutes.
We will approach each wireless protocol or setup differently to perform our
attacks. For WPA2, we will be using airmon , airodump and aireplay
tools. Airmon puts the wireless card into monitoring mode, so it will monitor
what's going on around you. The airodump will save the traffic that's going
on around you to a PCAP file. Aireplay will enable you to inject packets into
this traffic; we'll see this in details.
By default, the virtual machine version of Kali does not have access to the
built-in network card. So, I will be using an external USB Wi-Fi adapter. A
TP link wireless USB adapter is recommended. Press connect and you will be
able to have a Wi-Fi connection on your virtual machine, as shown below.
You can as well use Kali live bootable DVD for the purpose of this setup.
This command will help us capture all the wireless traffic in our range. The
BSSID is the MAC address of access point or Wi-Fi. The CH represents the
channel in where the connection is running on, the encryption type is mostly
WPA2 for all, and ESSID is the name of the connection. I will do this attack
on my network named Majo. Press control + C to stop the capture.
Now that we have some information about the access point we need to attack.
The next step is to feed those arguments to airodump-ng in order to write
the traffic related to the specified hotspot to a file. We will use airodump-ng
with arguments such as w to specify the file that we will capture the traffic to,
let us name it attack1. The c argument is to specify the channel number,
which is channel five in our case, and then BSSID which is the MAC address
of the access point.
airodump-ng -w attack1 -c 5 –bssidE4:6F:13:31:65:1C wlan0mon
Now you will see all the endpoints connected to the specified hotspot. The
cap file will be capturing all the related traffic under the BSSID specified. In
order for us to perform the attack, we need one more thing; to capture the
wireless handshake. We have two options here; either you do this manually
since we are testing on our local spot. So, you disconnect one of your
workstations or smartphones from Wi-Fi and reconnect again, so that you
will be able to capture the handshake, or you can inject a de-authentication
packet so that certain Wi-Fi client will reauthenticate, thus you will be able to
capture the handshake.
To do that, open the terminal and type the airplay-ng command as shown
below. The zero argument is for de-authentication, the argument 10 is to
specify the number of de-authentication packets that you need to send, you
can use any number, the -a argument specifies the source MAC address of
the hotspot. We need to send these packets to a workstation or a smartphone
connected to the hotspot, here you specify the host Mac address using the c
argument. The WPA handshake should appear on the active traffic capture
screen, as shown below. and you will be able to get a capture file with a
handshake.
aireplay-ng -0 10 -a E4:6F:13:31:65:1C -c 0C:8C:24:0F:66:A8
wlan0mon
Now that we have a cap file that has a WPA handshake, we are ready to crack
the “Majo” Wi-Fi network. Type in the command aircrack-ng with the -w
argument, which stands for a word list. The thing here is that WPA2
networks are very strong and we cannot just crack them by trial and error like
we do for example in web. So, we need to use word list. Depending on if you
have a strong word list, you will be able to crack this hotspot better, if you
have a weak word list, you will not be able to crack that.
I will use a wordlist that I have created. The aircrack-ng command will go
through all the passwords in the file and try them. Argument -b stands for
the BSSID we are attempting to crack. End the command using the cap file
we captured, as shown below. We are now ready, just press enter, and you
will see that the key was found, as shown below.
WPS Cracking
In the previous section, we cracked a WPA2 access point after capturing a
wireless handshake, and running the file capture against a wordlist. The
efficiency of the attack will mainly depend on the strength of your wordlist.
Sometimes the passwords will have upper characters, special characters,
numbers, etc. and it can take years to crack and access a hotspot. Here comes
the WPS cracking to offer an added value in terms of cracking an 8-digit pin
on the router and not a password. Luckily, we don’t need to crack the full 8
digits, but the first four, which gives us a realistic combination of number to
guess.
The good thing once you have the WPS PIN; is that even if the victim
changed their WPA2 password, running Reaver tool against the same access
point with the same WPS PIN will give you the current password or the
changed password in a matter of seconds.
So, let us go directly and run this Reaver application. First of all, enable the
monitoring mode on your network interface using the airmon-ng command,
then issue the command wash -i wlan0mon . This command will show you
all the neighboring access points, you will see the version of the WPS and
whether it is locked or not.
Go to the terminal again and type reaver -i to specify the interface, and then
-b to specify the access point MAC address, and run -vv which stands for
very verbose to view the updates on the terminal. Invoke the command and
leave it overnight, at the end, the Reaver will display WPS PIN and will
display the current WPA2 password.
reaver -i wlan0mon -b E4:6F:13:31:65:1C -vv
Suppose that the victim changed his password, all we have to do is to run
Reaver again with the same command plus the eight digit PIN that you
already got from the previous attack (12345670 in this example), and Reaver
will just display the new password within a matter of seconds.
reaver -i wlan0mon -b E4:6F:13:31:65:1C -vv -p 12345670
This list includes detailed best practices for both the detection and
remediation of vulnerabilities. Building on the success of the previous
OWASP top 10, which is the 2013 version available on the left side, OWASP
has produced an updated list.
The OWASP compilation is mainly done by examining both the occurrence
rate and the overall severity of each of the threats. A couple of things
changed from the 2013 version to the 2017 version, two of the items, which
are A4 and A7 from the 2013 version, institute direct object reference, and
missing function level access control, were emerged to one item in the 2017
list, which is the broken access control. Couple of items from the 2013 lists
didn't qualify to be in the 2017 list, which are the cross-site request forgery,
and invalidated redirects and forward. On top of that, we have a couple of
new items in the updated list, which are the XML external entities
vulnerability, insecure deserialization, and insufficient logging and
monitoring.
Injection
If your application is receiving user input that goes to the back-end databases;
then your application might be vulnerable and can face code injection attacks
if the input is not handled well. Injection attacks are set of security
vulnerabilities which occur when an attacker sends untrusted data to an
interpreter that is executed as a command without proper authorization.
Injection types are SQL, OS and XXE, which are the XML external entities.
Broken Authentication
When an application functions are not implemented correctly, the attack
surface is open for attackers to easily break in and compromise password,
session IDs, etc.
So, sessions should be unique to each individual user and without some
necessary session management, an attacker can sneak and steal credentials
and information.
Sensitive Data Exposure
As the name says, it occurs when security controls such as HTTPS are not
implemented correctly, thus leaving a hole for attackers to steal sensitive
information such as financial data, usernames, password, IDs, PII
information, etc.
XML External Entities
XML external entities attack is a type of injection attack, and it happens when
the application parses or takes XML input and parses them. The attack occurs
when the XML input contains a reference to an external entity that is
processed by a weak XML parsing, so this attack will lead to different
leakages such as disclosure of information, denial of service and server-side
request forgery.
Broken Access Control
Broken access control is a result of merging the insecure direct object
reference and missing function level access control. Access Control is meant
to control what authorized users are allowed and are not allowed to do within
a web application and to establish proper access control. When this is not
implemented correctly, attackers will exploit this to perform unauthorized
tasks.
Security Configuration
Security configuration is the most commonly seen issues according to
OWASP, strong security requires good and secure practices of configuring
applications, frameworks, servers, databases etc.
Cross-site Scripting
Cross-site scripting is the most famous one on the list in my opinion, and it
allows attackers to inject client site scripts into public facing web pages.
Insecure Deserialization
Serialization is the process of turning some object into a data format that can
be restored later. Users serialize objects in order to save them to storage or to
send as part of communications. Deserialization is taking data structure from
some format and rebuilding it to an object.
Using Components with Known Vulnerabilities
It’s when you use libraries and frameworks in your application from an open-
source community, and in many cases those libraries are vulnerable which
will result in making your application vulnerable as well.
Insufficient Logging and Monitoring
A coupled with missing or ineffective integration with incident response will
allow attackers to further attack your system and actually maintain persistent
attack or persistent access to your system in order to tamper, extract and
destroy data.
Metasploitable VM
The metasploitable virtual machine is an intentionally vulnerable version of
the ubuntu Linux. It is designed for testing your security skills in terms of
penetration testing and ethical hacking. It is available as a VMware image,
you can browse to the rapid seven website or GitHub and download the VM
from there, import the VM to your player, and once the machine starts, you
will be presented by this console as shown below.
You just have to type the msfadmin as username and msfadmin as the
password, and then write ifconfig to see the IP address of this machine, in
this case below, it is 211.139.
Now, we will go to our browser and type this IP address, we will be
presented by a list of web applications like TWiki, Phpmyadmin, Mutillidae,
DVWA and WebDAV. All of these are deliberately vulnerable web
applications which come pre-installed in the metasploitable tool image.
To access any of these applications just press on them, and as you can see
below, this is the Mutillidae web application.
It contains all of the vulnerabilities from the OWASP top 10, plus a number
of other vulnerabilities inspired by the damn vulnerable web application.
Mutillidae allows the user to change the security level, you can toggle the
security as you can see below.
If the application is damaged by the user injection and hacks, just click on the
reset DB, and you will reset the application to the original state. You can test
your skills on the OWASP top 10 by clicking on the left menu and all the top
vulnerabilities are presented.
As for the damn vulnerable web application (DVWA), just use the username
of ‘admin’ and the password ‘password’, then you will be presented by the
homepage which has enough instruction. The damn vulnerable application is
a PHP/MySQL web application that is actually as its name says, it is
vulnerable. Once again, the main goal of that is to aid you in testing your
skills for penetration testing and ethical hacking.
Discover Vulnerabilities in Websites
Nikto
Nikto, is an open source web server scanner, which performs comprehensive
tests against multiple vulnerabilities, including dangerous files, outdated
versions, and mainly the OWASP top 10 vulnerabilities.
Nikto performs over 6,000 tests against a website. The large number of tests
for both security vulnerabilities and misconfigured web servers makes it a go
to tool for many security professionals and systems administrators.
It is important to mention that it is very wise to start with scanning a website
before performing any penetration testing on it. Let us get to the bread and
butter of that, just open your Kali terminal, write nikto -h, and you will see
the help menu. One of the important switches that we will use is the format
and the tuning. For the tuning, you can choose your scan to perform tests
against these vulnerabilities including SQL injections, file upload,
information to disclose and etc.
Now, if you go to your web server, your web browser, I have installed
metasploitable tool on this IP as shown below.
It is just a virtual machine; it contains various web applications. For example,
Damn Vulnerable Web Application. I will issue my nikto command against
this web server:
nikto<dash>h , which means host and then just put the IP of the server, and
then press enter.
It will start giving some information about the server, the websites hosted on
Apache are using Ubuntu Linux server. Nikto will get some of the
vulnerabilities that are included on the server; such as the process scripting
production header is not defined, x content type options header is not set. As
well, there are some OSVDB, which is open source vulnerability database,
which is similar to the common vulnerability exposure CVEs, you can just
look them up on the internet and it will tell you exactly what type of
vulnerability that is.
So this is one of the tests that include lots of options, if you want to feel
comfortable, just export it, put <dash> output and then specify the file name
output nikto, and then <dash>Format , make sure to put the F uppercase, and
then HTML and press enter.
It will create the nikto file by loading the results to an HTML format. Right-
click on the file and open in Firefox, and you will be able to see the report in
an HTML format. This is very important, especially if you are a penetration
tester, it is very important to document all the work that you do, it tells you
the target IP, the target hostname, the ports, we can change the port by
issuing the hyphen p switch and just put any port, but by default it is 80. The
server is running Apache version 2.2.8 on Ubuntu, you can see all the
vulnerabilities with the description and the link to the OSVDB entries.
Finally, in conclusion, it is a very handy report.
Now going back again to nikto, as we saw once we issued this -h is that we
can tune our scan for different purposes. Like if you want to scan specifically
for SQL injections, we need to use the argument nine, so let me tell you how
to do that.
Suppose that we do not want to output:
nikto -h<IP> , then Tuning , then number nine.
It will specifically scan this website against the SQL injection attack, and you
can see the results.
Now you can as well use HTTP in the hostname forward slash, and then
specifically mention the application which is the damn vulnerable web
application. That will scan against SQL injection attacks on the damn
vulnerable web application. As you notice, it is a very handy tool; it is very
easy to use, and it is considered somehow a standard for web vulnerability
scanning.
OWASP ZAP
Another useful tool is the integration testing tool for finding vulnerabilities in
web application named OWASP ZAP.
The OWASP Zed Attack Proxy (ZAP) is one of the world’s most popular
free security tools and is actively maintained by hundreds of international
volunteers. It is intended to be used by both those new to application security
as well as professional penetration testers. It is easy to invoke just go to
applications, then web applications analysis and click on OWASP ZAP.
Follow the instructions on the screen to start the application. OWASP ZAP is
an easy to use tool, you only need to enter the IP address of the web server or
the web application and just press on the attack button.
OWASP ZAP will run through the list of URLs and the applications in that
box,
It will eventually display color coded vulnerabilities under alerts and will
categorize them by criticality (red, orange, yellow, and blue).
Now, let me tell you about some advanced features of this tool. Most of the
applications today uses password authentication in order to secure their
application. You can select an application, for example, the damn vulnerable
web application, right click on the POST URL which is a link for login
authentication, click on Include in Context → Default context, then select
the authentication method in case you want to provide the username and
password. As you can see below, you can put the username and password
here. You can select the URL, it will pop up the arguments automatically,
just make sure to select username and password.
For the users, just need to add the user of the website in order to authenticate.
So, we will put admin and just write admin and password which is the default
credentials for that and just have to press okay, make sure that session
management is cookie based on which is the default, press OK and then right
click on that and perform the attack again. Just start the scan and it will list as
well the vulnerabilities under the alerts tab in a criticality-based manner.
If you want to know if the website is vulnerable, just go to the URL and add
an apostrophe after the one, now just press enter, it will return an error
message.
You can copy the original link, without the apostrophe of course, and go to
the Kali terminal, and issue the sqlmap command. You can use the -h to
get the list of switches that you can use, but will go directly into executing
the command. So, sqlmap , then use the -u switch for the URL, and then
paste that URL.
SQL Map has detected that the DBMS running behind this website is
MySQL.
Add --dbs to the initial command. This will try to get the list of databases that
lie behind this website. Just press enter and wait for the magic.
You will be able to see that the available databases are tool
information_schema and romanian_svc . We are interested in the
Romanian_svc database. The other command we should issue at this stage is
the same as the original one but with the -D switch to specify the database
name, romanian_svcin our case, and then use --tables . The --tables will
fetch all the tables that are in the romanian_svc database. Press enter; as you
will see the list of tables in this database.
We are interested in getting the content of the table named, for example,
ra_autori . So add that and then --columns , it will display all the columns in
the table ra_autoriunder the database romanian_svc . You will see the
schema design of the table; it has like a couple of columns that we can dump
to our local computer.
So just get back the previous command and remove these columns, use -C ,
and then you can select the column names like nume , nume_nd , and
prenume .
And then U –dump switch, to retrieve the content of this table with all the
relevant information in it.
You will be able to see the content of the table, and the dump is now on our
PC. You will be able to see the path where the dump was downloaded to our
computer.
If you want to see it, copy the link and open a new window. Use leafpad then
paste, and press enter. This table does not contain confidential information; it
is just for tutorial reasons. Some of the websites might be vulnerable and you
might be interested in targeting tables that have usernames and passwords.
Some of the vulnerable websites have their passwords hashed.
The best part about this tool is able to automatically decrypt these hashes for
you. Sometimes SQL map might not be able to crack the passwords, so you
can use other applications or tools like John the Ripper to do that.
Go to your Kali machine and open the burp suite form the main menu. Make
sure to go to the proxy tab and turn off the interception.
The interception can be defined as all the requests will be queued there and
you need to forward them to the destination server manually. Disable that
feature for the time being. Now go to the options tab to spot the port where
the burp suite is running on; 8080 in this case.
Now open the web browser (Firefox ESR) on your Kali machine, go to the
preferences and make sure to configure the proxy settings to use the Port
8080, as shown below.
Now all the traffic that is going out from this browser will pass through our
burp suite proxy before hitting the server. Let us close that box and navigate
to the meta exploitable machine, to the damn vulnerable web application, as
shown below.
Now if you go back to your burp suite, under the Target tab and the Sitemap
sub-tab, you will see that it has identified the applications under the relevant
IP.
Now we want to Brute force into DVWA by trying to guess the username and
password. Right-click on the identified login attempt, and press send to
intruder
Go to the intruder tab, then to the positions tab, you will see that the burp
suite has identified these arguments that have been sent to the servers.
Now we will choose the type of attack, we have sniper attack, battering,
pitchfork, and cluster bomb. A sniper attack is used to Brute force on one
argument. Meanwhile, a cluster bomb is used to brute force more than one
argument. In our case, it is a cluster bomb. Choose that, then go to the
payload tab, you will see that it has identified two arguments under the
payload set. Argument one is username; we will select the payload type as a
simple list. The same goes for the password attack or the password payload.
Now going to the payload options, we can add random usernames, but I will
only use admin. As for the password payload options, I will load a wordlist I
created earlier.
The only thing left to do is to press on the Start attack. Of course, in the
professional version, you will have more options to do. The attack will start
and you will be able to see the different combinations burp suite is
performing. Eventually, if you are using the proper word lists, it will guess
the username and the password. Scanning through the results, you will see
that the location is login for these unsuccessful attempts. Meanwhile, the
location is the index for this attempt which is the correct one.
Simple Ways to Gain Access
Various Password Attacks
We will touch upon a juicy topic on how to gain access to systems.
Theoretically speaking, if you have the right password, you will gain access
to the system. But also, we need to answer the following question: How can I
get the password?
There are two ways to do that, offline or online attacks. An offline attack is
when the target in question has been compromised, and you have acquired
the file that has the hashes of the passwords. The file is usually moved to
your system, where you apply techniques such as brute force, hybrid, or
rainbow table attacks to crack the password, at your own time and
convenience.
Meanwhile, online password attacks happen when you do not have access
directly to the system, and you are trying to gain access remotely. This is
something that usually happens when you are presented by a web form, for
example, or other types of authentication forms.
The attacker will employ, dictionary attacks, brute force attacks, and other
types of attacks such as man-in-the-middle, replay, and wire sniffing. The
key difference between both of the attacks is the fact that for an offline attack
to take place, you must have the hash for the password, meanwhile, the
online attack is live and a bit noisy as it will alert administrators that certain
attack is taking place, and you might as well be blocked. Your IP might be
blacklisted and some password policies might apply for the lockout period.
It is important to point out that online attacks are more difficult to execute
than offline attacks.
Non-technical attacks have to do with phishing techniques, social
engineering, and shoulder surfing that usually takes place in public places,
along with dumpster diving, which happens when a criminal digs into the
trash of a victim to get more information about possible passwords. A
dictionary attack and a brute force attack are common between both offline
and online; it is usually the easiest way to adopt for guessing passwords. A
dictionary attack could be identified when the attacker uses a file that has
possible words from the dictionary and tries to guess the password either
manually or using a system or an application.
A Brute force attack happens when the attacker uses a character set, like all
the uppercase characters, the lowercase characters, the symbols, or all the
numbers, and then this combination takes place to generate the username and
password. This is usually considered a lengthy process.
Hybrid attacks are a combination of attacks. On one side, it is simply a
dictionary attack, while the other is the result of a brute force attack.
Alternatively, you can use rule-based attacks to replace the brute force ones.
Below is a list of attacks, and the techniques used in each.
Offline Password Attacks: Dictionary, Brute force, Hybrid, Rule-based,
Rainbow Table
Online Password Attacks: Dictionary, Brute force, Resetting, MITM, Replay,
Wire Sniffing
Non-technical Password Attacks: Social Engineering, Shoulder Surfing,
Dumpster Diving.
Rule-based attacks happen when you have information about the target’s
password nature. If you have the password policy of the victim or the
company that you are ethically attacking, you will feed this information in an
application that will generate passwords based on that criteria. Statistically
speaking, this will enhance the time needed to crack a password.
The Rainbow table is a list of pre-computed hashes, where the corresponding
password is there next to the hash, which is already cracked. To do that, you
just compare the hash that you have with the hash found in the rainbow tables
and if there is a match, BINGO!
For online password attacks, the same techniques apply in terms of using a
dictionary and brute force attacks. In many cases, it is easier to reset a
password than to guess it. If you have access to the system you might use a
bootable Linux CD. With the help of certain applications, you will be able to
find user names and reset their passwords.
Other types of techniques apply when you do not want to interact directly
with the victim, but you are there on the network sniffing, capturing hashes,
and reusing them to authenticate.
Hashing in a Nutshell
A cryptographic hash function is a mathematical formula that helps you
convert a given value to another string value that is irreversible. The resulting
value after hashing is smaller compared to the data that passed through the
function. Often these strings have a fixed length.
As you can see below the input varies from Fox to the red fox, jumps over the
blue dog, we are using the same cryptographic hash function and the resulting
hash or message digest is of the same length. Even if we change one
character, the red fox jumps over the blue dog, and between the input where
we removed the V, the resulting value is a totally different hash. So, to put it
another way; hashes are fingerprints of some data and it is about random-
looking characters that uniquely identify the data in question.
We can hash anything; you can hash text, sentence, password, you can hash a
file, you can hash an mp4 file. In short, you can hash anything.
We use hash for three purposes; to verify files, software creators often take
your file download and run it through a hash function, and then on their
official site, the hash and the file to download. So, for you to verify that you
have downloaded the right file, it hasn't been compromised or infected with a
malware, you just download the file, and generate, attach and compare the
hashes that are found on the website and the hashes that you generate. If these
match, then you have downloaded the right file.
Let us take a simple example, if you open PowerShell, and go to the root.
Suppose that you downloaded a file, and you want to get the hash of this file,
to know that this file has not been compromised, you can do this by running
this command: Get-FileHash and then the name of the file to get its hash.
Now you have to compare it to the hash found on the website that you have
downloaded the file from. If there is a match, then it is the original file.
The other purpose of hashing is password storage. There are two ways
passwords are typically stored on a server. The first is in a clearly visible
plain text, clearly an issue! So, the best way to store passwords is to hash
them first. When you first create a password on a secure system, it hashes the
password before storing it. So, it does not store your actual password in a
database; but it stores the hash of the password, and forgets what you actually
typed. The next time you type in your password, it hashes what you typed in
and compares the hash that is generated with the hash that is stored in the
database, and if there is a match, you will be granted access. This is so
valuable because if the hashes, or even the hash database have been stolen, it
cannot be read by the bad guys supposedly, instead of seeing a list of
passwords, they will see a list of hashes that can be useless.
The third type of usage is database searching. Hashing can speed up the
process of searching through a database, so that when we store a long list of
names in a table, and we need to find a certain name in that list, the computer
can search for the name of course, but that might be a long process because it
has to match a large string of characters. So, we can significantly shorten that
time by creating a hash for every name on the list, and as long as the hash is
shorter than the average name length, then the search will be faster and
easier.
Below is a list of mostly used hashes
Length Example
SHA-1 160 bits 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
SHA-256 256 bits 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
SHA-512 512 bits b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d778
MD4 128 bits 8a9d093f14f8701df17732b2bb182c74
MD5 128 bits 5f4dcc3b5aa765d61d8327deb882cf99
LM (case 128 bits D6F6E4A3E600550693E28745B8BF4BA6
insensitive)
NT or 128 bits 8846F7EAEE8FB117AD06BDD830B7586C
NTLMv2
Remove the user and remove the colon then go through the hash until the
next colon, remove the next colon and the rest of the file. So now you have a
clean file that only has hashes, close it. Now we will open hashcat from the
main menu (See the steps below).
Once you open it, the help menu will pop up, you will be able to see different
options that you will use. Mainly, we will use the M option which specifies
the hash type, the A option, which specifies the attack mode, and the O
option which specifies the output.
So, going down, you will be able to see the hash modes it supports as I said
earlier, lots of hashes; MD4, MD5, SHAs, etc. To make it easier, you can go
to the site ashcat.net, and you will be able to see them in a tabular format.
The output formats are hash, plain text, etc.
The attack modes can be straight, which means dictionary attack or wordlist
attack, combination attack, Brute force, or a hybrid wordlist plus mask. And
the device types of port it can be CPU, GPU or FPGA.
So, because this is the fastest application for password attacks, it will not only
run on CPUs, it will be optimized thrown on GPUs, and PGA, which are
application-specific kind of processes. So, let us go to the bread and butter
and type the command: hashcat-m . M will specify the hash type that we
want to crack. The encryption method in Linux is SHA512.
If you go again to the site, as SHA512 for UNIX, the number is 1800. So type
m space 1800, then a, which specifies the attack type, we will go just a
dictionary attack type, then you will specify the output. The output will be
put in the cracked.txt file, and then you refer to the location of the hash file,
which is hash, hackedhash.lst.
And then we will be using a simple word list, wordlist.txt, and then we will
use force.
During the cracking phase, you can press on s to see the status, it will tell you
that it is running, and this is the target hash that we want to crack, the time
started, and the estimated time, as it will take around three hours to finish.
If you press again on status, you will see that the progress, so let us wait.
Make sure that if you use the wrong hash type, the application will give you
an error and will not be able to start cracking the hash. So, make sure you do
well base research on the type of the hash that you are cracking. One of the
applications that might be beneficial is the hash identifier, you open it and
just paste the hash, and it will tell you what kind of hash is that.
Check the application status after a few hours; now you will find that it is
cracked, meaning that the password has been figured out. To be able to see
the password, locate the cracked.txt file, to see the hash that has been
cracked, and the password, as shown below.
Execute an Offline Password Attack on Windows:
In order to crack passwords in an offline mode, you must first obtain the
hashes stored within the operating system. In our case, the operating system
is windows and these hashes are stored in the SAM file which is located
under C:/Windows/System32/config. If you try to open this SAM file, it will
tell you that it cannot be opened. So obviously this file is not accessible while
the operating system is booted.
If you have physical access to the Windows machine, you can run a Kali live
CD that is capable of reading NTFS drives and capable of mounting the
windows partitions. This way you will copy the SAM file easily to an
external media. Now go online to
https://www.openwall.com/passwords/windows-pwdumpand download a
copy of PW dump or password dump.
Extract this folder to your Windows machine on the root C drive. Then go to
the command line, run it in admin mode and go to the password dump, then
issue the command pwdump.exe, then redirect the output to cracked.txt file,
as shown below.
Go to the password dump folder and open the cracked.txt file, you will notice
that the hashes of the Windows machine has been dumped, and you will see
the list of usernames, the IDs of the usernames, and two hashes separated by
column. The hash on the left side is the old LM hash, and the hash on the
right side is the new NT or NTLM hash, which is more secure.
Copy the NTLM hash and go to the Kali machine, open the terminal, now we
want to create a file to store this hash. Use the command echo, and then
redirect the output to a file named windowshash.txt. Use cat to view the
content of the file, as seen below.
Now we will use John the Ripper to crack this hash. John the Ripper is
actually one of my favorite password cracking tools because it supports lots
of hashes. It is very easy to use; in your terminal, type in John, and a help
menu will pop up, the syntax is very easy, use John, options, and password
file.
If you write john, then list equal formats, you will see all the hashes that are
supported by John. If you do not specify the format, John will kind of
recognize the format on its own. But to make things easier, we will tell john
the format type of the hash which is NT. Specify the file that contains the
hash you want to crack, then you specify a word list, any word list. John can
use its own word list or you can download extra word lists from the internet.
You will learn in the upcoming sections on how to create good word lists.
But in the meantime, I have created my own word list for the sake of this
example. Wordlist equals wl.lst, just a random word list that I am using and
just hit enter, as shown below.
Clear the screen, type if config to see the IP address assigned to this machine
to use in the attack. Open another terminal in Kali and run the Nmap
command on metasploitable2 IP, just to see the services running on the
machine, it has lots of services running FTP, SSH, Telnet, etc.
We want to try to attack this machine on the FTP service. Just type in Hydra,
we will provide the username as msfadmin, and we will also provide a word
list which is rockyou.txt. The service to attack is FTP, and I provide the IP
address. It is as simple as that, you just wait for a couple of minutes or even
seconds before Hydra pops up the password, which is msfadmin. We will do
the same for the Telnet services, you just changed the protocol from FTP to
Telnet, and just press enter and hydra will do the same. Quite easy as well.
You can do the same for SSH and lots of other services.
Run an Online Password Attack on a Router
We will now attempt to crack the password of the router that connects us to
the internet, let us ping it first to make sure that we have a connection. For
this purpose, we will use a tool called Medusa to try to figure out the
password, and once you write medusa, the switch's menu will appear. It is
actually quite easy to use.
But first, let me explain a bit about Medusa which is a very fast and
massively parallel modular login with Brute force. It has modules available to
support almost any service that allows remote authentication using a
password such as FTP, POP3, Microsoft SQL, MySQL SMTP, Telnet, and
VNC. Compared to Hydra, which is process-based, Medusa is thread based,
which means it is actually much faster than Hydra. Let us go to the bread and
butter and try to crack the password. Issue the commandment medusa, then
provide the host IP using the h switch, and then you provide the username,
usually the default username is admin. The password; just enter P in
uppercase and provide the path to the rockyou.txt word list. Then specify the
protocol which is HTTP.
Hit enter and watch Medusa do the work. Medusa will try various passwords
that are found in the wordlist which contains more than 14 million passwords.
It will go through all the options until it finds the right password.
After we have generated the rainbow table and sorted it using the rtsort
command, now it is time to crack a hash using this method. Just write
rainbowcrack then use dot to refer to the rainbow tables found and the
current directory, then provide the H argument and provide the hash. For this
purpose, we will go to an online MD5 hash generator and select any string
(1111 in this case). Copy the hash, then paste it and hit enter. It is very fast as
you can notice and the results should tell you that the hash corresponds to the
password.
Design Effective Wordlists
Word lists can be obtained from password cracking programs, or by
downloading them from the internet. Wordlists are used for general purposes,
they have many random passwords, thus they are huge in size.
For example, you can search the internet for a wordlist called darkc0de. Or
you can search for another famous word list called Rocky0u. These contain
more than 14 million passwords that are compliant with the latest password
policies.
Suppose that you want to create your own word list for a specific attack, you
can use two tools for this purpose. The first one is called crunch, which is a
wordlist generator based on the user-specified character set. It takes the
character set designated by the user and generates all combinations and
permutations possible into a new wordlist.
The second tool is called CUPP. CUPP stands for Common User Passwords
Profiler, and it is available on GitHub. Copy the Github link, go to your Kali
machine, open the terminal and write the following command; git clone, then
paste the URL and wait for it to be cloned on your local machine.
Invoke the ls command, navigate to the cup directory, then list its content.
So, you will write python3, then the name of the file, and the argument of -i .
This will prompt you with lots of questions. So basically; this tool will gather
information about the target and will use this information to generate its own
word list.
Here's an example. Suppose the name of the victim is John and the surname
is Doe, the nickname is Joe, and the birth date is 11-December, 1992. His
partner's name is Ryan, her nickname is Ray, and her birth date is 02-05-
2000. Their child's name is Will, the child's nickname is Willie, and the birth
date is 05-07-2004.
Pet’s name is Tom, the company name is just a random company name,
Innovate Corp. Do you want to add some keywords to the victim? If you have
some keywords, like you can describe him; he is handsome, he works in the
technology field. So just imagine some of the words that this victim might be
using. Do you want to add special characters to the end of the word? Yes. Do
you want to add some random numbers to the end of the word? Yes.
Do you want to enable the leet mode? Yes or no?
Leet mode is the usage of ASCII characters to replace Latin characters in
ways that it reflects resemblance. 1337 resembles leet. If we write a password
like p@ssw0rd, the zero resembles the O and the @ resembles the A. So we
will say yes, and it will take some time to generate the word lists containing
more than 60,000 words.
So, let us open the list called john.txt. I will use a leaf pad to open john.txt.
The list will be containing all the permutations and all the combinations of
the information provided to the victim. So probably, the victim might be
using one of these permutations. Because the passwords you use usually
include your name, family name, your pet us name, birth date, your partner's
name, etcetera. This will help you do a more successful attack with a high
probability of guessing the password.
Now moving to crunch, just type crunch and hit enter and you will see the
syntax on how to run it.
You will specify the minimum length of the password you want, and the
maximum length of the password you want. If you hit enter, it will use the
default character set of alpha lowercase, so just hit enter, and now it will
generate a huge word list containing more than a million passwords, so I will
just stop it at some point.
To make things easier, you can specify the characters set that you want. In
this case, I will use the character set of abcd123. Hit Enter, it will only use
these characters sets to generate a password with a minimum four, maximum
five, and you will get the results. If you want to include numbers as well, you
can add it to the character set, hit enter, and you will see the result. You can
as well export this file by using the argument of O and then just rename it
mywordlist.txt, it will just redirect the output to the file.
You can notice that all the combinations and the possibilities from the
characters set you have chosen.
Now, to make things more interesting, suppose that we want to add a pattern
to the password, we have to use special symbols; at to specify lowercase,
comma to specify uppercase, percentage sign to specify numbers, and the psi
to specify symbols. Suppose that my pattern will be in the password, which is
a four-character password, for example, just to make it easier for you to
understand.
We will always start with lowercase; we want to use number and then
uppercase and we want our password always to end with the letter Z. So, we
have a four-letter password. As you can see below, this is the character set we
are choosing from, and the pattern is four characters. The first character is
lowercase, then number that uppercase and a standard Z. So, let us discover
how it goes. It will generate 1820 password, and you will see all the
permutations. Let us take them to an output file to make it easier, and open
that.
So, the first letter is lowercase, then number all the time, then uppercase, then
Z, and these are all the possible combinations. Of course, you can make it
more complex by using longer passwords, and by using an extended
character set. For this purpose, and as we have seen with rainbow tables
before, the character set is found in a table or in a file called charset.txt.
So, let us see the content of this file. It has all the character sets, numeric, the
alphanumeric, [] alpha, and all our numeric and the mix alpha, etcetera. So,
let us use this file to generate a word list in crunch, so we will use the same
command, just invoke the F argument to specify the file again.
And now we need to specify the character set name. Again, let us open it and
leaf pad and remember the character set name. For example, it is lowered
alpha dash numeric, so let us go to the command again and write lower-alpha
dash numeric.
So it will use the lower alpha dash numeric character set from this file, and let
us output this file to rainbow wordlist.txt, and on top of that, let us zip it by
using the Z argument and using the gunzip utility, so just press enter and wait
for the result. As you will notice, it will create this file; Rainbow wordlist.txt
with all the permutations and all the combinations from the lower
alphanumeric character set under this file, and all the passwords are of length
of four characters.
So, let us see the file after unzipping it. All the passwords are the length of
four with all the combinations from the chosen character set. A sample is
shown below.
Proven Social Engineering Techniques
Attack Vectors
Social engineering is the art of manipulating people psychologically so they
give up confidential information; we will not be using any of the technical
approaches we learned earlier. One of the attack vectors can be pretexting,
which is the act of creating or inventing a scenario to lure the victim to
participate in it.
A famous example can be those emails you usually receive about an African
prince who has passed away and your name appears on his will, where you
are asked to provide a copy of your passport and a couple of dollars so that
they process this further, some people fall for this trick.
Another attack vector is diversion theft, which can be understood through the
following example. If you are going to a bank to deposit your money in an
ATM, maybe some guys would lie to you that the ATM machine is currently
out of order and that you can just deposit your money in a van related to the
bank or a certain kiosk related to a bank, so it is actually diverting the
attention or changing the actual action that needs to be performed by the
victim.
Phishing is the act of sending emails that appear to come from a legitimate
business or a bank, in where you are asked to provide information or
verification such as credit card number, CVV number, and similar related
information. Spear phishing is the same as phishing but it is targeting a
specific group and the rate of success is more than the phishing because
phishing is targeted towards the mass, and it has a low rate of success, but in
spear-phishing the attacker does more research and he attacks certain groups
of people so that the probability of having a successful attack is higher.
Baiting attacks use a false promise to pique a victim’s greed or curiosity. For
example, if you create a USB drive, you put a malicious file in it, and you
throw it in a public place such as a parking, an elevator, walkways. You
might mark this USB as confidential, or salaries of 2021, etc. Some people
will fall for the trick, and they will take this USB and just put it in their
computers just out of curiosity to see what is in it. At this moment, the
computer will be infected depending on the payload as well and the attacker
might have full remote control over this computer.
Tailgating is when the attacker gains access to a restricted area by following a
person or entering behind that person who used his legitimate access, so that
the person will have access to this area without any kind of identification or
any kind of questions asked.
Vishing is voice phishing; it is where the criminal practices social
engineering over the telephone system to gain access to private or personal
financial information, etc.
Water holing is similar to phishing, but in a different context. With most of
the cases, people are aware of phishing attacks, and they are not ready to
press on the links of any of these emails, but they are ready to press on the
links on the websites they trust. Some kind of research will be done in this
aspect so that the attacker will research the websites that are mostly visited by
this user, and will then check the vulnerabilities found on this website to
inject these links. And the user will, since the user is trusting the website,
he/she will be more inclined to press on these links.
So, we will get a list of results having PDF files, we have to look into them.
Let us open these files and search for the word “confidential”. So, this is just
a basic way to search for confidential documents, if you are targeting
someone in mind, you need to fine-grain your search criteria. But in general,
it is very easy to find such information using Google search.
Suppose that you want to find passwords, for example. Log files contain a
string called 'your password is'. So, let us search for the string, 'your
password is' in a text file type. This will bring a couple of log files; you just
can open and look into them. Below is a sample result.
Suppose that you want to search for IP cameras or print servers that are
published over the internet. Two arguments come in handy here, in title and
URL. The in title argument will search in the title of the page, and the
argument in URL will search for the URL of the page only. So in the title, let
us say the network print server and file type is SHTM, you will be able to see
a couple of results.
Another example, if you want to find a page with grades, for example, final
grades, you can use this in URL, final grades, and the site we are looking at is
an educational site. You will get a list of final grades plus IDs. As you notice,
you can tailor the research in ways you want using advanced operators, again
in URL, Intext file type, site, there are lots more you can use, but these are
the basic ones.
And let me tell you something else. Instead of keeping those arguments in
mind, you can go to the exploit DB website on www.exploit-db.com/google-
hacking-database, Google hacking database, and you will see all of these
vulnerabilities in one place. All you have to do is to search for the category.
Let us take an example of vulnerable files, or maybe files containing
passwords. These are some of the examples here, as shown below.
If you master Google search and Google Advanced operators, you can have
access to anything published online such as firewalls, intrusion detection
systems, video recording systems, ups monitors, even building management
systems, IP telephones, and even credit card information and CVV
information. To have a smooth start, get yourself familiar with the list of
vulnerabilities on the exploit DB website.
To start, press on the icon there to create a graph. On the left side, you will
see the relevant entities that you can start with. The concept of Maltego is
that you drag an entity to the graph and start drilling down further on it. You
can start with the domain name, with the person, or with the company. You
have lots of entities here to start with, email address, etc. In our case, we will
start with a domain name.
Press on the domain entity and drag it to the graph, double click on the icon,
and enter the domain name you want to inquire about. Suppose that I want to
inquire about souq.com.
Press OK, and then right-click on the icon, you will see a list of transforms
related to DNS, domain owner details, email addresses that are found on this
domain, and other files. So actually, we can get lots of information just by
starting from a domain, relevant information can seek to make it easy, just
press run all and see the progress bar below.
Once it finishes, it will populate a very complex but useful graph. You see
the entity, as well the DNS records associated with this domain; you can
double click on each and see the details. It is giving you the relationship in a
top-down approach; it gives you as well, some relevant websites, the MX
records, the location of this domain, other relevant emails that are found on
this domain. As you can notice, there are names, the name servers as well,
obviously, the website, the persons whose names are found on the website,
and some telephone numbers, some emails as well, etc. Below is the graph in
zoomed out and zoomed in versions.
It is always interesting to see the emails and the persons. So as you can see
below, Shaker Qawasmi, you can right-click on this person, and just run
another transform to get more details.
As we said earlier, I am using the free transforms, there are other transforms
that are paid and you need to create an account on the website relevant to this
transformation and provide your key in order to be able to them. So let us try
to get the email address of this person just by right-clicking on him and
running the transform. And finally, we will get the email address of this
person on souq.com. So actually, it is a very handy tool, which gives you lots
of information related to the target you want to inquire about.
What do you want to do? We want to attack mass mails, not just one single
email, so select option number two, it will ask you for the path of the file that
has the list of emails. For this purpose, I have created an email list txt file,
random emails, so that I can provide the path.
Now it will ask you about your Gmail account or an open email relay. So I
will use my Gmail account for this purpose. But you can provide an open
relay for this purpose as well. The name that will appear is; email password,
do not flag for higher priority. Do you want to attach a file? I will not attach a
file, because usually file attachment like malicious file attachments are
blocked at the email control level, whatever, it is a firewall, its email filtering
system, etcetera, usually, these attacks do not work if you have an attachment
within the email. So it is better to provide a link that has the attachment, once
you click on the link, you will be able to download that attachment.
I will write a subject in my email subject, salaries for example, and then send
that email in a plain form, not HTML.
Now it will ask me about the body. In the body, I will put a link to a
malicious file, which I will be hosting on my machine. For this purpose, we
will open another terminal, and we will run the set toolkit again, we will
select social engineering, but this time, we will create a payload and a list of
option number four. So we will create this payload generated, hosted on our
web server, and put the link and the email address. We will do option number
two, create a reverse TCP Meterpreter, the host will be the local ID of our
computer, the listener, just generic number 4444. Now it should be
generating the payload on our machine, it will take some time generating
payload. And finally, you will find that the payload has been generated under
a specific path. We will copy this path. Now it is asking us if we want to start
a listener?
Yes, let us start a listener. It will initiate a Metasploit console session and a
listener will be invoked. Meanwhile, we will open a new terminal and copy
the file exe to the webroot directory. We will copy the file from the path to
www HTML.
How can I reach it?
It is the ip/payload.exe. Again, I can go to bitly.com and put my IP there, I
can ask it to shorten the IP. Copy that, go again to the first instance, and put
this in the body, we will press enter and then write END. Now, the
application will attempt to send the emails to the entire list that we have in
the provided text file.
We will choose option one, which will use the existing web templates in the
SET tool, IP address for the postback is the local IP address we are using. To
know it write ifconfig and you will find your IP address, press enter, then it
will tell you which you want to use.
First of all, let us use the Google template, so template number two and it will
create the file or the website under these directories. It will create a fake
Gmail website that we will use to harvest the credentials from the users. Press
Enter and now we need to think about that. You want to attempt to disable
apache, seems an apache is running and this website wants to run. So, press
yes, the harvester will be ready, have it in browser for your site. So actually,
our IP address now is hosting a fake Gmail website.
How to test that? We need to go to a browser on our Windows machine and
type the IP address of the Kali machine, and it has a Google page. For
example, type any email, and any password, and then sign in. You can
observe the behavior, it will direct you to the Google page. And if we go to
our machine, we will be able to capture the credentials.
You will get the email and password that we used.
So, now we learned how to spoof Facebook, Twitter, Gmail pages, and how
to harvest the accounts. Now if you can link it to some of the techniques we
studied earlier, such as DNS poisoning, ARP poisoning, you will be able to
link the chains and come up with a real-world scenario on how to combine
social engineering with network attack techniques.
Perform Attacks on Mobile Phones
Mobile Attack Surface
Nowadays, mobile devices dominate the consumer use and habits from a
personal and enterprise perspective. Thus, they are ubiquitous and found
everywhere. The basic risk segments can be divided into five main Mobile
Application Security categories, starting from the mobile device itself, going
through network security, web service security, database security, and
application management procedures.
The mobile device risk spectrum starts with the data storage. Is the data on
the mobile device encrypted or not? About data transmission, we can talk
about HTTPS versus HTTP, STPS versus secure FTP. So, is the application
utilizing secure protocol versus open protocols?
Reverse engineering is a very important area when we talk about mobile
applications. Are there binary protections in place? If there is no binary
protections in place, anyone can have access to this mobile app and just
reverse engineer it and get the source code and get to know the details of the
architecture of the mobile app and more.
When you install an application you grant it access to local resources, is the
application having access to only the resources it needs, or it is having
elevated access? The other mobile attack surface is the network threat itself.
Here we mainly talk about HTTP versus HTTPS using SSL, using TLS,
because if you do that, it will cover all the wireless connectivity issues. You
will prevent hackers from doing session hijacking and DNS spoofing.
Thus, we need to know how these technologies work. Does it mean that if
you use SSL, you are safe? No. We will see in the following examples that
we can decrypt SSL as if we are not using SSL in the first place. So, we need
to know how to use and utilize SSL within our mobile applications.
Another important security aspect is the webserver security. Do we have any
processes in place to identify and apply critical system security patches? Do
we have a process in place to assign roles and responsibilities for people who
will take ownership of the actions performed on the webserver? do we use
processes to mitigate DDOS attacks such as captcha? do we have password
policies in place to look up attacks and to look at accounts that have been
attempting to brute force using incorrect passwords? These are trivial threats
not specifically related to the mobile attack surface, however, it is important
to mention them here.
The other attack surface is the database threat, who has privileged access to
our database? Are we sanitizing the data we are getting from applications
before we insert them into our database? Are we checking the logic of the
data we are getting from mobile apps? Are we utilizing the latest updates to
patch our database?
The last mobile attack surface is related to application management threats.
As you know, many enterprise mobile apps are distributed using application
management software. Thus, who have access to this application
management software? Who can deploy our source code to online stores such
as Google Play or Apple Store? Is our mobile app signed by the enterprise
account? Who can or who can do remote wiping either fully for the mobile
devices or partially only for the organizational data?
Now we have two channels; one between the mobile and the proxy, and the
other between the proxy and the server, the channel between the mobile and
the proxy is using the fake self-generated certificate. Please note that we will
be able to look into this channel because we have the public and the private
key. The other channel is between the proxy server and the original server,
which is using the original certificate provided by the server itself.
On our mobile application, we need to change the proxy settings to refer to
the IP and the port number of the proxy we have just set up. It is good to
mention that we will be using a proxy server called Charles for this example,
but you can use any proxy servers available out there because the concept is
the same. You can use burp, you can use fiddler, and you can use a man-in-
the-middle proxy.
On top of that, you can as well download some mobile applications,
especially on Android devices that will mimic this whole setup, it will be
easier for you to just download an application which will automatically install
a certificate on the mobile and you will be able to monitor or capture the
traffic and analyze it. You can use the SSH droid or proxy droid, and many
other applications on Google store out there.
Going back to the timeline, you need to go to www.charlesproxy.com and
install the proxy from there. After that, open the application and you will be
presented by the below interface.
Now we need to go to our mobile device and route all the traffic from our
mobile through the proxy. To do so, go to the Wi-Fi connection that you are
currently using, then go to configure proxy, select manual, and then use the
server and the port, which is Charles proxy running on. Go to the help menu,
SSL proxy, and then install the certificate on the mobile device. Charles
proxy will tell you its IP and the port number that it is running on. Now we
use this information to configure our mobile to pass all the traffic through the
proxy.
Now go to the browser of the mobile, and you will notice that it tells you to
browse to n URL to download and install the certificate. So it generated a
self-signed certificate, which we need to install on our mobile device. To do
so, we open the browser and go to charles.pro/ssl, and it will prompt us to
install this profile or certificate. You just press install, again install and done,
now we have installed the certificate.
On Charles proxy, go to SSL proxy settings, where SSL proxy should be
disabled by default. We will just open a generic mobile app from our mobile
device and try to login using our generic username and password on any web
page that accepts login credentials. So just press login, and you can notice on
the left side that Charles highlighted this event that is taking place there. So if
you press on that, it will tell you that SSL proxy is not enabled, then you can
go to content and you will see that it is a scrambled content since the
connection to the server is encrypted, and we are not able to see any of this
traffic.
To do so, or to be able to see or check the tunnel, go to SSL proxy settings,
and then enable SSL proxy, keeping in mind that we have already installed
the certificate on our mobile. Press OK again, we need to go back again to
our mobile application, clear the session, and for the mobile application, we
will just log in again. You will see that activity is shown below and now you
will see that some file structure is being populated under this URL.
Press on this file, go to the Contents tab, you will be able to see the username
and password that we used, along with other information. The information on
the top is the request and the information at the bottom is the response we got
from the server. Since this is an unauthenticated response, this is what we got
from the server.
From the sequence there, you will be able to see all the connections that are
being passed through this proxy and the result. So, this is a successful
attempt. We have got some cookie information, API URL information,
although the attempt to sign in was not successful.
Go again to this mobile, try to sign in with a real username and password to
authenticate to this application. Keep in mind that we are doing this just to
test our application if it is secure over the internet.
Charles proxy generated lots of information, authorization codes, profile
related information cookies, and some internal hierarchy on the server. So,
the more you navigate through the mobile app, the more information you will
be able to get on Charles proxy.
The most important thing is that if this proxy is on, for example, a hotspot,
and users are authenticating through it, they will be able to see all this
information. Under the cookies, you will see all the information that we are
able to get. Under the text form, you will see the URL with the device token,
username, and password to authenticate. That goes for the form and the roof
format as well.
This is an important piece of information that an attacker can get to perform
another attack. I therefore recommend encrypting this information at the
application level and the code level. So do not depend on the SSL or the
encrypted tunnel; you have to take the security measures at the level of the
application itself while writing the code.
It is obvious that the mobile application we tested didn't perform some of
these steps correctly. The mobile application isn't checking if the certificate is
issued by a trusted authority; it just accepted our self-signed certificate. And
unfortunately, mobile application writers often ignore the need to check
certificates; they blindly accept any SSL certificate without understanding
how SSL works. To protect against that, you need to use certificate pinning.
When you are doing that you are checking if the certificate name matches the
webserver name that you are connected to, and once you do that, you will
automatically reject any other certificate.
After the decoding is over, navigate to the resultant directory and check the
files. You will see it has organized the extracted files. Similarly, like an
Android project where you have the assets, the resources, and the Java code
itself. The assets usually are files that are not compiled within the source files
of the project. Meanwhile, resources are compiled within the Android code.
Let us drill down into the assets; you will be able to see strings compilation,
list of values, and the fonts that are being used. You can see as well the
graphics, used within the WhatsApp application. And if you go directly to the
code, the extension is SMALI. And eventually, you will be able to see all the
Java code which is extracted from the WhatsApp application. To see the
actual Java code, you need to use an application called dex2jar.
Suppose that you did some changes to the Whatsapp code, now we need to
build these files into a new apk file ready for distribution. For this purpose,
you can use apktool again, b for build and select the file, the directory name
exactly, it is WhatsApp uppercase, and then use the O argument, call it
mywhatsapp.apk, now we are building it again, but taking the changes we did
into consideration. The results will take some time, in the end, it will create
the new apk file, as shown below.
As you can see below, this is my new version of the WhatsApp called
mywhatsapp.apk.
Can we prevent hackers from decompiling our applications? Well, generally
speaking, we can make their life harder, and the harder we make it the fewer
will remain. But actually, it takes a lot of time and effort to make our record
difficult to crack, but we cannot make it impossible to crack. So here are
some of the tips that we can use in order to make the life of the hacker
difficult.
We can use code obfuscation; this is the usual word that is used. It means we
can mystify our code or we can complicate our code, we can use a couple of
applications such as ProGuard, and Dexguard, these applications actually do
a good job and can make reverse engineering difficult. It can encrypt strings
and detect code tampering. ProGuard is an open-source application, while
Dexguard is a commercial and paid application and it does a job better than
the ProGuard.
You can as well use NDK, which is the native development kit for Android to
write libraries in C and then you can import them to your Java code, which
makes it difficult to decompile. Regardless of the code complication that you
do, always try to encrypt and send messages and make sure those messages
cannot be repeated. So use some timing or some kind of sequence to assure
the integrity of the communication between the application and the server and
always authenticate your client.
When it is done, you will need to move this file from your Kali machine to
the end-user. You can do that using various techniques such as social
engineering, for this purpose, we will copy the file from this machine to our
phone directly, and you will be able to see it under the download section as
trojan.apk.
On the other hand, now we need to create a listener on our server that will
listen to this incoming connection. Launch the Armitage application. If you
don’t have it installed then use the command apt install, Armitage. It will take
some time to load for the first time. On the left pane, type Android.
Go to the payload section and double click on reverse_tcp, you will see that
the IP is automatically populated; now we only need to match the local port
with the port that we have used when we created the apk file, as shown below
Press on launch and Armitage will start the handler locally, and it will be
waiting for connections on this port. We will go to our Android device then
to the download application and you only need to install it as usual.
Notice that when you open the mobile application, the meterpreter session
will be established and it will show you that an Android or a Linux based
device has been compromised. Now we have full access to the remote
Android phone. It is worth noting that we are doing this in a lab. But actually,
you can use it over the internet using your real IP and port forwarding. Just
right click on the compromised machine, and you can interact using the
meterpreter shell; type help and you will see all the commands that you can
invoke. You can as well explore and browse the files that exist on this phone.
We are able to see many personal files such as passwords and credit card
details. If you go again to the meterpreter session as we did earlier, with the
type of the help, you can invoke a couple of commands, such an interesting
command will be dump_contacts , it will search for the contacts on the
phone, and it will dump them locally on a file, as shown below.
Web shells can be used to maintain access or even hack a website, most of
them are detected by antivirus and the famous ones are c99 and c100 shells.
HTTP tunnel is a tool that creates a bi-directional data stream tunneled into
HTTP requests and the requests can be sent to an HTTP proxy if desired.
DNS to TCP is a tunneling tool that helps pass TCP traffic through DNS
traffic, meaning on port 53. This is another important tool because most of
the times port 53 is used to legitimately identify services, as such, it is open
most of the time.
If you know the antivirus application that is running on the potential target
system, you might want to test your backdoor or trojan horse on
www.virustotal.com. This website will give you the detectability of common
and antivirus application vendors against a file that you upload. This will help
you execute a successful attack.
Netcat Simplified
In simple terms, Netcat is a computer utility for reading from and writing to
network connections using TCP or UDP. It can be used to:
Now we will go to our Kali machine, and from there, we will connect
remotely to the cloud machine and try to open a conversation with the server,
so will issue the command and nc -nv, then the IP address 173.248.132.230.
Then we will specify the port and press enter, it will tell us that this port is
now open. So now there's a tunnel between these two computers, the Kali,
which is on the private network, and the Windows Server which is on the
internet.
So, what can we do now?
Actually, we can open a chat session, for example. So, let us say, "Hello,
from Kali" and we press enter. Now if you go to the Windows machine, you
will see this message popped up there, and from the Windows machine, I can
as well reply, "Hello from Windows machine". If I go to the Kali, I will see
that the message has been popped up there as well.
By issuing this command, we have transferred the spd.exe file from the Kali
machine to the Windows machine. If you go there, you will see that a new
status has been issued, connections from this IP address by the public IP
address of my router, so if we quit this session, and go to DIR, to list the
directory, we will be able to see this file, we will put that exe that we have
transferred from our Kali machine to our Windows machine. If we open this,
we will be able to see the file, the size, the creation date, and time of the file.
The fourth example is about the remote administration, as we saw earlier, we
have two machines; the Kali which is on our LAN, and the Windows
machine which is on the cloud. Suppose that the user using the Cloud
Machine wants remote assistance from the user using Kali machine. So, the
user using Kali will log on remotely to the user on the Windows machine.
The user on the Windows machine will issue this command, nc-nlvp , then
the port 2222, then minus -ecmd.exe. This command says, "Any user who
connects remotely on the port 2222 will be redirected to the command
prompt, the command or the console, the command.exe".
From the Kali side, we will issue this command, nc -nv , then the IP address,
then the port. When you press enter, you will be redirected to the command
line of Windows. So now you have full control to remotely manage windows
through the command line. It can list the files and the sky is the limit, now we
have full access and full control over the command line.
In the last example, suppose that the user using Kali wants remote assistance
from the user on the Windows machine, but the user on Kali is behind a
firewall and his IP is natted, so he cannot expose these services for it as the
windows guy did previously. So, in this case, we will go to the Windows
machine, and we will issue the following command, nc -nlvp and then this
port. Then from our Kali machine, we will put the following command, nc -
nv , IP address, then the port we want to connect to, then argument -E which
is to run a program, and which program we will run? Surprisingly it is the
batch, the connection is now open. If you go to our Windows machine and
run a UNIX command like ifconfig and press enter. Now we have full
remote access to the batch terminal on Kali and you will be able to see that
the IP address is 182.168.200.130, and all the other information. You can as
well issue any other command. So, as you guessed, you can use Netcat as a
backdoor to access systems. One of the drawbacks of Netcat is that the traffic
is not encrypted for that, we have an enhanced version of Netcat called Ncat.
It is important to know that because running Netcat creates open ports on
your machine, the use of Netcat can present a significant security risk if used
improperly, so make sure not to leave catch running while you are not using
it.
Install a Backdoor
Exploiting a computer is great work. However, our goal as penetration testers
is to maintain access to this compromised computer and to reduce the time
we already consumed and all the efforts we put in attacking the same
machine over and over again.
So, for this purpose, we need to install a backdoor upon our first access or
compromise. To do this, we will use Netcat. As we learned earlier in the
previous section, Netcat can act as a simple backdoor. Suppose that you have
a meterpreter session on a compromised computer, in this case, our computer
is a Windows 10 machine, and we have a meterpreter session. The first thing
we need to do is to upload this Netcat program.
For this purpose, we will issue the upload command from our meterpreter
session and we will refer to the Netcat program on our desktop. Then we will
point to the location where we need to upload it on the Windows machine. It
will be under SysWOW64.
As you know, on a windows 10 machine, which is 64-bits, you have system
32 and 64 directories, Windows automatically handles the file placement of
your 32-bit file or 64-bit files, in this case, this nc.exe is a 32-bit file, so even
if you put it in system 32, it will automatically appear in SysWOW64. To
make it easier, write the following path c:\\windows\\syswow64\\, just press
enter, and you will see that the file has been uploaded to this directory.
Go to the Windows machine and try to search for this file. You will find the
file and the upload time as well. Going back to our Kali machine, we have the
file placed on the victim’s machine, but we still need to have a mechanism
that this file is booted or loaded upon the boot of the Windows machine each
time. So each time the user restarts or boots a machine, this Netcat file will
start listening automatically.
So, for this purpose, we need to create a registry key called Netcat, that will
boot up the service every time. This will give us permanent access to the
victim's machine.
On the meterpreter session, write enum-k , to see the list of services that are
automatically run currently on this target machine. Use the command as seen
in the image below, to find there are no children or no identified key.
So now we need to create the key to set this process to run upon the boot of
the computer. Use the command of regsetval , key, and use the same value
for the key, then use the v argument for the new value and we call it Netcat.
And then we use the d for data, so the data in this registry should be
C:\windows\SysWOW64, then nc.exe and we will make it listen. The listener
daemon will be on port 6666. Now we will execute command.exe. Hit enter
and you will get a message that it has successfully set the key.
I have created a simple website for this tutorial. It is a generic website that
has a couple of pages in addition to upload your CV page. The purpose is to
upload our backdoor file to this web server. Many of the websites in the wild
offer this feature where you can upload your CV, you can upload a couple of
images, many of them block PHP extension files, but some of them do not do
so, you have to check vulnerable websites for that. You can as well leverage
what we have learned before to remotely hack over FTP and then you can
upload your backdoor file. Navigate to upload your CV page, click on
browse, select the backdoor file that we have created and upload, you will see
that the file backdoor.php have been uploaded. It is supposedly uploaded
under a specific path, so copy this path, go again to your terminal and issue
the weevely command.
We want to establish a remote session with our backdoor file, we will use the
weevely command again, write weevely, then enter the URL and change the
upload.php to backdoor.php, and then provide your password. We have to
check if it is connected, just list and you will be able to see the content of the
files on the server, also you will be able to print working directory, and you
will see that we are working under the var/www/html content.
You can as well go to the root of these websites var/www/html and do
another listing, to see the index.php file, which is the homepage. Again, let us
go to the homepage and try to refresh, so now we want to deface this website,
we will remove the index.php and upload our index.php. You can type help
to see all the modules that you can use on weevely, such as upload files,
download files, brute force SQL, and SQL databases dump. For this purpose,
we will be using file upload file to remove commands.
Let us go again to the web browser and refresh the page so the index of PHP
now is gone. Again, let us go to our Kali machine and try to upload a simple
index.php file that we just created; it is on the desktop again. So
root/Desktop/index.php, now we specified the origin, we have to specify the
destination of that which will be again under var/www/html and it will be
named index.php.
It will give us a true, now let us go again to the website and refresh it and you
will notice that we have defaced the website and uploaded our own PHP
index file. In a nutshell, we installed the backdoor using the upload utility, we
connected to the backdoor, removed the index file and replaced it with our
own. Simple!
We will put the IP of our kali server, then we will create a simple php file that
will get the encryption keys via the info argument. Scrolling down, you will
be able to see the extension of the encrypted files (.locked by default); you
can change that to your own extension. Below, you will be able to see all the
extensions of the files that will be encrypted, you can add and remove any of
the files that you want to encrypt on the victim's machine.
Scrolling towards the end of the source code, you will see the string path
which is the path of the attack. In this example, the ransomware will only
encrypt the files under the test folder which is found on the desktop.
Navigating towards the end of the source code, you will see the test file that
we will be created on the victim’s machine, and the message that we will put
in this text file. For example, this message, "You have been hacked; send us
an amount of 0.5 bitcoins to this address to view your files again".
The most important part is the target URL. So, in this target URL, you are
sending the key from the victim to the web server that you have set up that
will contain encryption key. We will create a web server on the Kali machine,
and then we will create a php file on the root directory of the webserver to
receive the key.
So, for this purpose, we will call the file keys.php on the kali server’s root,
and we will get the information through the info argument. You need to
populate the IP of the web server; in this case, it is 192.168.211.143. Setting
up the web server is quite easy, go to your Kali machine and navigate to
var/www/html, list the contents; you have the index.php.
Now you need to create the keys.php file, use geditkeys.php, and once this
file opens, just paste the following code. This is the php script and the
keys.php file that will get the data from the info get argument and put it in the
data.txt file.
For the same purpose, we need to create the data.txt file in the same root path
of our web server.So use the same command gedit data.txt, open the file and
make sure to save it.
After you create the data.txt file, it is important to grant it access. Now go to
var/www/html, right-click on data.txt properties, then permissions, go to the
group, navigate to www-data and give it read and write access.
Now let us list the directory. We have the data.txt to save the encryption files
and the keys.php, which has the php script that will get the information via
the info get argument. The only thing left to do is to start the apache service.
Now everything is in place for the attack.
After we have edited the file with the path, extensions of the encrypted files,
the extension types, and the folder that we are going to attack along with
writing up the message to the victim, now it is time to compile the csharp
project. Navigate to the hidden-tear folder that you have downloaded under
the bin, under the debug folder, you will be able to see the hidden-tear.exe
file, as shown below.
Now open the decryptorcsharp project, and make sure to go to the path and
update it as we did for the ransomware files. Navigate to the build menu and
compile the solution. Navigating to the decrypter folder under bin, you will
find the decrypter.exe file created. Now we will move the ransomware and
the decrypter file to the victim's machine. Double click on the ransomware
and notice what will happen. The file will change to .redpython extension and
it will be encrypted. A new file as well will be populated that has our
message. Now go to the Kali machine.
Remember in the same directory, we had the file data.txt, so let us check
what is in that file. As you can see below, this is the name of the victim's
machine, this is the username of the victim, and this is the key use to encrypt
the file. Now, in order to decrypt the files, just run the hidden-tear decrypter,
paste the password, and then click decrypt files to have them decrypted.
All the traffic is blocked through the corporate firewall, except the DNS
traffic on port 53 that is used to resolve URLs. So, attackers will leverage
these open ports to set up an external command and control center to perform
various types of malicious acts.
First of all, we need to install the dnscat2 server on our Kali machine and
then run it. For this purpose, you just have to copy the code shown below to
update the repository of Kali and we will install Ruby on Rails, then we will
install the bundler, and then we will get the dnscat2 from GitHub, it will
clone it on our Kali machine, then we will navigate to dnscat2 directory and
then we will run bundle install.
apt-get update
apt-get -y install ruby-dev git make g++A
gem install bundler
git clone https://github.com/iagox86/dnscat2.git
cd dnscat2/server
bundle install
Now you need to run Ruby and invoke the dnscat2 command.
ruby ./dnscat2.rb
The dnscat2 servers will start listening to Port 53. And now our server will be
set up and ready.
To interact with the first session, type session-I 1, and you will see the name
of the client, the victim. Now we have a remote shell to interact with.
Type help to see all the commands that you can run remotely.
Now let us try to run notepad remotely. Just type execnotepad.exe and press
enter; it will tell you that the request has been sent.
Go to the victim’s machine and you will see that notepad is opened. With
creating each session, you will be notified on the server and you can interact
accordingly using this command of session-i and the number of the session.
Tunnels have been established between the client and server over Port 53,
just to make sure that it is over the port 53, we will run Wireshark in order to
sniff the traffic and investigate the type of traffic being sent and received. We
will select the proper interface and press capture. Wireshark is active on the
server-side, let us trigger the same notepad command.
As you will notice, the protocol captured is mainly DNS, so anyone who is
monitoring the victim's network traffic will only see DNS queries. This
traffic will of course blend with the noise that is present on many networks.
Let us say, for example, we are establishing the initial command and control
connection, it requires dnscat2 client to resolve a TXT record which is a very
normal thing to do, thus it will not trigger an alert. To protect against this
type of attack, you should block outbound DNS traffic and only allow trusted
DNS servers interaction.
Secret Sauce BONUS
Wi-Fi Jamming Tool
Have you ever thought of blocking Wi-Fi signals or kicking someone out
from your Wi-Fi connection? Well, this is the right topic for you. We are
going to create a simple Wi-Fi jammer that is so tiny that it can fit into your
pocket, so that you can carry it anywhere just by powering it up through a
simple power bank, or even your mobile phone.
First of all, browse to Ali Express and search for NodeMcu, and then click on
the first result which is a wireless module NodeMcu version.
This is very important; as you need to see this in the device manager on your
Windows machine. It will tell you in which port it is connected to, as shown
below.
Navigate to the website deauth.me and set up the NodeMcu using the online
interactive step-by-step tutorial. It will ask you first if you are a novice or
expert, press novice. It will ask you to download the bin file, click to
download it from the GitHub. You can see the latest releases of the bin file
and download the latest release.
Let us go back to the site, press next, and select the operating system you are
using. You need to download the flasher software. The flasher software will
help you upload the bin file or populate the firmware on the NodeMcu
device. Press next, select the COM port that the board is on. Press next and
you will be presented with a step-by-step on how to upload the firmware.
You need to open the flasher, you will notice that the device is connected to
COM8 port, go to config and select the location for the bin file. Now it is
asking us to press on the operations tab and press on the flash button.
Next, select the COM8 port, then press on the flash button. It will take some
time to upload the firmware, once you see the checkmark, it means that the
firmware has been uploaded successfully.
Go to the advanced tab and use the default that you can see on the chip.
Now things are in place, you need to connect to this Wi-Fi SSID named
pwned, open the Wi-Fi, click pwned, and press connect. You will be
prompted to enter a password for the first time which is deauther. Navigate to
the IP 192.168.4 and you will be presented with the application that we have
just populated on the NodeMcu.
The first tab is used to scan all the neighboring Wi-Fi connections. Once you
do that, you will notice that the blue LED light on the chip will turn on, it will
take a couple of seconds and then it will turn off. Once it turns off, press on
the reload, you will get all the neighboring Wi-Fi networks.
After that, select one access point, and then press on the scan stations button.
Again, the blue lead on the chip will turn on, it will take 15 seconds to scan
the stations that are connected to this access point. During the scanning of the
stations, you will be disconnected from the pwned network. After the
scanning is complete, make sure to connected again to the pwned network.
Press on the reload button and go down to the stations section. Select all, so
we are selecting all the stations that are associated with this access point.
Then go to the attacks menu, you will note three types of attacks; the
authentication attack, beacon attack, and the probe.
As for the authentication attack, which is the main application, we will select
six targets. So, once we start pressing this time, it will start sending the de-
authentication frames to all these six targets, so none of these six targets will
be able to connect. This chip runs on 2.5 gigahertz, all the clients running on
2.5 gigahertz will be disconnected. All the clients running for example on the
5 gigahertz they will not be affected by this attack.
So, now we will discover the effect of this attack on a client that is connected
to our network. We can use another laptop, connect to the access point, and
use Google where there is an internet connection. Now we will initiate a de-
authentication attack from the NodeMcu and just notice what will happen in a
while. Just wait for a couple of seconds and you will see that there is a yellow
mark, which obviously says that there is no internet connectivity.
Refresh the list of Wi-Fi SSIDs, you will find that there is no internet access.
After a few seconds, it will identify the network and connect to it. Refresh the
list again, it is connected, but the de-authentication packets will disconnect
the client in a while. This can go on forever, depending on your
configuration.
Some of you might think how can Arduino be used to hack computers? Since
it supports keyboard emulation, we can build sketches on the Arduino IDE,
which is a file actually that has .ino extension. These sketches contain
keyboard instructions to type commands and execute, just like the popular
USB rubber ducky does. We upload our payload, and once the USB is
inserted, the script will automatically run. So let us start building that.
You need to install the Arduino IDE. Simply go to the console and write apt-
get install Arduino to install the IDE. To initiate or open the IDE, write
arduino in the terminal.
Go to the website https://github.com/hak5darren/USB-Rubber-
Ducky/wiki/Payloads. It is an amazing page that has a lot of rubber ducky
scripts.
So, let us begin with the first one which is the simplest one, hello world. If
you click on that, you will be able to see the simple scripting language that
rubber ducky supports.
But Arduino does not support the scripting language of ducky. So, we have to
convert this to the Arduino language. Navigate to
https://d4n5h.github.io/Duckuino/ website to convert the ducky script into the
Arduino language. You have to paste your code and press on compile and
just press on copy.
After that, open the Arduino IDE and paste the converted script. Just to give
you a quick overview on how this code works. So as you can see below, this
is a sketch file, it is just a regular file with .ino extension; it has two main
procedures; the setup procedure, and the loop procedure. It also includes
some of the important header files.
The setup procedure will only be executed when Arduino is powered on and
initialized, the loop procedure will be executed repeatedly over and over
again until Arduino is powered off.
We will plug our Arduino chip, connect it to our mini USB cable and plug it
into our laptop. Go to the tools menu and select the board, it is Arduino
Leonardo and the port is on com6. Compile the hello world converted code
you pasted. You should receive a message ‘Done compiling’. Upload the
script to the chip by pressing on the upload button. Open notepad, then plug
the device, to see the following:
Compile then upload the code to the chip. You have to remove the USB as
fast as possible in order to avoid the attack being run on your computer. Our
payload is now loaded onto our Arduino device.
All that you need to do is to plug the USB in any machine you want to attack.
Once you do that, the sequence will take place in a matter of seconds. We
will open the users and see that redpython user is created in the admin group.
Biography
Mohamad Mahjoub is a prolific writer and a Cyber Security Expert. A
licensed and certified CISSP, ISO 27005 Risk Manager, CISA, PMP, ISO
27001 LI, and ITIL. He obtained his Master’s Degree in Computer Science
from the Lebanese American University, where he graduated with magna
cum laude. After spending many years working as an IT project manager for
one of the Multinational Pharmaceutical companies, Mohamad moved to the
Banking sector to attain a senior role in Information Security Audit. He has
then relocated to Dubai to join a smart university as an Information Security
Manager.
Mohamad’s accomplishment and research acumen is a drive force that’s
rooted in his professionalism. He is trained and certified to offer firsthand
professional Cyber Security services to individuals and companies. Since
2012, Mohamad has delivered many IT courses to fresh graduates, IT
professionals, executive management, and business owners, that’s on top of
his online multi-lingual Cyber Security courses that have more than 100,000
students enrolled worldwide, as of date. Currently, Mohamad works as CISO
for a French multinational company, where he is responsible for the security
of IT and OT of the industrial water technology operations throughout the
Arabian Gulf and Middle East area. With more than 16 years of experience in
the Cyber Security field, Mohamad is a trusted expert who have established a
track record of success in the Cyber Security domain.
In a world of ubiquitous technology; Mohamad believes that Cyber Security
is more important than ever.
I will be glad to connect with you through
LinkedIn:https://www.linkedin.com/in/mohammadmahjoub/