SQL Attacks

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/67

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

68 Terms

1
New cards

Crime Continues — key idea

Many (if not most) computer crimes are digital versions of old crimes.

2
New cards

Examples of "old crimes" that went digital

Pyramid schemes, Vandalism, Theft, Junk mail/spam, False advertising, Fraud ("This is the IRS…").

3
New cards

What changed regarding access?

You don't need to physically raid a location to get info; you don't need to be in the same country; governments have stepped up hacking each other.

4
New cards

SQL Injection historical context (Side Note)

SQL injection has always been a possibility; what changed was the ability to do that injecting online.

5
New cards

What changed regarding rules?

Before: the country you worked in made the laws. Now: with content available anywhere, countries (including US) attempt to enforce laws on content from elsewhere.

6
New cards

SQL Injection Source (Citation)

Clarke, J. (2012). SQL Injection Attacks and Defense (2nd ed.). Syngress.

7
New cards

Why are most queries not static strings?

We build queries dynamically based on input.

8
New cards

Examples of inputs driving dynamic queries

Searching for a name in contacts; adding a user; removing a user; Authentication (are you really you?).

9
New cards

SQL Injection definition

Using input to make a dynamic SQL statement do something it shouldn't.

10
New cards

SQL Injection "shape" (concept)

Take something that should be simple and make it complex.

11
New cards

E-commerce search box example query

SELECT * FROM PRODUCTS WHERE Name LIKE '%%';

12
New cards

E-commerce expected input example

"iPhone"

13
New cards

E-commerce manipulated input example

"iPhone' OR Name LIKE '"

14
New cards

Resulting injected query (Search)

SELECT * FROM PRODUCTS WHERE Name LIKE '%iPhone' OR Name LIKE '%';

15
New cards

Effect of 'OR' in the search injection

OR means that either clause matching keeps the row.

16
New cards

Effect of "Name LIKE '%'"

It matches anything.

17
New cards

Search injection advanced example input

"iPhone' OR 1=1 OR Name LIKE '"

18
New cards

Example Product Table Columns

Name, Price, Available, Availability_date, Quantity

19
New cards

Example Product Table Data (Rows)

iPhone 17 ($799), iPad Pro M5 (No stock), Macbook Air M5 (No stock), Pixel 10 Pro ($1099), Pixel 10 Fold ($1799).

20
New cards

Result of search injection attack (Slide 14)

1 query shows everything (including unreleased products); A lot of data returned (slows the server down).

21
New cards

Authentication Injection — How it works

The web page sends username/password to the server to validate.

22
New cards

Authentication intended query

SELECT COUNT(*) FROM USERS WHERE User ='' AND Password ='';

23
New cards

Authentication logic check

We look for a COUNT > 0.

24
New cards

Why use COUNT for authentication?

COUNT is all we need; we shouldn't need the actual results because we supplied them.

25
New cards

Authentication manipulated input example

Put "me' OR '1'='1" for the password.

26
New cards

Resulting injected query (Authentication)

SELECT COUNT(*) FROM USERS WHERE User='me' AND Password='me' OR '1'='1';

27
New cards

Why '1'='1' is dangerous

It is always true.

28
New cards

Why OR breaks authentication logic

OR makes the whole clause true.

29
New cards

Operator Precedence in SQL (Footnote)

AND has precedence over OR, so OR is the last thing evaluated.

30
New cards

Result of Authentication Injection

COUNT(*) is > 0; the attacker authenticates without knowing a username or password.

31
New cards

Password storage warning

Passwords shouldn't be stored as "plain text" (the way you typed them).

32
New cards

How passwords should be stored

Using a 1-way hash (a value you can't easily turn back into the original password).

33
New cards

Linux password storage note

On Linux systems you can say "sudo /etc/shadow" and see all of the (hashed) passwords.

34
New cards

Can you log in with a retrieved hashed password?

No, because the hashed value would be hashed again into something else before checking it.

35
New cards

Breach consequence note

This is why most breaches are of the "change your password soon" variety rather than full-on access.

36
New cards

Real-life Attack: Sony (2011)

Compromised 77 million PlayStation accounts; Cost Sony about $170 million.

37
New cards

Real-life Attack: Heartland Payments (2008)

Compromised 130 million credit/debit card numbers; Cost $200 million and 50% of stock price.

38
New cards

Real-life Attack: Yahoo! (2012)

Leaked 500 million email addresses and passwords.

39
New cards

Yahoo! breach specific vulnerability

The leaked passwords were unencrypted.

40
New cards

Web Request Step 1: Browser

The public part; where you fill out fields, click buttons, etc.

41
New cards

Web Request Step 2: Server

The hidden parts; where user data turns into database actions (often dynamically building SQL).

42
New cards

Web Request Step 3: Database

The part we're familiar with; returns results to server, then to user.

43
New cards

Vulnerable Java Code Example

String query = "SELECT * … LIKE '%" + text + "%'"; // Blindly trusting the text field.

44
New cards

Where to guard against SQL Injection?

The database will run any valid query, so it's up to us (the code) to sanitize the input.

45
New cards

Sanitizing Code Example (Java)

if (query.contains("'")) { // Error: invalid query }

46
New cards

Responsibility for sanitation (Complexity)

As architectures get complex, it's easy to think "the layer before/after me will do it," leading to no validation.

47
New cards

Two parts of the solution

  1. Detection, 2. Avoidance.

48
New cards

Oracle "escape" characters (Detection)

' (string/data), | (pipe/run function), , (comma), . (dot), * (star), / (slash), " (quote).

49
New cards

Whitelist strategy

"Only these characters are allowed."

50
New cards

Whitelist vs Blacklist

Blacklists require knowing all characters that could cause problems; Whitelists allow only known safe ones.

51
New cards

Regex […] meaning

Match any ONE of those characters.

52
New cards

Regex example: a[bc]d

Matches: abd, acd. Does NOT match: abcd, add.

53
New cards

Regex [^…] meaning

Match anything BUT those characters.

54
New cards

Regex example: a[^bc]d

Matches: add, a7d. Does NOT match: abd, acd.

55
New cards

Regex ranges meaning

[a-d] matches a, b, c, or d.

56
New cards

Regex example: 9[0-9]

Matches: 99, 90, 92. Does NOT match: 9Q, 9a.

57
New cards

Whitelist regex example: [^0-9A-Za-z ]

Matches anything that is NOT a space, a letter, or a number.

58
New cards

Interpretation of Whitelist Regex match

If the input matches the regex (meaning it found a bad character), the input is INVALID.

59
New cards

Avoidance Principle

Write code that assumes less about the input.

60
New cards

Avoidance Example (Authentication Count)

0 means unauthorized; 1 means authorized; Anything else is an error!

61
New cards

Attacker trick: Bad Queries

Intentionally creating a bad query (e.g., invalid attribute name) to see error results.

62
New cards

What raw error messages reveal

Which database is used (Oracle, MySQL), table names, and attribute names.

63
New cards

Error Handling Solution

Turn error messages into something less useful (hide stack traces).

64
New cards

Four ways to Audit Code

Code reviews, Static code analysis, Penetration (pen) testing, Automated tests.

65
New cards

Code Reviews

Experienced developers look at code; spot issues/best practices.

66
New cards

Static Code Analysis

Tools look for known issues (security, memory errors); beyond IDE checks; now uses AI.

67
New cards

Penetration (pen) testing

Developers try to break into your system.

68
New cards

Automated tests

Avoids introducing issues later (regressions).