我喜欢这个网站,它通过其他人的问题为我提供了很多帮助,现在我已加入,所以如果可以,我可以互相帮助。
我有一个问题。 在VM中运行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 :(得分:0)
$stdout.string
该行将返回一个String对象,其中包含输出的所有行,包含\ n个字符。 String对象没有任何方法。
也许您想获得一个字符串列表,表示输出行的列表。在这种情况下,您应该先拆分您的字符串:
temphosts.split("\n").each do |x|