Within end of March, the OWASP foundation will release the 2010 version of its major documentation project, the "Top 10 security risks in web applications."
Agenda: - The 10 most common web application attacks - Discovering the OWASP Top 10 document - Integrating the Top 10 within an existing SDLC, as a software vendor, or a software buyer.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Antonio Fontes / Confoo Conference, Montreal / 2010
7
Part 1: Top 10 major web application
attack techniques
Antonio Fontes / Confoo Conference, Montreal / 2010
8
Attacking the infrastructureAttacking the applicationAttacking the usersOther attacks
Antonio Fontes / Confoo Conference, Montreal / 2010
9
Attacking the infrastructurehitting the weakest layer
Antonio Fontes / Confoo Conference, Montreal / 2010
10
Web application
Application Server
Web Server
Operating System
Network devices
Are all unnecessary paths closed?Are all unnecessary ports closed?Is the admin interface reachable from the web?Can an administrative account be broken?Is the device up to date?
Are all unnecessary services disabled?Are all unnecessary accounts disabled?Have all default passwords been changed?Is the system up to date?
Are all unnecessary scripts removed?Are there any backup/test/unused resources?Is the web server up to date?Have all default passwords been changed?
Are all demo apps removed?Is the web server up to date?Is the admin area protected from external access?Is directory indexing been disabled?Were all default passwords changed?
Antonio Fontes / Confoo Conference, Montreal / 2010
11
Risk A6: Security misconfiguration
Antonio Fontes / Confoo Conference, Montreal / 2010
12
• What is the risk?– If there is a weaker link than the web application
itself, the attacker will switch to the flawed layer.
• What are the countermeasures?– Harden all layers• Reduce services and accounts to the minimum• No default passwords• Keep everything up to date• Apply security guidelines (OS security, Web server
security, Application server security, etc.)• Keep default web application configuration safe• “Deploy securely on a secure architecture”
Antonio Fontes / Confoo Conference, Montreal / 2010
13
Attacking the infrastructureAttacking the applicationAttacking the usersOther attacks
Antonio Fontes / Confoo Conference, Montreal / 2010
14
Attacking the applicationinjecting hostile code…
Antonio Fontes / Confoo Conference, Montreal / 2010
15
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
16
SELECT * FROM users usr WHERE usr.username = 'admin ';-- ‘AND usr.password = ‘bb21158c733229347bd4e681891e213d94c685be’
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
17
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
18
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
19
Any user input is a potential attack vector.
Antonio Fontes / Confoo Conference, Montreal / 2010
20
Risk A1: Injections
Antonio Fontes / Confoo Conference, Montreal / 2010
21
• RISK?– Any application entry point can be used as a
vector to inject hostile content that will modify expected behaviors.
• GOOD TO KNOW– All non-binding query languages are exposed!
(LDAP and Xpath….)
Antonio Fontes / Confoo Conference, Montreal / 2010
22
• COUNTERMEASURES?– All input can be modified client-side. Be sure to
validate:• Querystring parameters• Form fields (hidden fields also count)• File submissions : if you’re expecting a picture, then
make sure it is a picture!• Cookies• HTTP headers: all fields, including referrer are “user
input”
Antonio Fontes / Confoo Conference, Montreal / 2010
23
COUNTERMEASURES? (cont’d)• Never paste user input into query commands (SQL,
Xpath, LDAP, OS commands, etc.):• Use binding variables such as SQL parameters:
• If no binding model, encode input before pasting:• Doubled quotes (‘’) for SQL server• Escaped quotes (\’) for MySQL (PHP addslashes is helpful!)• Etc.
Antonio Fontes / Confoo Conference, Montreal / 2010
24
COUNTERMEASURES ?(cont’d)• Choose best validation strategy!• Best: Whitelist– When all possible values are known (enums, if/else if
statements, regular expressions, …)• Graylist:– Enforce business rules:
• What are the countermeasures?– Completely disallow access to sensitive file types– Validate ALL incoming requests
• Authorize explicitly (web.xml, ASP.Net page lifecycle, etc.)
– Don’t expose physical documents with permanent or guessable URLs
Antonio Fontes / Confoo Conference, Montreal / 2010
42
Attacking the infrastructureAttacking the applicationAttacking the usersOther attacks
Antonio Fontes / Confoo Conference, Montreal / 2010
43
Attacking the usersredirecting users elsewhere…
Antonio Fontes / Confoo Conference, Montreal / 2010
44
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
45
Risk A8: Non-validated redirects and
forwards
Antonio Fontes / Confoo Conference, Montreal / 2010
46
• What is the risk?– An attacker may use your website reputation as a
vector to redirect victims to a hostile website.
• What are the countermeasures?– Never allow absolute URL redirection.– If not possible: • Use a whitelist of valid hosts• Show a warning before redirecting the user
– If using a “web portal”, make sure redirect pages do not include sensitive information in URLs (aka single-signon-on information)
Antonio Fontes / Confoo Conference, Montreal / 2010
47
Attacking the usersrunning client hostile code in the
website…
Antonio Fontes / Confoo Conference, Montreal / 2010
48
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
49
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
50
Risk A2: Cross-site scripting
Antonio Fontes / Confoo Conference, Montreal / 2010
51
• What is the risk?– An attacker might inject client-side hostile code in
the web application, which will be returned to a victim.
Antonio Fontes / Confoo Conference, Montreal / 2010
52
What are the countermeasures?• Sanitize output. Encode to destination
format.– For HTML output, use HtmlEntities:• <div id=“comment”>Here is my
<script>attack</script></div>
<div id=“comment”>Here is my <script>attack</script></div>
Antonio Fontes / Confoo Conference, Montreal / 2010
53
What are the countermeasures?• Sanitize output, encode to destination
format:– For XML output, use predefined entities:• <says>“here is my <script>”</says>
<says><![CDATA[here is my <script>]]></says>
• <says>my input is <script></says> <says>my input is <script></says>
Antonio Fontes / Confoo Conference, Montreal / 2010
54
Attacking the usersreplaying predictable requests…
Antonio Fontes / Confoo Conference, Montreal / 2010
55
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
56
what if?
Antonio Fontes / Confoo Conference, Montreal / 2010
57
Risk A5: Cross-site Request Forgery
Antonio Fontes / Confoo Conference, Montreal / 2010
58
• What is the risk?– An attacker might build her own website and
trigger requests on the visitor’s browser. (yes, that’s exactly what it seems to be...)
Antonio Fontes / Confoo Conference, Montreal / 2010
59
What are the countermeasures?• Implement unpredictable requests for all
sensitive actions– Use temporary random hidden control fields:
<input type=hidden name=check value=ab23b4a/>
– Link forms to the user session:if(!(Request.Form[“checker”]).Equals(SessionID))
// return error
– Use CAPTCHA– Use out-of-band verification:• SMS / Voice call / Cryptographic tokens, etc.
Antonio Fontes / Confoo Conference, Montreal / 2010
60
Attacking the infrastructureAttacking the applicationAttacking the usersOther attacks
Antonio Fontes / Confoo Conference, Montreal / 2010
61
Other attacksbreaking weak cryptography…
Antonio Fontes / Confoo Conference, Montreal / 2010
62
what if?
Encrypting with Base64
$cookie = base64($sessionId);
It’s not encryption, it’s encoding!
Antonio Fontes / Confoo Conference, Montreal / 2010
63
what if?
Encrypting user passwords with AES256$password = encrypt($get_[“password”],AES256,key);
reversible encryption!
Antonio Fontes / Confoo Conference, Montreal / 2010
64
what if?
Hashing user passwords with md5
$password = md5($get_[“password”]);
weak algorithm!
Antonio Fontes / Confoo Conference, Montreal / 2010
65
what if?
Hashing user passwords with SHA-256$password = sha($get_[“password”]);
Missing seed!
Antonio Fontes / Confoo Conference, Montreal / 2010
66
what if?
Building keys with Math.RandomByte[] key = Math.RandBytes(128);
Weak random number generator!
Antonio Fontes / Confoo Conference, Montreal / 2010
67
what if?
Deriving a key from human entered secret$key = md5($GET_[“secret”]);
Weak key entropy!
Antonio Fontes / Confoo Conference, Montreal / 2010
68
what if?
Using ECB mode of operation$bytes = encrypt($text, key);// returns: {0xAF00CADACCE34A4D}$bytes2 = encrypt($text, key);// returns: {0xAF00CADACCE34A4D}
Weak mode of operation!
Antonio Fontes / Confoo Conference, Montreal / 2010
69
what if?
Using CBC mode of operation$bytes = encrypt($text, key);// returns: {0xAF00CADACCE34A4D}$bytes2 = encrypt($text, key);// returns: {0xAF00CADACCE34A4D}
Non-random initialization vectors!
Antonio Fontes / Confoo Conference, Montreal / 2010
70
what if?
Decrypting with internal secretString clearText = CryptUtils.Decrypt($bytes, Parameters.SecretKey);
Hard-coded secret!
Antonio Fontes / Confoo Conference, Montreal / 2010
71
what if?
blablabla
Another problem.
Antonio Fontes / Confoo Conference, Montreal / 2010
72
Risk A9: Insecure cryptographic storage
Antonio Fontes / Confoo Conference, Montreal / 2010
73
• What is the risk?– An attacker might not need as much time as you
expected to decrypt your data.– If one of these words sounds foggy to you, there is
a risk:• Asymmetric/symmetric encryption, offline encryption,
r ?Antonio Fontes / Confoo Conference, Montreal / 2010
77
Risk A10: Insufficient transport layer
protection
Antonio Fontes / Confoo Conference, Montreal / 2010
78
• What is the risk?– Traffic eavesdropping, due to insufficient transport
layer protection.
• What are the countermeasures?– Require an SSL encrypted link.– Use appropriate certificates (signed and valid).– Prevent cookies from leaving the encrypted link
(“secure” flag enabled).
Antonio Fontes / Confoo Conference, Montreal / 2010
79 Antonio Fontes / Confoo Conference, Montreal / 2010
Security Misconfigurati
onInjection
Insecure Direct Object
References
Broken Authentication and
Session Management
Failure to Restrict URL
Access
Unvalidated Redirects and
Forwards
Cross Site Scripting (XSS)
Cross Site Request
Forgery (CSRF)
Insecure Cryptographic
Storage
Insufficient Transport Layer
Protection
WHAT IS THE RISK LEVEL ?LOW HIGH
80
Part 2: Assessing the risks induced by
these 10 attacks
Antonio Fontes / Confoo Conference, Montreal / 2010
81
Hopefully, someone did it…
Antonio Fontes / Confoo Conference, Montreal / 2010
82
rating the risks
Antonio Fontes / Confoo Conference, Montreal / 2010
Threat agent Attack vector Prevalance Detectability Technical Impact Business impact
?Easy Widespread Easy Severe
?Average Common Average ModerateDifficult Uncommon Difficult Minor
2 1 1 2
3 * 1.3 * 2 ? = 2,6x?
XSS (example)
83 Antonio Fontes / Confoo Conference, Montreal / 2010
A1: Injection
A2: Cross Site Scripting (XSS)
A3: Broken Authentication and
Session Management
A4: Insecure Direct Object References
A5: Cross Site Request
Forgery (CSRF)
A6: Security Misconfigurati
on
A7: Failure to Restrict URL
Access
A8: Unvalidated Redirects and
Forwards
A9: Insecure Cryptographic
Storage
A10: Insufficient Transport Layer
Protection
OWASP Top 10 – 2010 RC1The top ten web application security risks