How to crack the encrypted stored procedure

xiaoxiao2021-03-06  111

/ * - Crack function, process, trigger, view. SQLSERVER2000

- Author: J9988 - * // * - call example

- Decrypt the designated stored procedure EXEC SP_DECRYPT 'Appsp_test'

- declare all the memory decryption procedure tb cursor for select name from sysobjects where xtype = 'P' and status> 0 declare @name sysname open tb fetch next from tb into @name while @@ fetch_status = 0 begin print '/ * ------- Store [' @ Name '] ----------- * / 'Exec sp_decrypt @name fetch next from tb @name end close TB DEAALLOCATE TB - * /

IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]. [sp_decrypt]') And ObjectProperty (ID, n'isprocedure ') = 1) Drop Procedure [dbo]. [sp_decrypt] Go

Create Procedure SP_Decrypt (@Objectname VARCHAR (50)) ASBEGINSET NOCOUNT ON - 9CBS: J9988 Copyright: 2004.04.15 --v3.1 - Crack bytes are not limited, suitable for SQLServer2000 stored procedures, functions, views, triggers - Correct the previous version of the trigger does not decrypt the error correctly - Discover a wrong, please e_mail: 9cbsj9988@tom.combegin treage @ Objectname1 varchar (100), @ orgvarbin varbinary (4000) Declare @ sql1 nvarchar (4000), @ sql2 varchar (8000), @ sql3 nvarchar (4000), @ sql4 nvarchar (4000) DECLARE @ OrigSpText1 nvarchar (4000), @ OrigSpText2 nvarchar (4000), @ OrigSpText3 nvarchar (4000), @resultsp nvarchar (4000) declare @i INT, @ status int, @ type var, @ @ @ n int, @ Q int, @ j int, @ K int, @ encrypted int, @ Number Intselect @ type = xtype, @ ParentID = Parent_obj from sysobjects where id = Object_id (@Objectname)

create table #temp (number int, colid int, ctext varbinary (8000), encrypted int, status int) insert #temp SELECT number, colid, ctext, encrypted, status FROM syscomments WHERE id = object_id (@objectName) select @ number = Max (Number) from #tempset @ K = 0WHILE @K <= @ Number BeginiF EXISTS (SELECT 1 from syscomments where id = Object_id (@Objectname) and number = @ K) Beginif @ Type = 'p'set @ SQL1 = Case1 @number> 1 Then 'ALTER Procedure' @objectname ';' RTRIM (@K) 'with encryption as' else 'alter procedure' @ Objectname 'with encryption as' END)

if @ type = 'TR'begindeclare @parent_obj varchar (255), @ tr_parent_xtype varchar (10) select @ parent_obj = parent_obj from sysobjects where id = object_id (@objectName) select @ tr_parent_xtype = xtype from sysobjects where id = @ parent_objif @tr_parent_xtype = 'V'beginset @ sql1 =' ALTER TRIGGER ' @ objectname ' ON ' OBJECT_NAME (@parentid) ' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 'endelsebeginset @ sql1 =' ALTER TRIGGER ' @ objectname ' ON ' Object_name (@ParentID) 'with Encryption for Insert Asprint 1' End

Endif @ type = 'fn' or @ type = 'tf' or @ type = 'iF'set @ SQL1 = (case @Type when' Tf 'Ten' ALTER FUNCTION ' @Objectname ' (@ a char (1)) Returns @B Table (a varchar (10)) with encryption as begin insert @B select @a return end 'When' fn '1name '(@OBJECTNAME ) (@ a char (1)) Returns char (1) WITH ENCRYPTION AS Begin Return @a end'when '@ =alter function' @objectname '(@ a char (1)) Returns Table with encryption as return select @a as a'end) if @ type =' v 'set @ SQL1 =' Alter View ' @ ObjectName ' with Encryption As SELECT 1 AS F '

Set @ q = len (@ SQL1) set @ SQL1 = @ SQL1 Replicate ('-', 4000- @ q) SELECT @ SQL2 = Replicate ('-', 8000) set @ SQL3 = 'Exec (@ SQL1'Select @ colid = max (color) from #temp where number = @ K set @ n = 1WHILE @n <= ceiling (@ colid-1) / 2) And len (@ SQL3) <= 3996begin set @ SQL3 = @ SQL3 ' @' set @ n = @ n 1ndset @ SQL3 = @ SQL3 ')' EXEC SP_EXECUTESQL @ SQL3, N '@ SQL1 NVARCHAR (4000), @ sql1 = @ SQL1, @ = @ SQL2

Endset @ k = @ K 1END

Set @ K = 0WHILE @K <= @ Number Begin

IF exists (SELECT 1 from syscomments where id = Object_id (@Objectname) and number = @ K) Beginselect @ colid = max (colid) from #temp where number = @ K set @ n = 1

while @n <= @ colidbeginselect @ OrigSpText1 = ctext, @ encrypted = encrypted, @ status = status FROM #temp WHERE colid = @ n and number = @ kSET @ OrigSpText3 = (SELECT ctext FROM syscomments WHERE id = object_id (@objectName) And colid = @ n and number = @ K) if @ n = 1beginif @ type = 'p'Set @ origsptext2 = (Case when @number> 1 Then' crete procedure ' @objectname '; ' RTRIM (@K) ) 'With encryption as' else 'crete procedure' @Objectname 'with encryption as' end)

IF @ type = 'fn' or @ type = 'tf' or @ type = 'iF'set @ origsptext2 = (case @Type when' TF 'TEN' CREATE FUNCTION ' @ObjectName ' (@ a char (1)) Returns @B Table (a varchar (10)) with encryption as begin insert @B select @a return end 'when' fn 'dam @Objectname ' (@ a char (1)) Returns char (1) WITH ENCRYPTION AS Begin Return @a end'when 'f' Then'create Function ' @objectname ' (@ a char (1)) Returns Table with Encryption As Return SELECT @a as a'end)

IF @ Type = 'tr' begin

if @ tr_parent_xtype = 'V'beginset @ OrigSpText2 =' CREATE TRIGGER ' @ objectname ' ON ' OBJECT_NAME (@parentid) ' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 'endelsebeginset @ OrigSpText2 =' CREATE TRIGGER ' @ objectname ' ON ' Object_name (@parentid) ' with Encryption for Insert Asprint 1 'Endend

IF @ type = 'V'Set @ igsptext2 =' create view ' @ ObjectName ' with encryption as select 1 as f '

SET @ q = 4000-len (@ OrigsPText2) set @ origsptext2 = @ igigsptext2 replicate ('-', @ q) endelsebeginset @ igigsptext2 = replicate ('-', 4000) endset @ = 1

Set @Resultsp = Replicate (N'A ', (DatalesPtext1) / 2)))

While @i <= datalength (@ ptext1) / 2begin

Set @Resultsp = stuff (@Resultsp, @i, 1, nchar (unicode (@ ptext1, @i, 1)) ^ (unicode (@ ptext2, @i, 1)) ^ unicode (@ @ 1 OrigspText3, @i, 1)))))) SET @ i = @ i 1ndset @ orgvarbin = CAST (@ ptext1 as varbinary (8000)) set @ resultsp = (casten @ Encrypted = 1 Then @Resultsp Else Convert (nvarchar (4000), Case When @ status & 2 = 2 THEN UNCOMPRESS (@orgvarbin) Else @orgvarbin end) @Resultsp

Set @ n = @ n 1

end

Endset @ k = @ K 1END

Drop Table #TemProllback Tranend

转载请注明原文地址:https://www.9cbs.com/read-125624.html

New Post(0)