Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQL Injection

1 view
Skip to first unread message

Chris

unread,
Oct 1, 2007, 12:07:24 AM10/1/07
to
Hi,

I am trying to create a database procedure that will produce a list of
results based on a Google like search.

e.g. "Frank Spencer" -car +BBC

I would normally produce a dynamic where clause something like this:-
select title from videos where title like '%Frank Spencer%' and title like
'%BBC%' and title not like '%BBC%'
but I believe that would be open to a sql attack and I should be using
parameters.

I could create a parameter for each but I do not know how many words will be
entered and then I need to evaluate the + and - signs to be like and not
like.

I'm sure this gets done all the time so if anyone can supply a url of an
example I would be grateful.

Thanks

Chris


infi...@gmail.com

unread,
Oct 28, 2007, 7:38:00 AM10/28/07
to
Hi Chris,

> I would normally produce a dynamic where clause something like this:-
> select title from videos where title like '%Frank Spencer%' and title like
> '%BBC%' and title not like '%BBC%'
> but I believe that would be open to a sql attack and I should be using parameters.

In your case do not use the user data directly,
first pass that data in a function and pass into query

Your Query will:

Select title from videos where title like
dbo.FNAGetValidString('%Frank Spencer%') and title like
'%BBC%' and title not like dbo.FNAGetValidString('%BCC%')

---------Function Script you can add other unwanted charectar

Alter FUNCTION FNAGetValidString(@Str as varchar(200))
RETURNS varchar(20) AS
BEGIN
set @Str=replace(@Str,'--','')
set @Str=replace(@Str,'-','')
set @Str=replace(@Str,'+','')
set @Str=replace(@Str,'drop+','')

return @Str
END

Hope this will Help you !

MCP
Raghu Bhandari

0 new messages