这篇文章将为大家详细讲解有关SQL SERVER SP的解密过程介绍,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
在SQL SERVER里,已知微软在加密和解密存储过程时用的是RC4算法。下面是解密存储过程的解题思路,读者可以据此自己写个解密小程序。
想解密SP,其实就是解答下列一道证明题。
已知条件:
证明过程:
/** Object: StoredProcedure [dbo].[dbtwin_sp_decrypt] Script Date: 01/01/2020 21:09:31 **/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dbtwin_sp_decrypt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[dbtwin_sp_decrypt]
GO
/** Object: StoredProcedure [dbo].[dbtwin_sp_decrypt] Script Date: 01/01/2020 21:09:31 **/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[dbtwin_sp_decrypt](@procname sysname = NULL)
AS
DECLARE @encrypted NVARCHAR(MAX)
DECLARE @encryptedLength INT
DECLARE @tempStr NVARCHAR(MAX)
DECLARE @tempHead NVARCHAR(MAX)
DECLARE @tempBody NVARCHAR(MAX)
DECLARE @dummySp NVARCHAR(MAX)
DECLARE @dummyEncrypted NVARCHAR(MAX)
DECLARE @decryptedMessage NVARCHAR(MAX)
DECLARE @cnt INT
DECLARE @decryptedChar NCHAR(1)
SET NOCOUNT ON
SET @encrypted = (SELECT imageval FROM sys.sysobjvalues WHERE object_name(objid)=@procname)
SET @encryptedLength=DATALENGTH(@encrypted) / 2
SET @tempStr = N'PROCEDURE ' + @procname + N' WITH ENCRYPTION AS'
BEGIN TRAN
SET @tempHead = N'ALTER ' + @tempStr
SET @tempBody = REPLICATE(N' ',(@encryptedLength - LEN(@tempHead)))
EXEC(@tempHead + @tempBody)
SET @dummyEncrypted = (SELECT imageval FROM sys.sysobjvalues WHERE object_name(objid)=@procname)
ROLLBACK TRAN
SET @dummySp =N'CREATE ' + @tempStr + @tempBody
SET @decryptedMessage =''
SET @cnt = 1
WHILE @cnt <> @encryptedLength
BEGIN
SET @decryptedChar =NCHAR(UNICODE(SUBSTRING(@encrypted, @cnt, 1)) ^
UNICODE(SUBSTRING(@dummySp, @cnt, 1)) ^
UNICODE(SUBSTRING(@dummyEncrypted, @cnt, 1)))
SET @decryptedChar=ISNULL(@decryptedChar,N' ')
SET @decryptedMessage = @decryptedMessage + @decryptedChar
SET @cnt = @cnt + 1
END
SELECT @decryptedMessage
GO
看完上述内容,你们对SQL SERVER SP的解密过程大概了解了吗?如果想了解更多相关文章内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。