Replace inserted Trojan records in batches in SqlServer

Source: Internet
Author: User

Recently, I found a batch replacement of inserted Trojan records and found a good statement, which is very useful. I only use a dozen rows of cursor statements, the malicious trojan of all tables in the database is cleared, and the probability of this record being searched by Google is very small. I will repost it here! In the future, we hope that future generations can get help.
The original article is as follows:
Copy codeThe Code is as follows:
Declare @ t varchar (555), @ c varchar (555), @ inScript varchar (8000)
Set @ inScript = 'malicious Code'
Declare table_cursor cursor for select. name, B. name from sysobjects a, syscolumns B where. id = B. id and. xtype = 'U' and (B. xtype = 99 or B. xtype = 35 or B. xtype = 231 or B. (xtype = 167)
Open table_cursor
Fetch next from table_cursor into @ t, @ c
While (@ fetch_status = 0)
Begin
Exec ('Update ['+ @ t +'] set ['+ @ c +'] = replace (cast (['+ @ c +'] as varchar (8000 )), ''' + @ inScript + ''','''')')
Fetch next from table_cursor into @ t, @ c
End
Close table_cursor
Deallocate table_cursor;

Completely eliminate SQL Injection
1. Do not use the sa user to connect to the database
2. Create a public permission database user and use the user to access the database
3. [role] Remove the select access permission of the public role to the sysobjects and syscolumns objects.
4. Right-click a [user] user name and choose "properties"> "Permissions"> "sysobjects" and "syscolumns"
5. Use the following code to check whether the permission is correct. If the permission is displayed, the permission is too high ):
Copy codeThe Code is as follows:
DECLARE @ T varchar (255 ),
@ C varchar (255)
DECLARE Table_Cursor CURSOR
Select a. name, B. name from sysobjects a, syscolumns B
Where. id = B. id and. xtype = 'U' and (B. xtype = 99 or B. xtype = 35 or B. xtype = 231 or B. (xtype = 167)
OPEN Table_Cursor
Fetch next from Table_Cursor INTO @ T, @ C
WHILE (@ FETCH_STATUS = 0)
BEGIN print @ c
Fetch next from Table_Cursor INTO @ T, @ C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor

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.