Slide 1

Slide 1 text

A tale of making internet pollution free Finding & Exploiting Client-Side Prototype Pollution in the Wild

Slide 2

Slide 2 text

Mohan SRK P ● I like browsers, electron and CTFs ● @s1r1u5_ ● Web and shit posting ● @rootxharsh Harsh Jaiswal

Slide 3

Slide 3 text

Agenda ● Javascript Prototype ● Prototype Pollution ● Methodology To Find & Exploit Prototype Pollution at Scale ● Case Studies & Results ● Ways To Mitigate Prototype Pollution ● Conclusion

Slide 4

Slide 4 text

Javascript Prototype

Slide 5

Slide 5 text

Javascript Prototype ● Javascript is an prototype based language ● Objects inherits properties and methods via prototype object. ● Object based inheritance is cool, but it has a security hole.

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Prototype Pollution

Slide 9

Slide 9 text

Prototype Pollution ● Properties in Object.prototype are available to all the objects created in the application through prototype chain. ● If Object.prototype is tampered by the malicious user somehow then all the objects in the applications will have access to the tampered property.

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Passed query parameters → ?user=harsh
 
 Resulting query object → {“user”: “harsh”}
 


Slide 12

Slide 12 text

Passed query parameters → ?user[id]=1
 
 Resulting query object → {“user”: {“id”:1}}
 


Slide 13

Slide 13 text

Passed query parameters → ?user[id]=1&__proto__[foo]=bar
 
 Resulting query object → {“user”: {“id”:1}}
 
 Where did __proto__ go?


Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Methodology To Find & Exploit Prototype Pollution at Scale

Slide 16

Slide 16 text

Methodology

Slide 17

Slide 17 text

Detection Selenium script/Nuclei Template - Initially, used this to find sites which has vulnerable location parsing either via query value or hash value in the URL. - Advantage: - Scalable - Disadvantage: - Only finds vulnerable location parsing - We can’t scan Authenticated Pages

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Detection Chrome Extension - To scan authenticated pages manually, we wrote an extension. - Advantage: Can scan Authenticated Pages. - Disadvantage: - Only finds vulnerable location parsing. - Not Scalable.

Slide 20

Slide 20 text

Detection Static Analysis Tool - To find all code components which leads to pollution we need to do static analysis. - Used CodeQL. - Advantage: Can find all sources and sinks which leads to prototype pollution. - Disadvantage: Not scalable.

Slide 21

Slide 21 text

Script Gadgets What is Script Gadget? A script gadget is a piece of code in the application which can be triggered via prototype pollution and can be used to upgrade prototype pollution to XSS.

Slide 22

Slide 22 text

Script Gadgets What is Script Gadget? A script gadget is a piece of code in the application which can be triggered via prototype pollution and can be used to upgrade prototype pollution to XSS. - Hard and Interesting part after detection. - Need to find the gadget most of the time. - If you are lucky, pollute.js and untrusted-types can quickly find one. - Idea: I think it can be automated with CodeQL

Slide 23

Slide 23 text

Identification of Lib

Slide 24

Slide 24 text

Scanning from DB

Slide 25

Slide 25 text

Case Study: Bug found using CodeQL ● Downloaded JS on top pages of Google, FB, and some private programs. ● Created a database with CodeQL. codeql database create --language=javascript --source-root database vulnerable_db / ● Run the Query on DB codeql query run --database=./vulnerable_db ../pp-automation/learn.ql

Slide 26

Slide 26 text

Case Study: Bug found using CodeQL

Slide 27

Slide 27 text

Case Study: Apple XSS using Chrome extension Rahul’s https://github.com/msrkp/PPScan

Slide 28

Slide 28 text

Case Study: Pollution found using python selenium bot. https://blog.swiftype.com/#__proto__[asdf]=alert(document.domain)

Slide 29

Slide 29 text

Results

Slide 30

Slide 30 text

Results ● Number of vulnerable libraries found: 18 ● Number of bugs reported to vulnerability disclosure programs: ~80 ● Total Bounties earned by ~10 people: ~ 40k

Slide 31

Slide 31 text

Mitigations

Slide 32

Slide 32 text

Mitigations ● Remove the vulnerable code ● Object.prototype freezing, Object sealing, or Object.create(null) is not enough ○ For how not to fix you should definitely check BlackFan’s talk and pugpug challenge in Bsides Ahmedabad CTF.

Slide 33

Slide 33 text

Conclusion

Slide 34

Slide 34 text

Conclusion ● New attack surface ● Feature proposal: Mitigation for Client-Side Prototype Pollution · Issue #33 · WICG/document-policy · GitHub

Slide 35

Slide 35 text

Research Team • Sergey Bobrov @Black2Fan • Mohan SRK P @S1r1u5_ • terjanq @terjanq • Beomjin Lee @po6ix • Masato Kinugawa @kinugawamasato • Rahul Maini @iamnoooob • Harsh Jaiswal @rootxharsh • Mikhail Egorov @0ang3el • Nikita Stupin @_nikitastupin

Slide 36

Slide 36 text

Thanks to other researchers • @_holyvier_ • @SecurityMB • @wcbowling • @corb3nik

Slide 37

Slide 37 text

Thanks

Slide 38

Slide 38 text

Questions?