- 이 글은 아직 현업을 경험하지 못한 보안 공부생의 정리 글이니, 정확하지 않을 수도 있습니다.-
Prototype Pollution이란?
Javascript는 객체 지향 언어이다. python, java는 class 라는 개념으로 상속을 구현하지만, javascript는 prototype을 이용하여 상속을 구현한다. (물론 class도 사용하지만, 본질은 prototype이긴 함)
모든 객체는 최상위 객체를 원형(prototype)으로 삼고 이를 참조하는 방식으로 상속과 비슷하게 구현되는 것.
쉽게 말해 어떤 객체의 프로퍼티를 찾을 때, 자바스크립트는
1. 해당 객체 확인
2. __proto__로 연결된 부모 객체 확인
3. 계속 거슬러 올라가다가 마지막에 전역 객체인 Object.prototype까지 확인
4. 없으면 undefined
이런 식으로 계속 부모 객체로 거슬러 올라가면서 프로퍼티를 찾는다. 이 과정을 prototype chain이라고 부르고.
Prototype Pollution은 이러한 prototype을 공격자가 임의로 수정하여 원하는 동작을 유발시키는 공격 방식이다. XSS에서 심하면 RCE까지도 가능하다.
let a = {};
a['__proto__']['hello'] = 'bello';
console.log(a.hello); // 'bello'
let b = {};
console.log(b.hello); // 'bello'
console.log(b['__proto__']); // [Object: null prototype] { hello: 'bello' }
console.log(Object.prototype['hello']); // bello
console.log(Object.constructor.prototype['hello']); // bello
console.log(Object.__proto__['hello']); // bello
이처럼 하나의 객체의 prototype을 수정하면 전역 객체인 Object까지 영향을 미치는 것을 확인할 수 있다.
병합, 복제 등의 코드가 입력값이나 외부 데이터를 안전하게 검증하지 않을 때 사용자 조작으로 일어날 수 있는데,
portswigger에 예시 문제를 하나 뜯어보며 알아보자.
Lab: DOM XSS via client-side prototype pollution | Web Security Academy
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 ...
portswigger.net
해당 문제는 prototype pollution을 연계하여 XSS 공격을 유발하게 되어 있다.
/resources/js/deparam.js
/resources/js/searchLogger.js
프론트엔드 코드를 뜯어보면 이 두 라이브러리를 가져와서 사용하는 것을 볼 수 있다.
deparam의 경우 파라미터의 병합을, searchLogger에서는 스크립트의 동적 삽입을 담당한다.
특히 transport_url 라는 속성을 가져와 script.src에 넣어 동적 삽입하기 때문에 해당 속성을 오염 타겟으로 삼아
/?__proto__[transport_url]=data:,alert(1);
// {__proto__ : "data:,alert(1);"} //
이렇게 data: scheme을 사용하여 XSS를 유도할 수 있다.
서버 측의 경우..는 클라이언트 측보다 발생하기 어렵다.
애초에 블랙박스 방식으로는 거의 못찾을 것 같고, 찾는다고 해도 결국 시스템의 환경변수나 전역 객체를 건드려야 하기 때문에
시스템 자체가 다운될 수도 있으니까.
관련해서 자세한 글이 있으니 읽어보면 크게 도움될 것 같다.
https://portswigger.net/research/server-side-prototype-pollution
Server-side prototype pollution: Black-box detection without the DoS
Server-side prototype pollution is hard to detect black-box without causing a DoS. In this post, we introduce a range of safe detection techniques, which we've also implemented in an open source Burp
portswigger.net
Reference
https://www.hahwul.com/cullinan/attack/prototype-pollution/
https://www.igloo.co.kr/security-information/prototype-pollution-
'Study' 카테고리의 다른 글
| JWT (Json web token) (0) | 2025.08.20 |
|---|---|
| Web cache deception (0) | 2025.07.19 |
| pugjs 취약점 (0) | 2025.06.26 |
| Unicode case mapping collision (0) | 2025.06.26 |
| CSP (1) | 2025.06.24 |