What is xss vulnerability. Using XSS vulnerabilities to the maximum. Examples of XSS vulnerabilities

Cross-site scripting (XSS) is a vulnerability that involves the injection of client-side code (JavaScript) into a web page that other users are viewing.

The vulnerability arises from insufficient filtering of data that a user submits for insertion into a web page. It is much easier to understand with a specific example. Think of any guestbook - these are programs that are designed to accept data from the user and then display it. Let's imagine that the guestbook does not check or filter the input data in any way, but simply displays it.

You can sketch your simplest script (there is nothing easier than writing bad scripts in PHP - a lot of people do this). But there are already plenty of ready-made options. For example, I suggest getting started with Dojo and the OWASP Mutillidae II. There is a similar example there. In standalone Dojo, go to your browser at: http: //localhost/mutillidae/index.php? Page = add-to-your-blog.php

If one of the users entered:

Then the web page will display:

Hey! I like your site.

And if the user enters like this:

Hey! I like your site.

Then it will be displayed like this:

Browsers store many cookies on a large number of sites. Each site can only receive cookies saved by itself. For example, example.com has stored some cookies in your browser. If you visit another.com site, this site (client and server scripts) cannot access the cookies stored by example.com.

If the site example.com is vulnerable to XSS, then this means that we can in one way or another inject JavaScript code into it, and this code will be executed on behalf of the site example.com! Those. this code will, for example, gain access to the cookies of the site example.com.

I think everyone remembers that JavaScript is executed in the user's browsers, i.e. in the presence of XSS, the injected malicious code gains access to the data of the user who opened the website page.

The injected code can do everything that JavaScript can, namely:

  • accesses the cookies of the site you are viewing
  • can make any changes to the appearance of the page
  • accesses the clipboard
  • can inject JavaScript programs, for example, key loggers (interceptors of pressed keys)
  • hook on BeEF
  • and etc.

Simplest cookie example:

Actually, alert used only for XSS detection. The real malicious payload performs covert actions. It secretly communicates with the attacker's remote server and transfers the stolen data to it.

XSS views

The most important thing to understand about the types of XSS is that they are:

  • Stored (Persistent)
  • Reflected (Impermanent)

An example of constants:

  • A specially crafted guestbook message (comment, forum message, profile) entered by an attacker and saved on the server is downloaded from the server every time users request to display this page.
  • An attacker gained access to server data, for example, through SQL injection, and injected malicious JavaScript code (with keyloggers or with BeEF) into the data displayed to the user.

An example of volatile:

  • There is a search on the site, which, along with the search results, shows something like "You searched for: [search string]", while the data is not filtered properly. Since such a page is displayed only for those who have a link to it, the attack will not work until the attacker sends the link to other users of the site. Instead of sending a link to the victim, you can use the placement of a malicious script on a neutral site visited by the victim.

They also distinguish (some as a kind of volatile XSS vulnerabilities, some say that this kind can also be a kind of persistent XSS):

  • DOM models

Features of DOM-based XSS

To put it quite simply, we can see the malicious code of "regular" volatile XSS if we open the HTML code. For example, a link is formed like this:

Http://example.com/search.php?q= "/>

And when we open the source HTML code, we see something like this: