CSW Exp 5-10
CSW Exp 5-10
Figure 5: Default Gateway responds to the Broadcast Message with its MAC
Figure 6: Host A update its ARP Cache with IP and MAC address mapping
First of all, Host A is requesting an IP address that is not in the range of the Local
Area network IPs. Therefore, it will ask for the MAC address of the default gateway
IP (192.186.1.254 in this cases) by sending a layer 2 broadcast message to all the
hosts in the LAN. As shown in figure 4, Host B will ignore the message as it is not
matching with its IP. But router default gateway recognizes it as its IP address and
responds to Host A by including the MAC address in the response. After that, Host
a will dynamically cache that mapping in ARP cache. Now whenever sending traffic
to the outer networks, Host A will use that MAC address together with the default
gateway IP address for the generation of frames for the Data Link Layer of the OSI
model.
ARP Spoofing/Poisoning
ARP Spoofing is a technique where the attacker sends Malicious ARP Packets to
the default gateway and to the host who is communicating with the default
gateway in the local area network. The main intention is to associate the
attacker’s MAC address with the IP address of another host, such as the default
gateway, causing any traffic meant for that IP address to be sent to the attacker
instead. It allows the attacker to modify traffic and intercept data frames. As a
result, leading to a comma attacking terminology called the Man in the
Middle Attack (MITM).
Figure 7: Now Host B which is the Unethical Hacker/Attacker launch an ARP
Poisoning Attack
Figure 25: Explore PWD (password) field in Wireshark as messages are not
encrypted since using the HTTP protocol
Figure 26: Ettercap automatically detect and display packets or frames with PWD
(password) fields
Nowadays, ARP Poisoning is rare and avoided due to reasons like the usage of
encrypted communication in HTTPS protocol, Dynamic ARP Inspection, Static ARP
Entries, VPNs, and Packet Filters.
MiTM Attack with Ettercap
Man-in-the-Middle attacks can be among the most productive and nefarious
attacks. If the attacker/hacker can place themselves between two systems
(usually client and server) they can control the flow of traffic between the two
systems. In this way they can eavesdrop on the traffic, delete the traffic, inject
malware and even alter the traffic (imagine altering email!). In previous tutorials, I
showed you how to arpspoof and dnsspoof to execute a MiTM attack, but in this
tutorial we will use a GUI MitM tool known as Ettercap.
Ettercap is probably the most widely used MiTM attack tool (followed closely
behind by Cain and Abel, which we will look at in the later tutorial).
Ettercap was developed by Albert Ornaghi and Marco Valleri. It basically a suite of
tools to simplify MiTM attacks. It can be used either from the command line (CLI)
or the graphical user interface (GUI). In this lesson, we will use the GUI.
Ettercap enables us to place ourselves in the middle between two machines and
then;
• infect the traffic with malware
• delete traffic
• sniff passwords
• provide fake certificates for HTTPS
• DNS spoof
The principles and techniques of a MiTM attack remain the same as with arpspoof
with the small exception of the ip_forward. Unlike arpspoof, ettercap does not
use ip forwarding in the Linux kernel, but instead uses it own module to forward
IP packets.
It important to note that ettercap requires root privileges to open its Layer 2
(datalink) sockets. In addition, as you might expect, it can slow down
communication between the two target systems as it does its own processing.
Ettercap is GUI based tool built into Kali so need to download and install anything,
so let's get started doing a MiTM attack with Ettercap.
Step #1: Start ettercap
Let's view the help file for ettercap by typing;
kali > ettercap -h
As you can see, ettercap has a significant help file for running it from a command
line, but the only thing we need from here is the switch to run it in graphical
mode. In the bottom line of the screenshot (not the bottom line of the actual help
file as I have truncated it in the interest of space), you can see the -G switch. This
after the command ettercap will launch the ettercap GUI.
kali > ettercap -G
When we do, the ettercap GUI will start as seen below.
The first step in launching our MiTM attach is to start sniffing. Go to pulldown
menu that says "Sniff" and click on "Unified Sniffing".
Our next step to find the hosts on the network. Click on the "Hosts" tab and you
will see a menu that includes "Scan for Hosts". Click on it and ettercap will begin
scanning the network for hosts.
Now, using that same "Hosts" tab, click on "Hosts List". This will display all the
hosts that ettercap has discovered on your network as seen in the screenshot
below.
Now, select one of the hosts that will be the target of this attack in the window by
clicking on it and then click on "Add to Target 1" at the bottom of the window.
When you do so, ettercap will add that host as the first target in our MiTM attack
as seen in the screenshot below.
Next, select the second host in this attack and then click "Add to Target 2".
Finally, go to the menu above and click on MITM tab and the drop down menu
will have a selection called "ARP Poisoning" as seen in the screenshot below.
Select it and it will open a pop window like below. Select "Sniff remote
connections".
When we press OK, ettercap will begin ARP poisoning and you will see ettercap
respond in its main windows with the message below.
Now, we have successfully placed ourselves between the two targets systems and
all their traffic must flow through us. This is where the fun begins as we can now
delete, manipulate, impersonate and view all their traffic.
Altering the Traffic
As I mentioned above, the real risk in a MiTM attack is that the attacker can
eavesdrop on the Internet traffic as well as alter it, if they want. In this section,
now that we are between the two systems we will demonstrate the risks of MiTM
attack. We will use the MiTM attack to edit/alter the Internet traffic as seen by
the target. In this way, the attacker can actually alter the content of websites,
alter the content of an email, change the pictures seen by the target in their
Internet traffic, delete specific Internet traffic packets, etc. The message should
be clear, when we have placed ourselves in the middle, the target is at our mercy!
Step #2: Alter the Traffic
In this next section, we will be altering the traffic from an internal corporate
Intranet site. This site is used by all the employees for corporate announcements,
scheduling, etc. Although this scenario is within a corporate Intranet within a LAN,
the technique and effect would be the same over the wider Internet. In our
scenario, the manager has posted a new starting time for the following day
because of a very heavy work load. As a result, he wants everyone to begin work
at 6 am and he posts this to the corporate intranet site for all the employees to
see. Our attacker has malicious intentions toward the target and wants to alter
the message to the target so that they instead come to work late, at 11 am. This is
likely to have negative repercussions for the target from the manager, exactly
what the attacker wants.
Step #3, Create the Intranet Site
The corporate Intranet announcement page looks like the screenshot below.
Everyone in the department will see it and although they are disappointed in the
earlier start time, they adjust their schedule to help with the additional workload.
Our attacker doesn't want the target to see this message, but rather an altered
message to mislead him as to the new starting time.
As you can see in the screenshot above, there are numerous Ettercap filter files.
Note the one named etter.filter.examples. Let's open it with Leafpad and see
what it contains.
kali > leafpad etter.filter.examples
This file contains numerous Ettercap filter examples of various types. We can use
these as templates for creating our own filters. Notice the various types;
• display a message on port 22
• log all telnet traffic
• log all traffic except http
• do some operation on the payload of the packet (in this case change numeric
values)
• drop any packet containing a particular word or string
• log SSH decrypted packets matching a regular expression
• and many more
In our case, we want to replace words from a website with other words to alter
the meaning of the message. That is, we want to replace "Heavy" with "Light" and
"6" with "11" so that the message read by the target would be changed to:
Due to the Light Workload, Everyone is Expected to Come to Work at 11am
Ettercap has a pre-built filter file for doing precisely that! It's the etter.filter file.
Let's open it with Leafpad and take a look around.
kali > leafpad etter.filter
Notice, starting with Line 21 after the comments, we have some simple code that
searches for TCP traffic (if (ip.proto == TCP)) and it contains data that matches the
word "ethercap" (search (DATA.data, "ethercap")) then log and replace it with
ettercap (replace("etthercap", "ettercap") ) and create message of what
happened (msg("Correctly substituted and logged. \n")) We can use this same
code, but replace the words it is looking for and replacing it with the words we
want to replace, namely "Heavy" and "6".
Next, we have to edit this Ettercap filter file. First, copy and paste all the
uncommented code so that you now have two stanzas. Then replace the word
"ethercap" with "Heavy" in the first stanza and in the second stanza, replace the
word "ethercap" with "6" as seen the screenshot below.
Make all the changes circled in the screenshot above and save the file.
Step #5: Compile the Filter
Now, before can use the filter, we must compile it. Open a terminal and type;
kali >etterfilter etter.filter -o etter.filter.heavy
Where:
etterfilter is the command to compile the filter file
etter.filter is the input file
-o etter.filter.heavy directs the compiled output to a new file
Step #6: Add the Filter to Ettercap
Now that filter file has been recompiled and ready to use, we can go back to the
Ettercap GUI and select "Filters" and now, click on our compiled new filter that we
created. When it appears in the "Selection" window, go ahead and click OK. This
should now activate an automatic process whereby, in real time, whenever the
word " Heavy" is seen in the Internet traffic it, is replaced with "Light" and
whenever the number "6" appears, it replaces it with "11". It's important to note
that this replacement with take place on ALL internet traffic coming to the target.
Now, when the target goes to the Intranet site announcing the new starting time,
they will see the following web page as seen below. Everyone else will see the
actual Intranet site, but the target will have those two words changed.
This tutorial demonstrates how easy a MitM attack is using ettercap and the
power of being able to alter the traffic to the target system seamlessly and
transparently. The end-user has no indication that their traffic has been altered!
Experiment-6
Object: - SQL Injection: Use DVWA to practice SQL injection attacks.
Demonstrate how an attacker can manipulate input fields to extract,
modify, or delete database information.
To find out if this form has a SQL Injection loophole, we can try it by inputting
single quotes (‘).
Doing Attack
After determining that there is a security hole, I try to input the following payload:
%’ or ‘0’ = ‘0
SELECT first_name, last_name FROM users WHERE user_id = ‘%’ or ‘0’ = ‘0’;
We can also modify the payload. Examples are as follows to view information on
the version of the DBMS being used.
So, how can we reduce this risk? One way to reduce this risk is to use
whitelist/blacklist validation.
Blacklist validation works by detecting if the input contains a forbidden string. This
validation can reject malicious queries like drop tables which can wipe out our
entire data. Whitelist validation works by only accepting input if it belongs to a
reserved string/word. This method can be achieved by checking if the input is an
integer or providing a list of inputs on the front-end.
Experiment-7
Object: - Cross-Site Scripting (XSS): Exploit XSS vulnerabilities in
DVWA to inject malicious scripts into web pages. Show the potential
impact of XSS attacks, such as stealing cookies or defacing websites.
TYPES OF XSS:
1. Reflected XSS
2. Stored XSS
In this case, hacker data is not stored on the website. reflected XSS only execute
on the victim side. reflected cross-site scripting A hacker sends input script that
website then reflected back to the victim’s browser, where hacker it executed the
malicious JavaScript payloads.
Requirements:
1. Xampp or wamp
Payload: <script>alert(“xss”)</script>
Stored cross-site scripting (XSS) In this case the hacker malicious code is stored
target website and the web server. when an attacker can send malicious
JavaScript into the website and that script is executed other users’ computers that
is stored (XSS) cross-site scripting.
Payload: <script>alert(document.domain)</script>
DVWA Medium Level Stored XSS
Dom base (XSS) cross-site scripting attack is a short-form document object model
based cross-site scripting. That is, the page itself HTTP response does not change,
An attacker may use several DOM objects to create a Cross-site Scripting attack.
The most popular objects from this perspective are documents.URL,
document.location, and document.referrer.
Payload:
localhost/dvwa/vulnerabilities/xss_d/?default=<script>alert(1)</script>
DVWA Medium level DOM BASE:
Payload:
localhost/dvwa/vulnerabilities/xss_d/?default=English#<script>alert(1)</script>
and reload your browser.
Source code
The flaw in this code is that it lacks proper CSRF protection. It allows an attacker to
craft a malicious URL and trick a logged-in user into unknowingly executing
unwanted actions on their behalf.
The vulnerability lies in the fact that the code doesn’t include any mechanism to
verify the origin of the request. As a result, an attacker can construct a URL
containing the necessary parameters (password_new and password_conf) and
send it to a victim. If the victim clicks on the malicious link while authenticated on
the vulnerable website, the code will execute the password change without any
further authentication or user consent.
After changing the password you can see in the url is that it lacks the necessary
CSRF token. In the absence of CSRF protection, an attacker can still exploit this
vulnerability by tricking the victim into clicking on the URL while logged in to the
vulnerable website.
Now we will Display the HTML code for the page, which includes a link to
download a game called “FIFA 2023. and password has been changed by attacker”
If attacker send this link to the victim, the password will be changed.
If the victim tries to open the html page. It will looks like this….
When victim tries to click on the FIFA link, the password “12345” will be changed
automatically
Security: Medium
First things first, lets change the security level of the DVWA.
If we try to use low security method then it wont work anymore
Low
Can you see the difference? Within the legitimate request we see there is a
Referer, where the request came from. That matches up so the request goes
ahead.
So what if we intercept the illegitimate request with Burp and add the HTTP
Referer. Like so.
Now we will try to intercept the website and add legitimate Referrer using
burpsuite
Experiment-9
Object: - File Inclusion Vulnerabilities: Explore remote and local file
inclusion vulnerabilities in DVWA. Show how attackers can include
malicious files on a server and execute arbitrary code.
It is an attack that allows an attacker to include a file on the web server through a
php script. This vulnerability arises when a web application lets the client submit
input into files or upload files to the server. A file include vulnerability is distinct
from a generic Directory Traversal Attack, in that directory traversal is a way of
gaining unauthorized file system access, and a file inclusion vulnerability subverts
how an application loads code for execution. Successful exploitation of a file
include vulnerability will result in remote code execution on the web server that
runs the affected web application.
LFI vulnerabilities allow an attacker to read (and sometimes execute) files on the
victim machine. This can be very dangerous because if the web server is
misconfigured and running with high privileges, the attacker may gain access to
sensitive information. If the attacker is able to place code on the web server
through other means, then they may be able to execute arbitrary commands.
RFI vulnerabilities are easier to exploit but less common. Instead of accessing a file
on the local machine, the attacker is able to execute code hosted on their own
machine.
Remote File inclusion (RFI) and Local File Inclusion (LFI) are vulnerabilities that are
often found in poorly-written web applications. These vulnerabilities occur when a
web application allows the user to submit input into files or upload files to the
server. In order to demonstrate these attacks, we will be using the Damn
Vulnerable Web Application (DVWA).
1. XAMPP
2. Damn Vulnerable Web Application (DVWA)
NOTE: Currently, lets focus on file inclusion attacks. I am going to show you how to
setup lab using xampp, dvwa and many more in my next upcoming blogs.
Since you have an idea what LFI is, let’s see it in action. We will perform LFI attacks
through different levels of difficulty offered by DVWA.
Difficulty: LOW
Now start your machine and login to DVWA, then go to DVWA security tab and
change the difficulty level to low.
Now, go on and try the exploits we used in low difficulty. You will notice that you
can’t read files like before using the directory traversal method. So, as you can see
in the below snapshot of source page, the server is more secure and is filtering the
‘../’ or ‘..\’pattern. Let’s try to access the file without ‘../’ or ‘..\’.
As you can see, it worked by directly entering the name of the file. Let’s level up
the difficulty to HIGH.
Difficulty: HIGH
Change the difficulty to HIGH and try all exploits from medium difficulty, and you’ll
notice none of them will works because the target is more secure, as it is only
accepting “include.php” or inputs starting with the word “file”. If you try anything
else, it will show “File not Found”.
In this level of security, we can still gather sensitive info using the “File” URI
scheme. (because it starts with the word “file”)
This is how you can exploit file inclusion vulnerability using local files on the
webserver.
Remote File Inclusion in Action
Now, let’s try to exploit this vulnerability using remote files hosted on the attacker
machine.
Difficulty: LOW
?page=http://www.google.com
Difficulty: MEDIUM
Change the difficulty to medium and check as we did it in the low difficulty. You’ll
notice, it’s not working anymore. The target is now filtering “http” and “https” as
shown in source page.
so try the attack with “HTTP” (in CAPS) or any one word in caps like I used as
shown in snapshot (httP)and it’ll work.
?page=httP://imdb.com
Difficulty: HIGH
We can’t exploit the high difficulty using RFI as you can see in source page,we
know that the target web-server is only accepting “include.php” or anything that’s
starting with the word “file” that’s why we can’t include anything from an outside
server.
d) For filenames, use stringent whitelist that limits the character set to be used.
g) Environment Hardening.
h) Develop and run your code in the most recent versions of PHP available.
The attack will utilize Hydra as a parallelized login cracker and the ‘rockyou.txt’
wordlist that will be demonstrated on the login form below.
Initially, barely any information was disclosed. However, a wild guess would be to
use one of the most popular usernames on any web application, which is “admin”.
Before proceeding with the attack, we must first collect more information. Open a
Burp Suite browser and direct it to the DVWA page, which will look exactly like the
one on a regular browser. Now, try logging in using a random password. For this
attempt, the username “admin” and password “admin123” was used. For Burp
Suite to scan the web application, turn on the Intercept mode right before clicking
on the “Login” button.
With the incorporation of all the elements and components listed on the table,
Hydra will systematically attempt the various combinations of passwords from the
‘rockyou.txt’ wordlist in an attempt to crack the password for the “admin”
account.
The result of the attack reveals the password to be “password”, which will show
that the login is successful, hence concluding the demonstration.
The demonstrated attack proves how easy malicious actors can breach through
accounts with weak passwords. Therefore, it is always important to set a password
that complies with the standardized strong password policy or instead incorporate
the use of a more robust passphrase.