Full Analysis of MSSQL Stored Procedure decryption process

Source: Internet
Author: User
Because I got a Q & A program of my own in the past two days, I found that the developer encrypted my stored procedure, depressed, and found a solution. now share: Open the query analyzer, go to your database and run the following SQL statement: CREATEPROCEDUREsp_decrypt (@ objectNamevarchar (50) ASbeginbegintra

Because I got a Q & A program of my own in the past two days, I found that the developer encrypted my stored procedure, depressed, and found a solution. now share: Open the query analyzer, go to your database and run the following SQL statement: CREATEPROCEDURE sp_decrypt (@ objectName varchar (50) AS begin tra

Because I got a Q & A program of my own in the past two days, I found that the developer encrypted my stored procedure, depressed, and found a solution. Now I share it with you:

Open the query analyzer, locate your database, and execute the following SQL statement:

Create procedure sp_decrypt (@ objectName varchar (50 ))
AS
Begin
Begin transaction
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), @ resulnvtsp archar (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'
-- Set @ sql1 = 'alter PROCEDURE '+ @ objectName +' with encryption'
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 '--
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 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 processure '+ @ 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
Rollback transaction
End
GO

Note: replace @ objectName with the name of the stored procedure you want to crack (for example, replace it with @ ***. com ).

In this way, you create a stored procedure called sp_decrypt in your database,

Call sp_decrypt in the query analyzer to decrypt the stored procedure to be cracked. The statement is as follows:

Exec sp_decrypt 'stored procedure name'

Here is an example of a specific statement: exec sp_decrypt '***. com' (note that the name is "single quotation marks ").

After the decryption is completed, copy the SQL script to your server and restore it.

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.