1 16-Databases


Previous: 15-BufferOverflow.html

1.1 Exploits of a mom

16-Databases/exploits_of_a_mom.png

1.2 Jokes of a dad

Where do I keep all these dad jokes?
In a dadabase…

1.3 Screencasts

1.4 Database Security

Computers are mostly used for storing stuff, and most of that stuff is in databases…

1.4.1 DBMS

DataBase Management System

What is a Database?

16-Databases/f1-crop.png

1.4.2 Relational Databases

Multi-table database with unifying primary key:
16-Databases/f2-crop.png

Relational Database Elements
16-Databases/image7.png

Primary key

Foreign key

View/virtual table

Relational Database
16-Databases/f3-crop.png

View on a Database
16-Databases/f4-crop.png

1.4.3 Structured Query Language (SQL)

https://www.w3schools.com/sql/default.asp (Read this guide if you want to know about Web security!)

Table Creation

CREATE TABLE department
(
   Did INTEGER PRIMARY KEY,
   Dname CHAR (30),
   Dacctno CHAR (6)
)

Table Creation

CREATE TABLE employee
(
   Ename CHAR (30),
   Did INTEGER,
   SalaryCode INTEGER,
   Eid INTEGER PRIMARY KEY,
   Ephone CHAR (10),
   FOREIGN KEY (Did) REFERENCES department (Did)
)

Retrieving Information

SELECT Ename, Eid, Ephone
   FROM Employee
   WHERE Did = 15

This query returns the Ename, Eid, and Ephone fields from the Employee table for all employees assigned to department 15

View Creation
The view in Figure 5.4(b) above is created using the following SQL statement:

CREATE VIEW newtable (Dname, Ename, Eid, Ephone)
   AS SELECT D.Dname E.Ename, E.Eid, E.Ephone
   FROM Department D Employee E
   WHERE E.Did = D.Did

1.5 SQL Injection Attacks (SQLi)

https://en.wikipedia.org/wiki/Sql_injection
https://www.w3schools.com/sql/sql_injection.asp (part of the above-referenced tutorial)
https://www.hacksplaining.com/exercises/sql-injection (Good interactive exercise; show in class)

SQLi overview
16-Databases/f5-crop.png

1.5.1 Injection technique

1.5.1.1 Example

As a simple example, consider a script that build an SQL query by combining predefined strings with text entered by a user:

var Shipcity;
ShipCity = Request.form ("ShipCity");
var sql = "select * from OrdersTable
where ShipCity = ' " +
ShipCity + " ' ";

The intention of the above script’s designer is that a user will enter the name of a city.

Example usage
When the script is executed, the user is prompted to enter a city, and if the user enters Boston, then the following SQL query is generated:
'SELECT * FROM OrdersTable WHERE ShipCity = 'Boston

Example attack
Suppose, however, the user enters the following:
'Boston'; DROP table OrdersTable--

This results in the following SQL query:
'SELECT * FROM OrdersTable WHERE ShipCity = 'Boston'; DROP table OrdersTable--

SQLi Attack Avenues

1.5.2 Attack Types

1.5.2.1 In-band Attacks

1.5.2.2 Tautology Example

1.5.2.3 Inferential Attack

1.5.2.4 Out-of-Band Attack

1.5.3 SQLi Countermeasures

1.5.3.1 Defensive Coding

1.5.3.2 Detection

1.5.3.3 Run-time Prevention

1.6 Database Access Control

1.6.1 SQL Access Controls

Two commands for managing access rights:

  1. Grant: Used to grant one or more access rights or can be used to assign a user to a role
  2. Revoke: Revokes the access rights

Typical access rights are:

The grant command

GRANT {privileges | role}
[ON table]
TO {user | role | PUBLIC}
[IDENTIFIED BY password]
[WITH GRANT OPTION]

Example:
GRANT SELECT ON ANY TABLE TO rifclair

REVOKE {privileges | role}
[ON table]
FROM {user | role | PUBLIC}

REVOKE SELECT ON ANY TABLE FROM ricflair

Cascading Authorizations

Privilege Revocation
16-Databases/f6-crop.png

1.7 Role-Based Access Control (RBAC)

1.7.1 Categories of Database Users

Microsoft SQL Server Roles
16-Databases/image13.png

1.8 Inference Attacks

1.8.1 Attack Method

What is an Inference Attack?

Inference Attacks
16-Databases/f7-crop.png

Example of an Inference Attack on (Salary-Name)
16-Databases/f8-crop.png

1.8.2 Inference Detection

+++++++++++++++++++
Cahoot-16.1

1.9 Database Encryption

1.9.1 Remote Encryption

Database Encryption

How to Process Encrypted Query

  1. The user issues an SQL query for fields from one or more records with a specific value of the primary key
  2. The query processor at the client encrypts the primary key, modifies the SQL query accordingly, and transmits the query to the server
  3. The server processes the query using the encrypted value of the primary key and returns the appropriate record or records
  4. The query processor decrypts the data and returns the results

Database Encryption: Decrypt only Locally
16-Databases/f9-crop.png

Encrypted Query, where database is stored in encrypted form, and thus queries are made for ciphertext itself, as far as the database is concerned.

SELECT Ename, Eid, Ephone
   FROM Employee
   WHERE Did = 15
SELECT Ename, Eid, Ephone
   FROM Employee
   WHERE Did = 1000110111001110

1.9.2 Indexing on Encrypted Data

16-Databases/f10-crop.png
16-Databases/pasted_image.png

Next: 17-DefensiveProgramming.html