19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13 n Attacking Users: O<strong>the</strong>r Techniques 507<br />

significant as one specifically designed for administrators to execute arbitrary<br />

SQL queries. If a query can be injected that performs some sensitive action,<br />

or that retrieves data via some out-of-band channel, this attack can be performed<br />

by nonadministrative users via CSRF.<br />

Au<strong>the</strong>ntication and CSRF<br />

Since CSRF attacks involve performing some privileged action within <strong>the</strong> context<br />

of <strong>the</strong> victim user’s session, <strong>the</strong>y normally require <strong>the</strong> user to be logged in to<br />

<strong>the</strong> <strong>application</strong> at <strong>the</strong> time of <strong>the</strong> attack.<br />

One location where numerous dangerous CSRF vulnerabilities have arisen<br />

is in <strong>the</strong> <strong>web</strong> interfaces used by home DSL routers. These devices often contain<br />

sensitive functions, such as <strong>the</strong> ability to open all ports on <strong>the</strong> Internet-facing<br />

firewall. Since <strong>the</strong>se functions are often not protected against CSRF, and since<br />

most users do not modify <strong>the</strong> device’s default internal IP address, <strong>the</strong>y are<br />

vulnerable to CSRF attacks delivered by malicious external sites. However, <strong>the</strong><br />

devices concerned often require au<strong>the</strong>ntication to make sensitive changes, and<br />

most users generally are not logged in to <strong>the</strong>ir device.<br />

If <strong>the</strong> device’s <strong>web</strong> interface uses forms-based au<strong>the</strong>ntication, it is often possible<br />

to perform a two-stage attack by first logging <strong>the</strong> user in to <strong>the</strong> device and <strong>the</strong>n<br />

performing <strong>the</strong> au<strong>the</strong>nticated action. Since most users do not modify <strong>the</strong> default<br />

credentials for devices of this kind (perhaps on <strong>the</strong> assumption that <strong>the</strong> <strong>web</strong><br />

interface can be accessed only from <strong>the</strong> internal home network), <strong>the</strong> attacker’s<br />

<strong>web</strong> page can first issue a login request containing default credentials. The device<br />

<strong>the</strong>n sets a session token in <strong>the</strong> user’s browser, which is sent automatically in<br />

any subsequent requests, including those generated by <strong>the</strong> attacker.<br />

In o<strong>the</strong>r situations, an attacker may require that <strong>the</strong> victim user be logged<br />

in to <strong>the</strong> <strong>application</strong> under <strong>the</strong> attacker’s own user context to deliver a specific<br />

attack. For example, consider an <strong>application</strong> that allows users to upload and store<br />

files. These files can be downloaded later, but only by <strong>the</strong> user who uploaded<br />

<strong>the</strong>m. Suppose that <strong>the</strong> function can be used to perform stored XSS attacks,<br />

because no filtering of file contents occurs (see Chapter 12). This vulnerability<br />

might appear to be harmless, on <strong>the</strong> basis that an attacker could only use it to<br />

attack himself. However, using CSRF techniques, an attacker can in fact exploit<br />

<strong>the</strong> stored XSS vulnerability to compromise o<strong>the</strong>r users. As already described,<br />

<strong>the</strong> attacker’s <strong>web</strong> page can make a CSRF request to force a victim user to log<br />

in using <strong>the</strong> attacker’s credentials. The attacker’s page can <strong>the</strong>n make a CSRF<br />

request to download a malicious file. When <strong>the</strong> user’s browser processes this file,<br />

<strong>the</strong> attacker’s XSS payload executes, and <strong>the</strong> user’s session with <strong>the</strong> vulnerable<br />

<strong>application</strong> is compromised. Although <strong>the</strong> victim is currently logged in using

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!