SQL Server Security - Attack


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

SQL Server Security - Attack

  1. 1. SQL Server Security Attack & Defense Chip Andrews (www.sqlsecurity.com) January 2003 AtlantaMDF Users Group
  2. 2. Presentation Outline <ul><li>Introduction </li></ul><ul><li>Attack </li></ul><ul><ul><li>Fingerprinting </li></ul></ul><ul><ul><li>Account Acquisition </li></ul></ul><ul><ul><li>Privilege Escalation </li></ul></ul><ul><ul><li>SQL-Injection </li></ul></ul><ul><li>Defense </li></ul><ul><ul><li>Tools (Scanners/Patches) </li></ul></ul><ul><ul><li>Hardening Scripts </li></ul></ul><ul><ul><li>Secure Deployment </li></ul></ul><ul><ul><li>Input Validation </li></ul></ul><ul><ul><li>Best-Practices </li></ul></ul>
  3. 3. SQL Server Presence <ul><li>Biztalk Server 2000 </li></ul><ul><li>Commerce Server 2000 </li></ul><ul><li>Application Center Server 2000 </li></ul><ul><li>Third-Party Apps (SQL/MSDE) </li></ul><ul><ul><li>Tumbleweed Worldsecure </li></ul></ul><ul><ul><li>Valadeo Technologies, Inc. </li></ul></ul><ul><ul><li>O’Reilly & Associates, Inc. (WebBoard) </li></ul></ul><ul><ul><li>Telemate.net </li></ul></ul><ul><li>Hierarchical File systems looming in the future (rumored link between Yukon and Longhorn development) </li></ul>
  4. 4. MSDE Proliferation <ul><li>Microsoft SQL Server Desktop Engine </li></ul><ul><li>(formerly the Microsoft Data Engine) </li></ul><ul><li>Development methodologies (agile) often suggest each developer (or team) have a local database instance </li></ul><ul><ul><li>http://martinfowler.com/articles/evodb.html </li></ul></ul><ul><li>Visual Studio.NET installs MSDE (vsDotNet/NetSDK) </li></ul><ul><li>.NET Framework SDK (required for samples) </li></ul><ul><li>Office XP </li></ul>
  5. 5. Section 1 - Attack <ul><li>Fingerprinting/Discovery </li></ul><ul><li>Acquiring Access </li></ul><ul><li>Privilege Escalation </li></ul><ul><li>Backdoors </li></ul><ul><li>Covering tracks </li></ul>
  6. 6. Discovery - Target Acquisition <ul><li>Server fingerprinting via IP stack identification </li></ul><ul><ul><li>Nmap/nmapnt </li></ul></ul><ul><ul><ul><ul><li>www.insecure.org/nmap </li></ul></ul></ul></ul><ul><ul><ul><ul><li>www.eeye.com </li></ul></ul></ul></ul><ul><li>IIS Web Servers - a good bet SQL Server is driving it </li></ul><ul><ul><li>telnet targetname 80 </li></ul></ul><ul><ul><li>HEAD / HTTP/1.0 </li></ul></ul><ul><ul><li>www.netcraft.com </li></ul></ul><ul><li>Dig for hints about target database usage </li></ul><ul><ul><li>Newsgroups </li></ul></ul><ul><ul><ul><li>Groups.google.com </li></ul></ul></ul><ul><ul><ul><li>SQL discussion boards (www.swynk.com) </li></ul></ul></ul><ul><ul><li>Job Postings </li></ul></ul><ul><ul><ul><li>Corporate website (click ‘careers’) </li></ul></ul></ul><ul><ul><ul><li>www.monster.com etc. </li></ul></ul></ul>
  7. 7. Discovery - Port Scanning <ul><li>Use nslookup / whois to determine IP addresses </li></ul><ul><ul><li>whois “target.”@whois.arin.net </li></ul></ul><ul><li>TCP port 1433 (and 2433) </li></ul><ul><ul><li>SQL Server defaults to listen on these ports since ip-sockets net-lib is installed by default (along with named pipes) </li></ul></ul><ul><ul><li>Hosting providers are particularly juicy targets </li></ul></ul><ul><li>UDP port 1434 (SQL Server Resolution Service) </li></ul>
  8. 8. SQL Server Discovery – UDP 1434 <ul><li>Multiple instancing capabilities of SQL Server 2000 make enumeration a functional requirement </li></ul><ul><li>A specially formed UDP packet directed at port 1434 will cause the SQL 2K listener service to divulge information about every instance of SQL Server running on that machine </li></ul><ul><ul><li>Packet Information </li></ul></ul><ul><ul><ul><li>Version (Inaccurate – does not show patch level) </li></ul></ul></ul><ul><ul><ul><li>Instance names </li></ul></ul></ul><ul><ul><ul><li>Net-libs supported </li></ul></ul></ul><ul><ul><ul><li>TCP ports and pipe names </li></ul></ul></ul><ul><ul><ul><li>Clustered status (bullseye!) </li></ul></ul></ul>
  9. 9. Broadcast Discovery <ul><li>Since the listener may exist on multiple machines, it is possible to send a broadcast UDP packet to port 1434 to discover all instances of SQL Server 2000 on a subnet </li></ul><ul><ul><li>Osql –L (will return a raw listing) but only of server names and only via broadcast to </li></ul></ul><ul><ul><li>Network subnets such as 192.168.1.x (with a mask) can be scanned using a single packet directed at </li></ul></ul><ul><ul><li>Any network class works find (Class A, B, C) </li></ul></ul>
  10. 10. SQLPing Utility <ul><ul><ul><li>Directs a custom udp packet at a specific target or subnet and enumerates the server info across multiple instances </li></ul></ul></ul>SQLPinging Listening.... ServerName:LANDROVER InstanceName:SQL2K IsClustered:No Version:8.00.194 tcp:1241 np:ANDROVERpipeMSSQL$SQL2Ksqlquery ServerName:LANDROVER InstanceName:MSSQLServer IsClustered:No Version:7.00.623 np:ANDROVERpipesqlquery tcp:1433 rpc:LANDROVER http://www.sqlsecurity.com
  11. 11. Discovery – Service Enumeration <ul><li>sc achine_name query bufsize= 60000|find “MSSQL” </li></ul><ul><li>Requires Windows authenticated user and NetBIOS connectivity </li></ul><ul><li>Easily scriptable (replace machine name with IP address) </li></ul><ul><li>Provides a way to see where SQL Servers exist on hosts even the server is not running or SQL TCP ports have been blocked </li></ul>
  12. 12. Account Acquisition <ul><li>Common Accounts </li></ul><ul><ul><li>Sa (In the name of all that is holy – do not leave this blank) </li></ul></ul><ul><ul><li>distributor_admin (nor this one…) </li></ul></ul><ul><li>Brute Force (mixed security model) </li></ul><ul><ul><li>Attacks the inherent weakness of the native SQL Server security model </li></ul></ul><ul><ul><li>Multiple freeware tools (sqldict, sqlpoke,sqlbf) </li></ul></ul><ul><ul><li>Mssqlserver lacks account lockouts or password complexity requirements </li></ul></ul><ul><ul><li>Do we even need to mention null ‘sa’ account passwords? </li></ul></ul>
  13. 13. Account Acquisition (cont.) <ul><li>Connection strings (mixed mode) </li></ul><ul><ul><li>Client registry (regedit) </li></ul></ul><ul><ul><li>Imbedded in ASP source or client-side script (RDS) </li></ul></ul><ul><ul><li>Config files (global.asa, connect.inc, web.config) </li></ul></ul><ul><li>Source code disclosure </li></ul><ul><ul><li>IIS has had plenty (online.securityfocus.com) </li></ul></ul><ul><li>Sniffing (mixed or NT security mode) </li></ul><ul><ul><li>Wifi networks </li></ul></ul><ul><ul><li>L0phtcrack (to obtain NT account) </li></ul></ul><ul><ul><li>Sniffing SQL (TCP 1433) traffic (non SSL/RPC) </li></ul></ul><ul><ul><ul><li>Plaintext transmission of credentials </li></ul></ul></ul><ul><ul><ul><li>Passwords trivially obfuscated (combination of Unicode sprinkled with an XOR operation) </li></ul></ul></ul>
  14. 14. De-obfuscating SQL Server Passwords s s a P Text 73 73 61 70 Hex 0111 0011 0111 0011 0110 0001 0111 0000 XOR 0101 1010 0101 1010 0101 1010 0101 1010 5A 0010 1001 0010 1001 0011 1011 0010 1010 Binary 29 29 3B 2A Swap Digits 92 92 B3 A2 Hex
  15. 15. Account Acquisition - SQL Injection <ul><li>Defined: The introduction of unintended SQL code to an application’s database at runtime. </li></ul><ul><li>This effectively provides an attacker with a SQL Server account by using your application as a middle-man in the attack </li></ul><ul><li>SQL injection attacks rarely alerts IDS systems (worsened by SSL) </li></ul><ul><li>Difficult to track down all the areas of exploitation since the only real solution is manual code review </li></ul><ul><li>No amount OS security, firewalls, patch diligence will stop SQL injection. </li></ul><ul><li>The best solution is good coding practices </li></ul>
  16. 16. SQL Injection Sample <ul><li>ASP Code Sample </li></ul><% Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;) Conn.open “dsn=myapp;Trusted_Connection=Yes“ Set RS = Conn.Execute(&quot;SELECT * from book_list where book_name=‘&quot; & request.form(“txtBookname”) & “’) %>
  17. 17. SQL Injection Sample Cont. <ul><li>Consider if the attacker searches for a book named: </li></ul><ul><ul><li>‘ union select name from sysobjects-- </li></ul></ul><ul><li>Single quote closes the intended statement </li></ul><ul><li>Union statement appends a new dataset to the query so the attacker can see information he wants </li></ul><ul><li>Could just as easily call any stored procedure or DDL command the attacker wanted given appropriate level of privilege </li></ul>
  18. 18. SQL Injection - Tricks <ul><li>Tricks attackers use </li></ul><ul><ul><li>UNION statements to append data ripped from other SQL </li></ul></ul><ul><ul><li>“—” double hyphen comment indicator to block out the rest of the intended SQL </li></ul></ul><ul><ul><li>Try a single quote in input fields to see if the query fails (failure usually indicates bad input validation and possible exploitation) </li></ul></ul><ul><ul><li>exec master..xp_cmdshell ‘ping HACKER_IP’ to check for ‘sa’-level exploitable hosts </li></ul></ul><ul><ul><li>select name from sysobjects where type = ‘u’ can expose tables to exploit </li></ul></ul><ul><ul><li>Insert tablename exec sp_whatever – good way to see output of stored procedures </li></ul></ul><ul><ul><li>Use @@version to return SQL Server and OS versions and Service Packs </li></ul></ul>
  19. 19. Account Acquisition – Buffer Overflows <ul><li>By overflowing buffers on listening ports it is possible to gain a system shell on an un-patched target server with the privilege level of the SQL Server service account (often LocalSystem) </li></ul><ul><li>There are known attacks against both the SQL Resolution service by David Litchfield ( http://online.securityfocus.com/bid/5311 ) and the TCP SQL Service listener “Hello Bug” by Dave Aitel (http://lists.insecure.org/lists/pen-test/2002/Aug/0016.html) </li></ul><ul><li>Exploit code for both is “in the wild” </li></ul><ul><li>Buffer overflows exist externally as well as internally (privilege escalation) through server functions and extended stored procedures </li></ul>
  20. 20. Privilege Escalation <ul><li>Primary methods </li></ul><ul><ul><li>Un-patched Server bugs such as </li></ul></ul><ul><ul><ul><li>_Many_ extended stored procedure privilege escalation attacks </li></ul></ul></ul><ul><ul><ul><li>Multiple Openrowset vulnerabilities </li></ul></ul></ul><ul><ul><ul><li>Check online.securityfocus.com/bid for the latest </li></ul></ul></ul><ul><ul><li>Trojan stored procedures (sp_who for example) </li></ul></ul><ul><ul><li>Deferred compilation (EXECUTE) </li></ul></ul>
  21. 21. Privilege Escalation (cont.) <ul><li>Other methods </li></ul><ul><ul><li>xp_regread (registry enumeration) </li></ul></ul><ul><ul><ul><li>Any normal user can see the service context via </li></ul></ul></ul><ul><li>master..xp_regread 'HKEY_LOCAL_MACHINE' ,'SYSTEMCurrentControlSetServicesMSSQLSERVER','ObjectName' </li></ul><ul><ul><li>Openrowset – heterogeneous queries can allow attackers to brute-force their way into other systems </li></ul></ul><ul><ul><li>Errors in extended stored procedures and system stored procedures </li></ul></ul><ul><ul><ul><li>SQLAgent Jobs - http://www.ngssoftware.com/advisories/mssql-esppu.txt </li></ul></ul></ul><ul><ul><ul><li>Webtasks </li></ul></ul></ul><ul><ul><ul><li>http://www.ngssoftware.com/advisories/mssql-webtasks.txt </li></ul></ul></ul><ul><ul><ul><li>The list goes on…. </li></ul></ul></ul><ul><ul><ul><ul><li>See online.securityfocus.com for a complete listing </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Bottom Line: if you are not keeping up with patches then any user with SQL Server access can trivially elevate privilege unless extensive steps have been taken </li></ul></ul></ul></ul>
  22. 22. They’re in as sysadmins - Now What? <ul><li>Create a backdoor SQL or NT account </li></ul><ul><li>Insert trojan extended stored procedures to capture passwords/data/events </li></ul><ul><li>Use tftp to pull in toolkits </li></ul><ul><li>Use this SQL Server to launch attacks against other hosts </li></ul><ul><li>Install proxy server to make this machine a platform for further attackers on other systems </li></ul><ul><li>Take your data and make you suffer </li></ul><ul><li>As usual – possibilities are limited only by the imagination </li></ul>
  23. 23. Attack Conclusion <ul><li>Take time to put yourself in the place of someone who really wants to get at you or your employer </li></ul><ul><ul><li>How far can you get? </li></ul></ul><ul><ul><li>What if the attacker is a former employee? </li></ul></ul><ul><ul><li>Do our defenses match the threat and risk levels? </li></ul></ul><ul><ul><li>Would be even be aware if we were under attack? </li></ul></ul><ul><li>Scan your networks and determine what people on the inside and the outside can access </li></ul><ul><li>Brute-force your own systems to be sure password complexity and account policies (if using Windows security) are sufficient </li></ul><ul><ul><li>Multitude of free tools at www.sqlsecurity.com </li></ul></ul>
  24. 24. Defense <ul><li>What can you do to protect against each level of attack? </li></ul><ul><li>How do I keep up to date with patches without an army of admins? </li></ul><ul><li>What are some general defensive guidelines? </li></ul><ul><li>What is the best defense for each type of SQL Server deployment? </li></ul>
  25. 25. Secure Installation/Configuration <ul><li>Lockdown scripts (www.sqlsecurity.com) </li></ul><ul><ul><li>Check service context </li></ul></ul><ul><ul><li>Check patch level </li></ul></ul><ul><ul><li>Set mode to Windows Authentication </li></ul></ul><ul><ul><li>Assign long, random ‘sa’ account password </li></ul></ul><ul><ul><li>Enable authentication auditing </li></ul></ul><ul><ul><li>Disable SQLAgent, Microsoft Distributed Transaction Coordinator (MSDTC), and MSSEARCH </li></ul></ul><ul><ul><li>Disable adhoc queries on all providers </li></ul></ul><ul><ul><li>Remove sample databases </li></ul></ul><ul><ul><li>Tighten permissions on master/msdb database objects </li></ul></ul><ul><ul><li>Increase log history </li></ul></ul><ul><ul><li>Delete temp files used for install/upgrades </li></ul></ul>
  26. 26. Discovery Defense <ul><li>Block UDP 1434 inbound </li></ul><ul><ul><li>BOL says you cannot do this but you can </li></ul></ul><ul><ul><li>Remember that named instances must be port configured on client </li></ul></ul><ul><li>Firewall connections from all untrusted clients by IP address </li></ul><ul><li>Remove un-needed netlibs </li></ul><ul><li>Keep credentials out of connection strings </li></ul><ul><li>Unfortunately the “Hide Server” option in TCP/IP properties does not help </li></ul><ul><ul><li>TCP port forced to 2433 </li></ul></ul><ul><ul><li>If any other netlibs are installed the server will still respond to UDP 1434 calls </li></ul></ul>
  27. 27. Account Acquisition Defense <ul><li>Strong password enforcement </li></ul><ul><ul><li>Entropy, Lifetime, Length </li></ul></ul><ul><li>Enable auditing (at least failed logins) </li></ul><ul><li>Encrypt all sensitive traffic </li></ul><ul><ul><li>SSL recommended </li></ul></ul><ul><ul><li>Multi-protocol encryption not recommended </li></ul></ul><ul><ul><ul><li>No multiple instance support (instances only supported on Named Pipes, TCP/IP, NWLink, and Shared Memory netlibs) </li></ul></ul></ul><ul><ul><ul><li>RPC encryption API only – weaker key management </li></ul></ul></ul><ul><li>Keep credentials out of connection strings and encrypted when possible </li></ul><ul><ul><li>DPAPI (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT08.asp) </li></ul></ul><ul><ul><li>Use Windows Auth when possible </li></ul></ul>
  28. 28. Privilege Escalation Defense <ul><li>Especially important to KEEP CURRENT WITH PATCHES </li></ul><ul><ul><li>Perform custom scripting if need-be </li></ul></ul><ul><ul><li>Use Commercially available patch tools </li></ul></ul><ul><ul><ul><li>HFNetChk Pro - www.shavlik.com </li></ul></ul></ul><ul><ul><ul><li>UpdateExpert – www.stbernard.com </li></ul></ul></ul><ul><ul><ul><li>Service Pack Manager 2000 - www.securitybastion.com </li></ul></ul></ul><ul><ul><li>Write Microsoft at sqlwish@microsoft.com and emplore them to: </li></ul></ul><ul><ul><ul><li>Include SQL Patches in Windows Update </li></ul></ul></ul><ul><ul><ul><li>Perform patches to all instances on demand </li></ul></ul></ul><ul><ul><ul><li>Make SQL Server patch installs more user-friendly </li></ul></ul></ul>
  29. 29. Privilege Escalation Defense <ul><li>As an admin, never run user-created stored procedures and functions without inspecting it first </li></ul><ul><ul><li>This can be particularly problematic when users encrypt stored procedures (see www.sqlsecurity.com for tools to decrypt) </li></ul></ul><ul><li>Run extended stored procedures using fully-qualified designation (master.dbo.xp_cmdshell) </li></ul><ul><li>Block access to public role to all procedures that could be abused (submit suggestions for Lockdown Script) </li></ul><ul><li>No longer recommending the “dropping” of extended stored procedures </li></ul><ul><ul><li>Complicates Service Pack Installations </li></ul></ul><ul><ul><li>Breaks vital SQL Server mechanisms such as the use of Enterprise Manager, Query Analyzer, and Profiler </li></ul></ul><ul><ul><li>Could break as Microsoft introduces new functionality </li></ul></ul>
  30. 30. SQL Injection Defenses: Input Validation <ul><li>Scrub input data to make sure it contains only acceptable characters </li></ul>Numbers only Set myregex = new regexp myregex.global = True myregex.pattern = “D+” cleaninput=myregex.replace Remove all characters except a-zA-Z0-9 Set myregex = new regexp myregex.global = True myregex.pattern = “W+” cleaninput=myregex.replace Remove single quotes to help prevent quote-closing attacks replace(inputstring,’,’’)
  31. 31. Input Validation – Stored Procedures <ul><li>Stored procedures can help enforce stronger typing but using them at every database access can be brutal due to the sheer number of procs that may need to be created or because of application requirements </li></ul><ul><ul><li>Since SQL Server has already compiled the query plan for the query, no further code injection is possible if we properly invoke the procedure </li></ul></ul>Create procedure sp_login @username varchar(20), @password varchar(20) AS Select * from users where username = @username and password = @password
  32. 32. Secure Implementation of SP <ul><li>Use SqlCommand and SqlParameter objects to explicitly identify parameters </li></ul><ul><li>SqlConnection cn = new SqlConnection(yourConnectionString); </li></ul><ul><li>SqlCommand cmd = new SqlCommand(&quot;usp_authors&quot;, cn); </li></ul><ul><li>// Mark the Command as a SPROC </li></ul><ul><li>cmd.CommandType = CommandType.StoredProcedure; </li></ul><ul><li>// Add Parameters to SPROC </li></ul><ul><li>SqlParameter prmLast = new SqlParameter(&quot;@last&quot;, SqlDbType.VarChar,50); </li></ul><ul><li>prmLast.Value = TextBox1.Text; </li></ul><ul><li>cmd.Parameters.Add(prmLast); </li></ul><ul><li>// Create and Fill the SqlDataReader </li></ul><ul><li>cn.Open(); </li></ul><ul><li>SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); </li></ul><ul><li>Use the same method even for text command types. Do not use string concatenation to build query strings. </li></ul>
  33. 33. Discipline <ul><li>Make sure developers adhere to the standards </li></ul><ul><ul><li>Develop a methodology </li></ul></ul><ul><ul><ul><li>Command/Parameter objects / stored procs </li></ul></ul></ul><ul><ul><ul><li>No access to production servers </li></ul></ul></ul><ul><ul><ul><li>Consistent database access and developer education </li></ul></ul></ul><ul><ul><li>Encourage reusable security components </li></ul></ul><ul><ul><li>Code review </li></ul></ul><ul><ul><li>QA Test Plans </li></ul></ul><ul><ul><li>Code with an intruder’s mindset </li></ul></ul>
  34. 34. Best Practices <ul><li>Use principle of least-privilege </li></ul><ul><li>Assign MSSQLServer service non-administrator user context </li></ul><ul><li>Take the time to properly implement trusted security (Windows Auth Mode) </li></ul><ul><li>Don’t place passwords in script/code </li></ul><ul><li>Assign complex ‘sa’ password even when using Windows Authentication </li></ul>
  35. 35. Best Practices (cont.) <ul><li>Write re-usable input validation routines and make their use mandatory </li></ul><ul><li>Use stored procedures wherever possible but avoid “string building” for executing them </li></ul><ul><li>Code reviews are an absolute necessity </li></ul><ul><li>Evaluate third-party code and applications with great scrutiny </li></ul><ul><li>Use SSL or IPSec to encrypt network traffic on suspect subnets (more applicable to client/server deployments but a powerful option) </li></ul>
  36. 36. Special Consideration : MSDE <ul><li>MSDE Difficulties </li></ul><ul><ul><li>Stealth install – users rarely aware it exists </li></ul></ul><ul><ul><li>Defaults to over-privileged LocalSystem security context </li></ul></ul><ul><ul><li>Separate service pack download </li></ul></ul><ul><ul><li>Multiple MSDE installer editions (the MSI file used to install – KB Q311762) </li></ul></ul><ul><ul><li>If you used any of the 15 other MSI installers besides sqlrun01.msi you must order an upgrade CD from Microsoft to apply a service pack </li></ul></ul><ul><ul><li>No tools to easily modify netlibs, audit level, security mode, or anything else for that matter </li></ul></ul>
  37. 37. Deployment Solutions: 1 - MSDE and Single User <ul><li>Remove ALL netlibs w/Server Network Utility or </li></ul><ul><li>EXECUTE master.dbo.xp_regwrite N'HKEY_LOCAL_MACHINE',N'SOFTWAREMicrosoftMSSQLServerMSSQLServerSuperSocketNetLib', N'ProtocolList',N'REG_SZ',’’ </li></ul><ul><li>Or (for non-default instances) </li></ul><ul><li>EXECUTE master.dbo.xp_regwrite N'HKEY_LOCAL_MACHINE', SOFTWAREMicrosoftMicrosoft SQL Server(instance_name)MSSQLServerSuperSocketNetLib’, N'ProtocolList',N'REG_SZ',’’ </li></ul><ul><ul><li>Local connections allowed only through the shared memory netlib (which cannot be removed) </li></ul></ul><ul><ul><li>User (local) or . To specify the server name in connection strings </li></ul></ul><ul><ul><li>Secure, lightweight, simple </li></ul></ul><ul><ul><li>Can easily restore netlibs temporarily if need be </li></ul></ul><ul><li>Lockdown scripts </li></ul>
  38. 38. Special Deployment Solutions 2 : Web-Based Applications (Forms Auth) <ul><li>Use Windows Authentication mode in SQL Server </li></ul><ul><ul><li>Alter IIS Metabase for Anonymous access specifying a low-priv local or domain user account </li></ul></ul><ul><ul><li>If local user is used, make sure same account/password exist on SQL Server </li></ul></ul><ul><ul><li>Turn of “Allow IIS to Control Password” option as this uses iissuba.dll and defeats ability to authenticate to the SQL Server </li></ul></ul><ul><ul><li>ASP.NET : aspnet_wp process runs in context specified in web.config or machine.config. Look for processModel key – userName attribute. (note that when an ASP.NET app runs with impersonation, this will cause authentication to occur using impersonated context and not the service context) </li></ul></ul><ul><li>Block ALL direct access to SQL Server except through web server and secure back-end systems (inbound only) </li></ul><ul><li>Encrypt data using asymmetric encryption methods using public key only – never store private key on this server </li></ul><ul><li>All this does *NOT* defeat connection pooling since SQL Server user context is always the same </li></ul>
  39. 39. Special Deployment Solutions 3 : Client/Server Deployments <ul><li>Patches especially important due to direct access issues </li></ul><ul><li>Implement SSL as a means of protecting data/credentials in-transit </li></ul><ul><ul><li>Use a private CA to issue server certificate for the SQL Server </li></ul></ul><ul><ul><li>Clients will not be able to connect without certificate in local “trusted” store (assuming SQL Server is requiring SSL) </li></ul></ul><ul><li>Application roles can be used to control access but this can also be achieved through the use of views and stored procedures which provide other benefits </li></ul><ul><li>Be aware the application role activation (sp_setapprole) passwords are stored on the client (they cannot be invoked via a stored procedure) so reverse engineering can yield the role password which would give the attacker access to whatever the role can access </li></ul>
  40. 40. New at SQLSecurity.com <ul><li>SQLPing.NET </li></ul><ul><ul><li>C# version of SQLPing. Source code included so functionality can be integrated into other applications </li></ul></ul><ul><li>SQL Server Tools Listing (Free and Commercial) </li></ul><ul><li>Lockdown Script Project </li></ul><ul><ul><li>I am soliciting feedback from anyone who wants to help </li></ul></ul><ul><li>Full SQL Server Version list (thanks to Ken Klaft) </li></ul>
  41. 41. Recommended Reading <ul><li>(*)Birkholz.    Special Ops: Host and Network Security for Microsoft, UNIX, and Oracle. Syngress, 2003. </li></ul><ul><li>(*)McClure, Scambray, and Kurtz. Hacking Exposed: Windows 2000 . Osborne, 2001. </li></ul><ul><li>Lewis, Morris. SQL Server Security Distilled. Curlingstone, 2002. </li></ul><ul><li>Howard, Levy, and Waymire. Designing Secure Web-Based Applications for Microsoft Windows 2000 . Microsoft Press, 2000. </li></ul><ul><li>Rain Forest Puppy – Phrack Magazine Volume 8, Issue 54 Dec 25 th , 1998, article 8 of 12. </li></ul><ul><li>David Litchfield. Remote Web Application Disassembly With ODBC Error Messages http://www.blackhat.com/presentations/win-usa-01/Litchfield/BHWin01Litchfield.doc </li></ul><ul><li>LeBlanc, Howard. Writing Secure Code . Microsoft Press, 2001. </li></ul><ul><li>McClure, Shah. Web Hacking . Addison Wesley, 2003. </li></ul><ul><li>(*) Books to which I have contributed chapters </li></ul>