Ethical Hacking
Ethical Hacking
Ethical Hacking
Testing
Rahul Shandilya
Types of Hacker
Grey, black, and white hackers are terms used to categorize individuals based
on their ethical and moral stance when it comes to hacking and cybersecu-
rity. These terms help dierentiate between hackers who use their skills for
dierent purposes. Here's an overview of each type:
Legal: They operate within the boundaries of the law and typ-
ically have permission to test and secure computer systems, net-
works, and software.
1
Examples: Some grey hat hackers disclose security aws they
discover, but they may not always follow legal procedures or eth-
ical guidelines.
2
3. Exploitation Tools:
Metasploit: A penetration testing framework that provides a
range of exploits, payloads, and post-exploitation modules.
7. Forensic Tools:
Autopsy: A digital forensics platform for analyzing disk images
and extracting information.
3
Maltego: A data mining tool for gathering information about
individuals and organizations.
Phases of Hacking
Reconnaissance and Footprinting Reconnaissance is where you gather
information about your target. Footprinting is just getting an idea of
the footprint of the organization, meaning the size and appearance.
This means trying to identify network blocks, hosts, locations, and
people.
Gaining Access This is where you can demonstrate that some services are
potentially vulnerable. You do that by exploiting the service.
Covering Tracks Covering your tracks is where you hide or delete any ev-
idence to which you managed to get access. Additionally, you should
cover up your continued access. This can be accomplished with mal-
ware that ensures that your actions aren't logged or perhaps misreports
system information, like network connections.
4
Security and Risk Management
Condentiality: Can actors who should not have access to the system
or information access the system or information?
Integrity: Can the data or the system be modied in some way that
is not intended?
Availability: Are the data or the system accessible when and how
they are intended to be?
5
Vulnerability For a threat to become an actual risk, the target being
threatened must be vulnerable in some manner. A vulnerability is a aw
that allows a threat to cause harm. Not all aws are vulnerabilities. To
take a non-security example, let's imagine a bridge. A bridge can have some
aesthetic aws; maybe some pavers are scratched or it isn't perfectly straight.
However, these aws aren't vulnerabilities because they don't pose any risk
of damage to the bridge. Alternatively, if the bridge does have structural
aws in its construction, it may be vulnerable to specic threats such as
overloading or too much wind.
Types of Malware
Malware is a broad term that can be associated to any program or script
that was intentionally developed to destroy data or cause damage to the
normal functionality of a computer or network, or to perform malicious ac-
tivities such as stealing sensitive information (e.g. login credentials, credit
card numbers, nancial information, etc.) or gaining unauthorized access
to computer systems. It can come in dierent formats, such as executables,
binary shell code, script, or rmware.
The widely used classication is made by malware type, with some being
more common than others. The most signicant and common malware types
are
6
and potentially to other systems as well. Viruses must execute to do
their malicious activities, so they target any type of le that could be
executed on the system.
Rootkits: These are a set of malicious software tools that give attack-
ers privileged access to the victim system. Attackers can then remotely
execute les, steal sensitive information, change the system congura-
tion, or alter the functionality of the security mechanism [1]. Unlike
virus and worms, rootkits cannot self-propagate or replicate but, it
must be installed on the target system.
7
ing the users' les and displays a message that demands payment (or
ransom) to restore its functionality. It can be spread to the victim's
devices through vulnerabilities in the system or through downloaded
les and links in phishing emails . According to security reports, re-
cent ransomware attacks focused on healthcare, local government, and
education sectors, in particular.
8
Hacking Mobile Platforms
We all know the rapid increase of mobile phone users and exibility of func-
tion and advancement to perform every task has brought a dramatic shift. As
mobile phones are popularly used for online transactions, banking applica-
tion, and other nancial applications, mobile phone devices must have strong
security to keep the transactions secure and condential. Similarly, mobiles
have important data such as contacts, messages, emails, login credentials,
and les which can be stolen easily once a phone is compromised.
9
Vulnerability Assessment
Vulnerability Categories
Vulnerabilities are grouped in categories based on their origins or impacts.
Thus, with categories, we can have preventive measures or solutions to vul-
nerabilities that are similar to each other.
10
When a program attempts to put more data into a buer than it can
store, the extra data will overwrite the memory area past the buer.
Writing outside the bounds of a block of allocated memory can corrupt
data, crash the program, or cause the execution of malicious code.
11
3. Deserialization Vulnerabilities : Serialization is the process of convert-
ing an object into a byte stream. This facilitates transferring the serial-
ized object over the network. Deserialization is the process of reversing
the byte stream into the original objects of programming language. The
problem occurs when the receiving node does not validated or verify
the deserialized object. In other words, if the receiving node deserial-
izes a byte stream and then directly uses the reconstructed object, an
attacker can inject a malicious object into that node.
Cryptographic Vulnerabilities
This category contains vulnerabilities related to how applications handle en-
cryption and decryption of sensitive information. A cryptographic vulnera-
bility leads to breaching the condentiality of information. And exploiting a
cryptographic vulnerability allows an attacker to access sensitive information.
This category can be further divided into the following three sub-categories:
12
Conguration Vulnerabilities
These vulnerabilities result from incorrect or improper conguration of ap-
plications. System administrators and IT engineers must always follow best
practices when conguring any appliance or service. The following are few
examples of Conguration Vulnerabilities:
13
DHCP Exhaustion : DHCP is a protocol responsible for assigning
dynamic IP address congurations to workstations in the LAN. DHCP
works through a process known as DORA Discover, Oer, Request,
and Acknowledge. Given the lack of any authentication mechanism,
an attacker can simulate the DORA process indenitely until the IP
address pool of the DHCP server is exhausted.
Authentication Vulnerabilities :
Authentication is the process of validating the identity of a certain entity
(e.g., a user or a process). Authentication is done through one or more of
the following:
Authorization Vulnerabilities
Authorization is the process of granting privileges and rights after an entity
has been authenticated. When a user accesses a system as a normal user (not
as root/administrator), all processes running by that user account will have
14
limited privileges. In case certain process requires to do a task with adminis-
trative privileges, it will elevate its privileges temporarily in order to perform
such task. However, it must drop those elevated privileges immediately after
the operation is completed. If the process failed to drop those privileges, the
process will continue running as root/admin and any other vulnerability will
have a greater impact on the system. In other words, later vulnerabilities
will be exploited with admin/root privileges instead of user privileges.
Hardware Vulnerabilities
This class contains vulnerabilities residing in the CPU hardware due to poor
manufacturing design. Thus, they cannot be patched easily; some require
patching the rmware, while others remain until the hardware component
is replaced and upgraded. The two vulnerabilities are called Meltdown and
Spectre and they aected Intel CPUs. These vulnerabilities exist because of
a modern CPU feature known as Speculative Execution.
Speculative Execution is a feature in modern CPUs that was implanted
to speed up the execution process of programs. However, under Speculative
Execution, the CPU executes both paths in advance prior to condition
evaluation and stores the results in its cache. And once the condition is
evaluated, the CPU chooses the right results from its cache. Given that
both logical branches have been executed and stored in the cache, a running
program that does not have privilege to see either of the logical branches,
may now run a so-called Side-Channel Attack and access the stored data.
By knowing the Cache address of the data, it can check the content of that
cache not by directly accessing it (since it has no permission), but rather by
how fast CPU rejects its attempt.
15
Exploits
Exploits are specic techniques or pieces of code that take advantage of vul-
nerabilities or weaknesses in computer systems, software, or networks to gain
unauthorized access, control, or privileges. Ethical hackers and penetration
testers use exploits to demonstrate and identify security aws, and their pri-
mary goal is to help organizations strengthen their security by identifying
and xing vulnerabilities before malicious hackers can exploit them.
Ethical Use: Ethical hackers and penetration testers use exploits with
the permission and knowledge of the organization they are testing.
Their actions are legal and intended to uncover and address security
issues.
16
Legality: Unauthorized use of exploits or hacking into systems with-
out explicit permission is illegal and unethical. Ethical hacking and
penetration testing are conducted within the boundaries of the law
and ethical guidelines.
injection-based attacks
Injection-based attacks allow threat actors and penetration testers to inject
customized code into an input eld within a form on a web application.
The web application will process the input and provide a response, as it is
designed to operate in a client-server model and a request-response model
too. However, if a user sends malformed code to a login form on a web
application, the user may be able to retrieve sensitive information from the
web application and the database server, and even perform operations on the
operating system of the hosting web server.
Without proper validation and sanitization of users' input, threat actors
are able to determine whether a web application has security vulnerabilities,
manipulate the data stored within the backend database server, and even
perform command injections on the host operating system.
17
operating system, which then executes the code. This will allow the threat
actor to execute commands on the host operating system of the web server.
SQL injection
https://owasp.org/www-community/attacks/SQL_Injection
18
Session Management Flaws
19
7. Session Impersonation: Attackers may use session management aws
to impersonate other users, gaining unauthorized access to their ac-
counts and data.
Session Hijacking
The attacker intercepts the session and takes over the legitimate authenti-
cated session. When a session authentication process is complete, and the
user is authorized to use resources such as web services, TCP communica-
tion or other, the attacker takes advantage of this authenticated session and
places himself in between the authenticated user and the host. Authenti-
cation process initiates at the start of TCP session only, once the attacker
successfully hijacks the authenticated TCP session, trac can be monitored,
or attacker can get the role of the legitimate authenticated user. Session hi-
jacking becomes successful because of weak session IDs or no blocking upon
receiving an invalid session ID.
20
Session Hijacking Techniques
Session Hijacking process is categorized into the following three techniques:
21
Types of Session Hijacking
Active Attack The active attack includes interception in the active session
from the attacker. An attacker may send packets to the host in the active
attack. In an active attack, the attacker is manipulating the legitimate users
of the connection. As the result of an active attack, the legitimate user is
disconnected from the attacker.
Passive Attack The passive attack includes hijacking a session and mon-
itoring the communication between hosts without sending any packet.
22
Hijacking is basically the process of taking control over an existing active
session between an authenticated user and a target host. The attacker uses
the authenticated session of a legitimate user without initiating a new session
with the target.
After observing the above session IDs, you can easily identify the constant
part and other variable parts. In the above example, ABCD is the constant
part, 01012017 is a date. and the last section is the time. An attacker may
attempt with the following session ID at 19:25:10
23
Compromising Session IDs Using Man-in-the-Middle Attack The
process of compromising the session ID using Man-in-the-Middle attack re-
quires splitting of the connection between Victim and Web server into two
connections, one of them between Victim-to-Attacker and another between
Attacker-to-Server.
24
Cross-site Script Attack Cross-site Scripting attack is performed by an
attacker by sending a crafted link with a malicious script. When the user
clicks this malicious link, the script will be executed. This script may be
coded to extract the Session IDs and send it to the attacker.
25
MITM
IP Spoong
TCP/IP Hijacking
TCP/IP hijacking process is the network level attack on a TCP session in
which an attacker predicts the sequence number of a packet owing between
victim and host. To perform TCP/IP attack, the attacker must be on the
same network with the victim. Usually, the attacker uses sning tools to cap-
ture the packets and extract the sequence number. By injecting the spoofed
packet session can be interrupted. Communication from the legitimate user
can be disrupted by a Denial-of-Service attack or Reset connection.
Source Routing
Source routing is a technique of sending the packet via selected route. In
session hijacking, this technique is used to attempt IP spoong as a legitimate
host with the help of Source routing to direct the trac through the path
identical to the victim's path.
RST Hijacking
RST hijacking is the process of sending Reset (RST) packet to the victim
with the spoofed source address. Acknowledgment number used in this Reset
packet is also predicted. When the victim receives this packet, it could not
identify that the packet is spoofed believing the actual source has sent the
packet resulting in resetting the connection. RST packet can be crafted using
packet crafting tools.
26
Blind Hijacking
Blind Hijacking is the technique in which attacker is not able to capture the
return trac. In Blind hijacking, attacker captures the packet coming from
victim destined towards the server, inject malicious packet and forward to
the target server.
UDP Hijacking
UDP Session Hijacking process is quite simpler than TCP session hijacking.
Since the UDP is a connectionless protocol, it does not require any sequence
packet between requesting client and host. UDP session hijacking is all about
sending the response packet before a destination server responds. There are
several techniques to intercept the coming trac from the destination server
Countermeasures
IPSec
IPSec stands for IP security. As the name suggests, it is used for the secu-
rity of general IP trac. The power of IPsec lies in its ability to support
27
multiple protocols and algorithms. It also incorporates new advancements in
encryption and hashing protocols. The main objective of IPSec is to provide
CIA (condentiality, integrity, and authentication) for virtual networks used
in current networking environments. IPSec makes sure the above objectives
are in action by the time packet enters a VPN tunnel until it reaches the
other end of the tunnel.
Integrity. IPSec uses hashing protocols (MD5 and SHA) for providing
integrity. Hashed Message Authentication (HMAC) can also be used
for checking the data integrity.
Modes of IPsec
There are two working modes of IPSec namely tunnel and transport mode.
Each has its features and implementation procedure.
28
IPSec Tunnel Mode Being the default mode set in Cisco devices, tunnel
mode protects the entire IP packet from originating device. It means for
every original packet; another packet is generated with new IP header and
send over the untrusted network to the VPN peer located on another end of
the logical connection. Tunnel mode is commonly used in case of Site-to-Site
VPN where two secure IPSec gateways are connected over public internet
using IPSec VPN connection. Consider the following diagram:
This shows IPSec Tunnel Mode with ESP header:
Similarly, when AH is used; new IP Packet format will be:
IPsec Transport Mode In transport mode, IPsec VPN secures the data
eld or payload of originating IP trac by using encryption, hashing or
both. New IPsec headers encapsulate only payload eld while the original IP
headers remain unchanged. Tunnel mode is used when original IP packets
are the source and destination address of secure IPsec peers. For example,
securing the management trac of router is a perfect example of IPsec VPN
implementation using transport mode. From a conguration point of view,
both tunnel and transport modes are dened in the conguration of transform
set. It will be covered in the Lab scenario of this section.
This diagram shows IPsec Transport Mode with ESP header:
Similarly, in case of AH:
29
Cross-Site Scripting
30
this example, an attacker could trick the web page into adding malicious
code by writing a comment containing the following
<script> alert("You've been hacked")</script>
If the programmer had correctly sanitized the comment, it wouldn't have
contained the <script> tags and the browser wouldn't have interpreted it as
code.
Categories of XSS
1. Stored XSS (Persistent XSS): In a Stored XSS attack, the malicious
script or code is permanently stored on the target server, often in a
database or in a web application's storage, such as comments or user
proles. When a user visits a page that retrieves and displays the stored
data, the injected script is executed in the user's browser. This type of
XSS attack is particularly dangerous because it aects multiple users
who view the same tainted content.
31
Online Crime
1. First Schedule: Deals with documents to which the Act shall not
apply.
32
5. Hacking for malicious purposes.
6. Penalty for publishing Digital Signature Certicate false in certain par-
ticulars.
7. Penalty for misrepresentation.
8. Conscation.
9. Power to investigate oences.
10. Protected System.
11. Penalties for conscation not to interfere with other punishments.
12. Act to apply for oence or contravention committed outside India.
13. Publication for fraud purposes.
14. Power of Controller to give directions.
SECTION PUNISHMENT
Section 43 This section of IT Act, 2000 states that any act of destroying,
altering or stealing computer system/network or deleting data
with malicious intentions without authorization from owner of
the computer is liable for the payment to be made to owner
as compensation for damages.
Section 43A This section of IT Act, 2000 states that any corporate body
dealing with sensitive information that fails to implement rea-
sonable security practices causing loss of other person will also
liable as convict for compensation to the aected party.
Section 66 Hacking of a Computer System with malicious intentions like
fraud will be punished with 3 years imprisonment or the ne
of Rs.5,00,000 or both.
Section 66 B, C, D Fraud or dishonesty using or transmitting information or iden-
tity theft is punishable with 3 years imprisonment or Rs.
1,00,000 ne or both.
Section 66 E This Section is for Violation of privacy by transmitting image
of private area is punishable with 3 years imprisonment or
2,00,000 ne or both.
Section 66 F This Section is on Cyber Terrorism aecting unity, integrity,
security, sovereignty of India through digital medium is liable
for life imprisonment.
Section 67 This section states publishing obscene information or pornog-
raphy or transmission of obscene content in public is liable for
imprisonment up to 5 years or ne of Rs. 10,00,000 or both.
33
Social Engineering
While an organization may have a lot of security solutions, a threat actor can
use psychological techniques to manipulate and trick a person into retrieving
sensitive/condential information and even performing a task. This is the
art of hacking the human mind in the eld of cybersecurity, and it's known
as social engineering.
Consensus - This element allows threat actors to use social proof that
an action is considered to be normal because others are doing the same
thing.
34
Scarcity - This factor is used to inform the potential victims that an
event needs to be completed within a specic time, such as immediately.
35
Computer-based
In computer-based social engineering, the attacker uses computing devices to
assist them in tricking a potential victim into revealing sensitive/condential
information or performing an action.
The following are common types of computer-based social engineering:
Water hole: In this type of attack, the threat actor observes where
employees of a target organization are commonly visiting such as a
website. The threat actor will create a fake, malicious clone of the
website and attempt to redirect the users to the malicious website. This
technique is used to compromise all of the website visitors' devices and
not just the employees of the target organization.
Mobile-based
Mobile-based social engineering can include creating a malicious app for
smartphones and tablets with a very attractive feature that will lure users
into downloading and installing the app on their devices. To mask the true
nature of the malicious app, attackers use names similar to those of popu-
lar apps on the ocial mobile app stores. Once the malicious app has been
installed on the victim's device, the app can retrieve and send the victim's
user credentials back to the threat actor
36
The following are common types of mobile-based social engineering at-
tacks:
Social networking
Threat actors usually attempt to create a fake prole and establish com-
munication with their targets. They pretend to be someone else using im-
personation while trying to trick their victim into revealing sensitive details
about themselves. Additionally, there are many cases where a person's ac-
count is compromised and the threat actor uses the compromised account to
communicate with other people in the victim's friends/connections list.
The following are some methods that are used to lure the employees of a
target organization:
Using a false identity by using the names of employees from the target
organization
Getting a user to join a fake user group and then asking them to provide
credentials, such as their date of birth and their spouse's name
37
During a doxing attack, the threat actor gathers personal information about
someone by searching for the information that was posted by the target.
Implement a password policy that ensures that users change their pass-
words periodically while avoiding reusing previous passwords. This will
ensure that if an employee's password is leaked via a social engineering
attack, the password in the attacker's hands could be rendered obsolete
by the password policy.
Ensure security guards escort all guests and visitors while in the com-
pound.
38
Implement the classication of information. The classication of infor-
mation allows only those with the required security clearance to view
certain data and have access to certain systems.
39
Intrusion Detection System
40
Figure 1: Sensor deployment as IDS
41
Not all signatures are enabled by default. The network administrator
needs to tune the IPS/IDS module so that false positive generated for
legitimate trac must not be generated.
42
of the host machine. It creates a ltering layer and lters out any
malicious application call to the OS. There are four major types of
Host-based IDS/IPS:
43
Figure 2: Host-based vs. Network-based IDS/IPS solution.
Firewall
Although the features above provide isolation in some sense, The fol-
lowing are the few reasons a dedicated rewall appliance (either in
hardware or software) is preferred in production environments:
44
Risks Protection by rewall
Access by un- Firewalls try to categorize the network into dierent por-
trusted entities tions. One portion is considered as a trusted portion of
internal LAN. Public internet and interfaces connected
to are considered as an untrusted portion. Similarly,
servers accessed by untrusted entities are placed in a
special segment known as a demilitarized zone (DMZ).
By allowing only specic access to these servers, like
port 90 of the web server, rewall hide the functionality
of network device which makes it dicult for an attacker
to understand the physical topology of the network.
Deep Packet One of the interesting features of the dedicated rewall is
Inspection their ability to inspect the trac more than just IP and
and protocols port level. By using digital certicates, Next Generation
exploitation Firewalls available today can inspect trac up to layer
7. A rewall can also limit the number of established
as well as half-open TCP/UDP connections to mitigate
DDoS attacks
Access Control By implementing local AAA or by using ACS/ISE
servers, the rewall can permit trac based on AAA
policy.
Antivirus and By integrating IPS/IDP modules with rewall, mali-
protection from cious data can be detected and ltered at the edge of
infected data the network to protect the end-users
Firewall Architecture
1. Bastion Host
Bastion Host is a computer system that is placed in between public
and private network. It is intended to be the crossing point where
all trac is passed through. Certain roles and responsibilities
are assigned to this computer to perform. Bastion host has two
interfaces, one connected to the public network while the another
is connected to the private network.
45
2. Screened Subnet
Screened Subnet can be set up with a rewall with three inter-
faces. These three interfaces are connected with the internal pri-
vate network, Public network, and Demilitarized Zone (DMZ). In
this architecture, each zone is separated by another zone hence
compromise of one zone will not aect another zone.
3. Multi-homed Firewall
Multi-homed rewall referred to two or more networks where each
interface is connected to its network. It increases the eciency
and reliability of a network. A rewall with two or more interfaces
allows further subdivision.
Types of Firewall
46
Source address
Destination address
Source port
Destination port
3. Application-Level Firewall:
Application Level Firewall can work at layer 3 up to the layer 7
of OSI model. Normally, a specialized or open source software
running on high-end server acts as an intermediary between client
and destination address. As these rewalls can operate up to layer
7, more granular control of packets moving in and out of network is
possible. Similarly, it becomes very dicult for an attacker to get
the topology view of inside or trusted network because connection
requests terminate on Application/Proxy rewalls.
47
4. Stateful Multilayer Inspection Firewall:
As the name depicts, this saves the state of current sessions in
a table known as a stateful database. Stateful inspection and
rewalls using this technique normally deny any trac between
trusted and untrusted interfaces. Whenever an end-device from
trusted interface wants to communicate with some destination ad-
dress attached to the untrusted interface of the rewall, its entry
will be made in a stateful database table containing layer 3 and
layer 2 information.
5. Transparent rewalls:
Transparent rewalls work exactly like above-mentioned techniques,
but the interfaces of the rewall itself are layer 2 in nature. IP
addresses are not assigned to any interface, think of it as a switch
48
with ports assigned to some VLAN. The only IP address assigned
to the transparent rewall is for management purposes. Similarly,
as there is no addition of extra hop between end-devices, the user
will not be able to be aware of any new additions to network
infrastructure and custom- made applications may work without
any problem.
7. Personal Firewalls:
Personal Firewall is also known as desktop rewalls, helps the
end-users personal computers from general attacks from intrud-
ers. Such rewalls appear to be great security line of defense for
users who are constantly connected to the internet via DSL or
cable modem. Personal rewalls help by providing inbound and
outbound ltering, controlling internet connectivity to and from
the computer (both in a domain based and workgroup mode) and
altering the user for any attempts of intrusions.
49