CLICK HERE.exe SQL Injections Security Meetup Month 1 of 12 - - PowerPoint PPT Presentation

click here exe sql injections
SMART_READER_LITE
LIVE PREVIEW

CLICK HERE.exe SQL Injections Security Meetup Month 1 of 12 - - PowerPoint PPT Presentation

CLICK HERE.exe SQL Injections Security Meetup Month 1 of 12 (January) This month: SQL Injections Next month: XSS / CSRF Meetup Group for times/dates Plan of Attack History of SQL Basic Injections Protections


slide-1
SLIDE 1

CLICK HERE.exe

slide-2
SLIDE 2

SQL Injections

Security Meetup

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

Month 1 of 12 (January)

slide-4
SLIDE 4
  • History of SQL
  • Basic Injections
  • Protections
  • Advanced Injections
  • Tips and Fun

Plan of Attack

slide-5
SLIDE 5

Who are you?

  • Connor Tumbleson
  • Sourcetoad Engineer
  • Apktool - RE Tool
  • @iBotPeaches
slide-6
SLIDE 6
  • IBM introduced.
  • Invented — all data is related.
  • Went public a few years later.
  • The language was known as SQL
  • Structured Query Language

1970: SEQUEL is born

slide-7
SLIDE 7
  • Clauses - actions
  • Expressions - scalars / arrays
  • Predicates - conditions
  • Queries - retrieve by condition
  • Statements - modifying by condition

SQL: Syntax

slide-8
SLIDE 8

With a 1999 Database

slide-9
SLIDE 9

Login Page

slide-10
SLIDE 10

Succesful Login

slide-11
SLIDE 11

SELECT * FROM users WHERE username=‘user’ AND password=‘connor’

A Basic Query

slide-12
SLIDE 12

Lets try the “Admin” account

slide-13
SLIDE 13

Lets try the “Admin” account

slide-14
SLIDE 14

SELECT * FROM users WHERE username=‘admin’ AND password=‘’ OR '1'='1' #’

A Basic Injected Query

slide-15
SLIDE 15

A Basic Injected Query Explained

  • End the existing blob
  • Add a logic gate (OR)
  • Pass the logic gate
  • Comment out rest of query

SELECT * FROM users WHERE username=‘admin’ AND password=‘’ OR '1'='1' #’

slide-16
SLIDE 16

Succesful Login :)

slide-17
SLIDE 17

Too easy right? Well the world updated

  • Prepared Statements (preferred)
  • Stored Procedures (ew)
  • Whitelist (not feasible)
  • Escaping (cat n mouse)
slide-18
SLIDE 18

SQL Protections: Escaping

  • What do you escape?
slide-19
SLIDE 19

SQL Protections: Danger of Escaping

  • Unicode
  • Implicit

Conversion

slide-20
SLIDE 20

Escaping - XKCD

Credit to XKCD

slide-21
SLIDE 21

SQL Protections: Whitelists

  • Not feasible
  • Ordering
  • Filtering
  • Searching (😖)
slide-22
SLIDE 22

SQL Protections: Stored Procedures

  • Moves logic into DB
  • If done right, could work
  • Dynamic generation could be bad
  • Opinion: Dislike them
slide-23
SLIDE 23

SQL Protections: Prepared Statements

  • The only 100% solution.
  • Period.
  • Effectively splits data from logic.
  • Laravel does this (behind scenes)

SELECT * FROM users WHERE username=? AND password=?

slide-24
SLIDE 24

SQL Protections: Prepared Statements

  • Common method is substitution via ?
  • Alternatively, :named

SELECT * FROM users WHERE username=? AND password=? SELECT * FROM users WHERE username=:username AND password=:password

slide-25
SLIDE 25

Types of SQL Injections

  • In Band
  • Classic
  • Error / Union
  • Blind
  • Boolean / Time
  • Out of Band
slide-26
SLIDE 26

SQL: In Band - Classic Error

  • Information Extraction
  • Learn database structure
slide-27
SLIDE 27

SQL: In Band - Union

  • Imagine a table of items.
  • Injection of adding data (union)
  • Pivot to system tables (easy to identify)
slide-28
SLIDE 28

SQL: Blind - Boolean

  • A method to answer T/F questions
  • Does the page change based on query?
  • Helpful when nothing outputting.
slide-29
SLIDE 29

SQL: Blind - Timing

  • Much like Boolean, but time oriented.
  • SLEEP(1)
  • Can issue T/F statement
  • Wait for return
slide-30
SLIDE 30

SQL: Out of Band

  • Strange
  • Different medium return from request.
  • Exfiltration via HTTP/DNS/Email
slide-31
SLIDE 31

WAF: Web Application Firewall

  • Popular: ModSecurity
  • Rules to prevent SQL injection
  • Not perfect
  • Works off regular expressions.
slide-32
SLIDE 32

Advanced Time

slide-33
SLIDE 33

Advanced Technique: Bitwise Operations

  • Enumeration of a,b,c,d,e,f etc
  • a = true/false
  • b = true/false
  • Enumeration via bit-shifting 00000000
  • 0 = true/false
  • 01 = true/false
slide-34
SLIDE 34

Example Time.

  • Lets assume we found a “settings” table
  • Blind injection, so need to enumerate
  • (but lets cheat first)
slide-35
SLIDE 35
  • First. We need length
slide-36
SLIDE 36

So now what?

  • We know a length 3 string.
  • We are assuming alphanumeric
  • Lets try brute forcing two ways.
  • Alphabet scan
  • Bit shifting
slide-37
SLIDE 37

Alphabet Scan - First Letter

  • Request 1 - “a” - Fail
  • Request 2 - “b” - Fail
  • Request 3 - “c” - Pass :)
  • 3 Requests - “c??”
slide-38
SLIDE 38

Alphabet Scan - Second Letter

  • Request 1 - “a” - Pass :)
  • Too Easy
  • 4 Requests - “ca?”
slide-39
SLIDE 39

Alphabet Scan - Third Letter

  • Request 1 - “a” - Fail
  • Request 2 - “b” - Fail
  • Request … - “Fail”
  • Request 20 - “t” - Pass :)
  • 24 Requests - “cat” :)
slide-40
SLIDE 40

Recap: Alphabet Scan

  • Via true/false questions.
  • We learned “salt” was “cat”
  • It took 26 queries to database
  • (once we started counting)
slide-41
SLIDE 41

Bitwise Scan - Intro

  • We need to know binary.
  • So what is cat (ASCII)?
  • c = 99 (01100011)
  • a = 65 (01100001)
  • t = 116 (01110100)
slide-42
SLIDE 42

Bit-Shifting - Introduction

  • Shifting “???” 7 bits
  • Remember 0 is an index
  • We know 0???????
slide-43
SLIDE 43

Bit-Shifting - Next bit

  • Shifting “???” 6 bits
  • We know 01??????
  • So previous + current = now
  • So 0 + (1 or 0) = 1 or 0
slide-44
SLIDE 44

Bit-Shifting - Next bit

  • Shifting “???” 5 bits
  • We know 011?????
  • So previous + current = now
  • So 1 + (2 or 3) = 3 or 4
slide-45
SLIDE 45

Bit-Shifting - Skip a few steps

  • Shifting all bit locations of first character
  • We know 01100011
  • We learned “c”.
  • Took 8 requests.
slide-46
SLIDE 46

Bit-Shifting - Rinse and Repeat

  • We learned “a” - 01100001
  • We learned “t” - 01110100
slide-47
SLIDE 47

Recap: Bit-Shifting Scan

  • Via true/false questions.
  • We learned “salt” was “cat”
  • It took 24 queries to database
  • (once we started counting)
  • So it was quicker.
slide-48
SLIDE 48

Advanced Technique: Mega Payloads

  • If injection working.
  • Construct query that compounds.
  • Run out the memory.
slide-49
SLIDE 49

Advanced Technique: 2nd Generation

  • Instead of injection.
  • Use UGC to insert an injection
  • Database might react on that
  • Tough to use unless common product
  • Forum software, out of box, etc
slide-50
SLIDE 50

Funny Injections & Tools

slide-51
SLIDE 51

User Generated Injection

  • Wait till the scanners read this.
slide-52
SLIDE 52

Creative Thinking

  • Can’t get a bill if you have no plate.
slide-53
SLIDE 53

Creative Thinking - Backfired

  • $12,049 in fines.

bit.ly/2SWLbRU

slide-54
SLIDE 54

Tool: sqlmap

  • Automate everything we discussed.
slide-55
SLIDE 55

sqlmap

  • Run it against our first example
slide-56
SLIDE 56

sqlmap

  • Enumeration of data quickly.
slide-57
SLIDE 57
  • We learned a bit about SQL
  • We learned injection types
  • We explored some complex injections
  • We had some fun

Concluding

slide-58
SLIDE 58

Thanks! connortumbleson.com @iBotPeaches