sql注入數(shù)據(jù)庫修復(fù)的兩種實(shí)例方法
1.第一種情況是 需要將指定的 注入字符串全部替換掉(僅替換注入的字符串為空)
declare @delStr nvarchar(500)
set @delStr='<script src=http://www.dbjr.com.cn/js/common.js></script>' --這里被注入的字段串
/****************************************/
/**********以下為操作實(shí)體************/
set nocount on
declare @tableName nvarchar(100),@columnName nvarchar(100),@tbID int,@iRow int,@iResult int
declare @sql nvarchar(2000)
set @iResult=0
declare cur cursor for
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 for
select name from syscolumns where xtype in (231,167,239,175, 35, 99) and id=@tbID
open cur1
fetch next from cur1 into @columnName
while @@fetch_status=0
begin
set @sql='update [' + @tableName + '] set ['+ @columnName +']= SUBSTRING([' + @columnName + '],' + '1, PATINDEX( ''%' + @delStr + '%'', [' + @columnName + '])-1) + ' + 'SUBSTRING([' + @columnName + '], PATINDEX( ''%' + @delStr + '%'', [' + @columnName + ']) + ' + 'len(''' + @delStr + ''') , datalength([' + @columnName + '])) where ['+@columnName+'] like ''%'+@delStr+'%'''
exec sp_executesql @sql
set @iRow=@@rowcount
set @iResult=@iResult+@iRow
if @iRow>0
begin
print '表:'+@tableName+',列:'+@columnName+'被更新'+convert(varchar(10),@iRow)+'條記錄;'
end
fetch next from cur1 into @columnName
end
close cur1
deallocate cur1
fetch next from cur into @tableName,@tbID
end
print '數(shù)據(jù)庫教程共有'+convert(varchar(10),@iResult)+'條記錄被更新!!!'
close cur
deallocate cur
set nocount off
2.第二種是 需要將注入到表中起始位置到最后都刪掉。(此種方法直接找到注入的起始位置,后面的全部刪掉)
--恢復(fù)被注入數(shù)據(jù)庫
--2013-09-26
declare @delStr nvarchar(500)
set @delStr='</title><style>.' --被注入的字段串的開始采樣,從此位置后面的數(shù)據(jù)都為注入數(shù)據(jù)
/**********以下為操作實(shí)體************/
set nocount on
declare @tableName nvarchar(100),@columnName nvarchar(100),@tbID int,@iRow int,@iResult int
declare @sql nvarchar(2000)
set @iResult=0
declare cur cursor for
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 for
select name from syscolumns where xtype in (231,167,239,175, 35, 99) and id=@tbID
open cur1
fetch next from cur1 into @columnName
while @@fetch_status=0
begin
set @sql='update [' + @tableName + '] set ['+ @columnName +']=
SUBSTRING([' + @columnName + '],1, PATINDEX( ''%' + @delStr + '%'', [' + @columnName + '])-1) where ['+@columnName+'] like ''%'+@delStr+'%'''
exec sp_executesql @sql
set @iRow=@@rowcount
set @iResult=@iResult+@iRow
if @iRow>0
begin
print '表:'+@tableName+',列:'+@columnName+'被更新'+convert(varchar(10),@iRow)+'條記錄;'
end
fetch next from cur1 into @columnName
end
close cur1
deallocate cur1
fetch next from cur into @tableName,@tbID
end
print '數(shù)據(jù)庫教程共有'+convert(varchar(10),@iResult)+'條記錄被更新!!!'
close cur
deallocate cur
set nocount off
- 淺談三種數(shù)據(jù)庫的?SQL?注入
- 數(shù)據(jù)庫之SQL注入原理以及過程的簡單介紹
- 一個(gè)簡單的后臺與數(shù)據(jù)庫交互的登錄與注冊[sql注入處理、以及MD5加密]
- Mysql數(shù)據(jù)庫使用concat函數(shù)執(zhí)行SQL注入查詢
- 數(shù)據(jù)庫SqlParameter 的插入操作,防止sql注入的實(shí)現(xiàn)代碼
- SQL數(shù)據(jù)庫的高級sql注入的一些知識
- 數(shù)據(jù)庫中的內(nèi)容字段被掛馬的替換方法 SQL注入
- ASP+MSSQL2000 數(shù)據(jù)庫被批量注入后的解決方法
- sql注入數(shù)據(jù)庫原理詳情介紹
相關(guān)文章
一個(gè)函數(shù)解決SQLServer中bigint 轉(zhuǎn) int帶符號時(shí)報(bào)錯(cuò)問題
這篇文章主要介紹了解決SQLServer中bigint 轉(zhuǎn) int帶符號時(shí)報(bào)錯(cuò)問題的函數(shù),需要的朋友可以參考下2014-08-08數(shù)據(jù)庫表的創(chuàng)建、管理和數(shù)據(jù)操作(實(shí)驗(yàn)一)
這篇文章主要介紹了數(shù)據(jù)庫中表的創(chuàng)建、管理和數(shù)據(jù)操作,感興趣的小伙伴可以參考一下2015-08-08企業(yè)管理器備份和還原SQL Server數(shù)據(jù)庫
本文我們主要介紹了利用SQL Server數(shù)據(jù)庫的企業(yè)管理器來備份和還原數(shù)據(jù)庫的方法以及每日自動(dòng)備份數(shù)據(jù)庫的設(shè)置,希望能夠?qū)δ兴鶐椭?/div> 2015-08-08SqlServer2012中First_Value函數(shù)簡單分析
SQL SERVER 2012 T-SQL新增幾個(gè)聚合函數(shù): FIRST_VALUE LAST_VALUE LEAD LAG,今天我們首先來簡單分析下FIRST_VALUE,希望對大家有所幫助,能夠盡快熟悉這個(gè)聚合函數(shù)2014-08-08sql存儲過程實(shí)例--動(dòng)態(tài)根據(jù)表數(shù)據(jù)復(fù)制一個(gè)表的數(shù)據(jù)到另一個(gè)表
這篇文章主要介紹了sql存儲過程實(shí)例--動(dòng)態(tài)根據(jù)表數(shù)據(jù)復(fù)制一個(gè)表的數(shù)據(jù)到另一個(gè)表的相關(guān)資料,需要的朋友可以參考下2017-10-10最新評論