I’m in your browser,pwning your stuff!
Atakowanie poprzez rozszerzenia Google Chrome
Krzysztof Kotowicz
/whoami
• IT security consultant @ SecuRing
• Web security research(BlackHat, BruCON, Confidence, ...)
• blog.kotowicz.net
• @kkotowicz
Plan
• Po co atakować (poprzez) rozszerzenia Google Chrome?
• Jak to robić?
• Nie da się prościej?
Po co?
http://www.flickr.com/photos/hans905/4124897248/in/photostream/
Same origin policy
• XSS - wykonanie kodu w ramach origin ofiary
• CSRF - wykonanie u ofiary akcji żądaniem z origin atakującego
x = new XMLHttpRequest()x.open(“POST”, “//victim.pl”)x.send(“delete_account&id=1”)
“><script>alert(document.cookie)</script>
Text
http://www.flickr.com/photos/dimi15/707990005/in/photostream/
SOP bypass
• //superevr.com/blog/2012/top-level-universal-xss/
• //blog.detectify.com/post/32947196572/universal-xss-in-opera
• Rzadkie, ograniczone zastosowanie
• Polegają na błędach w przeglądarkach
http://www.flickr.com/photos/iloveblue/3302032125/in/photostream/
Rozszerzenia Chrome
• Aplikacje HTML5
• html, javascript, css
• Spakowane do pliku .crx
• podpisany zip
• Instalacja poprzez Chrome Web Store
• lub manualnie
Rozszerzenia Chrome
• Uprawnienia określone w pliku manifest.json
• Dostęp do wielu ważnych API
• chrome.tabs
• chrome.bookmarks
• chrome.history
• chrome.cookies
• NPAPI plugins
Rozszerzenia Chrome
• Rozszerzenia to aplikacje HTML
• Te same klasy podatności
• w tym XSS
Rozszerzenia Chrome
• XSS w rozszerzeniu może oznaczać
• UXSS
• dostęp do historii URL
• dostęp r/w do cookies
• dostęp do plików
• wykonanie dowolnego kodu
Jak?
DOM
DOM
js.js
content script.js
DOM
js.js
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
js.js
view.html
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
js.js
view.html
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
background.jsjs.js
view.html
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
background.js
APIcookies, history, tabs, plugins, ...
js.js
view.html
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
view.html
content script.js
getElementById(),
createElement(),
innerHTM
L
DOM
chro
me.exte
nsion
.
sendR
eque
st
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
view.html
content script.js
DOM
background.js
API
js.js
view.html
content script.js
DOM
background.js
API
js.js
view.html
content script.js
DOM
background.js
API
js.js
view.html
content script.js
DOM
background.js
API
js.js
view.html
content script.js
DOM
background.js
API
js.js
chrome.tabs.executeScript
Podatności
XSS w content script
• content script otrzymuje dane
• z view
• z DOM
• umieszcza je bez escape’owania w DOM
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
XSS w content script
• Skutki:
• dostęp do DOM
• nieograniczony XHR
DEMO - zzzap-itchrome.tabs.executeScript(null, { code: "(" + funcLaunchZzzapIt.toString() + ")('" + tab.url.replace("'","\\'") + "', '" + tab.title.replace("'","\\'") + "', 'open')"});
XSS w view
• content-script bierze dane z DOM strony
• wysyła je do view
• view wyświetla je bez escape’owania
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
view.html
content script.js
DOM
background.js
chrome.*
APIcookies, history, tabs, plugins, ...
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
XSS w view
• Skutki
• możliwość persystencji w tle
• dostęp do chrome.* API (limitowany uprawnieniami)
<link rel="alternate" type="application/rss+xml" title="hello <img src=x onerror='payload'>"href="/rss.rss">
DEMO - Slick RSS: feed finder
Podatności w NPAPI
• Zawartość ze strony trafia do view
• View przekazuje ją do pluginu NPAPI
• Wywołanie podatności w pluginie
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPI
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPI
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPI
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPI
Podatności w NPAPI
• Przykład: cr-gpg 0.7.8
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));}
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
view.html
content script.js
DOM
background.js
chrome.*
API
js.js
getElementById(),
createElement(),
innerHTM
L
chro
me.exte
nsion
.
sendR
eque
st
NPAPIcmd.exegpg.exe
Prościej?
• alert(1) - i co dalej?
• Potrzebne narzędzie do automatyzacji
• Jak BeEF, ale do eksploitacji rozszerzeń Chrome
http://www.flickr.com/photos/josephwuorigami/3165180003/
Eksploitacja
• Monitorowanie tabów
• Wykonanie JS na każdym tabie
• Wyciąganie HTML
• Odczyt/zapis cookies
• Manipulacja historią
• Ustawienia proxy
Uruchamianie serwera$ php -vPHP 5.3.12 (cli) (built: Jun 7 2012 22:49:42) Copyright (c) 1997-2012 The PHP GroupZend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
$ php server.php 2>command.logXSS ChEF serverby Krzysztof Kotowicz - kkotowicz at gmail dot com
Usage: php server.php [port=8080] [host=127.0.0.1]Communication is logged to stderr, use php server.php [port] 2>log.txt2012-07-22 12:40:06 [info] Server created2012-07-22 12:40:06 ChEF server is listening on 127.0.0.1:80802012-07-22 12:40:06 [info] [client 127.0.0.1:60431] Connected2012-07-22 12:40:06 [info] [client 127.0.0.1:60431] Performing handshake2012-07-22 12:40:06 [info] [client 127.0.0.1:60431] Handshake sent2012-07-22 12:40:06 New hook c3590977550 from 127.0.0.1...
Hook code
Konsola
Wybór sesji
Payloady
Screenshoty
Pytania?
• https://github.com/koto/xsschef
• @kkotowicz
Top Related