SlideShare a Scribd company logo
SEA-SURFING IN ASP.NET MVC
BARTOSZ LENAR
THE PLAN
BASICS
 http requests
 authentication
 cookies
 session
SEA-SURFING
 unfixable bug
 hacking the system
 csrf attack
 token-based defence
SPA
 problems
 server-side layer
 client-side layer
FIDDLER
responses
requests
HTTP
REQUEST
 Method
 Version
 Host
 Rest as key-value pairs:
 Accept
 Cache-control
 …
 BODY
RESPONSE
 Status dode
 Version
 Date
 Rest as key-value pairs:
 Content-type
 Content-length
 …
 BODY
COOKIES
 exist in headers as another key-value pair "with parameters"
 cookies consist of
 name
 value
 domain & path
 expiration date
 restrictions (security)
COOKIES SCENARIO
2. responds with cookie visited: true
1. sends request to example.org
4. sends request to example.org
with visited:true cookie in headers
3. saves
visited:true
for example.org
5. knows that client
visited this page earlier
HTTP REQUESTS AND COOKIES
WEB AUTHENTICATION
 authentication system
 authorize once at the beginning
 use the system all the time
 but http protocol is stateless!
 every request is independent
 how to simulate the states?
 how to identify request from the specific user?
STATES SCENARIO
2. generates über-random identifier
1. sends first request to example.org
5. sends next request to example.org
with UserId: QB32SDXC8 cookie in headers
4. saves
UserId:QB32S…
for example.org 3. sends it back in cookie
UserId: QB32SDXC8
SESSION
 so far: server is able to distinguish users
 session: server-side bag for user data
 key: previously generated identifier stored in cookie
 like QB32SDXC8
 value: yet another dictionary
 user-specific data like name, address, etc.
 security and access data like roles, privileges, etc.
 forms
HACK THE SYSTEM
 do we want to be an authorized user?
 no! we want to act like one!
 to hack the system = to "steal" someone’s session
 maybe "someone” is:
 facebook user – we have all his private data, photos, etc.
 bank user – we know how much money he has
 …
 admin – we can do anything
SESSION HIJACKING
 system/browser backdoor
 steal the cookie from memory
 xss
 sidejacking
 main-in-the middle
 fixation
 send user url with session id: http://example.org/?&sessionId=QB32SDXC8
 wait for the user to log in
 riding – our topic
THE ROADTO SESSION RIDING
 we want to download data stored under http://example.org/admin/secret
 let’s think:
 authentication & authorization is based on session
 session is based on cookies
 cookies are being sent to example.org with every request
 how about we prepare a website that sends request to the specified path?
LET’S TRYTO GET THE ADMIN’S SECRET
LET’S TRYTO GET THE ADMIN’S SECRET
 what actually happened?
1. browser downloads the entire DOM tree
2. img node is being located
3. browser automatically sends GET request to download the image
 but… there is no image at the end
 nevertheless, browser attached all cookies dedicated to example.org
<img src="http://example.org/admin/secret" />
LET’S TRYTO DO THE ADMIN’S JOB
 GET shouldn’t change anything
 http://example.org/admin/delete-user/?&username=admin
 you’re doing itWRONG!
 let’s mess up with POST / DELETE / PUT …
LET’S TRYTO DO THE ADMIN’S JOB
BUILDING THE FIREWALL
 how browser works:
 attacker is able to send cookies with the request …
 … but is not able to see them!
ANTI-FORGERY TOKEN – HOW IT’S MADE
2. generates über-random identifier: J723SDA
1. sends request to example.org
3. sends it back inside the form and in the cookie
AntiForgeryToken= J723SDA
<input name="_token" type="hidden"
value="J723SDA" />
ANTI-FORGERY TOKEN – HOW IT WORKS
1. sends request to example.org containing:
• cookie with token: J723SDA
• form value with token: J723SDA
2. validates the request:
• token in cookie is present? true
• token in form is present? true
• do they match each other? true
all true? it’s valid!
ANTI-FORGERY TOKEN – HOW IT SECURES
1. sends request to example.org containing:
• cookie with token: J723SDA
• form value with token: ??????????
2. validates the request:
• token in cookie is present? true
• token in form is present? false
• do they match each other? false
all true? no! respond with 403 Forbidden
DO THE TRICK IN ASP.NET MVC
EVEN MORE SECURE
 create a keyword based on:
 action-specific and user-specific data
 application, server, etc.
 our keyword: "BARTEK"
 hash the keyword: (0BDE667AA88E8832B61BF68C0D4E34A4) and split it:
 0BDE667AA88E8832 goes into cookie
 B61BF68C0D4E34A4 goes into form
 on request, compute the keyword once again and validate the tokens
PROBLEMS
 strongly relies on browser security
 doesn’t work with GET requests
 is it a problem in pure, REST service?
 to disable cookies = to disable all communication
 site vulnerable to XSS = we’re doomed
SINGLE PAGE APPS - PROBLEMS
 forms are pre-generated
 which form is going to be triggered next?
API WRAPPER – CLIENT SIDE
 write wrapper for all ajax communication (GET, POST, PUT, DELETE)
 requestSettings contains method, data, etc.
ApiWrapper.prototype._SendRequest = function (requestSettings) {
var self = this;
requestSettings.headers["Token"] = self.Token;
return $.ajax(requestSettings).always(function (arg1, textStatus, arg2) {
jqXHR = (textStatus !== "success") ? arg1 : arg2;
self.Token = jqXHR.getResponseHeader("Token");
document.cookie = "Token=" + self.TokenId + ";";
});
};
API WRAPPER – SERVER SIDE
 keep tokens in cache/database
 nosql
 custom ValidateAntiForgeryTokenAttribute
 validates token from cookie and header
 updating token if necessary
API WRAPPER - USAGE
 write wrapper for all ajax communication (GET, POST, PUT, DELETE)
 return jqXHR from all functions
api.Get('customers/' + customerId)
.success(function (data) {
self.Customer(data);
});
api.Post('customers/' + customerId, editedData)
.success(function () {
message.ReportSuccess();
});
SEA-SURFING IN ASP.NET MVC
QUESTIONS-SURFING
 Fiddler: http://www.telerik.com/fiddler
 Icons: http://www.visualpharm.com/
BARTOSZ LENAR
bartoszlenar@gmail.com
@bartoszlenar

More Related Content

PDF
What are JSON Web Tokens and Why Should I Care?
PPTX
DrupalTour. Ternopil — What's going on when you visit an URL (Andrij Sakhaniu...
PDF
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
PPTX
Building Secure User Interfaces With JWTs
PPTX
W3 conf hill-html5-security-realities
PDF
Json web token api authorization
PDF
Spring4 security
PPTX
How it's made - MyGet.org - AzureConf
What are JSON Web Tokens and Why Should I Care?
DrupalTour. Ternopil — What's going on when you visit an URL (Andrij Sakhaniu...
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
Building Secure User Interfaces With JWTs
W3 conf hill-html5-security-realities
Json web token api authorization
Spring4 security
How it's made - MyGet.org - AzureConf

What's hot (20)

PPTX
AZUG.BE - Azure User Group Belgium - First public meeting
PDF
AtlasCamp 2014: Connect Security
PDF
When Ajax Attacks! Web application security fundamentals
PPTX
Presentation on Top 10 Vulnerabilities in Web Application
PPTX
Token Based Authentication Systems with AngularJS & NodeJS
PPT
Top Ten Tips For Tenacious Defense In Asp.Net
PDF
WebView security on iOS (EN)
PDF
Owasp for dummies handouts
 
PDF
Subresource Integrity
PDF
Advanced workflows for mobile web design and development
PPTX
Avoiding Cross Site Scripting - Not as easy as you might think
PPTX
14. html 5 security considerations
PDF
The Hidden XSS - Attacking the Desktop & Mobile Platforms
PDF
From 0 to Spring Security 4.0
PDF
Web application finger printing - whitepaper
PPTX
Effective SOA
PDF
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
PPTX
Preventing XSRF in ASP.NET CORE apps
PPTX
Web fundamentals - part 1
PDF
Rest Security with JAX-RS
AZUG.BE - Azure User Group Belgium - First public meeting
AtlasCamp 2014: Connect Security
When Ajax Attacks! Web application security fundamentals
Presentation on Top 10 Vulnerabilities in Web Application
Token Based Authentication Systems with AngularJS & NodeJS
Top Ten Tips For Tenacious Defense In Asp.Net
WebView security on iOS (EN)
Owasp for dummies handouts
 
Subresource Integrity
Advanced workflows for mobile web design and development
Avoiding Cross Site Scripting - Not as easy as you might think
14. html 5 security considerations
The Hidden XSS - Attacking the Desktop & Mobile Platforms
From 0 to Spring Security 4.0
Web application finger printing - whitepaper
Effective SOA
They Ought to Know Better: Exploiting Security Gateways via Their Web Interfaces
Preventing XSRF in ASP.NET CORE apps
Web fundamentals - part 1
Rest Security with JAX-RS
Ad

Viewers also liked (19)

PPSX
Zmiana pracy mariola zieba antal
PDF
Continuous delivery
PDF
Akamai in a hyperconnected world
PDF
Abc zarządzania sobą
PDF
Scala
POT
Hostingowe i domenowe pułapki [97 2003]
PDF
Prezentacja v2(1)
PPT
Agile zrobtosam infomeet
PDF
Info meet katalog kraków 8 marca
PDF
Abc zarządzania sobą
PDF
Szczepan Faber mockito story (1)
PDF
PDF
Soft layer cloud without compromise
PDF
Przychodzi baba do lekarza na badania usability
PDF
Prezentacja personal branding
PDF
Big data ecosystem
PDF
Jakość utracona v13
PDF
Szczepan.faber.gradle
PDF
Patterns for organic architecture codedive
Zmiana pracy mariola zieba antal
Continuous delivery
Akamai in a hyperconnected world
Abc zarządzania sobą
Scala
Hostingowe i domenowe pułapki [97 2003]
Prezentacja v2(1)
Agile zrobtosam infomeet
Info meet katalog kraków 8 marca
Abc zarządzania sobą
Szczepan Faber mockito story (1)
Soft layer cloud without compromise
Przychodzi baba do lekarza na badania usability
Prezentacja personal branding
Big data ecosystem
Jakość utracona v13
Szczepan.faber.gradle
Patterns for organic architecture codedive
Ad

Similar to Sea surfing in asp.net mvc (20)

PPTX
Механизмы предотвращения атак в ASP.NET Core
PDF
Ch 13: Attacking Users: Other Techniques (Part 2)
PDF
Механизмы предотвращения атак в ASP.NET Core
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
PPT
Web 20 Security - Vordel
PDF
Top 10 Web Application vulnerabilities
PDF
Hacking Web Aplications using Cookie Poisoning
PDF
CNIT 129S Ch 7: Attacking Session Management
PPTX
JWT Authentication with AngularJS
PPTX
Browser Security 101
PDF
S8-Session Managment
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
PDF
Evolution Of Web Security
PPTX
Session management
PDF
Secure Coding BSSN Semarang Material.pdf
PDF
The Hacker's Guide To Session Hijacking
PPTX
Confidence web
PPT
A privacy-preserving defense mechanism against attacks
PDF
Securing Web Applications with Token Authentication
Механизмы предотвращения атак в ASP.NET Core
Ch 13: Attacking Users: Other Techniques (Part 2)
Механизмы предотвращения атак в ASP.NET Core
CNIT 129S: 13: Attacking Users: Other Techniques (Part 2 of 2)
Web 20 Security - Vordel
Top 10 Web Application vulnerabilities
Hacking Web Aplications using Cookie Poisoning
CNIT 129S Ch 7: Attacking Session Management
JWT Authentication with AngularJS
Browser Security 101
S8-Session Managment
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
Evolution Of Web Security
Session management
Secure Coding BSSN Semarang Material.pdf
The Hacker's Guide To Session Hijacking
Confidence web
A privacy-preserving defense mechanism against attacks
Securing Web Applications with Token Authentication

More from magda3695 (13)

PPTX
Prezentacja 20141129
PPTX
PDF
Dlaczego firmy wdrażają er py info_meet kraków
PDF
Systematic architect
PDF
Big data today and tomorrow
PDF
Info meet 8 02-2014
PPTX
Ccpm jako metoda planowania i kontroli projektów
PDF
Info meet pomiary wydajności
PDF
A rnav infomeet
PDF
Dług technologiczny czyli mały wkład w duże problemy
PDF
Akamai in a hyperconnected world
PPS
Antal international prezentacja_targi_it
PDF
Koprowski t certyfikacja_a_kariera_it_infomeet
Prezentacja 20141129
Dlaczego firmy wdrażają er py info_meet kraków
Systematic architect
Big data today and tomorrow
Info meet 8 02-2014
Ccpm jako metoda planowania i kontroli projektów
Info meet pomiary wydajności
A rnav infomeet
Dług technologiczny czyli mały wkład w duże problemy
Akamai in a hyperconnected world
Antal international prezentacja_targi_it
Koprowski t certyfikacja_a_kariera_it_infomeet

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Modernizing your data center with Dell and AMD
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Modernizing your data center with Dell and AMD
Reach Out and Touch Someone: Haptics and Empathic Computing
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

Sea surfing in asp.net mvc

  • 1. SEA-SURFING IN ASP.NET MVC BARTOSZ LENAR
  • 2. THE PLAN BASICS  http requests  authentication  cookies  session SEA-SURFING  unfixable bug  hacking the system  csrf attack  token-based defence SPA  problems  server-side layer  client-side layer
  • 4. HTTP REQUEST  Method  Version  Host  Rest as key-value pairs:  Accept  Cache-control  …  BODY RESPONSE  Status dode  Version  Date  Rest as key-value pairs:  Content-type  Content-length  …  BODY
  • 5. COOKIES  exist in headers as another key-value pair "with parameters"  cookies consist of  name  value  domain & path  expiration date  restrictions (security)
  • 6. COOKIES SCENARIO 2. responds with cookie visited: true 1. sends request to example.org 4. sends request to example.org with visited:true cookie in headers 3. saves visited:true for example.org 5. knows that client visited this page earlier
  • 8. WEB AUTHENTICATION  authentication system  authorize once at the beginning  use the system all the time  but http protocol is stateless!  every request is independent  how to simulate the states?  how to identify request from the specific user?
  • 9. STATES SCENARIO 2. generates über-random identifier 1. sends first request to example.org 5. sends next request to example.org with UserId: QB32SDXC8 cookie in headers 4. saves UserId:QB32S… for example.org 3. sends it back in cookie UserId: QB32SDXC8
  • 10. SESSION  so far: server is able to distinguish users  session: server-side bag for user data  key: previously generated identifier stored in cookie  like QB32SDXC8  value: yet another dictionary  user-specific data like name, address, etc.  security and access data like roles, privileges, etc.  forms
  • 11. HACK THE SYSTEM  do we want to be an authorized user?  no! we want to act like one!  to hack the system = to "steal" someone’s session  maybe "someone” is:  facebook user – we have all his private data, photos, etc.  bank user – we know how much money he has  …  admin – we can do anything
  • 12. SESSION HIJACKING  system/browser backdoor  steal the cookie from memory  xss  sidejacking  main-in-the middle  fixation  send user url with session id: http://example.org/?&sessionId=QB32SDXC8  wait for the user to log in  riding – our topic
  • 13. THE ROADTO SESSION RIDING  we want to download data stored under http://example.org/admin/secret  let’s think:  authentication & authorization is based on session  session is based on cookies  cookies are being sent to example.org with every request  how about we prepare a website that sends request to the specified path?
  • 14. LET’S TRYTO GET THE ADMIN’S SECRET
  • 15. LET’S TRYTO GET THE ADMIN’S SECRET  what actually happened? 1. browser downloads the entire DOM tree 2. img node is being located 3. browser automatically sends GET request to download the image  but… there is no image at the end  nevertheless, browser attached all cookies dedicated to example.org <img src="http://example.org/admin/secret" />
  • 16. LET’S TRYTO DO THE ADMIN’S JOB  GET shouldn’t change anything  http://example.org/admin/delete-user/?&username=admin  you’re doing itWRONG!  let’s mess up with POST / DELETE / PUT …
  • 17. LET’S TRYTO DO THE ADMIN’S JOB
  • 18. BUILDING THE FIREWALL  how browser works:  attacker is able to send cookies with the request …  … but is not able to see them!
  • 19. ANTI-FORGERY TOKEN – HOW IT’S MADE 2. generates über-random identifier: J723SDA 1. sends request to example.org 3. sends it back inside the form and in the cookie AntiForgeryToken= J723SDA <input name="_token" type="hidden" value="J723SDA" />
  • 20. ANTI-FORGERY TOKEN – HOW IT WORKS 1. sends request to example.org containing: • cookie with token: J723SDA • form value with token: J723SDA 2. validates the request: • token in cookie is present? true • token in form is present? true • do they match each other? true all true? it’s valid!
  • 21. ANTI-FORGERY TOKEN – HOW IT SECURES 1. sends request to example.org containing: • cookie with token: J723SDA • form value with token: ?????????? 2. validates the request: • token in cookie is present? true • token in form is present? false • do they match each other? false all true? no! respond with 403 Forbidden
  • 22. DO THE TRICK IN ASP.NET MVC
  • 23. EVEN MORE SECURE  create a keyword based on:  action-specific and user-specific data  application, server, etc.  our keyword: "BARTEK"  hash the keyword: (0BDE667AA88E8832B61BF68C0D4E34A4) and split it:  0BDE667AA88E8832 goes into cookie  B61BF68C0D4E34A4 goes into form  on request, compute the keyword once again and validate the tokens
  • 24. PROBLEMS  strongly relies on browser security  doesn’t work with GET requests  is it a problem in pure, REST service?  to disable cookies = to disable all communication  site vulnerable to XSS = we’re doomed
  • 25. SINGLE PAGE APPS - PROBLEMS  forms are pre-generated  which form is going to be triggered next?
  • 26. API WRAPPER – CLIENT SIDE  write wrapper for all ajax communication (GET, POST, PUT, DELETE)  requestSettings contains method, data, etc. ApiWrapper.prototype._SendRequest = function (requestSettings) { var self = this; requestSettings.headers["Token"] = self.Token; return $.ajax(requestSettings).always(function (arg1, textStatus, arg2) { jqXHR = (textStatus !== "success") ? arg1 : arg2; self.Token = jqXHR.getResponseHeader("Token"); document.cookie = "Token=" + self.TokenId + ";"; }); };
  • 27. API WRAPPER – SERVER SIDE  keep tokens in cache/database  nosql  custom ValidateAntiForgeryTokenAttribute  validates token from cookie and header  updating token if necessary
  • 28. API WRAPPER - USAGE  write wrapper for all ajax communication (GET, POST, PUT, DELETE)  return jqXHR from all functions api.Get('customers/' + customerId) .success(function (data) { self.Customer(data); }); api.Post('customers/' + customerId, editedData) .success(function () { message.ReportSuccess(); });
  • 29. SEA-SURFING IN ASP.NET MVC QUESTIONS-SURFING  Fiddler: http://www.telerik.com/fiddler  Icons: http://www.visualpharm.com/ BARTOSZ LENAR bartoszlenar@gmail.com @bartoszlenar