Batch replacement of inserted Trojan Horse records in SQL Server _mssql

Source: Internet
Author: User
Tags sql injection
Recently looked for a lot of replacement to be inserted in the Trojan record, found a good statement, very useful, just use more than 10 lines of travel slogan, the entire database of all the table malicious Trojan cleared away, and in Google search to this record chance is very small, this special reprint! In order to find their own later, but also hope that future generations can be helped.
The original text reads as follows:
Copy Code code as follows:

DECLARE @t varchar (555), @c varchar (555), @inScript varchar (8000)
Set @inScript = ' Malicious code '
Declare table_cursor cursor FOR select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.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 new public rights database user, and use this user to access the database
3. [Role] Remove role public to select access to sysobjects and syscolumns objects
4, [user] User name-> Right-Properties-permissions-sysobjects and syscolumns above "x"
5, through the following code detection (failure to represent the right, if it can be shown that the permissions are too high):
Copy Code code as follows:

DECLARE @T varchar (255),
@c varchar (255)
DECLARE Table_cursor Cursor for
Select a.name,b.name from sysobjects a,syscolumns b
where a.id=b.id and a.xtype= ' U ' and (b.xtype=99 or b.xtype=35 or b.xtype=231)
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.