Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Data Corruption Issues
 remove SQL injected script files

Author  Topic 

stegothdump
Starting Member

9 Posts

Posted - 2011-10-09 : 15:26:32
Hi There,

I have a SQL DB that needs cleansed of the recent SQL injection attack.

I have written the following code:

UPDATE [tableName]
SET columnName = REPLACE(CAST(columnName AS VARCHAR(8000)), '"></title><script src="http://1.verynx.cn/w.js"></script><!--', '')
WHERE columnName LIKE '%"></title><script src="http://1.verynx.cn/w.js"></script><!--%'

The problem is that <script src='http://visionaryliongroup.com.au/images/counter.php'></script> text includes a single apostrophe rather than the double quote as shown in the example above. how can i get round this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-09 : 20:41:45
You can escape it with two single quotes.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

stegothdump
Starting Member

9 Posts

Posted - 2011-10-10 : 03:14:42
so would that be two single quotes round the stuff i want to take out i.e

UPDATE Table1
SET Col1 = REPLACE(Col1, '<script src='http://www0.douhunqn.cn/csrss/w.js'></script>', '')

would become

UPDATE Table1
SET Col1 = REPLACE(Col1, ''<script src='http://www0.douhunqn.cn/csrss/w.js'></script>'', '')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-10-13 : 09:11:56
Also refer this
http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

paultech
Yak Posting Veteran

79 Posts

Posted - 2011-10-23 : 14:27:21
Hello ,May be you can use parameters instead of direct sql query ,by using parameters and parse to query ,it should prevented from sql injection

paul Tech
Go to Top of Page
   

- Advertisement -