# [Root Me] (Web - Server) NodeJS - Prototype Pollution Bypass

# NodeJS - Prototype Pollution Bypass

## Hint

```plaintext
isAdmin or not, that is the question
```

## Statement

```plaintext
A new web administrator has set up a site he calls "root me’s social network."
It appears to save all user posts, even if they are private.
Finish admin to find out the truth!
```

Bài này lúc mới vào sẽ bắt nhập 1 cái tên:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525272923/de51ace9-3926-4659-8679-322597166f87.png align="center")

* Actions &gt; My Post: Chức năng cho phép đăng post
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525433898/e89a175a-1125-4af7-a4b4-9a34b3f87cb9.png align="center")

Tạo thử 1 cái post:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525482607/8492373d-3e3a-437f-8834-cd3e44663e52.png align="center")

Tạo thêm cái nữa:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525499243/df3a5bba-e8fa-4774-80f7-99c4f74e9ba1.png align="center")

API của chức năng tạo post `POST /mypost`:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525857490/def1215f-18cc-44a7-9360-b014a42fbafc.png align="center")

Ở trong ảnh này có hint về 1 API nữa:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525433898/e89a175a-1125-4af7-a4b4-9a34b3f87cb9.png align="left")

`GET /createdPosts` là API để xem các post.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525807058/d074cc39-5c12-4268-9400-785fd0f82691.png align="center")

* Actions &gt; My Post: Chức năng cho phép chuyển trạng thái post từ **private** qua **public** và ngược lại.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682525374451/48477a57-90d7-4366-9aa8-634e72cc598d.png align="center")

`POST /profile` là API của chức năng này.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682526148777/c33a6ca0-4754-4cb2-8578-7fe55145d963.png align="center")

Mục tiêu là vào được chức năng Admin:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682528687779/e22eb0bf-c79f-492a-aab3-60bad422e718.png align="center")

Dựa theo hint thì mình đoán ở server đang sử dụng 1 đoạn check:

```javascript
var user = {};  
if (user.isAdmin = true) {  
//gửi flag  
}
```

Qua các dữ liệu trên thì mình đoán ở dưới server đang xử lý như sau:

```javascript
var full_post = {}; //đây là object gọi ra được từ API /createdPosts
var visibility = req.session.visibility; //lấy từ giá trị của trường visibility từ cookie
var post_title = req.body.title; // gửi từ param title của API /mypost
var post_content = req.body.post; // gửi từ param post của API /mypost

// Đây là đoạn để kiểm soát trạng thái của post là public hay private
if ((visibility = "public")) {
  full_post.visibility.post_title =  post_content;
}
```

Ở đây mình thấy có thể pollute object `full_post` như sau:

```javascript
full_post[__proto__][isAdmin] = true
```

Đây là các step mình làm:

* Bước 1: Vào **Proxy** bật **Intercept** lên
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682527423425/9e8a8824-01aa-4d4b-bb10-6a42b19ca12f.png align="center")

* Bước 2: Vào `POST /mypost` và đổi `visibility=__proto__`, `title="isAdmin"`, `post=true`. Nhớ để đúng data type, bản thân mình lúc đầu suy nghĩ theo cách này nhưng vì để data type của `post="true"` (tức là kiểu string) nên ko làm ra được. Và vì cái ko làm ra được mà mình loay hoay 2 tuần nghĩ thêm 7749 cách khác, nhưng hóa ra mọi thứ về đúng với cái ý tưởng đầu tiên mình làm.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682527688186/87d18934-3d72-4970-979c-50e322c10386.png align="center")
    
* Bước 3: Sau khi làm xong bước 2, lúc này `full_post[__proto__][isAdmin] = true` nghĩa là mọi object kế thừa thuộc tính `isAdmin` sẽ đều là `true` . Vậy thì `user[isAdmin]=true` (ta bypass được đoạn check vừa nãy). Giờ thì **forward** cái request vừa xong.
    
* Bước 4: Lên trình duyệt rồi vào giao diện cho admin, đây là API được gọi khi vào giao diện cho admin
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682528366054/9a25e284-ea53-449c-bae8-2bf3824a805d.png align="center")
    
    > Flag: `__pr0t0__.b3_C4r3ful_w1th_Pr0t0typ3`
