anatomy of a wordpress hack

111
@brennenbyrne

Upload: jessepollak

Post on 22-Apr-2015

1.183 views

Category:

Technology


1 download

DESCRIPTION

Slides for Brennen Byrne's talk, Anatomy of a WordPress Hack, given at WordCamp Boston.

TRANSCRIPT

Page 1: Anatomy of a WordPress Hack

@brennenbyrne

Page 2: Anatomy of a WordPress Hack

ANATOMY OF A WORDPRESS HACK

Page 3: Anatomy of a WordPress Hack

security is

hard

Page 4: Anatomy of a WordPress Hack

security is

REALLY

hard

Page 5: Anatomy of a WordPress Hack

security is

REALLY

REALLYhard

Page 6: Anatomy of a WordPress Hack

but probably

NOTfor the reasons you’re thinking

Page 7: Anatomy of a WordPress Hack

details

that’s because security is all about the

Page 8: Anatomy of a WordPress Hack

3 hacksthat broke wordpress

(and how they were fixed)

clickjacking

xss

sqli

Page 9: Anatomy of a WordPress Hack

this talk is probably for you

Page 10: Anatomy of a WordPress Hack

this talk is probably for you

(it’s a really good talk)

Page 11: Anatomy of a WordPress Hack

you might be wondering

“if these have already been fixed,why are we still talking about them?

Page 12: Anatomy of a WordPress Hack

almost 20% of the web runs on wordpress

Page 13: Anatomy of a WordPress Hack

almost 20% of the web runs on wordpress

lots of attacks on wordpress sites

Page 14: Anatomy of a WordPress Hack

almost 20% of the web runs on wordpress

they’ll happen again

lots of attacks on wordpress sites

Page 15: Anatomy of a WordPress Hack

almost 20% of the web runs on wordpress

lots of attacks on wordpress sites

they’ll happen again

it’s fun and interesting

Page 16: Anatomy of a WordPress Hack

hello, my name is brennen

@brennenbyrne

Page 17: Anatomy of a WordPress Hack

I’m a founder of Clef (getclef.com)

Page 18: Anatomy of a WordPress Hack

anatomy of a wordpress hack

Page 19: Anatomy of a WordPress Hack

XSScross site scripting

Page 20: Anatomy of a WordPress Hack

XSS cross site scripting

when a hacker is able to runarbitrary code in every user’s browser

Page 21: Anatomy of a WordPress Hack

let’s hack

Page 22: Anatomy of a WordPress Hack

how

Page 23: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

Page 24: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

begin html open tag

Page 25: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

unsanitized user input

}

Page 26: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

end html open tag

}

Page 27: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

begin html close tag

Page 28: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

unsanitized user input

}

Page 29: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

end html close tag

Page 30: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

unsanitized user input

}}

Page 31: Anatomy of a WordPress Hack

<{$icontag} class=‘gallery-icon’> ... </{$icontag}>

unsanitized user input

}}

Page 32: Anatomy of a WordPress Hack

unsanitized user input

Page 33: Anatomy of a WordPress Hack

unsanitized user input

exploit

Page 34: Anatomy of a WordPress Hack

script src=‘hack.js’

$icontag =

Page 35: Anatomy of a WordPress Hack

script src=‘hack.js’}

create a script tag

$icontag =

Page 36: Anatomy of a WordPress Hack

script src=‘hack.js’}load an evil script

$icontag =

Page 37: Anatomy of a WordPress Hack

how bad is this?

Page 38: Anatomy of a WordPress Hack

full site compromise

Page 39: Anatomy of a WordPress Hack

one line fix!

Page 40: Anatomy of a WordPress Hack

$icontag = tag_escape($icontag)

Page 41: Anatomy of a WordPress Hack

$icontag = tag_escape($icontag)}removes potentially

malicious code

Page 42: Anatomy of a WordPress Hack

Clickjacking

Page 43: Anatomy of a WordPress Hack

clickjackingwhen a hacker tricks you into clicking something you don’t want to click

Page 44: Anatomy of a WordPress Hack

let’s hack

Page 45: Anatomy of a WordPress Hack

how

Page 46: Anatomy of a WordPress Hack

this is your site

Page 47: Anatomy of a WordPress Hack

this is your site with an iframe

www.another-site.com

Page 48: Anatomy of a WordPress Hack

now imagine the green is the article

and the red is “delete post”

Page 49: Anatomy of a WordPress Hack

now imagine the green is the article

and the red is “delete post”

Page 50: Anatomy of a WordPress Hack

<iframe src=“admin_url” style=“opacity: 0; z-index: 100></iframe>

Page 51: Anatomy of a WordPress Hack

<iframe src=“admin_url” style=“opacity: 0; z-index: 100></iframe>}

embedding site in another site

}

Page 52: Anatomy of a WordPress Hack

SQL injection is a code injection technique, used to attack data driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).

<iframe src=“admin_url” style=“opacity: 0; z-index: 100></iframe>}

embedding admin page

Page 53: Anatomy of a WordPress Hack

SQL injection is a code injection technique, used to attack data driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).

<iframe src=“admin_url” style=“opacity: 0; z-index: 100></iframe>}admin page is fully transparent

Page 54: Anatomy of a WordPress Hack

<iframe src=“admin_url” style=“opacity: 0; z-index: 100”></iframe>}

admin page is above another page

Page 55: Anatomy of a WordPress Hack

delete post

Page 56: Anatomy of a WordPress Hack

allow embedding of valuable pages

Page 57: Anatomy of a WordPress Hack

how bad is this?

Page 58: Anatomy of a WordPress Hack

full site compromise

Page 59: Anatomy of a WordPress Hack

one line fix!

Page 60: Anatomy of a WordPress Hack

@header( 'X-Frame-Options: SAMEORIGIN' );

Page 61: Anatomy of a WordPress Hack

}

add header to requestsfor valuable pages

@header( 'X-Frame-Options: SAMEORIGIN' );

Page 62: Anatomy of a WordPress Hack

}tell browser to only allow

iframe embed when it’s on the same domain

@header( 'X-Frame-Options: SAMEORIGIN' );

Page 63: Anatomy of a WordPress Hack

SQL injection

Page 64: Anatomy of a WordPress Hack

SQL injectionwhen bad people access your database in bad ways

Page 65: Anatomy of a WordPress Hack

let’s hack

Page 66: Anatomy of a WordPress Hack

how

Page 67: Anatomy of a WordPress Hack

SELECT ... LIMIT $args[4]

Page 68: Anatomy of a WordPress Hack

SELECT ... LIMIT $args[4]}

select categories from database

Page 69: Anatomy of a WordPress Hack

SELECT ... LIMIT $args[4]}limit number of categories selected

Page 70: Anatomy of a WordPress Hack

SELECT ... LIMIT $args[4]}unsanitized user input

Page 71: Anatomy of a WordPress Hack

SELECT ... LIMIT $args[4]}unsanitized user input

Page 72: Anatomy of a WordPress Hack

unsanitized user input

Page 73: Anatomy of a WordPress Hack

exploitunsanitized user input

Page 74: Anatomy of a WordPress Hack

1 OFFSET 1 UNION ALL SELECT user_login, user_pass FROM wp_users

$args[4] =

Page 75: Anatomy of a WordPress Hack

1 OFFSET 1 UNION ALL SELECT user_login, user_pass FROM wp_users}

embed a second SQL query

Page 76: Anatomy of a WordPress Hack

1 OFFSET 1 UNION ALL SELECT user_login, user_pass FROM wp_users}

limit to 1 category and offset by 1

Page 77: Anatomy of a WordPress Hack

1 OFFSET 1 UNION ALL SELECT user_login, user_pass FROM wp_users

steal usernames and passwords

}

Page 78: Anatomy of a WordPress Hack

5 character fix!

Page 79: Anatomy of a WordPress Hack

(int) $args[4]

Page 80: Anatomy of a WordPress Hack

(int) $args[4]}sanitize user input by coercing it to an integer

Page 81: Anatomy of a WordPress Hack

how bad is this?

Page 82: Anatomy of a WordPress Hack

full site compromise

Page 83: Anatomy of a WordPress Hack
Page 84: Anatomy of a WordPress Hack

how does this happen?

Page 85: Anatomy of a WordPress Hack

security is in the details

Page 86: Anatomy of a WordPress Hack

security is hard

Page 87: Anatomy of a WordPress Hack

so what should you do?

Page 88: Anatomy of a WordPress Hack

you cannot know everything

1

Page 89: Anatomy of a WordPress Hack

you cannot know everything

1

Page 90: Anatomy of a WordPress Hack

1

you can always learn more

Page 91: Anatomy of a WordPress Hack

education

1

Page 92: Anatomy of a WordPress Hack

you will always make mistakes

2

Page 93: Anatomy of a WordPress Hack

you will always make mistakes

2

Page 94: Anatomy of a WordPress Hack

2

you must learn from your mistakes

Page 95: Anatomy of a WordPress Hack

experience

2

Page 96: Anatomy of a WordPress Hack

you cannot write secure code

3

Page 97: Anatomy of a WordPress Hack

you cannot write secure code

3

Page 98: Anatomy of a WordPress Hack

we can write secure code

3

Page 99: Anatomy of a WordPress Hack

we can write secure code

3

Page 100: Anatomy of a WordPress Hack

community

3

Page 101: Anatomy of a WordPress Hack

closing thoughts

Page 102: Anatomy of a WordPress Hack

thanks

Page 103: Anatomy of a WordPress Hack

XSS Jon Cave

Page 104: Anatomy of a WordPress Hack

XSS Jon Cave

Clickjacking Andrew Horton

Page 105: Anatomy of a WordPress Hack

XSS Jon Cave

SQLi Alexander Concha

Clickjacking Andrew Horton

Page 106: Anatomy of a WordPress Hack

XSS Jon Cave

SQLi Alexander Concha

WordPress Security Team

Clickjacking Andrew Horton

Page 107: Anatomy of a WordPress Hack

XSS Jon Cave

CSRF Alexander Concha

SQLi Alexander Concha

WordPress Security Team

WordPress Community

Page 108: Anatomy of a WordPress Hack

what if I find a security issue?

Page 109: Anatomy of a WordPress Hack

DO1. verify that it is a real issue

2. email [email protected]

DON’T1. maliciously exploit other wordpress sites

2. publish details of the vulnerability before it has been fixed

Page 110: Anatomy of a WordPress Hack

upgrade to

3.7

Page 111: Anatomy of a WordPress Hack

SELECT * FROM questions