Found, decrypting the SQL2000 stored procedure

Source: Internet
Author: User
Stored Procedure | Decrypt create the following stored procedure
and then call
EXEC sp_decrypt @objectName
(@objectName is the name of the stored procedure that was encrypted)
Exposed!
This program does not destroy the original stored procedure!
Oh, how fun!

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 @sql1 = @sql1 +replicate ('-', 4000-@q)
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 (@sql1 + @sql2 + @sql3 + @sql4 + @sql5 + @sql6 + @sql7 + @sql8 + @sql9 + @sql10)
While @n<=@m
Begin
SET @OrigSpText1 = (SELECT ctext from #temp WHERE colid=@n)
Set @objectname1 = @objectName + ' _t '
SET @OrigSpText3 = (SELECT ctext from syscomments WHERE id=object_id (@objectName) and Colid=@n)
If @n=1
Begin
SET @OrigSpText2 = ' CREATE PROCEDURE ' + @objectName + ' with encryption as '--
Set @q=4000-len (@OrigSpText2)
Set @OrigSpText2 = @OrigSpText2 +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 @i=@i+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 @n=@n+1
End
drop table #temp
End
Rollback TRANSACTION--add by Playyuer
Go



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.