automated web attacks using headless browsers · 2016-10-02 · a headless browser is a web browser...

32
© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster Automated Web Attacks Using Headless Browsers Dima Bekerman & Ben Herzberg September 2016

Upload: others

Post on 10-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Automated Web Attacks Using

Headless BrowsersDima Bekerman & Ben Herzberg

September 2016

Page 2: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

ben.about()

2

> ben.history

<· [“PT”,”Dev”]

> ben.employer

<· “Imperva Incapsula”

> ben.positionX

<· “Sec. Research Manager”

> ben.social

<· {“TWT”: “@KernelXSS”, “LNK”: “Ben Herzberg”}

Page 3: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

dima.about()

3

> dima.history

<· [“Machine Learning”, “Sec. Analysis”]

> dima.employer

<· “Imperva Incapsula”

> dima.positionX

<· “Security Researcher”

> dima.social

<· {“TWT”: “@_unxmaster”, “LNK”: “Dima Bekerman”}

Page 4: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Remember…

What happens in Novi Sad stays in Novi Sad

4

Page 5: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster5

Page 6: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Headless browser

A headless browser is a web browser without a graphical user interface.

It accesses web pages but doesn’t show them to any human being, it used to

provide the content of web pages to other programs.

6

https://en.wikipedia.org/wiki/Headless_browser

Page 7: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster7

Command line tool

HTTP library Web Browser

No JavaScript

No Dom

No Styling

No Layouts

Headless Browser

Page 8: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

A web browser engine is a program that renders marked up content and formatting information

8

Trident

Internet Explorer

Windows Mobile

EdgeHTML

Presto

Opera

Opera Mini

Opera Mobile

Gecko

Firefox

IceWeasel

SeaMonkey

WebKit

Safari

iOS

Chrome <27

Blink

Chrome 28+

Opera 15+

Android 4.4+

Web browser engine

Page 9: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster9

Is the

HTML

you write

DOM?

Nope

Is the

‘View-

Source’

DOM?

Nope

Is the

code in

DevTool

DOM?

Yep

The HTML you write is

parsed by the browser

and turned into the DOM

View Source just shows

you the HTML that

makes up that page.

It's probably the exact

HTML that you wrote.

DevTools panel

shows you a visual

representation of the

DOM.

What is DOM – Document Object Model?

Page 10: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster10

DOM representation

<div id="container">Hello World</div>

Source Code

<div id="container"></div>

<script>

var container = document.getElementById("container");

container.innerHTML = “Hello World";

</script>

Page 11: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Page processing

• JavaScript

• CSS

• SVG

• MathML

• WebGL

11

Page 12: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster12

Modernizer web features test

Page 13: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster13

ECMAScript test262

Page 14: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster14

PhantomJS

Awesomium

• Based on WebKit

• Cross Platform

• Portable

• Scriptable with JavaScript

• Good for WebUI automation

• Chromium based

• V8 – JavaScript Engine

• Programmable with .NET, C++

• Compiled to cross platform app

• Can be used as a module

SlimerJS

TrifleJS

Based on Gecko

Based on Trident

Chromium Embedded Framework

WebKit .NET

Page 15: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster15

Web Browser

Headless Browser

Page 16: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster16

Selenium / WebDriver

• Selenium is a browser control and automation system

• Manipulating a real web browser using a browser driver

• Manipulated browser must be installed

• Host OS should have a GUI framework

Page 17: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster17

The world of two contexts

Browser Context

Page Context

• JavaScript

• Evaluated by the web engine

• Has access to DOM objects

• Language depends on

framework

• Compiled / evaluated inside

framework interpreter

• Has access to OS

Page 18: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster18

The world of two contexts

Browser Contextmy_script.js

Page Contextexample.com

page.open(“example.com");

.

.

.

page.evaluate(function(){

return document.title;

});

Control

Page event

Inject

Callback

WebKit

function () {

return document.title;

}

Page 19: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Use Cases

• Test automation

• Crawl websites

• Render dynamic web page to static HTML

• Inject and execute arbitrary JavaScript code

• Perform actions

• Taking screen shots

• Monitor performance

19

Page 20: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Use Cases

• Content scraping

• Click fraud

• Fuzzing

• Bidding abuse

• Login brute force

• Botnet

• Sophisticated DDoS attacks

20

Page 21: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster21

Capture screen to image

Source Code

var page = require('webpage').create();

page.open(‘http://www.google.com’, function (status) {

page.render('google.png');

phantom.exit();

});

Page 22: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster22

Grabbing text

Source Code

//Page title

console.log(page.title);

// View-source

console.log(page.content);

//Content without HTML tags

console.log(page.plainText);

Page 23: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster23

Handle console and alerts

Source Code

//Handle console

page.onConsoleMessage = function(msg) {

console.log('CONSOLE: ' + msg);

};

//Handle alert

page.onAlert = function(msg) {

console.log('ALERT: ' + msg);

};

Page 24: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster24

Page 25: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster25

Page 26: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster26

Spot the differences

Page 27: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster27

Awesomium

Page 28: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster28

Source Code

webView.setWebViewClient(new WebViewClient() {

@Override

public void onPageFinished(WebView view, String url){

browser.loadUrl(

"javascript:window.HTMLOUT.processHTML(

document.getElementsByTagName('html'));");

}

});

Android WebView

Page 29: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster29

Page 30: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved. @Incapsula_com @KernelXSS @_unxmaster

Scenarios from the wild

• SEO tools scrape for dynamic content

• E-commerce abuse

• DDoS attacks from a mobile botnet

30

Page 31: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them

© 2016 Imperva, Inc. All rights reserved.

Хвала вам!THANK YOU!

Ben Herzberg Dima Bekerman

[email protected] [email protected]

@KernelXSS @_unxmaster

31

Page 32: Automated Web Attacks Using Headless Browsers · 2016-10-02 · A headless browser is a web browser without a graphical user interface. It accesses web pages but doesn’t show them