Clear the SQL database Trojan code

Source: Internet
Author: User

 

Declare @ delStr nvarchar (500)

-Set @ delStr = '< script src = http://www.bkjia.com/cn. js>'

Set @ delStr = '<script src = http://www.bkjia.com/cn. js> </script>'

/*************************************** */

 

************/

Set nocount on

 

Declare @ tableName nvarchar (100), @ columnName nvarchar (100), @ tbID int, @ iRow int, @ iResult int

Declare @ SQL nvarchar (500)

 

Set @ iResult = 0

Declare cur cursor

Select name, id from sysobjects where xtype = 'U'

 

Open cur

Fetch next from cur into @ tableName, @ tbID

 

While @ fetch_status = 0

Begin

Declare cur1 cursor

-Xtype in (231,167,239,175) is of the char, varchar, nchar, and nvarchar types.

Select name from syscolumns where xtype in (231,167,239,175) and id = @ tbID

Open cur1

Fetch next from cur1 into @ columnName

While @ fetch_status = 0

Begin

Set @ SQL = 'Update ['+ @ tableName +'] set ['+ @ columnName +'] = replace (convert (varchar (1000 ), ['+ @ columnName +']), "'+ @ delStr + "',"") where ['+ @ columnName +'] like "% '+ @ delStr +' % "'

Exec sp_executesql @ SQL

Set @ iRow = @ rowcount

Set @ iResult = @ iResult + @ iRow

If @ iRow> 0

Begin

Print 'table: '+ @ tableName +', column: '+ @ columnName +' updated '+ convert (varchar (10), @ iRow) + 'records ;'

End

Fetch next from cur1 into @ columnName

End

Close cur1

Deallocate cur1

 

Declare cur2 cursor

-Xtype in () is ntext or text

Select name from syscolumns where xtype in (99,35) and id = @ tbID

Open cur2

Fetch next from cur2 into @ columnName

While @ fetch_status = 0

Begin

Set @ SQL = 'Update ['+ @ tableName +'] set ['+ @ columnName +'] = replace (convert (nvarchar (1000 ), ['+ @ columnName +']), "'+ @ delStr + "',"") where ['+ @ columnName +'] like "% '+ @ delStr +' % "'

Exec sp_executesql @ SQL

Set @ iRow = @ rowcount

Set @ iResult = @ iResult + @ iRow

If @ iRow> 0

Begin

Print 'table: '+ @ tableName +', column: '+ @ columnName +' updated '+ convert (varchar (10), @ iRow) + 'records ;'

End

Fetch next from cur2 into @ columnName

End

Close cur2

Deallocate cur2

 

Fetch next from cur into @ tableName, @ tbID

End

Print 'database total '+ convert (varchar (10), @ iResult) +' records updated !!! '

 

Close cur

Deallocate cur

Set nocount off

From: webshell. cc

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.