我在Node.js中开发我的第一个应用程序,我认为我听不懂如何工作,因为我写的示例并未显示我认为它是什么去演出。Node.js:收听者的问题
我想使用一个模块(msfnode),它是一个metasploit RPC客户端,所以它通过websockets连接。
我做了一个类和构造有这样的代码:
this.clientmsf = new MetasploitClient({
login : options.login || 'myLogin',
password : options.password || 'myPassword'
});
this.clientmsf.on('connected',function(err,token) {
if (err) throw err;
});
所以我想我可以在这个类的其他功能使用对象“clientmsf”,它显示了一个错误:ERROR_MESSAGE:“无效的认证令牌”。这是代码:
this.clientmsf.exec(['console.create'], function(err,r){
consoleID = r.id;
console.log(r);
});
我觉得我有这个错误,因为我不知道node.js中的所有概念,所以我会,如果有人可以帮助我非常感激。
非常感谢。
PD。这是msfnode库的例子:
var metasploitClient = require('metasploitJSClient');
var onConnect = function(err,token) {
if (err) {
console.log(err.error_message);
process.exit(0);
}
metasploitVersion();
}
var metasploitVersion = function() {
// Do not care about token, it will automaticaly
// be added as the second arguments
// The first value of the array is the function
// you want to call. Full list is available
// in metasploit remote api documentation
var args = ['core.version'];
client.exec(args,function(err,r) {
if (err) return console.log('Error: '+err);
console.log('-> Version: '+r);
});
}
var client = new metasploitClient({
login:'myLogin',
password:'myPassword',
});
client.on('connected',onConnect);
错误:
{ error: true,
error_class: 'Msf::RPC::Exception',
error_string: 'Msf::RPC::Exception',
error_backtrace:
[ 'lib/msf/core/rpc/v10/service.rb:148:in `process\'',
'lib/msf/core/rpc/v10/service.rb:90:in `on_request_uri\'',
'lib/msf/core/rpc/v10/service.rb:72:in `block in start\'',
'lib/rex/proto/http/handler/proc.rb:38:in `call\'',
'lib/rex/proto/http/handler/proc.rb:38:in `on_request\'',
'lib/rex/proto/http/server.rb:363:in `dispatch_request\'',
'lib/rex/proto/http/server.rb:297:in `on_client_data\'',
'lib/rex/proto/http/server.rb:157:in `block in start\'',
'lib/rex/io/stream_server.rb:48:in `call\'',
'lib/rex/io/stream_server.rb:48:in `on_client_data\'',
'lib/rex/io/stream_server.rb:192:in `block in monitor_clients\'',
'lib/rex/io/stream_server.rb:190:in `each\'',
'lib/rex/io/stream_server.rb:190:in `monitor_clients\'',
'lib/rex/io/stream_server.rb:73:in `block in start\'',
'lib/rex/thread_factory.rb:22:in `call\'',
'lib/rex/thread_factory.rb:22:in `block in spawn\'',
'lib/msf/core/thread_manager.rb:100:in `call\'',
'lib/msf/core/thread_manager.rb:100:in `block in spawn\'' ],
error_message: 'Invalid Authentication Token',
error_code: 401 }
编辑2:
这就是我检查代码:
clientmsf.on('connected',function(err,token) {
if (err) throw err;
var consoleID;
console.log('token:' + token);
// should have connected by now
clientmsf.exec(['console.list'], function(err,r){
consoleID = r;
console.log(r);
});
console.log (consoleID);
});
这是它显示了什么:
token:[object Object]
undefined
{ consoles: [ { id: '0', prompt: 'msf > ', busy: false } ] }
这是您收到的通常节点让你在错误发生的行号整个错误消息?你真的在机器上启动了msfrpcd吗? –
不,错误来自Metasploit API。我认为麻烦可能是一种“竞争条件”,因为在连接之前执行“exec”并且对象还不知道该令牌。我要添加完整的错误。 感谢Vasil您的兴趣。 –