以下代码为我幸苦所得,如需转载请保留原出处
首发 www.yangxiaoyong.com 杨小勇
--批量注入字符串
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
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 + ']=rtrim(convert(varchar,['
+ @C + ']))+''''' )
FETCH NEXT FROM Table_Cursor INTO @T, @C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor
--批量清除字符串(针对nvarchar,ntext均非常有效)
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
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)),'''',''成功'')' )
FETCH NEXT FROM Table_Cursor INTO @T, @C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor
--批量清除字符串(对于nvarchar有限,对于ntext无效)
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
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(['+@C+'],'''',''成功'')' )
FETCH NEXT FROM Table_Cursor INTO @T, @C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor
关于数据库批量注入,及批量清除的方法[原创]
技术分享 | 2020/12/22tag: