Ethical Hacking-1
Ethical Hacking-1
Ethical Hacking-1
Lab setting:
To proceed with the hacking process, there are a few
prerequisites to be set up in our system answer call it a
lab. To create a lab, we need
Hacking machines: if you are hacking other
machines.
Websites to hack: if you are hacking websites.
Network to hack: if you are hacking networks.
Initial preparation:
The first operating system to install in our lab is Kali
Linux. Using an operating system designed for hacking
reduces our time and effort. It’s a Linux distro based on
Debian, the main difference between Kali Linux and the
original Debian Linux is that Kali Linux has a lot of
hacking testing tools pre-installed and pre-configured.
You can install Kali Linus as both the main machine and
a VM machine but here we are going to download it as a
VM machine. Download Kali Linux from the link:
https://zsecurity.org/download-custom-kali/
Initial preparation:
The first operating system to install in our lab is Kali
Linux. Using an operating system designed for hacking
reduces our time and effort. It’s a Linux distro based on
Debian, the main difference between Kali Linux and the
original Debian Linux is that Kali Linux has a lot of
hacking testing tools pre-installed and pre-configured.
You can install Kali Linus as both the main machine and
a VM machine but here we are going to download it as a
VM machine. Download Kali Linux from the link:
https://zsecurity.org/download-custom-kali/
To enable virtualization,
Reboot your computer.
While the system is turning on again, we should
enter the BIOS settings. To enter the BIOS settings, a
set of keys that should be pressed are given
according to your system.
Press the key that is relevant to your computer. The
BIOS settings window opens
To enable virtualization check for, VT-X, AMD-V,
SVM, and Vanderpool and enable the virtualization
and exit the window.
The computer restarts enabling the virtualization.
Basic overview:
1. Left top corner of the status bar
It has two options Application menu and places. The
application menu contains applications categorized as
information gathering applications, vulnerability
analysis, web application analysis, reverse engineering,
etc.,
The places option shows the most common place
visited in the system. It’s more of a shortcut so that you
can access the files from there.
2. Right top corner of the status bar
The right corner contains workspaces and the other
icons. Linux by default comes with different workplaces.
You can work in many workplaces at the same time. As
many workplaces as you’re using, Linux keeps creating
new workplaces. The shortcut to switch between
workplaces is ctrl+alt+up/down
The last icon has various options like sound control and
the list of connections available and the connected
network. In Kali, only external USB adapters can be used
for wifi and not built-in wifi cards. Kali should have an
internet connection for usage. There are also battery
and user settings.
3. Application bar
It has a list of application icons that are regularly used
and if you expand the bar you can have a view of all
applications.
Recommended chipsets:
1. RealTek RTL8812AU
2. Atheros AR9271
When it comes to an adapter, the brands are
irrelevant. You can go with any brand that has any of
these two chip sets as long as it is supported by the
Kali because these chipsets are the brain of the
adapter. To connect the adapter to the virtual
machine,
Start the VMware. Right-click on the Kali machine
and open settings.
→ →
Click on Add USB controller Finish.
In the USB compatibility, set it to USB 3.1
Check the “Show all USB devices” check box and
click ok.
Before connecting to Kali make sure you are
disconnected to the wireless adapter you already
connected to your computer.
Start Kali and log in.
Open the terminal and run the command, ifconfig.
This command lists all of the network interfaces
connected to this computer. It shows only the
default interfaces as of now.
Now connect the USB to your computer. A popular
window appears. Select the “connect to the virtual
machine” option and select the virtual machine to
which you are connected and click okay.
If you run the same command, ifconfig again, it
will show the interface of the USB adapter you
connected.
Changing MAC address:
Open the terminal and type the command,
ifconfig.
The list of the available network appears. The first
two networks eth0 and l0 are the default network
by Linux and the wlan0(in here) is the wireless
adapter you connected.
The ether configuration in thewlan0 is the MAC
address of your network.
The ether configuration is what should be
changed in order to change the MAC address of
the wireless adapter.
Wireless modes:
Whatever you do with the internet, it is always sent
in packets from your computer to the access
point. It will travel from the source MAC to the
destination MAC.
Since these packets are sent via air, if you are
within the range you will be able to capture the
data without even being the destination MAC.
To do this, you need to change the mode of
operation of your wireless interface to operate in
monitor mode.
Go to the terminal and run the command, iwconfig
This command only shows the wireless interfaces
and its default mode is “Managed”
It means the device can only capture packets that
have the destination MAC address that is directed
only to the Kali machine.
So this mode should be changed to access the
packets. Before changing any option of your
interface, the interface should be disabled.
To disable the interface.
ifconfig interface_name down
Now before changing the mode, run a command
that will kill the interferences the interface will
face while running in the monitor mode.
Run the command,
Airmon-ng check kill
Packet sniffing:
Now that we are connected to the monitor mode, we
can capture the packets that are not directed to your
computer. For that, we need a program to complete
the process. The program we are going to use is,
Airodump- NG
The It’s a packet snippet and it is designed to capture
packets while you are in monitor mode. It allows you
to see all the wireless networks around and show
detailed information about the MAC address, its
channel, its encryption and even the clients connected
to this network. Let’s see how to use it.
You will know more about ENC, CIPHER & AUTH in the
upcoming sections.
Here ‘a’ is the band argument for 5Ghz. Now, all the
networks including the 5Ghz network will be available
in the list.
Deauthentication attack:
This attack allows us to disconnect any device from
any network before connecting to any of these
networks without even knowing the passwords to the
network. To do this, we are going to pretend like the
client network by changing the MAC address of the
client. Followed by pretending the router MAC address
is our address until the device is disconnected. For
this, the command airplay-ng is used.
Go to the terminal and give the command,
Airplay-ng –deauth numberofthe_deauthpackets –a
MACaddress_oftargetnetwork –c
MACaddress_oftheclient interfacename
Working:
If a client sends something to the router. For eg., text.
The transmitter will encrypt the text using a key and
convert the normal text to gibberish. This encrypted
packet will now be sent to the router via air. And if a
hacker captures the packet now, it will be full of
gibberish as we saw in the previous sections.
The access point will be able to change the
encrypted message as it has the key. The same
procedure happens when the router wants to send
the message. The RC4 algorithm is the best but
the problem is with the implementation.
WEP generates a unique key to each packet when
sending it to the router. To do that initializes a
random 24bit initialization vector. Then this
initialization vector is added to the password.
People use it to connect o the network.
This generates a key stream and this is what
encrypts the data packet. Before sending the
packet to the air, the WEP appends the
initialization vector as plain text because the
router will be able to decrypt the packet only with
the key and the IV.
When the packet reaches the router, with the key
and the IV, the router generates a keystream and
transforms the gibberish into the actual text.
Cracking WPA/WPA2
With the wordlist created we are going to crack the
WPA2 with the handshake packet. The aircrack-ng
will unpack the handshake packet and derive useful
information. The message integrity(MIC) in the
handshake packet is the tool that is used to verify
the password.
ARP poisoning:
MITM is man-in-the-middle attacks, these attacks
can be launched only if we can intercept the
communication between two devices. Usually, the
client contacts the resource/Internet. In this
process, attacking in the middle of the contact and
gaining access to the data shared is called the MITM
attack. There are a lot of methods to do this, here,
we are going to learn about ARP attacks. It allows us
to redirect the flow of the packets. Any packets or
responses sent would be made to flow through the
Hacker’s computer. This allows the hacker to read,
modify or drop the data.
Basics of bettercap:
Bettercap can be used for what we did with ARP
spoof and much more. It can be used to capture
data, analyze it, see usernames and passwords, can
be used to bypass HTTPS and potentially bypass
HSTS.
Syntax to start bettercap:
Bettercap -iface [interfacename]
HTTPS bypass:
The data interception we did in the previous
modules will work only with HTTP because it sends
data in plaintext. That’s why a MITM can read all the
data. To overcome this, HTTPS was created. It adds
an extra layer to the data HTTP sends, which makes
the data into gibberish. So even if the data is
captured it cannot be read by anyone.
HTTPS use Transport Layer Security(TLS) and
Secure Sockets Layer(SSL) to encrypt the data and it
is very difficult to break. So to bypass this the
HTTPS connections should be downgraded to HTTP.
Since we are the MITM now, we can change the
target requests of HTTPS and give them the HTTP
request. To do this, we have to configure a tool
called, SSL strip.
HSTS bypass:
In the previous module, we saw that we cannot
intercept HSTS websites, it is because modern
websites by default come with a list of websites that
only should load over HTTPS. IN HSTS, the browser
knows that the website should only be loaded as
HTTPS & accepts it only if it comes back to HTTPS.
As a MITM, we cannot do anything about it as the
browser checks it locally with the list that is stored
on the computer itself.
The only solution to bypass HSTS is to make the
browser think that it is loading another website. To
do this, all HSTS links should be replaced with
similar links, but not the exact links. For eg.,
Facebook.com as Facebook.corn
Injecting codes:
As far now, we learnt how to intercept data and see
the shared images, URLs and passwords. Now, we
can modify the HTML code of the pages as they load
on the target browser. After capturing the HTML
code flowing through our computer, we can insert
any piece of code we want. HTML is only
responsible for buttons, forms and text on the
website and does not allow us to do much. But
modern websites allow javascript code and it can be
used to replace links, and images, insert new
elements and more.
Wireshark:
Wireshark is a network protocol analyzer and it is not
designed for hackers/hacking. It is designed for
administrators to make sure that everything on the
internet is working properly. It allows you to select an
interface and log out of everything other than that. It
also allows you to search through packets. It is not a
hacking tool, it only allows you to capture the traffic
that flows through your own computer and interface.
ARP attacks-detection:
ARP works when a request is trusted and clients
accept responses even if they didn’t send the
request. To check whether you are ARP poisoned,
you should continuously keep checking your MAC
address whether it is changed or not. But to make
this process easier, a tool called XRP does that
automatically.
Suspicious activity-detection:
Apart from XRP, even wireshark can be used to
detect suspicious activities in a network.
Before you go to the procedure, go to Edit →
Preferences → Protocols → ARP and check the
detect ARP request storms check box and click
okay.
Start the capture by clicking the blue icon in the
top left corner.
Try ARP poisoning in the Kali machine.
And now when we look at the output of the
Wireshark it has caught a lot of packets.
From this we can know that some device is
trying to send requests to other devices.
Go to analyze → Expert info and see detailed
information about the devices.
It shows what is wrong, the errors, the warnings
etc.,
Server-side attacks:
These are the attacks that don’t require user
interaction, these attacks can be used with servers,
and web servers and they can also be used against
normal computers. When you target a server with
the IP address of the server you can access it
directly on the internet. This way of information
gathering works if the device is on the same
network. But if you ping a network or a device you
can run all the attacks and all the information-
gathering methods. Here, we are targeting our
Metasploitable virtual machine.
Nexpose installation:
Nexpose is an enterprise tool with a vulnerability
management network mostly used in large
companies made by Rapid7.
It is designed to cover the whole vulnerability
management cycle, it can discover open ports,
running services, find exploits and more.
Download nexpose and install it.
Open the terminal and find the downloaded file
with the command ls.
The file is a binary executable, so before running
it should be changed to unexecutable.
To do that, chmod +x [filename]
Incoming connections:
The backdoor we created uses a reverse
payload, which means it doesn't open a port but
connects from the target computer to our
computer.
For this to work, a port should be opened on our
computer.
Run the metasploit framework to listen to
incoming connections.
To listen to connections, we are going to use a
module from metasploit. To use a module, use
[module name]
Backdoor testing:
To test the backdoor and to make sure it works
we are going to run it on our practice target
machine.
Go to the location where the web files are stored
and find the backdoor file created.
To start the kali browser, its services should be
started. To do that,
Service [name of the web server] start
Now go to the windows machine web browser
and search for the IP of the Kali machine. It will
open a basic web server page.
To go to the backdoor, Ipaddress/Filename and
there will be the backdoor file.
Download and run the file.
Now when we come back to the kali machine we
can see a new connection.
Now start the evil grade and it will wait for the
connection.
We are not the MITM yet, so open another
terminal and run bettercap and set the DNS
spoof to the domain website.
To listen to incoming connections, do a
metasploit exploit.
In the windows machine, when the update is
updated full access to the target machine will be
taken by us.
The client attacks work with ease and great but the
only limitation is that the hacker should be the
MITM. In this section, we are going to learn methods
of social engineering if we aren’t the MITM. It helps
to gather more information on the user and build a
strategy and backdoor based on the gathered
information.
Basics of maltego:
Maltego is a tool for gathering information and
the target of this tool can be a website, person,
computer or anything. It discovers the entities
associated with the target and displays them on
a graph.
Download and install the tool.
Login with your user credentials, and the tool
interface will be opened.
When you click the left topmost icon and you
open a new graph.
Trojan compiling:
The script should be changed into an executable
before starting it.
First change the extension of the file from .txt to
.au3
Go for all programs → compile → and select the
application.
Browse and open the script file. You can also
change the icon of the file and click convert.
Now set the incoming connections and run the
exploit.
Wait for the connection and once the connection
is received you will gain access.
Extensions spoofing:
When you attach the backdoor file with an image
file, then when downloaded its extension will be
.exe
So we should spoof the extension and change it
to the required extension.
This can be done by using a tool, right to the left
convertor. It gives a character to use in the
filename.
When the characters are used, the file name will
be read from right to left.
Eg., the previous filename - gtr.exe
Add the extension to be changed to the filename
in reverse.
If the file is to be changed as jpg.
gtrgpj.exe
Copy the character from the tool and add it
before the needed extension.
gtr[characters]gpj.exe
The characters cannot be seen but once you
paste it, the file name will be read from right to
left and will be changed to, gtrexe.jpg
Now rename the file to this name.
Don’t add the file as it is because sometimes the
browser eliminates the right-to-left override.
So, compress it and change it to an archive file.
This method can be used to create any type of
file.
Email spoofing(type 1)
The trojan backdoors can be delivered to the
target in many ways and this is where
information gathering plays a vital role.
With the information, you can pretend like a
friend, company, boss or anyone the target
knows.
To do this, go to google and search for, spoof
emails online.
But the problem with these services is that the
email sent will go only to spam and not to inbox.
In order to bypass this, an SMTP server can be
used. Search for a free SMTP server and signup.
Once you sign in, verification should be done
with your email address.
To send a fake email, we need a program
sendemail to do that job.
Open the kali machine and run the command,
sendemail –help to know more about it.
Initially the username and password should be
set so use the command,
Sendemail -xu [username] -xp [password] -s
[server]:[port]
The username and password can be found in
the transactional tab of the SMTP server.
Using beef:
Start beef and login
Get the script code and paste it into the
index.html file. Change the IP to the google Ip
and save it.
Go to Ip forward settings and set the beef IP
port. Add the beef Ip port to the public and target
port and enter the target Ip and save.
Browse the google Ip in the host machine and
you’ll be hooked to beef.
Instead of IP forwarding you can also set your
kali machine as a DM2 host if your router
supports it.
Enter your kali Ip address and save. Now all
requests the browser gets will be forwarded to
the kali machine.
Section 16: Post exploitation
Basics of meterpreter:
Open the kali machine and run the meterpreter
exploit.
Run help command to know more about the
meterpreter commands and module.
The background command minimises a window
by running background. Running the background
command takes you to the metasploit exploit
and you can run any command outside the
target maintaining the connection with the
target.
Pivoting:
Consider, our target machine is connected to a
network along with the other devices. Now, the
target is invisible to the hacker because it is hiding
behind a server. But the hacker could see another
device connected to the network and have access to
it. Since the hacker has the access to a device that is
connected to the same network as the target, it uses
the hacked system as a pivot to gain access to the
target machine. In simpler words, we are using a
hacked system to hack into another system.
To do this, we need to modify the network settings
of the virtual machines.
Open VMware and open the window’s network
settings.
Add a second network adapter to it and set the
network to Bridget instead of NAT.
Go to the metasploitable VM and set its
connection to the bridged network.
To set a route between the hacker computer and
the hacked computer, a tool called autoroute is
used.
Run sessions and use the command,
DNS information:
To gather the DNS information and records from
the DNS server, a website called Robtext.com is
used.
Enter the target on the website and hit enter.
A report about the website will be generated.
You can read the full report or navigate to the
required sections with the section tabs.
The report has the following information.
1. Digital name servers(Hosting website)
2. Google mail server
3. Ip address
4. Similar domains as the target
5. Quick info on the website
6. History
7. Graph and many more.
Discovering subdomains:
The target website is always in the format
target.com which is the domain name. All domain
names have a subdomain. Eg.,
subdomain.target.com or mail.google.com
Preventing vulnerabilities:
Only allow safe files to be downloaded and
check the file types.
Before executing a file, filter its inputs.
Disable allow_url and allow_fopen in your
machine.
Database tables:
Our target database is owasp10 and let’s try to
discover the tables in it. Run the command,
Reflected XSS:
It is very similar to SQL, browse through the web
and try to inject into the textbox.
It is not persistent and not stored, so it only
works when the target visits a specially crafted
URL.
Go to the DVWA website and select XSS
reflected. Let’s try to inject the JS code into the
textbox.
Exploiting XSS:
To exploit XSS and gain access to the target
computer, we are going to use beef.
Using the beef hook URL, we are going to inject it
into the stored XSS page, so everyone visiting
the page will be hooked to beef.
To hook victims, the default hook of beef should
be used.
Now the device opening the website will be
hooked to beef.
You can now run all the commands in the target
that we learnt in the previous sections.