I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

49
Copyright 2007 © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation OWASP http://www.owasp.org I'm in ur browser, pwning your stuff Attacking (with) Google Chrome extensions Krzysztof Kotowicz SecuRing [email protected]

description

My OWASP AppSec Europe 2013 talk.

Transcript of I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

Page 1: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

Copyright 2007 © The OWASP FoundationPermission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation

OWASP

http://www.owasp.org

I'm in ur browser, pwning your stuff

Attacking (with) Google Chrome extensions

Krzysztof [email protected]

Page 2: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

About me

Security researchclient side securityHTML5UI redressingChrome extensionsBlack Hat USA, BruCON, Hack in Paris, CONFidence, ...

IT security consultant @ SecuRingweb app, mobile pentestssecurity code reviews

2

Page 3: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Plan

3

Chrome Extensions architectureExploiting legacy (v1) extensionsManifest v2 fixesExploiting v2 extensions

"Break The Batman Part 3" by Eric Merced / Eric Merced aka stickfiguredancer

Page 4: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Chrome Extensions

Not plugins (Java, Flash, ...) HTML5 applications

html, javascript, cssInstalled from Chrome Web Store Access to privileged API

chrome.tabs chrome.bookmarks chrome.history chrome.cookies

4

Page 5: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Chrome Extensions - components

UI pages background page option pages extension UI

Content scripts run alongside website interaction with

websites

5

Page 6: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 6Diagram by Wade Alcorn. Thanks!

Page 7: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Chrome Extensions - manifest

Manifest lists permissions, UI pages, content scripts

7

{ "manifest_version": 2, "name": "Sample Extension", "content_scripts": [ { "matches": ["http://www.google.com/*"], "js": ["jquery.js", "myscript.js"] } ], "background": { "page": "background.html" }, "permissions": [ "tabs", "bookmarks", "cookies" "http://*/*", "https://*/*", ]}

Page 8: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Chrome Extensions - restrictions

8

scheme websites chrome API

UI page

content script

chrome-extension:// -

✔ limited by

permissions

http://✔

limited by URL-

Page 9: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Isolated worlds

9

DOM

content scriptJS

websiteJS

Page 10: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Exploiting v1 extensions

10

Page 11: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

UI page DOM XSS

content-script takes data off website DOM sends it to UI page view fails to escape data upon viewing it

cross-zone DOM XSS

11

Page 12: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 12

Page 13: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 12

Page 14: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 12

Page 15: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

UI page DOM XSS

Consequences XSS in chrome-extension:// access to chrome.* API

13

Slick RSS: feed finder 1.3

document.getElementById("heading").innerHTML = "Subscribed to '<strong>" + title + "</strong>'";

Page 16: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

UI page DOM XSS

Consequences XSS in chrome-extension:// access to chrome.* API

13

<link rel="alternate" type="application/rss+xml" title="hello <img src=x onerror='payload'>"href="/rss.rss">

Slick RSS: feed finder 1.3

document.getElementById("heading").innerHTML = "Subscribed to '<strong>" + title + "</strong>'";

Page 17: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Exploiting UI page XSS

Chrome Extension Exploitation Framework BEEF for Chrome extensions

14

https://github.com/koto/xsschef

Page 18: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

XSS ChEF

15

Page 19: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

XSS ChEF

16

Page 20: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

XSS ChEF

17

Page 21: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

XSS ChEF

18

Page 22: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Chrome extensions v1 summary

UI page XSS is very common note taking developer toolsRSS readers

Each XSS has big impact

How do you eradicate XSS without relying on developers?

19

Page 23: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 20

Page 24: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Manifest v2 fixes

21

Page 25: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Manifest v2

22

Content Security Policy obligatory for UI pages

no eval() no inline scripting no external scripts

XSS exploitation very difficult Manifest v1 extensions slowly deprecating

Jan 2014 - Chrome stops running them

All fixed?

script-src 'self'; object-src 'self'

Page 26: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Exploiting v2 extensions

23

Page 27: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

UI page XSS - new vectors

eval() used in JS templating librariesmustachejs underscorejs jQuery template hoganjs ...

Possible to relax CSP to allow unsafe-eval Some extensions use it

24

Page 28: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Content script XSS

Content scripts not subject to CSP Go figure...

25

Page 29: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 26

Page 30: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 26

Page 31: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 26

Page 32: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Content script XSS

XSS in http:// chrome-extension CSP bypass access to DOM access to cookies

27

Page 33: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

As sexy as self XSS...

28

Page 36: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Content script XSS

website CSP bypass “Content scripts can also make cross-site

XMLHttpRequests to the same sites as their parent extensions” http://developer.chrome.com/extensions/

content_scripts.html

29

"permissions": [ "http://*/*", "https://*/*", ]

40%

Page 37: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Content script XSS

Introducing Mosquito

(Another) Chrome Extension XSS Exploitation tool XSS-Proxy for the new era

30

http://www.growingherbsforbeginners.com/growing-herbs-for-mosquito-season/

https://github.com/koto/mosquito

Page 38: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Mosquito

31

XSSws:// HTTP/S proxy

inspired by MalaRIA by Erlend Oftedal and BeEF tunneling proxy by @antisnatchor

x = new XMLHttpRequest();x.open("GET", 'http://gmail.com', false);x.setRequestHeader('X-Mosquito', 'yeah!');x.send(null);

GET http://gmail.com HTTP/1.1Host: gmail.comX-Mosquito: yeah!

Page 40: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

NPAPI plugins vulnerabilities

UI page gets the payload Forwards it to NPAPI plugin Binary vulnerability in plugin

buffer overflow command injection ...

Code run with OS user permission No sandbox!

33

Page 41: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 34

Page 42: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 34

Page 43: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 34

Page 44: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP 34

Page 45: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

NPAPI plugins vulnerabilities

35

FB::variant gmailGPGAPI::encryptMessage(const FB::variant& recipients,const FB::variant& msg){ string gpgFileLocation = "\""+m_appPath +"gpg.exe\" "; //... vector<string> peopleToSendTo = recipients.convert_cast<vector<string> >(); string cmd = "c:\\windows\\system32\\cmd.exe /c "; cmd.append(gpgFileLocation); cmd.append("-e --armor"); cmd.append(" --trust-model=always"); for (unsigned int i = 0; i < peopleToSendTo.size(); i++) { cmd.append(" -r"); cmd.append(peopleToSendTo.at(i)); } cmd.append(" --output ");

CR-GPG 0.7.4

Page 46: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

NPAPI plugins vulnerabilities

35

FB::variant gmailGPGAPI::encryptMessage(const FB::variant& recipients,const FB::variant& msg){ string gpgFileLocation = "\""+m_appPath +"gpg.exe\" "; //... vector<string> peopleToSendTo = recipients.convert_cast<vector<string> >(); string cmd = "c:\\windows\\system32\\cmd.exe /c "; cmd.append(gpgFileLocation); cmd.append("-e --armor"); cmd.append(" --trust-model=always"); for (unsigned int i = 0; i < peopleToSendTo.size(); i++) { cmd.append(" -r"); cmd.append(peopleToSendTo.at(i)); } cmd.append(" --output ");

CR-GPG 0.7.4

-----BEGIN PGP MESSAGE-----Version: GnuPG v1.4.10 (GNU/Linux)

hQIOA5iUCyMfX/D2EAgAhikRs40xo05gNu9XSIO2jrjTIShwfWK2d7+9xlv9UjDN...-----END PGP MESSAGE-----

Page 47: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Bonus

CSP bypass through filesystem: API Filesystem API - virtual filesystem for HTML app

filesystem:http://example.com/file.png filesystem:chrome-extension://<id>/path.html

Postman - REST client v 0.8.1 180K users

including @webtonull

36

Page 48: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

Summary

Chrome extensions v2 still XSSable CSP should be treated as mitigation, not

prevention New tools for attack

37

Page 49: I'm in ur browser, pwning your stuff - Attacking (with) Google Chrome Extensions

OWASP

EOF

@kkotowicz http://blog.kotowicz.net https://github.com/koto More research:

Kyle Osborn, Matt Johansen – Hacking Google ChromeOS (Black Hat 2011)

http://www.eecs.berkeley.edu/~afelt/extensionvulnerabilities.pdf http://kotowicz.net/bh2012/advanced-chrome-extension-

exploitation-osborn-kotowicz.pdf Thanks: @0x[0-9a-f]{10}, @webtonull, @wisecwisec,

@johnwilander, @garethheyes, @antisnatchor, @freddyb,@internot_, @pdjstone, ....

38