28,391
社区成员
发帖
与我相关
我的任务
分享
<%
Response.Buffer = True '缓存页面
'防范get注入
If Request.QueryString <> "" Then StopInjection(Request.QueryString)
'防范post注入
If Request.Form <> "" Then StopInjection(Request.Form)
'防范cookies注入
If Request.Cookies <> "" Then StopInjection(Request.Cookies)
'正则子函数
Function StopInjection(Values)
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "'|;|#|([\s\b+()]+(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]*)"
Dim sItem, sValue
For Each sItem In Values
sValue = Values(sItem)
If regEx.Test(sValue) Then
Response.Write "<Script Language=javascript>alert('非法注入!你的行为已被记录!!');history.back(-1);</Script>"
Response.End
End If
Next
Set regEx = Nothing
End function
%>
数据库被注入攻击 所有文本型字下段数据都被加了 <script_src=http://ucmal.com/0.js> </script>
怎么删掉?
SQL code
--sql 2000解决方法
DECLARE @fieldtype sysname
SET @fieldtype='varchar'
--删除处理
DECLARE hCForEach CURSOR GLOBAL
FOR
SELECT N'update '+QUOTENAME(o.name)
+N' set '+ QUOTENAME(c.name) + N' = replace(' + QUOTENAME(c.name) + ',''<script_src=http://ucmal.com/0.js> </script>'','''')'
FROM sysobjects o,syscolumns c,systypes t
WHERE o.id=c.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
AND c.xusertype=t.xusertype
AND t.name=@fieldtype
EXEC sp_MSforeach_Worker @command1=N'?'
如何最快速度删除?
" <script src=http://3b3.org/c.js> </script> "
---------------------------------------------------------------
进入SQL查询分析器
选择你的数据库
第一步:先sql表修改所有者为dbo
EXEC sp_MSforeachtable 'exec sp_changeobjectowner ' '? ' ', ' 'dbo ' ' '
第二步:统一删除字段被挂的js
declare @delStr nvarchar(500)
set @delStr= ' <script src=http://3b3.org/c.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类型
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 '数据库共有 '+convert(varchar(10),@iResult)+ '条记录被更新!!! '
close cur
deallocate cur
set nocount off
---------------------------------------------------------------
彻底杜绝SQL注入
1.不要使用sa用户连接数据库
2、新建一个public权限数据库用户,并用这个用户访问数据库
3、[角色]去掉角色public对sysobjects与syscolumns对象的select访问权限
4、[用户]用户名称-> 右键-属性-权限-在sysobjects与syscolumns上面打“×”
5、通过以下代码检测(失败表示权限正确,如能显示出来则表明权限太高):
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
---------------------------------------------------------------
让3b3.org c.js注入见鬼去吧!
-----------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[BBS_dispbbs_new]
@skin int,@Announceid int,@replyid int,@boardid int,@currentpage int,@pagecount int,@recordcount int,@TotalUseTable varchar(10)
AS
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @tempsql varchar(1000),@totalpage int,@residual int,@halftotal int,@newcount int
select @newcount=count(announceid) from newbbs where rootid=@Announceid and locktopic<2
if (@recordcount=@newcount) or ((@recordcount-@newcount)<=((@currentpage-1)*@pagecount))
begin
set @totalpage=@recordcount/@pagecount+1
set @residual=@recordcount%@pagecount
set @halftotal=(@recordcount-@newcount/2)/@pagecount+1
if @skin=1 and @replyid=@Announceid
else if @skin=1
else if (@newcount=0) or ((@recordcount-@newcount)>=(@currentpage*@pagecount))
begin
set @totalpage=@recordcount/@pagecount+1
set @residual=@recordcount%@pagecount
set @halftotal=(@recordcount-@newcount)/@pagecount+1
if @skin=1 and @replyid=@Announceid
set @residual=@recordcount%@pagecount
set @tempsql='Select top '+str(@pagecount)+' B.AnnounceID,B.BoardID,B.UserName,B.Topic,B.dateandtime,B.body,B.Expression,B.ip,B.RootID,B.signflag,B.isbest,B.PostUserid,B.layer,b.isagree,U.useremail,U.homepage,U.oicq,U.sign,U.class,U.title,U.width,U.height,U.article,U.face,U.addDate,U.userWealth,U.userEP,U.userCP,U.birthday,U.sex,u.UserGroup,u.LockUser,u.userPower,U.titlepic,U.UserGroupID,U.LastLogin,B.PostBuyUser,U.online,B.anony,U.masterboard,b.awardinfo,U.userclass from '+@TotalUseTable+' B left join [user] U on U.UserID=B.PostUserID where B.BoardID='+str(@BoardID)+' and B.rootID='+str(@Announceid)+' and B.locktopic<2 and B.Announceid >=(select min(Announceid) from (select top '+str(@residual)+' announceid from '+@TotalUseTable+' where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 order by announceid desc) temptable ) order by B.AnnounceID'
execute(@tempsql)
set @residual=(@recordcount-@newcount)%@pagecount
set @tempsql='insert into newbbs(ParentID,BoardID,UserName,PostUserID,Topic,Body,DateAndTime,length,RootID,layer,orders,isbest,ip,Expression,locktopic,signflag,emailflag,isagree,isupload,isaudit,PostBuyUser,anony,awardinfo) select ParentID,BoardID,UserName,PostUserID,Topic,Body,DateAndTime,length,RootID,layer,orders,isbest,ip,Expression,locktopic,signflag,emailflag,isagree,isupload,isaudit,PostBuyUser,anony,awardinfo from '+@TotalUseTable+' where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 and announceid>=(select min(Announceid) from (select top '+str(@residual)+' announceid from '+@TotalUseTable+' where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 order by announceid desc) temptable ) order by announceid asc'
execute(@tempsql)
set @tempsql='delete from '+@TotalUseTable+' where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 and announceid>=(select min(Announceid) from (select top '+str(@residual)+' announceid from '+@TotalUseTable+' where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 order by announceid desc) temptable )'
execute(@tempsql)
set @residual=@newcount
set @tempsql='insert into newbbs(ParentID,BoardID,UserName,PostUserID,Topic,Body,DateAndTime,length,RootID,layer,orders,isbest,ip,Expression,locktopic,signflag,emailflag,isagree,isupload,isaudit,PostBuyUser,anony,awardinfo) select ParentID,BoardID,UserName,PostUserID,Topic,Body,DateAndTime,length,RootID,layer,orders,isbest,ip,Expression,locktopic,signflag,emailflag,isagree,isupload,isaudit,PostBuyUser,anony,awardinfo from newbbs where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 and announceid<=(select max(Announceid) from (select top '+str(@residual)+' announceid from newbbs where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 order by announceid) temptable ) order by announceid asc'
execute(@tempsql)
set @tempsql='delete from newbbs where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 and announceid<=(select max(Announceid) from (select top '+str(@residual)+' announceid from newbbs where BoardID='+str(@BoardID)+' and RootID='+str(@Announceid)+' and locktopic<2 order by announceid) temptable )'
execute(@tempsql)
--set @tempsql='Select top '+str(@pagecount)+' B.AnnounceID,B.BoardID,B.UserName,B.Topic,B.dateandtime,B.body,B.Expression,B.ip,B.RootID,B.signflag,B.isbest,B.PostUserid,B.layer,b.isagree,U.useremail,U.homepage,U.oicq,U.sign,U.class,U.title,U.width,U.height,U.article,U.face,U.addDate,U.userWealth,U.userEP,U.userCP,U.birthday,U.sex,u.UserGroup,u.LockUser,u.userPower,U.titlepic,U.UserGroupID,U.LastLogin,B.PostBuyUser,U.online,B.anony,U.masterboard,b.awardinfo,U.userclass from newbbs B left join [user] U on U.UserID=B.PostUserID where B.BoardID='+str(@BoardID)+' and B.rootID='+str(@Announceid)+' and B.locktopic<2 order by Announceid'
--execute(@tempsql)