Scanning for XSS flaws

Kali Linux has various tools that can be used to automate the testing of the XSS flaws. The more tedious but accurate method is by using the manual testing method, where you intercept the HTTP request using a proxy, manipulate each field, and replace it with your payload.

Applications are becoming more complex every day, with an increasing number of user editable fields that make manual testing very difficult as a vulnerable parameter may be overlooked by the tester. Manual testing is useful when you want to extensively test a specific parameter. From an attacker's point of view, automating the task of identifying vulnerable parameters could reduce the time of developing the final exploit. Kali Linux has several tools to automate the scanning of XSS flaws and we will discuss them in this section:

Zed Attack Proxy (ZAP) is an open source web application penetration testing tool maintained by OWASP. It's a fork of the Paros proxy. The version that comes with Kali Linux 2.0 is 2.4.1. The main features of ZAP are as follows:

ZAP works by default as a passive proxy; it won't actively intercept traffic unless you set a breakpoint on the URL for which you want to intercept the request and response. ZAP is located at Applications | Web Application Analysis

Our aim behind using ZAP is to identify XSS flaws in a web application. Similar to any other proxy, you need to first configure the web browser to tunnel the traffic through it. You could configure the browser manually or install a proxy add-on tool called FoxyProxy for Firefox, which requires an initial configuration. Once the add-on is configured, you only need to select the proxy settings from a drop-down menu, as shown in the following screenshot:

Zed Attack Proxy

ZAP is a versatile web application penetration testing tool. In the sites window, on the top-left corner, all the websites you visit are recorded. When you surf the website, a passive scan is performed by ZAP in the background and it tries to identify vulnerabilities by spidering the website.

It checks the HTTP request and response, and determines if there is a possibility of a flaw. Detected vulnerabilities are displayed in the Alerts tab in the bottom window. As shown in the following image, it found cookies that were set without the HTTPOnly flag:

Zed Attack Proxy

ZAP can be used to test for all the major vulnerabilities, but we would be using it specifically to test an application for XSS. In order to do this, we would have to define a scan policy to configure the XSS rules as part of the active scan.

At the top, you would see a menu named Analyse and select the Scan Policy under it. This will open the configuration window. For every test name, you would find a Threshold and Strength option:

Scan policy and attack

The following explains these options in detail

To configure the policy for XSS, give the policy a name and disable all the test on the left-hand side, except the cross-site scripting (persistent) and cross-site scripting (reflected) under injection. Click on Save Policy if you want to reuse it later. Then, right-click on the target URL and go to Attack | Active scan all in scope.

ZAP will then run the magic and will notify any XSS vulnerability (if identified) under the Alerts tab in the bottom window. If you select the alert, ZAP will display the exact HTTP request sent across to the server that triggered the flaw. As shown in the following screenshot, a script was injected in the author parameter:

Scan policy and attack

Cross-site scripter (Xsser) is a tool to automate the detection and exploitation of XSS vulnerabilities. The version that comes with Kali Linux is 1.6 (beta). Xsser also consist several options to circumvent the input validation filters implemented by the developer.

Some of the important features of Xsser are listed here:

The graphical user interface (GUI) of xsser can be started directly from the shell with the –gtk option. The GUI also includes a wizard for new users that asks for a few questions and creates a template. Once you have selected the various options as per your testing needs, click on Aim and let the tool do the rest:

Features

The more experienced hackers would be comfortable with the command-line interface. Run xsser –help to view the different option the tool supports. The important command line options are shown in the following table:

Option

Use

-u

This is used specify a target URL

-g

This is used to inject script in the GET parameter specified

-p

This is used to inject script in the POST parameter specified

--heuristic

This tries to identify which characters are filtered by the application

--cookie

This sets a cookie to the HTTP request

-s –v

These options will display statistical information and verbose output.

Xsser is an advance tool and includes many other options besides the ones listed in the table, but these should be good to get you started with the tool.

In the following example, we will test the vulnerable web application for a cross-site scripting flaw. The application requires authentication, and once authenticated, it sets a cookie to identify the user on further interactions. The cookie is passed in the request using the –cookie option. The parameter to be tested is passed using the –g option, as it is in the GET method:

The various default options set by xsser are also shown in the output, since we selected the Version option. Xsser then injects the parameter and tries to indentify whether it is vulnerable to XSS as shown in the following screenshot:

Features

Another interesting tool in Kali Linux is the web application audit and attack framework tool that is abbreviated as w3af. It is called a framework because it is very feature rich. It is a menu-driven tool; it includes time-saving and useful features such as the autocomplete functionality similar to Metasploit and is packed with various plugins.

The web application payload feature of w3af is the one that needs special mention. Exploiting a web application flaw and gaining access to the target machine by uploading a payload has always been a difficult task. W3af includes plugins that make the exploitation phase easier and also integrate with Metasploit, which allows it to upload a Metasploit payload on the target machine and use it for post exploitation.

Plugins in w3af are divided into several categories, and the major ones are listed as follows:

The w3af tool is located at Applications | Web Application Analysis. Alternately, you can start the command-line tool by typing w3af_console in the shell prompt. When the prompt returns, type in help to check out the commands available:

Plugins

To find all the different categories of plugins, type in plugins and then help. To explore the various plugins available under each category, type in the plugin category, for example, audit, as shown in the following screenshot:

Plugins

To configure each plugin for use, type in the category name and the first few characters of the plugin you are interested in and press the Tab key.