1 / 30

MySQL Security MySQL User Conference & Expo Tuesday, April 24 th , 2007

MySQL Security MySQL User Conference & Expo Tuesday, April 24 th , 2007. Sheeri Kritzer, MySQL DBA http://www.sheeri.com awfief@gmail.com. Overview. ACLs Test dbs & anonymous accounts OS files and permissions. Overview. Application data flow SQL Injection XSS. ACLs - Who Has Access?.

alpha
Download Presentation

MySQL Security MySQL User Conference & Expo Tuesday, April 24 th , 2007

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MySQL SecurityMySQL User Conference & ExpoTuesday, April 24th, 2007 Sheeri Kritzer, MySQL DBA http://www.sheeri.com awfief@gmail.com

  2. Overview • ACLs • Test dbs & anonymous accounts • OS files and permissions

  3. Overview • Application data flow • SQL Injection • XSS

  4. ACLs - Who Has Access? • SELECT user,host,password FROM mysql.user; • SUPER • Anonymous

  5. ACLs – From where? • % • %.company.com • 192.168.% or 10.0.%

  6. ACLs – From where? • localhost, --skip-networking • firewall • DOS

  7. ACLs – To Do What? • --local-infile=0 • --skip-symbolic-links • GRANT • MAX_QUERIES_PER_HOUR • MAX_UPDATES_PER_HOUR • MAX_CONNECTIONS_PER_HOUR

  8. Server Options • --bind-address • --skip-name-resolve • --skip-show-database

  9. Changing ACLs • How are ACL changes audited? • When do ACL changes happen?

  10. Audit Example - PHP • Create a table for information: CREATE TABLE `action` ( `user` varchar(77) NOT NULL default '', `asuser` varchar(77) NOT NULL default '', `db` varchar(64) NOT NULL default '', `query` mediumtext NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='77=16+1+60';

  11. Audit Example - PHP • Create the function: function my_mysql_query ($query, $dblink) { $action="INSERT INTO action (user,asuser, db,query) VALUES (CURRENT_USER(), USER(), DATABASE(), $query)"; mysql_query($action, $dblink); mysql_query($query, $dblink); }

  12. Audit Example - PHP • Use the function: $result = my_mysql_query($query,$dblink); INSERT INTO action (user, asuser, db, query) VALUES (CURRENT_USER(), USER(), DATABASE(), 'select foo from bar');

  13. Test Databases • Why get rid of them? • Copying tables • Stuff with data

  14. OS Files and Permissions • mysql server user • mysql server files & logs • Passwords on commandline • Office policies/runbook

  15. OS Files and Permissions • Backups • /etc/my.cnf, my.ini, .my.cnf • CLI, GUI tools • Personal history files

  16. How Does Your Data Flow? • Where is user data encrypted? • Where do errors go? • Where does the traffic flow?

  17. Administrative Applications • Same data, different interface • Reporting • VPN • “It's public” vs. “It's easily accessible”

  18. Plaintext Passwords Are Bad! • Storage of customer login • Compromised DB • Transmission of passwords/hashes • Users may use elsewhere

  19. Plaintext Passwords Are Bad! • Where are you encrypting? • Where are you checking?

  20. Validate User Input • ; \g \G ' “ UNION • HTML encoding • NULL / char(0) • VARCHAR and ' '

  21. Validate User Input • Save yourself time • Buffer overflows • CHARSET

  22. Trusting GET or POST • Only from certain pages • Even with valid session ids, cookies • register_globals=off in PHP Test your site! acetunix....

  23. Use Prepared Statements • MySQL • PREPARE stmt1 FROM 'SELECT uname FROM UserAuth WHERE uname=? and pass=?'; • SET @a = "alef"; SET @b = md5("alef"); • EXECUTE stmt1 USING @a, @b;

  24. Use Prepared Statements • MySQL • PREPARE stmt1 FROM 'SELECT uname FROM UserAuth WHERE uname=? and pass=?'; • SET @a = "alef"; SET @b = md5("alef"); • EXECUTE stmt1 USING @a, @b; • SET @a = "alef"; • SET @b = "alef' or 'x'='x"; • EXECUTE stmt1 USING @a, @b; • DEALLOCATE PREPARE stmt1;

  25. Use Prepared Statements • Prepared statement speed • Stored procedures

  26. Prepared Statements - Code • Perl • $query = $sql->prepare("SELECT uname FROM UserAuth WHERE uname = ? AND pass = ?"); • $query->execute($uname, $pass); • PHP • $stmt = $mysqli->prepare("SELECT uname FROM UserAuth WHERE uname = ? AND pass = ?"); • $stmt->bind_param($uname, $pass); • $stmt->execute();

  27. Prepared Statements - Code • Java • PreparedStatement pstmt = con.prepareStatement("SELECT uname FROM UserAuth WHERE uname = ? AND pass = ?"); • pstmt.setString(uname, pass); • ResultSet rset = pstmt.executeQuery();

  28. Prepared Statements - Code • .NET/C# • using(SqlCommand cmd = new SqlCommand("SELECT uname FROM UserAuth WHERE uname = @uname AND pass = @upass”,con)) { • cmd.Parameters.AddWithValue("@userName", userName); • cmd.Parameters.AddWithValue("@pass", pass); • using( SqlDataReader rdr = cmd.ExecuteReader() ){ • ...} • }

  29. Encryption • SSL is per-client • Unencrypted MySQL data streams shell> tcpdump -l -i eth0 -w -src or dst port 3306 | strings

  30. Feedback? • Other ideas....

More Related