SQL Injection woes...

Published 16 March 04 06:31 PM

So I forgot to blog about the SQL Injection problems that I have come across.  This certain one used SQL Injection to get into an admin side of a shopping cart website and made some changes to the payment parts and set the money to go to him/her.

The SQL Injection related to logging into a website with forms authentication with a Username and Password box.  In Classic ASP you could see something like

set adconn = Server.CreateObject(“ADODB.Connection”)
set adRS = Server.CreateObject(“ADODB.Recordset”) 
adconn.Open connectionString
strSQL = “select * from tblUsers WHERE UserId = ‘” & Request.Form(“username”) & “’ and Password=’” & Request.Form(“password”) & “’”
adRS.Open strSQL, adConn
if adRS.EOF Then
   ‘ not a user authenticated
else
   ‘ is a user authenticated
end if

So if I put in the box  junior’ or 1 = 1 –

So the statement would look like this:  select * from tblUsers where UserId = ‘junior’ or 1=1 -- ' and Password=’passwordfield’

Being that we used the double - SQL Server will only execute whether the UserId = junior or 1=1, which we all know that 1=1 so there will be a recordset coming back, and therefore it will be counted as authenticated.

Now this was a very simplistic example, and there are many more that are more complex, but it is fairly common to have situations like this where someone can get in and wreak some havoc.  So please remember to use the ADODB.Command and ADODB.Parameter so that you do not run into the SQL Injection attacks that you can have with concatenated strings.

 

Comments

# Enjoy Every Sandwich said on March 17, 2004 2:14 AM:
You have been Taken Out! Thanks for the post.
# Mischa said on March 17, 2004 8:10 AM:
simple solution not using parameters:

always use a function to replace single quotes with double single quotes.

replace (string,"'","''")

This is something which should always be used.

# TrackBack said on April 10, 2004 6:44 PM:
LSN WebLog » SQL Injection woes…
# stefan demetz said on July 13, 2004 5:41 PM:
http://dotnetjunkies.com/weblog/stefandemetz/posts/18763.aspx
# Love that ASP NET and SQL Server SQL Injection woes | wheelbarrow said on June 19, 2009 2:19 AM:

PingBack from http://wheelbarrowstyle.info/story.php?id=378

# Love that ASP NET and SQL Server SQL Injection woes | debt solutions said on June 19, 2009 1:53 PM:

PingBack from http://debtsolutionsnow.info/story.php?id=7046

Anonymous comments are disabled

This Blog

Syndication

Page view tracker