CLICK HERE.exe XSS & CSRF Security Meetup Month 2 of 12 - - PowerPoint PPT Presentation

click here exe xss csrf
SMART_READER_LITE
LIVE PREVIEW

CLICK HERE.exe XSS & CSRF Security Meetup Month 2 of 12 - - PowerPoint PPT Presentation

CLICK HERE.exe XSS & CSRF Security Meetup Month 2 of 12 (February) Last month: SQL Injections This month: XSS / CSRF Next month: DDoS / DoS Meetup Group for times/dates https://www.meetup.com/CLICK_HERE-exe/ Plan of Attack


slide-1
SLIDE 1

CLICK HERE.exe

slide-2
SLIDE 2

XSS & CSRF

Security Meetup

slide-3
SLIDE 3
  • Last month: SQL Injections
  • This month: XSS / CSRF
  • Next month: DDoS / DoS
  • Meetup Group for times/dates

Month 2 of 12 (February)

https://www.meetup.com/CLICK_HERE-exe/

slide-4
SLIDE 4
  • The Safe Web
  • The Malicious Web
  • XSS Abuse
  • CSRF Abuse
  • Protections

Plan of Attack

slide-5
SLIDE 5

Who are you?

  • Connor Tumbleson
  • Sourcetoad Engineer
  • Apktool - RE Tool
  • @iBotPeaches
slide-6
SLIDE 6
  • Security was an afterthought
  • Protocols were designed with trust
  • Didn’t expect dark intentions

The Safe Web

slide-7
SLIDE 7
  • Blogs
  • Message boards
  • Universities
  • News

Early Internet

slide-8
SLIDE 8
  • Banking
  • Health
  • Shopping
  • Everything

The Present Internet

slide-9
SLIDE 9

The Real Internet

slide-10
SLIDE 10
  • Internet users main purpose: abuse
  • Protocols needed upgrades
  • Developers needed teaching

The Malicious Web

slide-11
SLIDE 11
  • Cross-Site Scripting
  • CSS was taken, so XSS
  • (I made that up ^)
  • Malicious code running on trusted website
  • How does that happen though?

So start small: XSS

slide-12
SLIDE 12

Browsers evaluate HTML. Simple.

slide-13
SLIDE 13
  • UCG - User Generated Content
  • Comments, Forums, Contact Us etc
  • URL Tweaking

How do you inject code?

https://fakedemosite.com/search?query={searchTerm}

slide-14
SLIDE 14
  • Test bed: <script>alert(‘test’);</script>
  • Place this anywhere
  • URL, Comment, Post, Searchbox

How about an example

slide-15
SLIDE 15
  • The quick test.
  • If it works, then untrusted code can run.
  • Then what?

The classic alert box.

It’s time to escalate.

slide-16
SLIDE 16
  • Cookie Theft
  • document.cookie (session)
  • Key-logging
  • onKeyPress (passwords)
  • DOM Changes
  • action=“malicious.host” (harvesting)

Common XSS Attacks

slide-17
SLIDE 17

Demo - Logging

slide-18
SLIDE 18
  • Reflected XSS
  • Think search or URL
  • Stored XSS
  • Database, UCG
  • DOM XSS
  • Frontend JS, “SPA”

XSS Categories (Old)

slide-19
SLIDE 19
  • Bad URL
  • Trick someone to load

Reflected XSS

User Attacker Vulnerable Website

bad link clicked executed

slide-20
SLIDE 20
  • Untrusted data in DB
  • Emitted into page
  • Many could be affected

Stored XSS

slide-21
SLIDE 21
  • DOM changes based on input
  • Two way binding - Vue/Angular/React

DOM XSS

slide-22
SLIDE 22
  • Server XSS
  • Untrusted data comes from server
  • Client XSS
  • Untrusted data lives at DOM layer
  • AJAX, SPA, etc

XSS Categories (Modern)

slide-23
SLIDE 23
  • Escaping
  • Filter
  • HTTP Headers
  • httpOnly
  • CSP Rules

Prevention Techniques (XSS)

slide-24
SLIDE 24
  • Browsers don’t parse text twice.
  • So script tags are never processed

Prevention: Escaping (preferred)

slide-25
SLIDE 25

Prevention: Escaping (preferred)

<script>alert(‘foo’);</script>

&tl;script&gt;alert(&#x27;foo&#x27;);&lt;&#x2F;script&gt;

Escaped (you)

slide-26
SLIDE 26

Prevention: Escaping (preferred)

<script>alert(‘foo’);</script>

&tl;script&gt;alert(&#x27;foo&#x27;);&lt;&#x2F;script&gt;

Rendered (browser)

slide-27
SLIDE 27
  • Guide what you expect
  • Validation
  • “What is your name?”
  • Connor <script>hack you</script>

Prevention: Filter (not preferred)

slide-28
SLIDE 28
  • X-XSS-Protection HTTP Header
  • If URL matches executed JS, then block
  • Only protects Reflected XSS
  • Browsers dropping in favor of CSP rules

Prevention: Headers (abandoned)

slide-29
SLIDE 29
  • httpOnly flag when creating cookie
  • Prevents cookie being read client side
  • (if browser supports it)

Prevention: Cookie Setting (partial)

https://caniuse.com/#search=httpOnly

slide-30
SLIDE 30
  • Content Security Policy
  • A complex header to protect end users
  • Yes, it is complex.

Prevention: CSP (future)

slide-31
SLIDE 31
  • Only load images from x.com
  • Refuse to load inline Javascript
  • AJAX Requests only to “self”
  • Block or ignore violations

Prevention: CSP cont.

https://report-uri.com

slide-32
SLIDE 32

Switching to CSRF

slide-33
SLIDE 33
  • Cross Site Request Forgery
  • Executing a request in an unwanted way
  • Imagine submitting a form maliciously
  • Fake Story Time…

CSRF - Intro

slide-34
SLIDE 34
  • Lets say we all bank with {bank}
  • I send $5 to a friend on their website
  • I notice the URL is
  • GET bank.com/transfer?acct=Friend&amt=$5

CSRF - Early Internet

slide-35
SLIDE 35
  • GET probably wasn’t used.
  • I notice pattern.
  • I change the link to me.
  • Victim clicks link, they send me $5
  • <a href=“http://badlink">View Photos</a>

CSRF - Early Abuse

slide-36
SLIDE 36
  • Yeah that was too easy.
  • The world actually used POST

CSRF - Early Abuse

<form action=“bank.com/transfer"> <input name=“target” value=“friend” /> <input name=“amt” value=“5” /> <button type=“submit” value=“Send” /> </form>

slide-37
SLIDE 37
  • I make a comment section on my website
  • It also submits a hidden form to {bank}
  • If visitor banks with {bank} then
  • makes a comment
  • I just got $5 from them

CSRF - POST Abuse

slide-38
SLIDE 38
  • The victim is logged in with {bank}
  • Browser can't tell if legit or not
  • Browser makes request

CSRF - Wait. How did that work?

Bad Server Victim Legitimate Site

tricked link submit grab creds success

slide-39
SLIDE 39
  • Bank has noticed this abuse.
  • They start relying on referrer.
  • HTTP Header
  • Transfers MUST have referrer of
  • http://bank.com/manage

CSRF - POST Prevention Early Web

slide-40
SLIDE 40
  • Leaks information
  • May be empty or missing
  • Referrer may be
  • http://company.com/sekrit/x-pod-90-pro

CSRF - The Referrer Problem

slide-41
SLIDE 41
  • Lets make a random string
  • Put it on form, look for it during submit

CSRF - The Token Fix

slide-42
SLIDE 42
  • If someone makes a forged request
  • It cannot have the token
  • Thus, denied.
  • Normally, HTTP 419 (Auth Timeout)

CSRF - The Token Fix

slide-43
SLIDE 43

Advanced Time

slide-44
SLIDE 44
  • XSS attack bypasses ALL CSRF measures
  • Load the page, find the token
  • Load the token into malicious form
  • Submit the form
  • Pivoted XSS -> CSRF

CSRF - Why batched with XSS?

slide-45
SLIDE 45

Bypass CSRF

  • Google Results
  • 167k
  • Tons of methods
slide-46
SLIDE 46

SSRF - What is that?

  • SSRF - Server
  • Server Side Request Forgery
  • So forging a request from a server.
slide-47
SLIDE 47

SSRF - Example

  • Upload file or give URL
slide-48
SLIDE 48

SSRF - Example

  • If you put in URL - https://ibotpeaches.com/imgs/yer.jpg
  • Server downloads it.
  • Maybe because of CSP rules
  • Can’t load 3rd party images
  • So what happens?
slide-49
SLIDE 49

SSRF - Intended Flow

slide-50
SLIDE 50

SSRF - Malicious Flow

  • If you put in URL - http://127.0.0.1/nginx_status
  • Status page for NGINX (default)
  • Server reaches out.
  • Downloads it.
slide-51
SLIDE 51

SSRF - Malicious Flow

  • hmm…
slide-52
SLIDE 52

SSRF - Malicious Flow

  • That can’t be rendered as an image
  • Assuming no file validation
  • What actually is it?
slide-53
SLIDE 53

SSRF - Complete

  • Wow
  • Tricked a server
  • To download a local (internal) file and

return it to me.

slide-54
SLIDE 54

SSRF - In Real Life (Google)

https://opnsec.com/2018/07/into-the-borg-ssrf-inside-google-production-network/

slide-55
SLIDE 55

SSRF - In Real Life (Google)

https://opnsec.com/2018/07/into-the-borg-ssrf-inside-google-production-network/

  • Google Caja “cleans” HTML/CSS/JS
  • Needs to download and do magic
  • Author noticed downloads came from

internal network

slide-56
SLIDE 56

Bounties

slide-57
SLIDE 57
  • XSS is top 10 OWASP still
  • Stay with frameworks for CSRF protection
  • SSRF is a real thing
  • Don’t roll your own escaping

Concluding

slide-58
SLIDE 58

Thanks! connortumbleson.com @iBotPeaches