Slide 1

Slide 1 text

libinjection From SQLi to XSS Nick Galbreath @ngalbreath! Signal Sciences Corp! [email protected] Code Blue ∙ Tokyo ∙ 2014-02-18

Slide 2

Slide 2 text

This is also in English! ͜Ε͸೔ຊޠͰ΋͋Γ·͢! https://speakerdeck.com/ngalbreath/
 codeblue2014-en-libinjection-from-sqli-to-xss https://speakerdeck.com/ngalbreath/
 codeblue2014-jp-libinjection-from-sqli-to-xss

Slide 3

Slide 3 text

Nick Galbreath
 @ngalbreath • Founder/CTO of Signal Sciences Corp • Before: IponWeb (Moscow, Tokyo) • Before: Etsy (New York City) NEW

Slide 4

Slide 4 text

What is libinjection? • A small C-library to detect SQLi attacks in user- input • With API in python, lua and php • Introduced at Black Hat USA 2012 • Open source with BSD license • https://github.com/client9/libinjection

Slide 5

Slide 5 text

Why libinjection? • Existing detection is mostly done with regular expressions • No unit tests • No performance (speed) tests • No coverage tests • No accuracy or precision tests • No false positive tests • “what are they actually doing?”

Slide 6

Slide 6 text

libinjection SQLi Today • Version 3.9.1 • 8000+ unique SQLi fingerprints • 400+ unit tests • 85,000+ SQLi samples

Slide 7

Slide 7 text

In Use At • mod_security WAF http://www.modsecurity.org/ • ironbee WAF https://www.ironbee.com/ • glastopf honeypot http://glastopf.org/ • proprietary WAFs • internally at many companies • plus, a pure-java port
 https://github.com/Kanatoko/libinjection-Java • .NET wrapper
 https://github.com/kochetkov/ Libinjection.NetLibinjection.Net

Slide 8

Slide 8 text

XSS

Slide 9

Slide 9 text

Similar to SQLi • No standard detection library • Few, if any, have tests • Most are based using regular expressions • Can we do better?

Slide 10

Slide 10 text

Two Types of XSS • HTML injection attacks • Javascript injection attacks

Slide 11

Slide 11 text

XSS Javascript Injection • Includes DOM-style attacks • Attacks existing javascript code. • Detection can truly be done on client • A very hard problem

Slide 12

Slide 12 text

HTML Injection • HTML injection are attacks against the HTML tokenization algorithm 
 (text “foo” to tags , foo, ) • The goal is to change the context to ‘javascript’ and execute arbitrary code. • This seems detectable.

Slide 13

Slide 13 text

HTML Injection Samples XSS (raw HTML) (tag attribute name) (tag attribute value) (quoted value) (quoted value) (IE only!)

Slide 14

Slide 14 text

Browser HTML Tokenization • Previously every browser parsed or tokenised HTML differently. • This lead to a number of different attacks using broken html tags, special characters or encodings. • Now, most browsers now use the same algorithm from the HTML5 specification. • The HTML5 algorithm is very specific

Slide 15

Slide 15 text

Every Tokenization Step http://www.w3.org/html/wg/drafts/html/CR/syntax.html#tokenization

Slide 16

Slide 16 text

Is Clearly Defined

Slide 17

Slide 17 text

60+% of Desktop Browsers are HTML5 http://tnw.co/1cqFueo IE 9 9% IE 10 11% IE 11 10% Firefox 14% Chrome 13% Safari 5% ------------ HTML5 62%

Slide 18

Slide 18 text

~90% Mobile Browsers
 are HTML5 http://bit.ly/JQSZxb

Slide 19

Slide 19 text

Remainder is IE6, IE7 and IE8 • IE6 will, in time, go away. Really ;-) • IE7 has only 2% of market share • IE8 has up to 20% marketshare XP • Mostly on Windows XP • Marketshare can only do down

Slide 20

Slide 20 text

libinjection XSS

Slide 21

Slide 21 text

HTML injection attacks
 in HTML5 clients. • No: XML / XSLT injection • No: Any injection for IE6, IE7, Opera, FF and Chrome older than a year. • No: DOM style attacks (need a client solution)

Slide 22

Slide 22 text

libinjection html5 • Complete HTML5 Tokenizer. • Does not build a tree or DOMs • Just emits token events. • No copying of data

Slide 23

Slide 23 text

Tokenization Sample TAG_NAME_OPEN img ATTR_NAME src ATTR_VALUE junk ATTR_NAME onerror ATTR_VALUE alert(1); TAG_NAME_CLOSE >

Slide 24

Slide 24 text

Check in Each Context Each input is parsed in at least 6 different HTML contexts, because thats how XSS works! XSS (raw HTML) (tag attribute name) (tag attribute value) (quoted value) (quoted value) (IE only!)

Slide 25

Slide 25 text

Ban Problematic Tokens • Problematic tags, attributes, and values are cataloged. • Tags: , anything XML or SVG related • Attributes: on*, etc • Values: javascript URLs in various formats • and more…

Slide 26

Slide 26 text

Training Sources

Slide 27

Slide 27 text

XSS Cheat Sheets • Most are outdated (exploits for Firefox 3! ) • sorry OWASP :-( • Each entry validated to make sure they are valid for HTML5 browsers.

Slide 28

Slide 28 text

HTML5SEC.org • Fantastic resource • But lists many examples for Firefox 3 and/or obsolete Opera versions • Pruned to focus on HTML5 browsers

Slide 29

Slide 29 text

@soaj1664ashar • Produces interesting, new XSS regularly • If you like XSS, please follow him on Twitter • http://bit.ly/1bwXTgn • http://pastebin.com/u6FY1xDA • http://bit.ly/1iXODkW

Slide 30

Slide 30 text

Attack / Scanners • Integrated output of one XSS scanner • Using Shazzer fuzz database
 http://shazzer.co.uk/
 (Thanks to ModSecurity team)

Slide 31

Slide 31 text

Current Status

Slide 32

Slide 32 text

Available Now • Available on github:
 https://github.com/client9/libinjection • Home page:
 https://libinjection.client9.com/ • but… still alpha

Slide 33

Slide 33 text

$ make test-xss ./reader -t -i -x -m 10 ../data/xss* ../data/xss-html5secorg.txt 149 False test 62_1 ../data/xss-html5secorg.txt 151 False test 62_2 ../data/xss-html5secorg.txt 153 False test 62_3 ../data/xss-html5secorg.txt 352 False test 102 ../data/xss-soaj1664ashar-pastebin-u6FY1xDA.txt 96 False 92) <--` --!> ../data/xss-soaj1664ashar.txt 21 False ../data/xss-xenotix.txt 17 False "'`> ../data/xss-xenotix.txt 19 False '`">javascript:alert(1) ../data/xss-xenotix.txt 610 False `"'> ../data/xss-xenotix.txt 613 False `"'> ../data/xss-xenotix.txt 615 False `"'> ! XSS : 1628 SAFE : 11 TOTAL : 1639 ! Threshold is 10, got 11, failing. 1639 Total Samples 1628 Detected as XSS 11 False Negatives

Slide 34

Slide 34 text

IE Unbalanced Quotes • IE 8+ has strange behaviour with ‘unbalanced quotes’ inside comments and attribute values. • Work in progress

Slide 35

Slide 35 text

Performance   
 DIFDLTQFSTFDPOE

Slide 36

Slide 36 text

TODO 2014-02-17 • It’s alpha — so it’s likely to have some spectacular failures (bypasses) • False-positive QA not completed. • Currently does not handle some IE injections • Does not have a test-bed for experimenting 
 (maybe later this week). • More QA, code-coverage needed • No bindings for scripting languages (soon).

Slide 37

Slide 37 text