2011-04-12 73 views
0

我喜欢这个网站,它通过其他人的问题帮助了我很多,现在我加入了,所以我可以帮助对方。在运行meterpreter的ruby脚本时出错

我在这里有一个问题。 在虚拟机中运行meterpreter(来自metasploit套件)时,我尝试了一个脚本来传递受感染计算机中的所有端口,并在本地计算机中创建一个虚拟接口。但我得到错误

Undefined method: each

虽然要去代码:

def discovery() 
    ip_port = [] 
    # Alive hosts discovery 
    temphosts = [] 
    hosts = [] 
    ## oldstdout = $stdout ## Trick for capturing stdout 
    $stdout = StringIO.new 
    client.run_cmd('run landiscovery') 
    temphosts = $stdout.string 
    $stdout = oldstdout 
    print_status "Alive Hosts:" 
    temphosts.each do |x| 
    if x.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) 
     y = x.chomp 
     hosts << y 
     print " - #{y}\n" 
    end 
    end 
end 

我认为这是某种相关的行我与##包围。它必须是nil因此temphosts也是nil我也得到每个错误。

有人能指点我吗?

非常感谢。

PS:脚本,如果有人有兴趣在这里:http://tools.pentester.es/multirelay

再次感谢!

回答

0
$stdout.string 

此行将返回一个单一的String对象,其中包含输出的所有行,并包含\ n字符。 字符串对象没有任何每种方法。

也许你想得到一个字符串列表,代表你的输出行的列表。在这种情况下,你应该首先拆分你的字符串:

temphosts.split("\n").each do |x| 
+0

谢谢muriel!这工作。 – user1283604 2011-04-12 19:49:36