Advertisement

04.14.2008 at 06:22PM PDT, ID: 23322399
[x]
Attachment Details

ASP sql injection hack

Asked by michaelshavel in Active Server Pages (ASP), MS SQL Server, SQL Server 2005

Tags: ,

Hi,

I have inherited an  (old) ASP site (I'm a perl/c/Java programmer). The database on the backend (SQL 2005) was compromised by what I believe was SQL injection. The hacker put in a string calling a javascript into several text fields in one of my tables. I've deleted the offending data and it hasn't come back, yet. Looking around on message boards it looks like it was done to others today at the same time. The consensus in these boards is that is was an SQL Injection hack.
I've been doing some reading about this and it's probably the way it did happen on my site. The ASP is quite old (written in 2003).
I can't find anyplace in the ASP where the original programmer escaped the user inputed data (quotes, backticks, etc..).
So my first question is this.
How do I escape my fields to protect me against these bad chars. In perl I would just use a RegEx -- I assume it's similar in ASP but I don't know the syntax -- I'm trying to get this in asap.

Second question.
Here is a snip of the code in the script that updates the database. I'm not sure what this "replace" function is doing -- is that actually escaping any 'bad' chars? If so, then I guess the hacker got in some other way....

Thanks!!

Mike


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
<!-- #INCLUDE File="../ADOVBS.INC" -->
 
Query = "SELECT * FROM ANC WHERE (AncID = " & iAncID & ") "
	adoAnc.Open Query, Connect  ,adopenstatic, adlockreadonly
	
		if adoAnc.eof then
			sqlq="INSERT INTO ANC (Anc1, From, To, Header, ID) "
			sqlq=sqlq & "VALUES ('" & replace(request.form("Message"),"'","''") & "', '" & request.form("FromDt") & "','" & request.form("ToDt") & "', '" & replace(request.form("Head"),"'","''") & "', " & iID & ")"
		
		end if
 
 
		set adoCommand=Server.CreateObject("ADODB.Command")
 		Set adoCommand.ActiveConnection = Connect
 		adoCommand.CommandType = adCmdText
		adoCommand.CommandText = sqlq
		adoCommand.execute , , adExecuteNoRecords
[+][-]04.14.2008 at 06:44PM PDT, ID: 21355356

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.14.2008 at 07:22PM PDT, ID: 21355502

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), MS SQL Server, SQL Server 2005
Tags: Microsoft, ASP
Sign Up Now!
Solution Provided By: CyrexCore2k
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.14.2008 at 07:27PM PDT, ID: 21355516

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 02:18AM PDT, ID: 21357100

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628