SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
9 Ways to Hack a Web App
Martin G. Nystrom, CISSP-ISSAP
Security Architect
Cisco Systems, Inc.
www.cisco.com
TS-5935

           2005 JavaOneSM Conference | Session 5935   1
Why Worry?
      Recent headlines
      •    Net worm using Google to spread
            •   “…uses a flaw in the widely used community forum software
                known as the PHP Bulletin Board (phpBB) to spread…”

      •    California reports massive data breach
            •   “…The compromised system had the names, addresses,
                phone numbers, social security numbers, and dates of birth
                of everyone who provided or received care.”

      •    Google bug exposes e-mail to hackers
            •   “…By altering the “From” address field of an e-mail sent to
                the service, hackers could potentially find out a user’s
                personal information, including passwords. ...”

      •    truckstop.com web application stolen by competitor
            •   “…Getloaded’s officers also hacked into the code Creative
                used to operate its website.”



Sources: news.com, E-Week, SecurityFocus ,
                                                                              2005 JavaOneSM Conference | Session 5935 |   2
Goal



   Learn why and how to build Java web
   apps secured from the most common
   security hacks.




                             2005 JavaOneSM Conference | Session 5935 |   3
Agenda

• Intro and Overview
  • How vulnerable are web apps?
  • Basics of web hacking
• Web Architecture and Principles
  • How are most web-based Java apps deployed?
• Principles of Secure Programming
  • A “security mantra” for web developers
• 9 Most Common Web Vulnerabilities
  • …and how to fix them in Java

                                      2005 JavaOneSM Conference | Session 5935 |   4
95% of Web Apps Have Vulnerabilities

•   Cross-site scripting (80 percent)
•   SQL injection (62 percent)
•   Parameter tampering (60 percent)
•   Cookie poisoning (37 percent)
•   Database server (33 percent)
•   Web server (23 percent)
•   Buffer overflow (19 percent)


                                    2005 JavaOneSM Conference | Session 5935 |   5
Web Attack
• Discover
   •   Examine the environment
        • Identify open ports
        • Discover types/versions of apps running
        •    Banner grabbing
        •    Extensions (.jhtml, .jsp, etc.) and directory structures
   •   Generate and examine errors
        • Submit ridiculous input to provoke errors (fuzzing)
        • Database errors, stack traces very helpful
   •   Find info left behind (source code, comments, hidden fields)

• Target
   •   Login mechanism
   •   Input fields
   •   Session mgmt
   •   Infrastructure
                                                                        2005 JavaOneSM Conference | Session 5935 |   6
A Word of Warning

• These tools and techniques can
  be dangerous
• The difference between a hacker
  and a cracker is…permission
• Admins will see strange activity in
  logs, and come looking for you
• Authorities are prosecuting
  even the “good guys” for using
  these tools

                                    2005 JavaOneSM Conference | Session 5935 |   7
Security Principles of Web Architecture
•   Practice defense-in-depth
•   Separate services
     •   Web server, app server, db server on separate hosts

•   Limit privileges of application user
     •   File system (chroot or limit privs to read-only)
     •   Database system (limit privileges on tables, schemas, etc.)
     •   Privileges of running user (xxtomcat, apache, kobayashi, etc.)

•   Hide secrets
     •   Database account passwords
     •   Encryption keys

•   Use standard, vetted components, libraries
     •   Keep them patched

•   Log, and watch logs for unusual activity
•   Load-test and tune accordingly
                                                                      2005 JavaOneSM Conference | Session 5935 |   8
Principles for Secure Coding

• Don’t trust input from user
• Review for logic holes
• Leverage vetted resources
  • Infrastructure
  • Components
• Only give information needed
• Build/test to withstand load
  • Expected load
  • Potential DOS attack

                                 2005 JavaOneSM Conference | Session 5935 |   9
OWASP Top 10 Web Security Vulns
      1.     Unvalidated input
      2.     Broken access control
      3.     Broken account/session management
      4.     Cross-site scripting (XSS) flaws
      5.     Buffer overflows
      6.     Injection flaws
      7.     Improper error handling
      8.     Insecure storage
      9.     Denial-of-service
      10. Insecure configuration management

Source: www.owasp.org
                                                 2005 JavaOneSM Conference | Session 5935 | 10
#1: Unvalidated Input
• Attacker can easily change any part of the
  HTTP request before submitting
   •   URL
   •   Cookies
   •   Form fields
   •   Hidden fields
   •   Headers
• Input must be validated on the server
• Countermeasures
   • Code reviews (check variable against list
     of allowed values, not vice-versa)
   • Don’t accept unnecessary input from user
   • Store in session or trusted back-end store
   • Sanitize input with regex
                                                  2005 JavaOneSM Conference | Session 5935 | 11
What’s Wrong With This Picture?




                         2005 JavaOneSM Conference | Session 5935 | 12
#1: Unvalidated Input (Example)
public void doPost(HttpServletRequest req,…) {
  String customerId =
    req.getParameter(“customerId”);
  String sku = req.getParameter(“sku”);
  String stringPrice =
req.getParameter(“price”);
  Integer price = Integer.valueOf(stringPrice);
  // Store in the database

orderManager.submitOrder(sku,customerId,price);
} // end doPost
                                 2005 JavaOneSM Conference | Session 5935 | 13
#1: Unvalidated Input (Corrected)
public void doPost(HttpServletRequest req,…) {
  // Get customer data
  String customerId =
    req.getParameter(“customerId”);
  String sku = req.getParameter(“sku”);
  // Get price from database
  Integer price = skuManager.getPrice(sku);
  // Store in the database

orderManager.submitOrder(sku,customerId,price);
} // end doPost
                                 2005 JavaOneSM Conference | Session 5935 | 14
#2: Broken Access Control
• Inconsistently applied file system,
  URL controls
• Examples
   • Path traversal
       • Forced browsing past access control checks
       • File permissions—may allow access to
         config/password files
   • Logic flaws
   • Client-side caching
• Countermeasures
   • Use non-programmatic controls
   • Access control via central container
   • Code reviews
                                                  2005 JavaOneSM Conference | Session 5935 | 15
2005 JavaOneSM Conference | Session 5935 | 16
#2: Broken Access Control (Example)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
     try {
        String username = req.getParameter(“USERNAME”);
        String password = req.getParameter(“PASSWORD”);
        try {
           Connection connection = DatabaseUtilities.makeConnection();
           PreparedStatement statement = connection.prepareStatement
             (quot;SELECT * FROM user_system_data WHERE user_name = ? AND password = ?”);
           statement.setString(1,username);
           statement.setString(2,password);
           ResultSet results = statement.executeQuery(query);
           results.first();
           if (results.getString(1).equals(“”)) {
             s.setMessage(quot;Invalid username and password entered.quot;);
             return (makeLogin(s));
           } // end results check
        } catch (Exception e) {}
        // continue and display the page
        if (username != null && username.length() > 0) {
           return (makeUser(s, username, quot;PARAMETERSquot;));
        } // end username test
     } catch (Exception e) {
        s.setMessage(quot;Error generating quot; + this.getClass().getName());
     } // end try/catch
     return (makeLogin(s));
} // end doPost
                                                               2005 JavaOneSM Conference | Session 5935 | 17
#2: Broken Access Control (Solution)
 How to Set Up Basic Authentication
web.xml file
<security-constraint>
  <web-resource-collection>
      <web-resource-name>Admin</web-resource-name>
      <url-pattern>/jsp/admin/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <role-name>(accessLevel=Admin)</role-name>
  </auth-constraint>
</security-constraint>
<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>CCO</realm-name>
</login-config>




                                         2005 JavaOneSM Conference | Session 5935 | 18
#2: Broken Access Control (Solution)
How to Set Up Form Authentication
web.xml file
<!-- LOGIN AUTHENTICATION -->
  <login-config>
     <auth-method>FORM</auth-method>
     <realm-name>CCO</realm-name>
     <form-login-config>
       <form-login-page>login.jsp</form-login-page>
       <form-error-page>error.jsp</form-error-page>
     </form-login-config>
  </login-config>
login.jsp
<form method=quot;POSTquot; action= quot;j_security_checkquot; >
 <input type=quot;textquot; name= quot;j_usernamequot; >
 <input type=quot;passwordquot; name= quot;j_passwordquot; >
</form>
                                     2005 JavaOneSM Conference | Session 5935 | 19
#3: Broken Account and
Session Management
• Weak user authentication
   •   Password-only
   •   Easily guessable usernames (admin, etc.)
   •   Poorly implemented single sign-on (SSO)

• Weak resource authentication
   •   How are database passwords stored?
         •   Could it be disclosed via browser?
   •   Using IP to authenticate?
         •   Can be spoofed

• Countermeasures
   •   Use vetted single sign-on and session mgmt solution
   •     Netegrity SiteMinder
   •     RSA ClearTrust
   •   Strong passwords
   •   Remove default user names
   •   Protect sensitive files
                                                             2005 JavaOneSM Conference | Session 5935 | 20
What’s Wrong With This Picture?




                         2005 JavaOneSM Conference | Session 5935 | 21
#3: Broken Account/Session
  Management (Client Example—SSO)
public void doGet(HttpServletRequest req,…) {
  // Get user name
  String userId = req.getRemoteUser();
  Cookie ssoCookie = new
Cookie(“userid”,userId);
  ssoCookie.setPath(“/”);
  ssoCookie.setDomain(“cisco.com”);
  response.addCookie(ssoCookie);
  …
}

                                 2005 JavaOneSM Conference | Session 5935 | 22
#3: Broken Account/Session
   Management (Server Example—SSO)
public void doGet(HttpServletRequest req,…) {
 // Get user name
 Cookie[] cookies = req.Cookies();
 for (i=0; i < cookies.length; i++) {
   Cookie cookie = cookies[i];
   if (cookie.getName().equals(“ssoCookie”)) {
       String userId = cookie.getValue();
       HttpSession session = req.getSession();
       session.setAttribute(“userId”,userId);
   } // end if
 } // end for
} // end doGet

                                            2005 JavaOneSM Conference | Session 5935 | 23
#3: Broken Account/Session
        Management (Client Solution—SSO)
public void doGet(HttpServletRequest req,…) {
    // Get user name
    String userId = req.getRemoteUser();
    encryptedUserId = Encrypter.encrypt(userId);
    Cookie ssoCookie =
        new Cookie(“userid”,encrypteduserId);
    ssoCookie.setPath(“/”);
    ssoCookie.setDomain(“cisco.com”);
    response.addCookie(ssoCookie);
    …
}

                                           2005 JavaOneSM Conference | Session 5935 | 24
#3: Broken Account/Session
     Management (Server Solution—SSO)
public void doGet(HttpServletRequest req,…) {
 // Get user name
 Cookie[] cookies = req.Cookies();
 for (i=0; i < cookies.length; i++) {
   Cookie cookie = cookies[i];
   if (cookie.getName().equals(“ssoCookie”)) {
          String encryptedUserId = cookie.getValue();
          String userId = Encrypter.decrypt(encryptedUserId);
          if (isValid(userId)) {
                 HttpSession session = req.getSession();
                 session.setAttribute(“userId”,userId);
          } // end if isValid…
   } // end if cookie = ssoCookie…
 } // end for
} // end doGet


                                                                2005 JavaOneSM Conference | Session 5935 | 25
#4: Cross-Site Scripting (XSS)
•   Attacker…
     •   Inject code into web page that is then displayed
         to user in the browser
     •   Uses trusted application/company to reflect
         malicious code to end-user
     •   Can “hide” the malicious code w/unicode
•   Vulnerable anywhere user-supplied data is
    redisplayed w/out input validation or output encoding
•   2 types of attacks: stored and reflected
•   Can steal cookies, especially vulnerable on apps
    with form-based authentication
•   Countermeasures
     •   Input validation
           •   White-listing: a-z, A-Z, 0-9, etc.)
           •   Black-listing: “< > ( ) # &”
           •   Don’t forget these: “&lt &gt &#40 &#41 &#35 &#38”
     •   Output encoding (htmlEncode output)
     •   Truncate input fields to reasonable length
                                                                   2005 JavaOneSM Conference | Session 5935 | 26
What’s Wrong With This Picture?




                         2005 JavaOneSM Conference | Session 5935 | 27
#4: Cross-Site Scripting (Flaw)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {

   String title = req.getParameter(“TITLE”);

   String message = req.getParameter(“MESSAGE”);
  try {

     connection = DatabaseUtilities.makeConnection(s);

     PreparedStatement statement =
          connection.prepareStatement

            (“INSERT INTO messages VALUES(?,?)”);

     statement.setString(1,title);
     statement.setString(2,message);

     statement.executeUpdate();

   } catch (Exception e) {
     …

   } // end catch

} // end doPost

                                                                 2005 JavaOneSM Conference | Session 5935 | 28
#4: Cross-Site Scripting (Solution)
private static String stripEvilChars(String evilInput) {

      Pattern evilChars = Pattern.compile(“[^a-zA-Z0-9]”);

      return evilChars.matcher(evilInput).replaceAll(“”);

}

protected void doPost(HttpServletRequest req, HttpServletResponse res) {

    String title = stripEvilChars(req.getParameter(“TITLE”));

    String message = stripEvilChars(req.getParameter(“MESSAGE”));

    try {

        connection = DatabaseUtilities.makeConnection(s);

        PreparedStatement statement =

            connection.prepareStatement

               (“INSERT INTO messages VALUES(?,?)”);

        statement.setString(1,title);

        statement.setString(2,message);

        statement.executeUpdate();

      } catch (Exception e) {

        …

      } // end catch

} // end doPost
                                                                           2005 JavaOneSM Conference | Session 5935 | 29
#5: Buffer Overflow Errors

• Not generally an issue with Java apps
• Avoid use of native methods
  • Especially from untrusted sources




                                        2005 JavaOneSM Conference | Session 5935 | 30
#6: Injection Flaws
•   Allows attacker to relay malicious code in form variables or URL
     •   System commands
     •   SQL

•   Typical dangers
     •   Runtime.exec() to external programs (like sendmail)
     •   Dynamically concatenated SQL statements

•   Examples
     •   Path traversal: “../”
     •   Add more commands: “; rm –r *”
     •   SQL injection: “’ OR 1=1”

•   Countermeasures
     •   Use PreparedStatements in SQL
     •   Avoid Runtime.exec() calls (use libraries instead)
     •   Run with limited privileges
     •   Filter/validate input
                                                               2005 JavaOneSM Conference | Session 5935 | 31
What’s Wrong With This Picture?




                         2005 JavaOneSM Conference | Session 5935 | 32
#6: SQL Injection (Flaw)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
   String query =
     quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot;
     + req.getParameter(“ACCT_NUM”)
     + “’”;
   PrintWriter out = res.getWriter();
   // HTML stuff to out.println…
   try {
     connection = DatabaseUtilities.makeConnection(s);
     Statement statement = connection.createStatement();
     ResultSet results = statement.executeQuery(query);
     while (results.next ()) {
         out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”);
         out.println(quot;<TD>“ + rset.getString(2) + “</TD>”);
     } // end while
  } catch (Exception e) {
    // exception handling…
  } // end catch
} // end doPost

                                                    2005 JavaOneSM Conference | Session 5935 | 33
#6: SQL Injection (Fix)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
   PrintWriter out = res.getWriter();
   // HTML stuff to out.println…
   try {
     connection = DatabaseUtilities.makeConnection(s);
     PreparedStatement statement = connection.prepareStatement
           (quot;SELECT userid, name FROM user_data WHERE accountnum = ?“);
     statement.setString(1,req.getParameter(“ACCT_NUM”);
     ResultSet results = statement.executeQuery(query);
     while (results.next()) {
       out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”);
       out.println(quot;<TD>“ + rset.getString(2) + “</TD>”);
     } // end while
 } catch (Exception e) {
   // exception handling…
 } // end catch
} // end doPost


                                                           2005 JavaOneSM Conference | Session 5935 | 34
#7: Improper Error Handling
•   Examples: stack traces, DB dumps
•   Helps attacker know how to target the app
•   Often left behind during programmer debugging
•   Inconsistencies can be revealing
     •   “File not found” vs. “Access denied”
•   Gives insight into source code
     •   Logic flaws
     •   Default accounts, etc.
•   Good messages give enough info to user w/o giving
    too much info to attacker
•   Countermeasures
     •   Code review
     •   Modify default error pages (404, 401, etc.)
     •   Log details to log files, not returned in HTTP request
                                                                  2005 JavaOneSM Conference | Session 5935 | 35
What’s Wrong With This Picture?




                         2005 JavaOneSM Conference | Session 5935 | 36
#7: Improper Error Handling (Flaw)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
    String query =
      quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot;
      + req.getParameter(“ACCT_NUM”) + “’”;
    PrintWriter out = res.getWriter();
    // HTML stuff to out.println…
    try {
      connection = DatabaseUtilities.makeConnection(s);
      Statement statement = connection.createStatement();
      ResultSet results = statement.executeQuery(query);
      while (results.next()) {
        out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”);
        out.println(quot;<TD>“ + rset.getString(2) + “</TD>”);
      } // end while
  } catch (Exception e) {
     e.printStackTrace(out);
  } // end catch
} // end doPost




                                                             2005 JavaOneSM Conference | Session 5935 | 37
#7: Improper Error Handling (Solution)
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
    String query =
      quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot;
      + req.getParameter(“ACCT_NUM”) + “’”;
    PrintWriter out = res.getWriter();
    // HTML stuff to out.println…
    try {
      connection = DatabaseUtilities.makeConnection(s);
      Statement statement = connection.createStatement();
      ResultSet results = statement.executeQuery(query);
      while (results.next ()) {
     out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”);
     out.println(quot;<TD>“ + rset.getString(2) + “</TD>”);
      } // end while
  } catch (Exception e) {
     Logger logger = Logger.getLogger();
     logger.log(Level.SEVERE,”Error retrieving account number”,e);
     out.println(“Sorry, but we are unable to retrieve this account”);
    } // end catch
} // end doPost




                                                                 2005 JavaOneSM Conference | Session 5935 | 38
#8: Insecure Storage
•   Sensitive data such as credit cards,
    passwords, etc. must be protected
•   Examples of bad crypto
     •   Poor choice of algorithm
     •   Poor randomness in sessions/tokens
•   Storage locations must be protected
     •   Database
     •   Files
     •   Memory
•   Countermeasures
     •   Store only what you must
     •   Store a hash instead of the full value if you can
         (SHA-1, for example)
     •   Use only vetted, public cryptography

                                                             2005 JavaOneSM Conference | Session 5935 | 39
Encoding Is Not Encrypting




                         2005 JavaOneSM Conference | Session 5935 | 40
#8: Insecure Storage—Bad Example
public String encrypt(String plainText) {
    plainText = plainText.replace(“a”,”z”);
    plainText = plainText.replace(“b”,”y”);
    …
    return Base64Encoder.encode(plainText);
}




                                         2005 JavaOneSM Conference | Session 5935 | 41
#8: Insecure Storage—Fixed Example
public String encrypt(String plainText) {
    // Read encryptKey as a byte array from a file
    DESKeySpec keySpec = new DESKeySpec(encryptKey);
    SecretKeyFactory factory =
        new SecretKeyFactory.getInstance(“DES”);
    SecretKey key = factory.generateSecret(keySpec);
    Cipher cipher = Cipher.getInstance(“DES”);
    cipher.init(Cipher.ENCRYPT_MODE,key);
    byte[] utf8text = plainText.getBytes(“UTF8”);
    byte[] enryptedText = ecipher.doFinal(utf8text);
    return Base64Encoder.encode(encryptedText);
}


                                                     2005 JavaOneSM Conference | Session 5935 | 42
#9: Denial-Of-Service (DoS)
• Examples that may provoke DoS
    •   Heavy object allocation/reclamation
    •   Overuse of logging
    •   Unhandled exceptions
    •   Unresolved dependencies on
        other systems
         • Web services
         • Databases
• May impact other applications,
  hosts, databases, or network itself
• Countermeasures
    • Load testing
    • Code review

                                              2005 JavaOneSM Conference | Session 5935 | 43
#10: Insecure Configuration
Management
• Tension between “work out of the box”
  and “use only what you need”
• Developers ? web masters
• Examples
   •   Unpatched security flaws (BID example)
   •   Misconfigurations that allow directory traversal
   •   Administrative services accessible
   •   Default accounts/passwords
• Countermeasures
   •   Create and use hardening guides
   •   Turn off all unused services
   •   Set up and audit roles, permissions,
       and accounts
   •   Set up logging and alerts
                                                          2005 JavaOneSM Conference | Session 5935 | 44
Review: Principles for Secure Coding
• Don’t trust input from user
• Watch for logic holes
• Leverage common,
  vetted resources
• Only give information needed
• Leverage vetted infrastructure
  and components
• Build/test to withstand load
   • Expected load
   • Potential DOS attack

                                   2005 JavaOneSM Conference | Session 5935 | 45
For More Information
• References
   • Top 10 Web Application Vulnerabilities (OWASP)
   • Innocent Code, by Sverre H. Huseby
• Tools used in this preso
• WebGoat—vulnerable web applications for demonstration
• VMWare—runs Linux and Windows 2000 virtual machines
  on demo laptop
• nmap—host/port scanning to find vulnerable hosts
• Mozilla Firefox—browser that supports plug-ins for proxied HTTP,
  source browsing
   • SwitchProxy plug-in lets you quickly switch your proxies
   • WebDeveloper plug-in lets you easily clear HTTP auth
• WebScarab—HTTP proxy
                                                    2005 JavaOneSM Conference | Session 5935 | 46
Q&A


      2005 JavaOneSM Conference | Session 5935 | 47
9 Ways to Hack a Web App
Martin G. Nystrom, CISSP-ISSAP
Security Architect
Cisco Systems, Inc.
www.cisco.com
TS-5935

           2005 JavaOneSM Conference | Session 5935   48

Weitere ähnliche Inhalte

Ähnlich wie 9 Ways to Hack a Web App

Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processguest3379bd
 
Graphing for Security
Graphing for SecurityGraphing for Security
Graphing for Securitymr_secure
 
LogLogic SQL Server Hacking DBs April09
LogLogic SQL Server Hacking DBs April09LogLogic SQL Server Hacking DBs April09
LogLogic SQL Server Hacking DBs April09Mark Ginnebaugh
 
Securing your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
Securing your Oracle Fusion Middleware Environment, On-Prem and in the CloudSecuring your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
Securing your Oracle Fusion Middleware Environment, On-Prem and in the CloudRevelation Technologies
 
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...Quek Lilian
 
Architecture vulnerabilities in SAP platforms
Architecture vulnerabilities in SAP platformsArchitecture vulnerabilities in SAP platforms
Architecture vulnerabilities in SAP platformsERPScan
 
Hunting Security Bugs in Modern Web Applications
Hunting Security Bugs in Modern Web ApplicationsHunting Security Bugs in Modern Web Applications
Hunting Security Bugs in Modern Web ApplicationsToe Khaing
 
How the Cloud Shifts the Burden of Security to Development
How the Cloud Shifts the Burden of Security to DevelopmentHow the Cloud Shifts the Burden of Security to Development
How the Cloud Shifts the Burden of Security to DevelopmentErika Barron
 
Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Masoud Kalali
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsPositive Hack Days
 
Ruby On Rails Security 9984
Ruby On Rails Security 9984Ruby On Rails Security 9984
Ruby On Rails Security 9984Dr Rushi Raval
 
Java EE 6 Security in practice with GlassFish
Java EE 6 Security in practice with GlassFishJava EE 6 Security in practice with GlassFish
Java EE 6 Security in practice with GlassFishMarkus Eisele
 
Vulnerabilities in data processing levels
Vulnerabilities in data processing levelsVulnerabilities in data processing levels
Vulnerabilities in data processing levelsbeched
 
Minor Mistakes In Web Portals
Minor Mistakes In Web PortalsMinor Mistakes In Web Portals
Minor Mistakes In Web Portalsmsobiegraj
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Jim Manico
 
What should I do when my website got hack?
What should I do when my website got hack?What should I do when my website got hack?
What should I do when my website got hack?Sumedt Jitpukdebodin
 
Lesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsLesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsZendCon
 
手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務Mu Chun Wang
 

Ähnlich wie 9 Ways to Hack a Web App (20)

Whatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the processWhatever it takes - Fixing SQLIA and XSS in the process
Whatever it takes - Fixing SQLIA and XSS in the process
 
T5 Oli Aro
T5 Oli AroT5 Oli Aro
T5 Oli Aro
 
Graphing for Security
Graphing for SecurityGraphing for Security
Graphing for Security
 
LogLogic SQL Server Hacking DBs April09
LogLogic SQL Server Hacking DBs April09LogLogic SQL Server Hacking DBs April09
LogLogic SQL Server Hacking DBs April09
 
Securing your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
Securing your Oracle Fusion Middleware Environment, On-Prem and in the CloudSecuring your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
Securing your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
 
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
MS Innovation Day: A Lap Around Web Application Vulnerabilities by MVP Walter...
 
Architecture vulnerabilities in SAP platforms
Architecture vulnerabilities in SAP platformsArchitecture vulnerabilities in SAP platforms
Architecture vulnerabilities in SAP platforms
 
Hunting Security Bugs in Modern Web Applications
Hunting Security Bugs in Modern Web ApplicationsHunting Security Bugs in Modern Web Applications
Hunting Security Bugs in Modern Web Applications
 
How the Cloud Shifts the Burden of Security to Development
How the Cloud Shifts the Burden of Security to DevelopmentHow the Cloud Shifts the Burden of Security to Development
How the Cloud Shifts the Burden of Security to Development
 
Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881
 
Vulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing LevelsVulnerabilities on Various Data Processing Levels
Vulnerabilities on Various Data Processing Levels
 
Ruby On Rails Security 9984
Ruby On Rails Security 9984Ruby On Rails Security 9984
Ruby On Rails Security 9984
 
Java EE 6 Security in practice with GlassFish
Java EE 6 Security in practice with GlassFishJava EE 6 Security in practice with GlassFish
Java EE 6 Security in practice with GlassFish
 
Vulnerabilities in data processing levels
Vulnerabilities in data processing levelsVulnerabilities in data processing levels
Vulnerabilities in data processing levels
 
Minor Mistakes In Web Portals
Minor Mistakes In Web PortalsMinor Mistakes In Web Portals
Minor Mistakes In Web Portals
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
What should I do when my website got hack?
What should I do when my website got hack?What should I do when my website got hack?
What should I do when my website got hack?
 
Lesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP ApplicationsLesser Known Security Problems in PHP Applications
Lesser Known Security Problems in PHP Applications
 
Oracle11g Security
Oracle11g SecurityOracle11g Security
Oracle11g Security
 
手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務手把手教你如何串接 Log 到各種網路服務
手把手教你如何串接 Log 到各種網路服務
 

Mehr von elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makeselliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 

Mehr von elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Kürzlich hochgeladen

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Kürzlich hochgeladen (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

9 Ways to Hack a Web App

  • 1. 9 Ways to Hack a Web App Martin G. Nystrom, CISSP-ISSAP Security Architect Cisco Systems, Inc. www.cisco.com TS-5935 2005 JavaOneSM Conference | Session 5935 1
  • 2. Why Worry? Recent headlines • Net worm using Google to spread • “…uses a flaw in the widely used community forum software known as the PHP Bulletin Board (phpBB) to spread…” • California reports massive data breach • “…The compromised system had the names, addresses, phone numbers, social security numbers, and dates of birth of everyone who provided or received care.” • Google bug exposes e-mail to hackers • “…By altering the “From” address field of an e-mail sent to the service, hackers could potentially find out a user’s personal information, including passwords. ...” • truckstop.com web application stolen by competitor • “…Getloaded’s officers also hacked into the code Creative used to operate its website.” Sources: news.com, E-Week, SecurityFocus , 2005 JavaOneSM Conference | Session 5935 | 2
  • 3. Goal Learn why and how to build Java web apps secured from the most common security hacks. 2005 JavaOneSM Conference | Session 5935 | 3
  • 4. Agenda • Intro and Overview • How vulnerable are web apps? • Basics of web hacking • Web Architecture and Principles • How are most web-based Java apps deployed? • Principles of Secure Programming • A “security mantra” for web developers • 9 Most Common Web Vulnerabilities • …and how to fix them in Java 2005 JavaOneSM Conference | Session 5935 | 4
  • 5. 95% of Web Apps Have Vulnerabilities • Cross-site scripting (80 percent) • SQL injection (62 percent) • Parameter tampering (60 percent) • Cookie poisoning (37 percent) • Database server (33 percent) • Web server (23 percent) • Buffer overflow (19 percent) 2005 JavaOneSM Conference | Session 5935 | 5
  • 6. Web Attack • Discover • Examine the environment • Identify open ports • Discover types/versions of apps running • Banner grabbing • Extensions (.jhtml, .jsp, etc.) and directory structures • Generate and examine errors • Submit ridiculous input to provoke errors (fuzzing) • Database errors, stack traces very helpful • Find info left behind (source code, comments, hidden fields) • Target • Login mechanism • Input fields • Session mgmt • Infrastructure 2005 JavaOneSM Conference | Session 5935 | 6
  • 7. A Word of Warning • These tools and techniques can be dangerous • The difference between a hacker and a cracker is…permission • Admins will see strange activity in logs, and come looking for you • Authorities are prosecuting even the “good guys” for using these tools 2005 JavaOneSM Conference | Session 5935 | 7
  • 8. Security Principles of Web Architecture • Practice defense-in-depth • Separate services • Web server, app server, db server on separate hosts • Limit privileges of application user • File system (chroot or limit privs to read-only) • Database system (limit privileges on tables, schemas, etc.) • Privileges of running user (xxtomcat, apache, kobayashi, etc.) • Hide secrets • Database account passwords • Encryption keys • Use standard, vetted components, libraries • Keep them patched • Log, and watch logs for unusual activity • Load-test and tune accordingly 2005 JavaOneSM Conference | Session 5935 | 8
  • 9. Principles for Secure Coding • Don’t trust input from user • Review for logic holes • Leverage vetted resources • Infrastructure • Components • Only give information needed • Build/test to withstand load • Expected load • Potential DOS attack 2005 JavaOneSM Conference | Session 5935 | 9
  • 10. OWASP Top 10 Web Security Vulns 1. Unvalidated input 2. Broken access control 3. Broken account/session management 4. Cross-site scripting (XSS) flaws 5. Buffer overflows 6. Injection flaws 7. Improper error handling 8. Insecure storage 9. Denial-of-service 10. Insecure configuration management Source: www.owasp.org 2005 JavaOneSM Conference | Session 5935 | 10
  • 11. #1: Unvalidated Input • Attacker can easily change any part of the HTTP request before submitting • URL • Cookies • Form fields • Hidden fields • Headers • Input must be validated on the server • Countermeasures • Code reviews (check variable against list of allowed values, not vice-versa) • Don’t accept unnecessary input from user • Store in session or trusted back-end store • Sanitize input with regex 2005 JavaOneSM Conference | Session 5935 | 11
  • 12. What’s Wrong With This Picture? 2005 JavaOneSM Conference | Session 5935 | 12
  • 13. #1: Unvalidated Input (Example) public void doPost(HttpServletRequest req,…) { String customerId = req.getParameter(“customerId”); String sku = req.getParameter(“sku”); String stringPrice = req.getParameter(“price”); Integer price = Integer.valueOf(stringPrice); // Store in the database orderManager.submitOrder(sku,customerId,price); } // end doPost 2005 JavaOneSM Conference | Session 5935 | 13
  • 14. #1: Unvalidated Input (Corrected) public void doPost(HttpServletRequest req,…) { // Get customer data String customerId = req.getParameter(“customerId”); String sku = req.getParameter(“sku”); // Get price from database Integer price = skuManager.getPrice(sku); // Store in the database orderManager.submitOrder(sku,customerId,price); } // end doPost 2005 JavaOneSM Conference | Session 5935 | 14
  • 15. #2: Broken Access Control • Inconsistently applied file system, URL controls • Examples • Path traversal • Forced browsing past access control checks • File permissions—may allow access to config/password files • Logic flaws • Client-side caching • Countermeasures • Use non-programmatic controls • Access control via central container • Code reviews 2005 JavaOneSM Conference | Session 5935 | 15
  • 16. 2005 JavaOneSM Conference | Session 5935 | 16
  • 17. #2: Broken Access Control (Example) protected void doPost(HttpServletRequest req, HttpServletResponse res) { try { String username = req.getParameter(“USERNAME”); String password = req.getParameter(“PASSWORD”); try { Connection connection = DatabaseUtilities.makeConnection(); PreparedStatement statement = connection.prepareStatement (quot;SELECT * FROM user_system_data WHERE user_name = ? AND password = ?”); statement.setString(1,username); statement.setString(2,password); ResultSet results = statement.executeQuery(query); results.first(); if (results.getString(1).equals(“”)) { s.setMessage(quot;Invalid username and password entered.quot;); return (makeLogin(s)); } // end results check } catch (Exception e) {} // continue and display the page if (username != null && username.length() > 0) { return (makeUser(s, username, quot;PARAMETERSquot;)); } // end username test } catch (Exception e) { s.setMessage(quot;Error generating quot; + this.getClass().getName()); } // end try/catch return (makeLogin(s)); } // end doPost 2005 JavaOneSM Conference | Session 5935 | 17
  • 18. #2: Broken Access Control (Solution) How to Set Up Basic Authentication web.xml file <security-constraint> <web-resource-collection> <web-resource-name>Admin</web-resource-name> <url-pattern>/jsp/admin/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>(accessLevel=Admin)</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>CCO</realm-name> </login-config> 2005 JavaOneSM Conference | Session 5935 | 18
  • 19. #2: Broken Access Control (Solution) How to Set Up Form Authentication web.xml file <!-- LOGIN AUTHENTICATION --> <login-config> <auth-method>FORM</auth-method> <realm-name>CCO</realm-name> <form-login-config> <form-login-page>login.jsp</form-login-page> <form-error-page>error.jsp</form-error-page> </form-login-config> </login-config> login.jsp <form method=quot;POSTquot; action= quot;j_security_checkquot; > <input type=quot;textquot; name= quot;j_usernamequot; > <input type=quot;passwordquot; name= quot;j_passwordquot; > </form> 2005 JavaOneSM Conference | Session 5935 | 19
  • 20. #3: Broken Account and Session Management • Weak user authentication • Password-only • Easily guessable usernames (admin, etc.) • Poorly implemented single sign-on (SSO) • Weak resource authentication • How are database passwords stored? • Could it be disclosed via browser? • Using IP to authenticate? • Can be spoofed • Countermeasures • Use vetted single sign-on and session mgmt solution • Netegrity SiteMinder • RSA ClearTrust • Strong passwords • Remove default user names • Protect sensitive files 2005 JavaOneSM Conference | Session 5935 | 20
  • 21. What’s Wrong With This Picture? 2005 JavaOneSM Conference | Session 5935 | 21
  • 22. #3: Broken Account/Session Management (Client Example—SSO) public void doGet(HttpServletRequest req,…) { // Get user name String userId = req.getRemoteUser(); Cookie ssoCookie = new Cookie(“userid”,userId); ssoCookie.setPath(“/”); ssoCookie.setDomain(“cisco.com”); response.addCookie(ssoCookie); … } 2005 JavaOneSM Conference | Session 5935 | 22
  • 23. #3: Broken Account/Session Management (Server Example—SSO) public void doGet(HttpServletRequest req,…) { // Get user name Cookie[] cookies = req.Cookies(); for (i=0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(“ssoCookie”)) { String userId = cookie.getValue(); HttpSession session = req.getSession(); session.setAttribute(“userId”,userId); } // end if } // end for } // end doGet 2005 JavaOneSM Conference | Session 5935 | 23
  • 24. #3: Broken Account/Session Management (Client Solution—SSO) public void doGet(HttpServletRequest req,…) { // Get user name String userId = req.getRemoteUser(); encryptedUserId = Encrypter.encrypt(userId); Cookie ssoCookie = new Cookie(“userid”,encrypteduserId); ssoCookie.setPath(“/”); ssoCookie.setDomain(“cisco.com”); response.addCookie(ssoCookie); … } 2005 JavaOneSM Conference | Session 5935 | 24
  • 25. #3: Broken Account/Session Management (Server Solution—SSO) public void doGet(HttpServletRequest req,…) { // Get user name Cookie[] cookies = req.Cookies(); for (i=0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(“ssoCookie”)) { String encryptedUserId = cookie.getValue(); String userId = Encrypter.decrypt(encryptedUserId); if (isValid(userId)) { HttpSession session = req.getSession(); session.setAttribute(“userId”,userId); } // end if isValid… } // end if cookie = ssoCookie… } // end for } // end doGet 2005 JavaOneSM Conference | Session 5935 | 25
  • 26. #4: Cross-Site Scripting (XSS) • Attacker… • Inject code into web page that is then displayed to user in the browser • Uses trusted application/company to reflect malicious code to end-user • Can “hide” the malicious code w/unicode • Vulnerable anywhere user-supplied data is redisplayed w/out input validation or output encoding • 2 types of attacks: stored and reflected • Can steal cookies, especially vulnerable on apps with form-based authentication • Countermeasures • Input validation • White-listing: a-z, A-Z, 0-9, etc.) • Black-listing: “< > ( ) # &” • Don’t forget these: “&lt &gt &#40 &#41 &#35 &#38” • Output encoding (htmlEncode output) • Truncate input fields to reasonable length 2005 JavaOneSM Conference | Session 5935 | 26
  • 27. What’s Wrong With This Picture? 2005 JavaOneSM Conference | Session 5935 | 27
  • 28. #4: Cross-Site Scripting (Flaw) protected void doPost(HttpServletRequest req, HttpServletResponse res) { String title = req.getParameter(“TITLE”); String message = req.getParameter(“MESSAGE”); try { connection = DatabaseUtilities.makeConnection(s); PreparedStatement statement = connection.prepareStatement (“INSERT INTO messages VALUES(?,?)”); statement.setString(1,title); statement.setString(2,message); statement.executeUpdate(); } catch (Exception e) { … } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 28
  • 29. #4: Cross-Site Scripting (Solution) private static String stripEvilChars(String evilInput) { Pattern evilChars = Pattern.compile(“[^a-zA-Z0-9]”); return evilChars.matcher(evilInput).replaceAll(“”); } protected void doPost(HttpServletRequest req, HttpServletResponse res) { String title = stripEvilChars(req.getParameter(“TITLE”)); String message = stripEvilChars(req.getParameter(“MESSAGE”)); try { connection = DatabaseUtilities.makeConnection(s); PreparedStatement statement = connection.prepareStatement (“INSERT INTO messages VALUES(?,?)”); statement.setString(1,title); statement.setString(2,message); statement.executeUpdate(); } catch (Exception e) { … } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 29
  • 30. #5: Buffer Overflow Errors • Not generally an issue with Java apps • Avoid use of native methods • Especially from untrusted sources 2005 JavaOneSM Conference | Session 5935 | 30
  • 31. #6: Injection Flaws • Allows attacker to relay malicious code in form variables or URL • System commands • SQL • Typical dangers • Runtime.exec() to external programs (like sendmail) • Dynamically concatenated SQL statements • Examples • Path traversal: “../” • Add more commands: “; rm –r *” • SQL injection: “’ OR 1=1” • Countermeasures • Use PreparedStatements in SQL • Avoid Runtime.exec() calls (use libraries instead) • Run with limited privileges • Filter/validate input 2005 JavaOneSM Conference | Session 5935 | 31
  • 32. What’s Wrong With This Picture? 2005 JavaOneSM Conference | Session 5935 | 32
  • 33. #6: SQL Injection (Flaw) protected void doPost(HttpServletRequest req, HttpServletResponse res) { String query = quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot; + req.getParameter(“ACCT_NUM”) + “’”; PrintWriter out = res.getWriter(); // HTML stuff to out.println… try { connection = DatabaseUtilities.makeConnection(s); Statement statement = connection.createStatement(); ResultSet results = statement.executeQuery(query); while (results.next ()) { out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”); out.println(quot;<TD>“ + rset.getString(2) + “</TD>”); } // end while } catch (Exception e) { // exception handling… } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 33
  • 34. #6: SQL Injection (Fix) protected void doPost(HttpServletRequest req, HttpServletResponse res) { PrintWriter out = res.getWriter(); // HTML stuff to out.println… try { connection = DatabaseUtilities.makeConnection(s); PreparedStatement statement = connection.prepareStatement (quot;SELECT userid, name FROM user_data WHERE accountnum = ?“); statement.setString(1,req.getParameter(“ACCT_NUM”); ResultSet results = statement.executeQuery(query); while (results.next()) { out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”); out.println(quot;<TD>“ + rset.getString(2) + “</TD>”); } // end while } catch (Exception e) { // exception handling… } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 34
  • 35. #7: Improper Error Handling • Examples: stack traces, DB dumps • Helps attacker know how to target the app • Often left behind during programmer debugging • Inconsistencies can be revealing • “File not found” vs. “Access denied” • Gives insight into source code • Logic flaws • Default accounts, etc. • Good messages give enough info to user w/o giving too much info to attacker • Countermeasures • Code review • Modify default error pages (404, 401, etc.) • Log details to log files, not returned in HTTP request 2005 JavaOneSM Conference | Session 5935 | 35
  • 36. What’s Wrong With This Picture? 2005 JavaOneSM Conference | Session 5935 | 36
  • 37. #7: Improper Error Handling (Flaw) protected void doPost(HttpServletRequest req, HttpServletResponse res) { String query = quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot; + req.getParameter(“ACCT_NUM”) + “’”; PrintWriter out = res.getWriter(); // HTML stuff to out.println… try { connection = DatabaseUtilities.makeConnection(s); Statement statement = connection.createStatement(); ResultSet results = statement.executeQuery(query); while (results.next()) { out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”); out.println(quot;<TD>“ + rset.getString(2) + “</TD>”); } // end while } catch (Exception e) { e.printStackTrace(out); } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 37
  • 38. #7: Improper Error Handling (Solution) protected void doPost(HttpServletRequest req, HttpServletResponse res) { String query = quot;SELECT userid, name FROM user_data WHERE accountnum = 'quot; + req.getParameter(“ACCT_NUM”) + “’”; PrintWriter out = res.getWriter(); // HTML stuff to out.println… try { connection = DatabaseUtilities.makeConnection(s); Statement statement = connection.createStatement(); ResultSet results = statement.executeQuery(query); while (results.next ()) { out.println(quot;<TR><TD>“ + rset.getString(1) + “</TD>”); out.println(quot;<TD>“ + rset.getString(2) + “</TD>”); } // end while } catch (Exception e) { Logger logger = Logger.getLogger(); logger.log(Level.SEVERE,”Error retrieving account number”,e); out.println(“Sorry, but we are unable to retrieve this account”); } // end catch } // end doPost 2005 JavaOneSM Conference | Session 5935 | 38
  • 39. #8: Insecure Storage • Sensitive data such as credit cards, passwords, etc. must be protected • Examples of bad crypto • Poor choice of algorithm • Poor randomness in sessions/tokens • Storage locations must be protected • Database • Files • Memory • Countermeasures • Store only what you must • Store a hash instead of the full value if you can (SHA-1, for example) • Use only vetted, public cryptography 2005 JavaOneSM Conference | Session 5935 | 39
  • 40. Encoding Is Not Encrypting 2005 JavaOneSM Conference | Session 5935 | 40
  • 41. #8: Insecure Storage—Bad Example public String encrypt(String plainText) { plainText = plainText.replace(“a”,”z”); plainText = plainText.replace(“b”,”y”); … return Base64Encoder.encode(plainText); } 2005 JavaOneSM Conference | Session 5935 | 41
  • 42. #8: Insecure Storage—Fixed Example public String encrypt(String plainText) { // Read encryptKey as a byte array from a file DESKeySpec keySpec = new DESKeySpec(encryptKey); SecretKeyFactory factory = new SecretKeyFactory.getInstance(“DES”); SecretKey key = factory.generateSecret(keySpec); Cipher cipher = Cipher.getInstance(“DES”); cipher.init(Cipher.ENCRYPT_MODE,key); byte[] utf8text = plainText.getBytes(“UTF8”); byte[] enryptedText = ecipher.doFinal(utf8text); return Base64Encoder.encode(encryptedText); } 2005 JavaOneSM Conference | Session 5935 | 42
  • 43. #9: Denial-Of-Service (DoS) • Examples that may provoke DoS • Heavy object allocation/reclamation • Overuse of logging • Unhandled exceptions • Unresolved dependencies on other systems • Web services • Databases • May impact other applications, hosts, databases, or network itself • Countermeasures • Load testing • Code review 2005 JavaOneSM Conference | Session 5935 | 43
  • 44. #10: Insecure Configuration Management • Tension between “work out of the box” and “use only what you need” • Developers ? web masters • Examples • Unpatched security flaws (BID example) • Misconfigurations that allow directory traversal • Administrative services accessible • Default accounts/passwords • Countermeasures • Create and use hardening guides • Turn off all unused services • Set up and audit roles, permissions, and accounts • Set up logging and alerts 2005 JavaOneSM Conference | Session 5935 | 44
  • 45. Review: Principles for Secure Coding • Don’t trust input from user • Watch for logic holes • Leverage common, vetted resources • Only give information needed • Leverage vetted infrastructure and components • Build/test to withstand load • Expected load • Potential DOS attack 2005 JavaOneSM Conference | Session 5935 | 45
  • 46. For More Information • References • Top 10 Web Application Vulnerabilities (OWASP) • Innocent Code, by Sverre H. Huseby • Tools used in this preso • WebGoat—vulnerable web applications for demonstration • VMWare—runs Linux and Windows 2000 virtual machines on demo laptop • nmap—host/port scanning to find vulnerable hosts • Mozilla Firefox—browser that supports plug-ins for proxied HTTP, source browsing • SwitchProxy plug-in lets you quickly switch your proxies • WebDeveloper plug-in lets you easily clear HTTP auth • WebScarab—HTTP proxy 2005 JavaOneSM Conference | Session 5935 | 46
  • 47. Q&A 2005 JavaOneSM Conference | Session 5935 | 47
  • 48. 9 Ways to Hack a Web App Martin G. Nystrom, CISSP-ISSAP Security Architect Cisco Systems, Inc. www.cisco.com TS-5935 2005 JavaOneSM Conference | Session 5935 48