Thursday, January 10, 2008

SQL Server 2005 - Hacking password Encryption

SQL Server 2005 Encryption types
http://www.databasejournal.com/features/mssql/article.php/3714031

SQL Server 2005 provides the following mechanism of encryption in order to encrypt the data.
ENCRYPTION by passphrase
ENCRYPTION by symmetric keys
ENCRYPTION by Asymmetric keys
ENCRYPTION by certificates

SQL Server 2005 - Hacking password Encryption


USE [Master]
GO

/****** Object: StoredProcedure [dbo].[hack_encryption]
Script Date: 12/18/2007 18:18:36 ******/
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[hack_encryption]')
AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[hack_encryption]
GO
set nocount on
SET CONCAT_NULL_YIELDS_NULL OFF
go
USE [Master]
GO

/****** Object: StoredProcedure [dbo].[hack_encryption]
Script Date: 12/18/2007 18:18:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[hack_encryption] @encryptedtext varbinary(max)
as
declare @password varchar(6)
declare @i int
declare @j int
declare @k int
declare @l int
declare @m int
declare @n int


set @i=-1
set @j=-1
set @k=-1
set @l=-1
set @m=-1
set @n=-1
set @password =''

while @i<255
begin
while @j<255
begin
while @k<255
begin
while @l<255
begin
while @m<255
begin
while @n<=255
begin
set @password=isnull(char(@i),'') + isnull(char(@j),'')+isnull(char(@k),'')+ isnull(char(@l),'')+isnull(char(@m),'') + isnull(char(@n),'')
if convert(varchar(100),DecryptByPassPhrase(ltrim(rtrim(@password)),@encryptedtext)) is not null
begin
print 'This is the Encrypted text:' +@password
set @i=256;set @j=256;set @k=256;set @l=256;set @m=256;set @n=256;
print 'The actual data is :' +convert(varchar(100),DecryptByPassPhrase(ltrim(rtrim(@password)),@encryptedtext))
end
--print 'A'+ltrim(rtrim(@password))+'B'
--print convert(varchar(100),DecryptByPassPhrase(ltrim(rtrim(@password)),@encryptedtext))
set @n=@n+1
end
set @n=0
set @m=@m+1
end
set @m=0
set @l=@l+1
end
set @l=0
set @k=@k+1
end
set @k=0
set @j=@j+1
end
set @j=0
set @i=@i+1
end


GO