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
 New to SQL Server Programming
 Tables Currupted w/ rogue SQL Injection

Author  Topic 

medman
Starting Member

4 Posts

Posted - 2010-08-05 : 14:39:06
I am a windows sysadmin and I'm temporarily filling in the SQL admin role. I am definitely a newbie SQL admin. We got hit by a SQL injection attack yesterday out of South Korea and most of the fields in our Customer tables have the following script:
<script src=http//wtrc.kangwon.ac.kr/skin/rook.js>.
Needless to say with this script running thousands of times it's bringing our server to its knees. What is the best method to do a delete or search and replace across all tables and columns?

P.S. I have really, really strenthened our passwords

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 14:55:39
Moving this topic out of the data corruption form since this isn't SQL data corruption, it's just bad data.

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 14:56:14
Use this to search all columns of all tables in a database: http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 14:57:09
Then use UPDATE statement to do the replace.

UPDATE t1
SET c1 = REPLACE(c1, 'YourBadString', '')

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

Subscribe to my blog
Go to Top of Page

medman
Starting Member

4 Posts

Posted - 2010-08-05 : 16:18:27
Thanks Tara:
Can you also point me to a page that instructs me how to set up a stored procedure?
Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 16:20:25
http://msdn.microsoft.com/en-us/library/ms187926.aspx

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

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-06 : 02:11:09
"P.S. I have really, really strenthened our passwords"

That won't help if it WAS a SQL injection attack.

If you want to get original customer data back then you will have to restore from backup, or restore to a temporary database and selectively merge the data back - i.e. replace <SCRIPT> rubbish with the original Customer Name (or whatever was there before)
Go to Top of Page

medman
Starting Member

4 Posts

Posted - 2010-08-06 : 14:41:45
Hi Kristen. Thanks for the reply. Why do you say that? What is it that I have to do to stop these nasties from getting into SQL Server in the future?
Go to Top of Page

medman
Starting Member

4 Posts

Posted - 2010-08-06 : 14:46:19
Hi Kristen. I didn't read the rest of the post. Nothing in the Customer records was deleted. Just the scripts were concatenated on the end on the text in the various Customer DB fields. SO I think a straight forward replace would work fine.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-06 : 17:07:50
"Just the scripts were concatenated on the end on the text in the various Customer DB fields. SO I think a straight forward replace would work fine."

Sounds fine. The normal issue is when the field is not big enough for the original data plus the <SCRIPT> data and, depending on how the hack is made, sometime some original data can be lost. If it is just concatenated then you will be fine - however, watch out for where only part of the script was added (field was too small and truncated the remainder) - then a REPLACE won't remove it.

"Why do you say that? What is it that I have to do to stop these nasties from getting into SQL Server in the future?"

You need to read up on SQL Injection. It has nothing to do with password security, but the way that your program is written. It is possible that the hack was via the password, and not SQL Injection. But if it was SQL injection then your application will be vulnerable until you fix the application.
Go to Top of Page
   

- Advertisement -