首页 > 开发 > 综合 > 正文

解密SQL2000的存储过程

2024-07-21 02:05:49
字体:
来源:转载
供稿:网友

内容来自互联网,作者不明
drop procedure sp_decrypt
go
create  procedure sp_decrypt (@objectname varchar(50))
as
begin

begin transaction --add by playyuer

declare @objectname1 varchar(100)
declare @sql1 nvarchar(4000),@sql2 nvarchar(4000),@sql3 nvarchar(4000),@sql4 nvarchar(4000),@sql5 nvarchar(4000),@sql6 nvarchar(4000),@sql7 nvarchar(4000),@sql8 nvarchar(4000),@sql9 nvarchar(4000),@sql10 nvarchar(4000) 
declare  @origsptext1 nvarchar(4000),  @origsptext2 nvarchar(4000) , @origsptext3 nvarchar(4000), @resultsp nvarchar(4000)
declare  @i int , @t bigint
declare @m int,@n int,@q int
set @m=(select max(colid) from syscomments  where id = object_id(@objectname))
set @n=1
--get encrypted data
create table  #temp(colid int,ctext varbinary(8000))
insert #temp select colid,ctext from syscomments  where id = object_id(@objectname)
set @sql1='alter procedure '+ @objectname +' with encryption as '
--set @sql1='alter procedure '+ @objectname +' with encryption as '
set @q=len(@sql1)
set @[email protected]+replicate('-',[email protected])
select @sql2=replicate('-',4000),@sql3=replicate('-',4000),@sql4=replicate('-',4000),@sql5=replicate('-',4000),@sql6=replicate('-',4000),@sql7=replicate('-',4000),@sql8=replicate('-',4000),@sql9=replicate('-',4000),@sql10=replicate('-',4000)
exec(@[email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected])
while @n<[email protected]
begin
set @origsptext1=(select ctext from #temp  where [email protected])
set @[email protected]+'_t'
set @origsptext3=(select ctext from syscomments where id=object_id(@objectname) and [email protected])
if @n=1
begin
set @origsptext2='create procedure '+ @objectname +' with encryption as '--
set @q=4000-len(@origsptext2)
set @[email protected]+replicate('-',@q)
end
else
begin
set @origsptext2=replicate('-', 4000)
end
--start counter
set @i=1
--fill temporary variable
set @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))

--loop
while @i<=datalength(@origsptext1)/2
begin
--reverse encryption (xor original+bogus+bogus encrypted)
set @resultsp = stuff(@resultsp, @i, 1, nchar(unicode(substring(@origsptext1, @i, 1)) ^
                                (unicode(substring(@origsptext2, @i, 1)) ^
                                unicode(substring(@origsptext3, @i, 1)))))
    set @[email protected]+1
end
--drop original sp
--execute ('drop procedure '+ @objectname)
--remove encryption
--preserve case
set @resultsp=replace((@resultsp),'with encryption', '')
set @resultsp=replace((@resultsp),'with encryption', '')
set @resultsp=replace((@resultsp),'with encryption', '')
if charindex('with encryption',upper(@resultsp) )>0
  set @resultsp=replace(upper(@resultsp),'with encryption', '')
--replace stored procedure without enryption
print @resultsp
--execute( @resultsp)
set @[email protected]+1
end
drop table #temp
end
rollback transaction --add by playyuer
go

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表