Avoid misconceptions about SQL injection attacks



Request Information

Want more information? Fill out the form below and we'll contact you shortly.

Name

Phone

Email

Subject

Message




Date : 7/20/2010

You may know that if user input finds its way directly into SQL statements your site executes against the database, hackers may be able to take advantage of that fact and compromise your website.

One typical strategy to prevent such attacks is to put all the queries in stored procedures on the database. What many people don't realize, however, is that just moving queries into stored procedures doesn't necessarily offer protection.

If your application calls a stored procedure by passing a SQL string to the database, you may still be vulnerable. For example, consider the following VBScript using an ADO recordset and connection object to connect to Microsoft SQL Server:

set rs = conn.execute("usp_my_procedure " & strInput)

If the strInput variable contains a string passed from a form or querystring, it may compromise the database. All a hacker has to do is include a semicolon (;) to batch additional commands.

To avoid this problem, you can clean out any semicolons from the input. Or, to be extra safe, you can parameterize the input, such as in this VBScript example:

If strInput = "" Then
strInput = " "
End If
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn
cmd.CommandText = "usp_my_procedure"
cmd.Parameters.Append cmd.CreateParameter("@myinput", adVarChar,
adParamInput, 50, strInput)
rs.Open cmd

In addition, be aware that database commands, such as SQL Server's execute (or exec) T-SQL command, may similarly create a security hole. Furthermore, even hidden fields or data passed from the database could make you vulnerable. A hacker could spoof your form and put dangerous values into the hidden fields. Even values that a hacker has added to the database through "legitimate" means could come back to haunt you if a page later grabs that value and executes it.

 


Previous News: 7/13/2010

Avoid over-dependence on SQL*Plus with the Group By and Rollup SQL commands (8i+)

Control the style of links with CSS pseudo-classes

Create hyperlinks that point to areas in a workbook (Excel 2000/2002/2003/2004/2007)

Option Strict places an even tighter grip on applications (VB .NET)

Perform fail-safe firmware upgrades

Print certain slides as handouts (PowerPoint 2000/2002/2003/2004/2007)

Same Day

Avoid the hassle of escaping quotes with user-defined quotes

Create standalone software packages with the Microsoft Access Runtime

Never hit the wrong database again in the Query window

Remove a sender from your Outlook junk e-mail list (2003/2007)

Split your screen using only the keyboard (Word 2000/2002/2003/2004/2007)

Next News: 7/29/2010

Browse for audio files on FindSounds.com

Create recurring appointments in your Microsoft Outlook calendar (2000/2002/2003/2007)

Keep unnecessary files out of sight, but close at hand (Excel 2000/2002/2003/2004/2007)

Prevent mammoth numerical errors by forcing SQL Server to treat values as decimals

Protect your Web servers with URLScan

Validate radio buttons with a quick JavaScript

Share |
Since 1982, New Horizons Computer Learning Centers has grown to become the largest independent IT training company worldwide. We offer more courses, at more times and in more locations than any other computer and business training company. Businesses and individuals can choose from hundreds of course offerings, delivered by experts, and offered in hundreds of convenient locations around the world.


Albany, NY
(518) 452-6444
10 Airline Drive, Ste 101
Albany, NY 12205
Charlotte, NC
(704) 522-9747
9140 Arrowpoint Blvd, Ste 400
Charlotte, NC 28273
Harrisburg, PA
5095 Ritter Road, Ste 114
Mechanicsburg, PA 17055
Lancaster, PA
(717) 791-0200
1020 New Holland Ave
Lancaster, PA 17601