Database Management Systems

  • Database: 結構化的資料集合,供應用程式使用
  • Query language: 提供一個統一的介面來存取資料庫
  • Database management system (DBMS): 一組用來建立與維護資料庫的程式
    • DDL (Data Definition Language): 定義資料庫的邏輯結構與程序性屬性
    • DML (Data Manipulation Language): 提供應用程式開發者強大的工具集合
    • 需要超出一般作業系統型安全機制的安全能力
      • OS: 控制整個檔案的讀寫權限
      • Database: 需要 col & row level 的權限

Relational Databases

  • 由 tables 所構成
  • 每一個 column 儲存一種特定型態的資料
  • 每一列 row 包含每個 column 的一個具體值
  • 理想情況下,會有一個 column,其所有值都是唯一的,用來作為該 row 的 identifier/key (primary key)
  • 使用 query language 來存取符合特定條件的資料

Relational Database Elements

  • Relation/table/file
  • Tuple/row/record
  • Attribute/column/field

  • Primary key
    • 唯一識別一個 row
    • 由一個或多個 column names 組成
  • Foreign key
    • 將一個資料表連結到另一個資料表的欄位
  • View / virtual table
    • 是一個查詢的結果,會回傳從一個或多個 tables 中選出的 rows & columns

SQL Injection Attacks

最普遍且最危險的網路安全威脅之一

  • 被設計用來利用 Web 應用程式頁面的特性
  • 將惡意的 SQL 指令送到資料庫伺服器
  • 常見目標:
    • 大量竊取資料
    • 修改或刪除資料
    • 執行任意作業系統指令
    • 發動 DoS

Injection Technique

  • 典型的 SQL 注入攻擊: 提早結束原本的字串,並附加新的指令
  • Comment mark “--”: 後面的文字在執行時會被忽略
  • 考慮一個程式,它將預先定義的字串與使用者輸入的文字組合成 SQL 查詢
1
2
3
var Shipcity;
ShipCity = Request.form (“ShipCity”);
var sql = “select * from OrdersTable where ShipCity = ‘” + ShipCity + “’”;

輸入 Redmond’; DROP table OrdersTable--,變成:

1
2
select * from OrdersTable where ShipCity = 'Redmond'; 
DROP table OrdersTable--'

SQLi Attack Avenues

  • User input
    • 透過精心設計的使用者輸入來注入 SQL 指令
  • Physical user input
    • 發生在 Web 請求之外的攻擊
    • ex: 傳統條碼與 RFID 標籤
  • Server variables
    • ex: HTTP headers and network protocol headers
  • Second-order injection
  • Cookies

Example I: from User Input

1
2
strSQL = “SELECT * FROM users WHERE (name = ‘” + username + “’) and
(pw = ‘” + password + “’);
  • Target: “SELECT * FROM users;”
  • username: 1’ OR ‘1’=‘1
  • password: 1’ OR ‘1’=‘1
    • 後面是一定會成立的條件

Example II: from Server Variables

  • Web 應用程式會以多種方式使用這些變數,例如記錄使用統計資料
  • 攻擊者可以偽造 HTTP 與網路標頭中的值
    • ex: HTTP 請求的標頭
1
2
3
4
5
6
function ip_adr() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip_adr = $_SERVER['HTTP_X_FORWARDED_FOR']; }
else { $ip_adr = $_SERVER["REMOTE_ADDR"]; }
return $ip_adr;
}
  • How to launch an SQLi attack with HTTP_X_FORWARDED_FOR?
    • X_FORWARDED_FOR :127.0.0.1' or 1=1#
    • 相同原理

Example III: from Second-order Injection

  • 依賴系統或資料庫中已存在的資料來觸發攻擊
  • 考慮一個 Web 應用程式,會將使用者名稱與其他 session 資訊一起儲存
  • 給定一個 session 識別碼 (ex: cookie)
  • 先取得目前的 username,再用它去取得 SSN
1
2
“SELECT username FROM sessiontable WHERE session=‘”$_POST[‘sessionid’].”’”
“SELECT ssn FROM users WHERE username=‘”$_POST[‘username’].”’”
  • How to launch an SQLi attack with existing data?
    • username: XXX' OR username='JANE

Three Categories of SQLi Attacks

  • In-band attacks: 使用相同的通訊管道來注入 SQL 指令並取得結果
    • Tautology
      • 在一個或多個條件判斷中注入程式碼,使條件永遠為真
    • End-of-line comment
      • 在某個欄位注入程式碼後,後續的合法程式碼會被行尾註解符號取消執行
    • Piggybacked queries
      • 攻擊者在原本合法查詢後面附加額外 SQL 查詢,將攻擊附掛在正常請求上
  • Out-of-band attacks
    • 使用不同的通訊管道
      • ex: email
    • 當資訊無法透過正常方式取得,但資料庫伺服器的對外連線限制較寬鬆時使用
  • Inferential attacks
    • 沒有實際資料傳輸,而是透過發送特定請求並觀察回應來重建資料
    • Illegal/logically incorrect queries
      • 預設錯誤頁面過於詳細
      • 可收集 Web 應用後端資料庫的類型與結構等重要資訊
      • 被視為其他攻擊的前置資訊收集步驟
    • Blind SQL injection
      • 像是在問 true/false 問題
      • 即使系統夠安全、不回傳錯誤訊息,仍可推論資料庫中的資料

Countermeasures

  • Defensive coding
    • 手動的防禦性程式設計方法
    • Parameterized query insertion 參數化查詢
    • SQL DOM (Document Object Model)
  • Detection
    • Signature based: 特徵
    • Anomaly based: 異常行為
    • Code analysis
  • Run-time prevention
    • 在執行時檢查 SQL 查詢是否符合預期的查詢模型

Database Access Control

  • 假設使用者已經通過身分驗證,他們可能可以存取整個資料庫,或只是其中一部分
  • 商業與開源 DBMS 支援 DAC 或 RBAC
  • 管理政策類型:
    • Centralized administration
      • 少數具有特權的使用者可以授權或撤銷存取權限
    • Ownership-based administration
      • 資料表的建立者可以授權或撤銷該表的存取權限
    • Decentralized administration
      • 資料表擁有者可以授權或撤銷其他使用者的權限
      • 其他使用者也可以再授權或撤銷存取權限

Cascading Authorizations

  • Grant/Revoke options:
    • 可以讓存取權限在多個使用者之間傳遞 (cascade)不傳遞
    • Revoke convention
      • 當使用者 A 撤銷某個存取權限時,所有由此連鎖授權出去的權限也會被撤銷
      • 除非該權限即使沒有 A 當初的授權也仍然存在

Inference

  • 透過執行被授權的查詢,並從合法回應中推導出未被授權的資訊的過程
    • 多個資料項目的組合資訊: 可能比單一資料項目更敏感
  • Metadata: 關於資料項目之間相關性或依賴性的知識
  • Inference channel: 一種資訊傳遞路徑,透過它可以取得未被授權的資料

Example

  • Users of the views are not authorized to access the relationship between Salary and Name
  • However, it can be referred by the combination of the views
    • Knowledge of the table structure is needed

Inference Detection

  • 在資料庫設計階段進行 Inference detection
    • 透過改變資料庫結構來移除 Inference channel
      • ex: 將一個表拆成多個表,或使用更細粒度的存取控制
    • Availability 降低: 因為存取控制變得不必要地嚴格
  • 在查詢執行時進行 Inference detection
    • 在單次或一系列查詢時,消除 Inference channel
  • 需要某種 inference detection algorithm: 仍在研究中

Example

  • 考慮一個資料庫,包含人事資訊,例如員工的姓名、地址與薪資

    • Clerk: 只能看到姓名、地址與薪資資訊
    • Administrator: 可以看到姓名、地址、薪資,以及姓名與薪資的對應關係
  • 解法: 建立三個資料表

    • Employees (Emp#, Name, Address)
    • Salaries (S#, Salary)
    • Emp-Salary (Emp#, S#)
  • What if a new attribute, employee start date, is needed?

    • Where should it be added?
    • Employees table: 屬於員工本身的 attribute

Database Encryption

  • 資料庫通常是任何組織中最有價值的資訊資源
    • 由多層安全機制保護
      • Firewalls, authentication, general access control systems, DB access control systems, etc.
      • 加密是資料庫安全的最後一道防線
  • 應用範圍:
    • entire database
    • record level (rows)
    • attribute level (columns)
    • level of the individual field (specific fields)
  • 缺點:
    • Inflexibility: 很難進行資料搜尋
    • Key management: 授權使用者必須擁有 decryption key 才能存取資料

A Database Encryption Scheme

  • Data owner
    • 產生資料的組織,負責將資料提供出去,但要進行受控釋出 (controlled release)
  • User
    • 提出查詢請求的人類個體
  • Client
    • 前端系統,負責把使用者查詢轉換成對伺服器上加密資料的查詢
  • Server
    • 接收資料擁有者的加密資料,並提供給 client 進行存取的組織

Example

Straightforward Approach

考慮:

1
2
3
SELECT Ename, Eid, Ephone
FROM Employee
WHERE Did = 15
  • 假設使用加密金鑰 k
  • Ek(15)E_k(15) = 1000110111001110

Client 端會把查詢轉換成

1
2
3
SELECT Ename, Eid, Ephone  
FROM Employee
WHERE Did = 1000110111001110
  • It seems straightforward and sufficient, but what if the query is to retrieve all records with the Dids smaller than 100?

Flexible approach

  • 資料表中的每一筆 record (row) 都會被加密成一個 block
  • RiR_i: a continuous block Bi=(xi1xi2xiM)B_i= (x_{i1}| x_{i2} | ⋯ ||x_{iM})
  • 所有 attribute values 會被串接起來,形成一個 single binary block
  • 資料查詢時: 每個 table 會搭配 attribute index
  • 對每個 attribute 而言,其數值範圍會被切成互不重疊的區間 (non-overlapping partitions)
    • ex: employee ID (eid):
      • Index 1: [1, 200]
      • 2: [201, 400]
      • 3: [401, 600]
      • 4: [601, 800]
      • 5: [801, 1000]

Cloud Computing

NIST SP-800-145 defines cloud computing as:

A model for enabling ubiquitous, convenient, ondemand network access to a shared pool of configurable computing resources (e.g., networks, servers, storage, applications, and services) that can be rapidly provisioned and released with minimal management effort or service provider interaction.

Cloud Service Models

  • Software as a service (SaaS)
    • using software installed on clouds via web browsers
  • Platform as a service (PaaS)
    • enabling customers to developing their own applications running on operating systems provided by clouds
  • Infrastructure as a service (IaaS)
    • enabling customers to install their own operating systems (Amazon EC2 and Windows Azure)
    • Clouds provide hardware (virtualization of hardware)

Containers vs. Virtual Machines

Cloud Security Risks and Countermeasures

  • 濫用與惡意使用雲端運算: 註冊容易、有免費試用
    • 更嚴格的註冊流程
    • 監控流量
  • 不安全的介面與 API: API 對客戶開放
    • 分析安全模型
    • 強化身分驗證與存取控制
    • 了解 dependency chain
  • 惡意內部人員: 某些 roles 權限過高
    • 強化管理
    • 提高透明度
    • 資安事件通報
  • 共用技術問題: IaaS 共用基礎設施、IaaS 共用基礎設施
    • 使用 VM 隔離
    • 安全安裝與設定
    • 監控、掃描、稽核
    • 強化驗證與存取控制
  • 資料遺失或外洩
    • 強化 API 存取控制
    • 保護資料完整性
    • 資料保護分析
    • 強化管理
  • 帳號或服務被劫持: 帳密被竊
    • 禁止帳密共享
    • 使用雙重驗證 (2FA)
    • 監控
  • 不明風險 profile
    • 提供 log 與資料透明度
    • 公開基礎設施資訊 (部分或全部)
    • 監控與警示

Cloud Security as a Service

  • 將安全功能外包/轉移到雲端
    • Authentication, anti-virus, antimalware/spyware, intrusion detection, security event management, etc.

紅字整理

P5: DBMS Architecture, Security requirements: beyond the capability of typical OS-based security Why?

  • OS: typically control read and write access to entire files
  • Database: 需要 col & row level 的權限

P17: SQLi Example I: from User Input, How to bypass the verification check?

  • username: 1’ OR ‘1’=‘1
  • password: 1’ OR ‘1’=‘1
  • 在輸入後面放個一定會成立的條件

P17: SQLi Example II: from Server Variables, How to launch an SQLi attack with “HTTP_X_FORWARDED_FOR”?

  • X_FORWARDED_FOR :127.0.0.1' or 1=1#

P36: Example: Inference Problem and Solution, What if a new attribute, employee start date, is needed? Where should it be added?

  • Employees table: 屬於員工本身的 attribute