---
# System prepended metadata

title: 'WEB18: Prototype pollution'
tags: [portswigger]

---

# WEB18: Prototype pollution

## Lab: DOM XSS via client-side prototype pollution

```!
This lab is vulnerable to DOM XSS via client-side prototype pollution. To solve the lab:

Find a source that you can use to add arbitrary properties to the global Object.prototype.

Identify a gadget property that allows you to execute arbitrary JavaScript.

Combine these to call alert().

You can solve this lab manually in your browser, or use DOM Invader to help you.
```

Dùng Dom Invader ta tìm được các sources là 

![](https://i.imgur.com/JFTBmx0.png)

Tiếp theo sử dụng Scan for gadgets, ta được dẫn đến hàm searchLogger.js

![](https://i.imgur.com/k0KiagY.png)

ở đây với bug pp trước đó, ta có thể control được thuộc tính src của tag script

vậy final payload: `?__proto__[transport_url]=data:,alert(1);`

![](https://i.imgur.com/4ERNHyt.png)

solve

![](https://i.imgur.com/nBSeGar.png)

## Lab: DOM XSS via an alternative prototype pollution vector

```!
his lab is vulnerable to DOM XSS via client-side prototype pollution. To solve the lab:

Find a source that you can use to add arbitrary properties to the global Object.prototype.

Identify a gadget property that allows you to execute arbitrary JavaScript.

Combine these to call alert().

You can solve this lab manually in your browser, or use DOM Invader to help you.
```

Vẫn sử dụng DOM Invader, ta tìm được pp vector khác

![](https://i.imgur.com/s8mX4FK.png)

Và 1 sink khác

![](https://i.imgur.com/gIjXuzB.png)

Cụ thể là tại hàm này

![](https://i.imgur.com/FM1ZGTv.png)

Final payload: `?__proto__.sequence=);alert(1)}//`

![](https://i.imgur.com/TYiRYBJ.png)

Solve

![](https://i.imgur.com/UU37sx8.png)

## Lab: Client-side prototype pollution via flawed sanitization

```!
This lab is vulnerable to DOM XSS via client-side prototype pollution. Although the developers have implemented measures to prevent prototype pollution, these can be easily bypassed.

To solve the lab:

Find a source that you can use to add arbitrary properties to the global Object.prototype.

Identify a gadget property that allows you to execute arbitrary JavaScript.

Combine these to call alert().
```

Có thể thấy lần này trang web đã có biện pháp sanitize bằng cách replace đi chuỗi `constructor`, `__proto__` và `prototype`
![](https://i.imgur.com/JTvC7xj.png)

Tuy nhiên ta vẫn có thể bypass như sau:

![](https://i.imgur.com/GnMEoAC.png)

Sink ở hàm `searchLogger` trong file `searchLoggerFiltered.js`

![](https://i.imgur.com/Ot9xM3K.png)

Final payload

![](https://i.imgur.com/cGxg6j6.png)

Solve

![](https://i.imgur.com/UF54Y8W.png)

## Lab: Client-side prototype pollution in third-party libraries

```!
This lab is vulnerable to DOM XSS via client-side prototype pollution. This is due to a gadget in a third-party library, which is easy to miss due to the minified source code. Although it's technically possible to solve this lab manually, we recommend using DOM Invader as this will save you a considerable amount of time and effort.

To solve the lab:

Use DOM Invader to identify a prototype pollution and a gadget for DOM XSS.

Use the provided exploit server to deliver a payload to the victim that calls alert(document.cookie) in their browser.

This lab is based on real-world vulnerabilities discovered by PortSwigger Research. For more details, check out Widespread prototype pollution gadgets by Gareth Heyes.
```

DOM Invader tìm được 2 source như sau

![](https://i.imgur.com/rsCBHbE.png)

Và sink tương ứng là hàm setTimeout, cần pollute hitCallback:

![](https://i.imgur.com/dgWZl9C.png)

Ta thử test với alert(1)

![](https://i.imgur.com/vs78jIz.png)

Setup exploit server

![](https://i.imgur.com/y8VAOVZ.png)

Solve bài lab

![](https://i.imgur.com/otPmuqn.png)

## Lab: Client-side prototype pollution via browser APIs

```!
This lab is vulnerable to DOM XSS via client-side prototype pollution. The website's developers have noticed a potential gadget and attempted to patch it. However, you can bypass the measures they've taken.

To solve the lab:

Find a source that you can use to add arbitrary properties to the global Object.prototype.

Identify a gadget property that allows you to execute arbitrary JavaScript.

Combine these to call alert().

You can solve this lab manually in your browser, or use DOM Invader to help you.

This lab is based on real-world vulnerabilities discovered by PortSwigger Research. For more details, check out Widespread prototype pollution gadgets by Gareth Heyes.
```

Bài lab này thì source vẫn tương tự như cũ `?__proto__[key]=value`, tuy nhiên điểm khác đó là ở sink có thêm hàm defineProperty() nhưng lại không chỉ định property `value` trong tham số truyền vào (`descriptor`) vì vậy ta có thể pollute thuộc tính này để giá trị của `tranport_url` là payload xss

![](https://i.imgur.com/BjLqoWs.png)


![](https://i.imgur.com/Y5qc3Tp.png)

Solve

![](https://i.imgur.com/OlPZTFS.png)

## Lab: Privilege escalation via server-side prototype pollution

```!
This lab is built on Node.js and the Express framework. It is vulnerable to server-side prototype pollution because it unsafely merges user-controllable input into a server-side JavaScript object. This is simple to detect because any polluted properties inherited via the prototype chain are visible in an HTTP response.

To solve the lab:

- Find a prototype pollution source that you can use to add arbitrary properties to the global Object.prototype.
- Identify a gadget property that you can use to escalate your privileges.
- Access the admin panel and delete the user carlos.
You can log in to your own account with the following credentials: wiener:peter
```

Sau khi login với account cung cấp, ta thấy có chức năng change-address

![](https://i.imgur.com/tTYmqZc.png)

Request tương ứng với nó như sau

![](https://i.imgur.com/JZBaZZO.png)


Vậy thử PP ngay chỗ này

![](https://i.imgur.com/ytnjrF1.png)

-> thành công thay đổi property isAdmin thành true

Delete user carlos và solve bài lab

![](https://i.imgur.com/gZE7N90.png)

## Lab: Detecting server-side prototype pollution without polluted property reflection

```!
This lab is built on Node.js and the Express framework. It is vulnerable to server-side prototype pollution because it unsafely merges user-controllable input into a server-side JavaScript object.

To solve the lab, confirm the vulnerability by polluting Object.prototype in a way that triggers a noticeable but non-destructive change in the server's behavior. As this lab is designed to help you practice non-destructive detection techniques, you don't need to progress to exploitation.

You can log in to your own account with the following credentials: wiener:peter
```

Vẫn tính năng cũ, vẫn request cũ ta tiến hành detect pp

![](https://i.imgur.com/13r3yLp.png)

**Dùng Status code**

![](https://i.imgur.com/ot8qiWM.png)

![](https://i.imgur.com/HGYap1J.png)

![](https://i.imgur.com/Tg3QTQA.png)

**Dùng json spaces**

![](https://i.imgur.com/tQrlCVO.png)

![](https://i.imgur.com/jd0yoci.png)

**Dùng Charset override**

![](https://i.imgur.com/TVRLEl6.png)

![](https://i.imgur.com/l1cOlkv.png)

Solve 

![](https://i.imgur.com/fqQOS4r.png)

## Lab: Bypassing flawed input filters for server-side prototype pollution

```!
This lab is built on Node.js and the Express framework. It is vulnerable to server-side prototype pollution because it unsafely merges user-controllable input into a server-side JavaScript object.

To solve the lab:

- Find a prototype pollution source that you can use to add arbitrary properties to the global Object.prototype.
- Identify a gadget property that you can use to escalate your privileges.
- Access the admin panel and delete the user carlos.
You can log in to your own account with the following credentials: wiener:peter
```

Về request bị PP thì vẫn tương tự như các lab trước, thử pollute bình thường

![](https://i.imgur.com/i72urTT.png)
-> Không thành công, có thể bên phía server đã sanitize hoặc chặn cơ chế `__proto__`

Thử với `__pro__proto__to__`, vẫn không thành công

![](https://i.imgur.com/AvhkApG.png)

Cuối cùng, áp dụng PP thông qua constructor.prototype

![](https://i.imgur.com/MzgVstW.png)

Solve bài lab

![](https://i.imgur.com/IYLoUxC.png)

## Lab: Remote code execution via server-side prototype pollution

```!
This lab is built on Node.js and the Express framework. It is vulnerable to server-side prototype pollution because it unsafely merges user-controllable input into a server-side JavaScript object.

Due to the configuration of the server, it's possible to pollute Object.prototype in such a way that you can inject arbitrary system commands that are subsequently executed on the server.

To solve the lab:

Find a prototype pollution source that you can use to add arbitrary properties to the global Object.prototype.
Identify a gadget that you can use to inject and execute arbitrary system commands.
Trigger remote execution of a command that deletes the file /home/carlos/morale.txt.
In this lab, you already have escalated privileges, giving you access to admin functionality. You can log in to your own account with the following credentials: wiener:peter
```

Vẫn tính năng update address như cũ

![](https://i.imgur.com/oGozPbU.png)

Khác ở lab này đó là mặc định ta đã là admin và có quyền chạy các jobs

![](https://i.imgur.com/WSfMoRI.png)

![](https://i.imgur.com/7qcwIeF.png)

Ta đoán rằng tính năng này chạy hàm child_process.fork(), vì thế thử pollute options object của nó (object `execArgv`)

![](https://i.imgur.com/JJ9zPbz.png)

Sau đó chọn lại "Run maintenance jobs", kết quả


![](https://i.imgur.com/ErWwfQN.png)


## Lab: Exfiltrating sensitive data via server-side prototype pollution

```!
This lab is built on Node.js and the Express framework. It is vulnerable to server-side prototype pollution because it unsafely merges user-controllable input into a server-side JavaScript object.

Due to the configuration of the server, it's possible to pollute Object.prototype in such a way that you can inject arbitrary system commands that are subsequently executed on the server.

To solve the lab:

- Find a prototype pollution source that you can use to add arbitrary properties to the global Object.prototype.
- Identify a gadget that you can use to inject and execute arbitrary system commands.
- Trigger remote execution of a command that leaks the contents of Carlos's home directory (/home/carlos) to the public Burp Collaborator server.
- Exfiltrate the contents of a secret file in this directory to the public Burp Collaborator server.
- Submit the secret you obtain from the file using the button provided in the lab banner.
In this lab, you already have escalated privileges, giving you access to admin functionality. You can log in to your own account with the following credentials: wiener:peter
```

Dựa theo lí thuyết, ta đoán server sử dụng child_process.execSync(). Khai thác PP2RCE như sau

![](https://i.imgur.com/DCBPsU9.png)


![](https://i.imgur.com/HWfVLRH.png)

Chỉnh lại payload thành

![](https://i.imgur.com/CcrKK4D.png)

Và secret 

![](https://i.imgur.com/0mjyWg8.png)

Solve

![](https://i.imgur.com/7eJbWv4.png)


###### tags: `portswigger`