Web Security
Web Security
Web Security
3. What is OWASP?
The Open Web Application Security Project, or OWASP, is an international non-
profit organization whose sole purpose is to improve software security.OWASP
provided knowledge about the tactics that hackers use and how to fight them.
1
The OWASP Top 10 (2021) Categories are
1. Broken Access Control
2. Cryptographic Failures
3. Injection
4. Insecure Design
5. Security Misconfiguration
6. Vulnerable and Outdated Components
7. Identification and Authentication Failures
8. Software and Data Integrity Failures
9. Security Logging and Monitoring Failures
10. Server-Side Request Forgery
Now, I will explain each OWASP Top 10 category one by one. Let’s
start with Broken Access Control.
2
2. Secure file systems by disabling directory listings and protecting file meta-
data.
3. Maintain logs of access control failures and promptly notify administra-
tors.
4. Implement rate limiting across all system components to prevent auto-
mated attack attempts.
5. Regularly review and update access control policies
3
4. Regularly update cryptographic libraries : Keep your cryptographic
libraries up to date to ensure you are using the latest security patches and
algorithms.
5. Conduct regular security audits : Regularly audit your cryptographic
implementations to identify any potential vulnerabilities and address them
promptly.
4
2. Implement Input Validation and Sanitization : Validate and san-
itize all user inputs to ensure they meet the expected format and reject
any suspicious or unexpected inputs.
3. Use ORM Frameworks : Utilize Object-Relational Mapping (ORM)
frameworks to avoid direct query execution, as these frameworks handle
parameterization and help prevent injection attacks.
4. Perform Regular Code Reviews and Security Testing : Conduct
regular code reviews and security testing to identify and fix vulnerabilities
in your application.
5
3. Following the principle of least privilege by granting users only the mini-
mum access necessary for their tasks.
4. Implementing strong authentication mechanisms, access controls, and in-
put validation.
6
4. Implement Least Privilege Principle : Grant minimal access to users
and processes, limiting permissions to only what’s necessary. This reduces
the risk of security breaches, similar to restricting access to certain areas
in your home for guests.
5. Disable unnecessary features, services, and accounts.
7
sider deploying a virtual patch to monitor, detect, or protect against the
discovered issue.
5. Use tools to track and manage software dependencies.
8
21. Explain Software and Data Integrity Failures. (Eighth
on the OWASP list)
Software and data integrity failures are vulnerabilities in software or infrastruc-
ture that allow an attacker to modify or delete data in an unauthorized manner.
This can occur due to weaknesses in the software itself or inadequate security
measures implemented during development. Attackers can exploit these vulner-
abilities to gain access to sensitive information or manipulate data andcause
damage to the system.
The impact of software and data integrity failures can be severe. It can result
in financial losses, reputational damage, legal liabilities, loss of customer trust,
etc.
24. How Can You Protect Against Security Logging and Monitoring
Failures?
1. Ensure comprehensive logs are generated, capturing essential security
events, including user authentication, access control, and data manipu-
9
lation. This allows for effective tracking and detection of any malicious
activities.
2. Implement a process to regularly review and analyze logs with both au-
tomated tools and manual inspection to detect possible security incidents
and emerging threats.
3. Set up real-time monitoring and alerting systems to detect and respond to
security events swiftly to lessen the impact of attacks and prevent potential
breaches.
4. Securely store and protect log files to ensure their integrity and confiden-
tiality, including measures to prevent tampering and unauthorized access,
preserving the reliability of the logged data.
26. Impact
1. Unauthorized access within the organization, and it’s internal networks.
2. Arbitrary command execution.
3. Legal liabilities and reputational damage.
27. Mitigation
1. Whitelist Allowed URLs
2. Disable Unused URL Schemas
3. Implement URL validation and input sanitization to block malicious re-
quests.
4. Enforce network segmentation to restrict SSRF attack surface and limit
access to sensitive resources.
28. What are the changes between the OWASP 2017 &
2021 version?
• For the 2021 list, the OWASP added three new categories and added in
two categories
New
1. Insecure Design
2. Software and Data Integrity Failures
10
3. Server-Side Request Forgery ( SSRF )
Added
1. Injections
– The new OWASP Top 10 Update also contains the vulnerability Cross
Site Scripting (XSS) in injection because This vulnerability is funda-
mentally an injection as well.
2. Security Misconfiguration
– The new OWASP Top 10 Update also contains the vulnerability XML
External Entities (XXE) in Security Misconfiguration because ne-
glecting proper configuration of XML parsers can lead to exploitable
vulnerabilities, enabling attackers to leverage external entities for
unauthorized data access or manipulation.
11
30. Why XSS?
Because the majority of applications use JavaScript, and XSS is a JavaScript-
based issue. In XSS, the attacker is able to inject arbitrary JavaScript code into
a web application, which the web application then executes. which can lead to
various security issues. This can include stealing sensitive information like login
credentials, session tokens, or personal data.
35. Prevention
• Encode all user-supplied data to render it safe
• Content Security Policy (CSP)
12
• HTTPOnly and Secure Cookies
13
42. What is Authentication Bypass?
Attacker can bypass the username password or authentication/login flow of the
website. By exploiting this vulnerability, they can gain complete access to any
user’s account. It is considered to be a dangerous and high severity attack.
14
An attacker might attempt to inject various SQL commands into the
input parameter, such as single quotes (’), double quotes (“), hash
symbols (#), colons (;), and others. If the database returns an error
message like”You have an error in your SQL syntax,” then the attack
is considered successful.
Example URL with injection :
https://example.com/index.php?item=123'
2. Union-based SQLi : UNION-based SQLi, the attacker uses the
UNION SQL operator to combine the results of two or more SELECT
statements into a single result.
Example : A website’s search feature is vulnerable to SQL injection.
An attacker wants to retrieve user credentials from the users table.
1. Determine Column Count : Inject payloads to find the num-
ber of columns in the original query:
1. ' UNION SELECT 1--
2. ' UNION SELECT 1,2--
3. ' UNION SELECT 1,2,3-- (returns an error, it indicates the original query ha
2. Identify Columns for String Data : Inject payloads to find
which columns can hold string data
' UNION SELECT 1,'a'-- (If this query succeeds, it indicates the second column
3. Craft Payload to Retrieve Data : Construct a payload to
retrieve user credentials
1. ' UNION SELECT 1, username, password FROM users--
Complete URL look like this : https://example.com/search.php?category=1
UNION SELECT 1, username, password FROM users--
By executing this, the attacker can combine the product data
with the usernames and passwords from the users table, allowing
them to steal sensitive information.
15
Example : Let’s say a website’s login form is vulnerable to SQL
injection, and an attacker wants to verify if the user ‘admin’ exists.
They can use payloads that generate different responses based on the
truth of the condition.
' OR '1'='1'-- (true condition)
' OR '1'='2'-- (false condition)
If responses differ, it confirms that the web application is vulnera-
ble to blind SQL injection. By exploiting true and false conditions,
attackers can retrieve database information.
Attackers retrieve the payload length from true or false re-
sponses, e.g., http://example.com/index.php?id=1' AND
(length(database())) = 1 --+. If false, the length of the
database string is not equal to 1, and the attacker continues until
obtaining the actual length of the database. After determining the
database length, they proceed to find the first letter of the database
name and continue this process until they retrieve the complete
database name and so on.
2. Time-based Blind SQLi : Delays the server’s response to reveal
information based on whether a condition is true or false.
Example : Suppose a website’s search feature is vulnerable to SQL
injection. An attacker wants to determine if the database contains
a specific table called ‘users’. The attacker can use a payload that
delays the response if the condition is true:
' OR IF((SELECT COUNT(*) FROM users)>0, SLEEP(5), 0)--
If the server’s response is delayed, it indicates the condition is true,
allowing the attacker to infer the existence of the ‘users’ table.
Out-of-band SQLi
1. Out-of-band SQLi : Out-of-band SQL Injection occurs when the result
of the attacker’s activities is received using another channel (for example,
sent to another server)
• An example of Out-of-band SQL Injection would be injecting SQL
code into an email field of a vulnerable application to extract data.
For instance, the attacker could use a payload like:
'; SELECT * FROM users; --'
When the application processes this input and sends the extracted data,
the attacker receives it via a separate channel, such as an email sent to
their controlled server.
16
Second-Order-Injection
1. Second-Order-Injection : Second-Order Injection, also known as stored
SQL injection, is a type of SQL injection attack where the payload is
stored in the application’s database, and the malicious code is executed
later when the data is used in a query.
Example : Suppose there’s a web application where users can submit
reviews for products. The application stores these reviews in a database
and later displays them on the product page. The review submission form
has a field for the user’s name and another for the review text.
An attacker submits a review with their name containing a SQL injection
payload, such as:
Name: John'); INSERT INTO users (username, password) VALUES ('hacker', 'password'); --
The application stores this review in the database without executing the
payload immediately. Later, when the product page displays all the re-
views, the injected SQL code is executed, resulting in the insertion of a
new user (‘hacker’) into the ‘users’ table.
46. Prevention
• Parameterized Queries
• Using stored procedures
• Whitelist Input Validation
• Escaping All User Supplied Input
47. Impact
A successful SQL injection attack can result in unauthorized access to sensitive
data, such as: Passwords. Credit card details. Personal user information.
49. Prevention
• Implement Multi-factor Authentication
• Create Strong Password Policies
17
50. What is IDOR?
Insecure Direct Object References (IDOR) are a type of access control vulnera-
bility where an attacker can exploit IDOR by manipulating direct references to
these objects, typically found in URLs, form parameters, or API endpoints, to
gain unauthorized access to sensitive data or operations.
In simpler terms, IDOR allows attackers to access or manipulate resources
they’re not supposed to by directly referencing them, bypassing any access con-
trols or authorization mechanisms that should be in place.
For example, imagine a web application where users can view their own profile
by accessing a URL like example.com/profile?id=123. If the application fails to
verify that the user making the request is authorized to view the profile with
ID 123, an attacker could change the ID parameter to view other users’ profiles,
potentially exposing sensitive information.
Prevention : To prevent IDOR vulnerabilities, developers should implement
proper access controls and authorization checks to ensure that users can only
access resources they’re authorized to access. This often involves validating user
input, enforcing least privilege principles, and using indirect references or tokens
instead of direct object references. Regular security testing and code reviews
can also help identify and remediate IDOR vulnerabilities in applications.
18
53. Impact
• Complete compromise of the web application, if the victim is an adminis-
trative account
• Bypassing protection mechanism
• Reading or modifying application data
54. Mitigation
• CSRF tokens help prevent CSRF attacks because attackers cannot make
requests to the backend without valid tokens. Each CSRF token should
be secret, unpredictable, and unique to the user session.
19
• Soft tokens : Soft tokens involve entering a secret code or message sent
to a device to prove possession of the device. They send an encrypted
code (like OTP) via authorized app or SMS to a smartphone.
web token
• The authentication via web token is a fully digital process. Here, the server
and the client interface interact upon the user’s request. The client sends
the user credentials to the server and the server verifies them, generates
the digital signature, and sends it back to the client. Web tokens are
popularly known as JSON Web Token (JWT), a standard for creating
digitally signed tokens.
20
associated vulnerabilities are also known as “application logic vulnerabilities”
or simply “logic flaws.”
Example : Imagine an online store where customers can apply discount codes
to their orders. The intended function is for each discount code to be used only
once per customer. However, due to a logic flaw, the system doesn’t properly
track the usage of discount codes. An attacker discovers this and repeatedly
uses the same discount code on multiple orders, significantly reducing the cost
of their purchases without authorization. This flaw allows the attacker to bypass
the intended rules, leading to financial loss for the store.
21
1. Thorough Requirements Analysis : Clearly understand and validate
business rules.
2. Input Validation : Strictly validate and sanitize user inputs to prevent
injection attacks and data manipulation.
3. Access Control : Enforce fine-grained access control to restrict user
access based on roles and privileges.
4. Session Management : Implement secure session handling techniques
to prevent session hijacking and fixation attacks.
5. Continuous Testing : Regularly conduct security testing and code re-
views to identify and mitigate vulnerabilities.
22
65. What are your fav open source tools?
1. Nuclei : Nuclei is my favorite open-source tool because of its extensive
collection of templates and regular updates.
66. Are there any paid tools that you wish to recommend
for use in our organization?
Burp Suite : I believe this tool can handle the majority of our tasks effectively.
Additionally, there are numerous open-source alternatives available for other
tasks.
23
represent the characters < and >. These are metacharacters used to denote XML
tags.
24
Asymmetric encryption : Asymmetric encryption also known as public-key
encryption, uses a pair of keys: a public key and a private key. The public key
is widely distributed and is used for encryption, while the private key is kept
secret and is used for decryption. This setup allows anyone to send encrypted
messages to the owner of the public key, but only the owner can decrypt them
using their private key.
25
78. What is encryption, and why is it important for web
application security?
Encryption is the process of converting plaintext data into ciphertext, making
it unreadable to unauthorized users. This transformation is accomplished using
an encryption algorithm and a cryptographic key. Encryption is crucial for web
application security as it prevents unauthorized access to sensitive information
and safeguards data integrity during transmission over the internet.
26
82. What is OS command injection?
OS command injection, also referred to as shell injection, enables attackers to
execute operating system (OS) commands on the server hosting an application,
and typically fully compromise the application and its data. Often, an attacker
can leverage an OS command injection vulnerability to compromise other parts
of the hosting infrastructure, and exploit trust relationships to pivot the attack
to other systems within the organization.
Example : In a web application where users can perform a traceroute, an
attacker injects an OS command along with the IP address:
127.0.0.1; cat /etc/passwd
With this input, the server executes the legitimate traceroute command but also
runs the injected command, granting the attacker access to sensitive system
information such as /etc/passwd.
27
85. Impacts of code injection
1. An attacker is able to execute arbitrary server-side code. which result in
a total loss of integrity, availability, and confidentiality within the appli-
cation
2. An attacker may also abuse a code injection vulnerability to execute ter-
minal commands on that server and pivot to adjacent systems.
28
Local File Inclusion (LFI)
Local File Inclusion (LFI) is a type of vulnerability commonly found in web ap-
plications that allows an attacker to include files located on the server. Typically,
web applications dynamically include files in their code to load content such as
configuration files, scripts, or templates. However, if the application does not
properly sanitize user input, an attacker can manipulate the input to include
arbitrary files from the local file system.With LFI, attackers can exploit this
vulnerability to access sensitive files stored on the server, such as configuration
files, user credentials, or system files.
Example : Consider a website that includes files based on a “page” parameter
in the URL, like so:
http://example.com/index.php?page=about.php
If the website doesn’t properly validate or sanitize user input, an attacker could
manipulate the “page” parameter to include arbitrary files from the server’s file
system. For instance, they could change the URL to:
http://example.com/index.php?page=/etc/passwd
29
91. What is Privilege? Type of Escalation.
Privilege escalation typically involves gaining higher-level permissions within a
system or application.
30
This can happen when user input is directly embedded into templates without
proper validation or sanitization, allowing an attacker to inject template code
that is executed by the server.
31
broken lock is a vulnerability because it’s a weakness that the burglar could use
to get inside easily.
Risk : Risk is like the chance of something bad happening when a weakness
is exposed. It’s a mix of how likely that bad thing is to occur and how much
damage it could do. Organizations look at risks to figure out how to protect
themselves from threats exploiting vulnerabilities.
Example : The risk is the chance that the burglar will actually break in because
of that broken lock. If the neighborhood has a lot of burglaries and your house
has a broken lock, the risk of a break-in is high. But if you fix the lock and add
security measures, like an alarm system, you reduce the risk.
Summary:
Threat : Something bad that could happen (e.g., burglar). Vulnerability: A
weakness that can be exploited (e.g., broken lock). Risk: The chance of the bad
thing happening and causing harm.
32
4. X-XSS-Protection : Enables a built-in XSS filter in modern web
browsers to detect and mitigate certain types of XSS attacks.
• Example : X-XSS-Protection: 1; mode=block
5. Content-Type Options : Prevents browsers from trying to guess the
MIME type of a resource, which can help mitigate MIME sniffing attacks.
• Example : X-Content-Type-Options: nosniff
33