Database System Security: Paul Wagner, Wagnerpj@uwec - Edu
Database System Security: Paul Wagner, Wagnerpj@uwec - Edu
Paul Wagner, [email protected] UW-Stout Information and Cyber Security Workshop 8/24/2006
Background
Need
Background (cont.)
Goals
Consider database security issues in context of general security principles and ideas Consider issues relating to both database storage and database system communication with other applications
Main Message
Database system security is more than securing the database
Secure database Secure DBMS Secure applications / application development Secure operating system in relation to database system Secure web server in relation to database system Secure network environment in relation to database system
Secure databases
Database a domain-specific collection of data; e.g. an Employee database Historical database security topics and issues
Users, Passwords
Default users/passwords
Oracle: sys, system accounts privileged (Oracle 8i and prior - with default passwords) Oracle: scott account well-known account and password, part of public group e.g. public can access all_users table general password policies (length, domain, changing, protection)
System - actions Objects data Collections of system privileges Giving (removing )privileges or roles to (from) users
Roles
Grant / Revoke
Secure DBMS
Database Management System (DBMS) the domainindependent set of software used to manage and access your database(s) Possible Holes in DBMS
http://technet.oracle.com/deploy/security/alerts.htm (50+ listed) Majority of problems - buffer overflow problems in (legacy) DBMS code Miscellaneous attacks (Denial of Service, source code disclosure of JSPs, others) Oracle example - UTL_FILE package in PL/SQL
allows read/write access to files in directory specified in utl_file_dir parameter in init.ora possible access through symbolic links
SQL Injection
SQL Injection
Typical scenario
Three-tier application (web interface, application, database) Overall application tracks own usernames and passwords in database (advantage: can manage users in real time) Web interface accepts username and password, passes these to application layer as parameters
Note: String values must be single quoted in SQL, so application provides this for each passed string parameter Expecting one row to be returned if success, no rows if failure Common variant SELECT COUNT(*) FROM
Attacker enters:
any username (valid or invalid) password of: Aa OR =
Query becomes: SELECT * FROM users_table WHERE username = anyname AND password = Aa OR = ; Note: WHERE clause => F and F or T => F or T => T
AND has higher precedence than OR
All user/pass rows returned to application If application checking for 0 vs. more than 0 rows, attacker is in
Variable interpolation String concatenation with variables and/or constants String format functions like sprintf() String templating with variable replacement
-; %
// SQL comment character // SQL command separator // SQL LIKE subclause wildcard character
Note: -- comments out rest of line, including terminating single quote in application
Query becomes: SELECT * FROM users_table WHERE username = anyname AND password = OR 1=1--;
SELECT * FROM users_table WHERE username = anyname AND password = foo; // returns nothing DELETE FROM users_table WHERE username LIKE %
User creates account with user = root-Application escapes and inserts as root-User resets password Your query fetches username from database to verify account exists with correct old password UPDATE users_table SET PASSWORD=pass WHERE username = root-- NOTE: above scenario allows user to reset the password on the real root account
Use Prepared Statements instead of regular Statements in your SQL code Regular Statements
SQL query is generated entirely at run-time Custom procedure and data are compiled and run
Compilation allows combination of procedure and data, allowing problems with SQL metacharacters
String sqlQuery = null; Statement stmt = null; sqlQuery = "select * from users where " + "username = " + "'" + fe.getUsername() + "'" + " and " + "upassword = " + "'" + fe.getPassword() + "'"; stmt = conn.createStatement(); rset = stmt.executeQuery(sqlQuery);
Prepared Statements
SQL query is precompiled with placeholders Data is added in at run-time, converted to correct type for the given fields
String sqlQuery = null; PreparedStatement pStmt = null; sqlQuery = "select * from users where username = ? and upassword = ?"; pStmt = conn.prepareStatement(sqlQuery); pStmt.setString(1, fe.getUsername()); pStmt.setString(2, fe.getPassword()); rset = pStmt.executeQuery();
E.g. our use for username field value, password field value
Example: if also asking user for information that determines choice of table name, cannot use a prepared statement
Most common client applications (vendor-supplied or user-programmed) at least encrypt the connection password Some clients encrypt the connection user Certain DBMSs have varying levels of security (e.g. PostgreSQL) One DBMS transmits the connection password length (MS SQL Server 2005 Express)
J2EE JDBC, Servlets, JSPs, JNDI, EJBs, .NET many components Assume network filtering most evil traffic Application can control fine-grain behavior, application protocol security
Role Pattern
disassociation of users and privileges
Windows
Secure administrative accounts Control registry access Need good account policies Others
Linux/Unix
Choose different account names than standard suggestions Restrict use of the account that owns Oracle software Secure temporary directory Some Oracle files are SUID (root) Command line SQL*Plus with user/pass parameters appears under ps output Others
Ensure secure communication from web clients to web server Use MaxClients to limit possible connections Others
Integration with other MS products (e.g. Exchange Server) Many known vulnerabilities over recent versions (patches available) Others
Secure Network
Interaction of Oracle and Network
Miscellaneous Issues
Newer Oracle Security Features
Virtual Private Databases (VPDs) Oracle Label Security Good policy: develop a comprehensive audit system for database activity tracking
Can write to OS as well as into database for additional security, accountability for all working with databases
Auditing
Exercise
Overall Security Examination of Oracle in Networked Environment
3) Application:
Test for SQL Injection, other application weaknesses
Exercise (cont.)
Similar types of tasks for OS, Web Server, Network components Task: develop report, including specifics for all areas
References
Oracle Security Handbook by Theriault and Newman; Osborne/Oracle Press, 2001. Oracle Database Administration: The Essential Reference, Kreines and Laskey; OReilly, 1999. Pete Finnigans Oracle Security web site, http://www.petefinnigan.com/orasec.htm James Waldens SIGCSE 2006 workshop on Software Programming Security: Buffer Overflows and Other Common Mistakes Eric Lobner, Matthew Giuliani, Paul Wagner; Investigating Database Security in a Network Environment, paper published at MICS 2006, www.micsymposium.org