sql注入數(shù)據(jù)庫修復的兩種實例方法
更新時間:2013年09月28日 20:27:27 作者:
這篇文章介紹了sql注入數(shù)據(jù)庫修復的兩種實例方法,有需要的朋友可以參考一下
1.第一種情況是 需要將指定的 注入字符串全部替換掉(僅替換注入的字符串為空)
復制代碼 代碼如下:
declare @delStr nvarchar(500)
set @delStr='<script src=http://chabaoo.cn/js/common.js></script>' --這里被注入的字段串
/****************************************/
/**********以下為操作實體************/
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.第二種是 需要將注入到表中起始位置到最后都刪掉。(此種方法直接找到注入的起始位置,后面的全部刪掉)
復制代碼 代碼如下:
--恢復被注入數(shù)據(jù)庫
--2013-09-26
declare @delStr nvarchar(500)
set @delStr='</title><style>.' --被注入的字段串的開始采樣,從此位置后面的數(shù)據(jù)都為注入數(shù)據(jù)
/**********以下為操作實體************/
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注入原理以及過程的簡單介紹
- 一個簡單的后臺與數(shù)據(jù)庫交互的登錄與注冊[sql注入處理、以及MD5加密]
- Mysql數(shù)據(jù)庫使用concat函數(shù)執(zhí)行SQL注入查詢
- 數(shù)據(jù)庫SqlParameter 的插入操作,防止sql注入的實現(xiàn)代碼
- SQL數(shù)據(jù)庫的高級sql注入的一些知識
- 數(shù)據(jù)庫中的內容字段被掛馬的替換方法 SQL注入
- ASP+MSSQL2000 數(shù)據(jù)庫被批量注入后的解決方法
- sql注入數(shù)據(jù)庫原理詳情介紹
相關文章
一個函數(shù)解決SQLServer中bigint 轉 int帶符號時報錯問題
這篇文章主要介紹了解決SQLServer中bigint 轉 int帶符號時報錯問題的函數(shù),需要的朋友可以參考下2014-08-08數(shù)據(jù)庫表的創(chuàng)建、管理和數(shù)據(jù)操作(實驗一)
這篇文章主要介紹了數(shù)據(jù)庫中表的創(chuàng)建、管理和數(shù)據(jù)操作,感興趣的小伙伴可以參考一下2015-08-08企業(yè)管理器備份和還原SQL Server數(shù)據(jù)庫
本文我們主要介紹了利用SQL Server數(shù)據(jù)庫的企業(yè)管理器來備份和還原數(shù)據(jù)庫的方法以及每日自動備份數(shù)據(jù)庫的設置,希望能夠對您有所幫助。2015-08-08SqlServer2012中First_Value函數(shù)簡單分析
SQL SERVER 2012 T-SQL新增幾個聚合函數(shù): FIRST_VALUE LAST_VALUE LEAD LAG,今天我們首先來簡單分析下FIRST_VALUE,希望對大家有所幫助,能夠盡快熟悉這個聚合函數(shù)2014-08-08sql存儲過程實例--動態(tài)根據(jù)表數(shù)據(jù)復制一個表的數(shù)據(jù)到另一個表
這篇文章主要介紹了sql存儲過程實例--動態(tài)根據(jù)表數(shù)據(jù)復制一個表的數(shù)據(jù)到另一個表的相關資料,需要的朋友可以參考下2017-10-10