Error in ruby script while running meterpreter
I love this website, it has helped me a lot through other people's questions, now I have joined so I can help each others if I can.
I have an issue here. While running meterpreter (from metasploit suite) in a VM, I have tried a script that relays all the ports in the compromised machine and creates a virtual interface in your local machine. But I'm getting the error
Undefined method: each
.
While going to the code:
def discovery()
ip_port = []
# Alive hosts discovery
temphosts = []
hosts = []
## oldstdout = $stdout ## Trick开发者_Python百科 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
I think it is somehow related to the line I have surrounded with ##
. It has to be nil
so temphosts
is nil
too and I get the each error.
Can someone point me in a good direction?
Thanks greatly appreciated.
PS: The scripts if someone is interested are in here: http://tools.pentester.es/multirelay
Thanks again!
$stdout.string
This line will return a single String object, containing all the lines of your output, with \n characters included. String objects do not have any each method.
Maybe you wanted to get a list of Strings, representing the list of lines of your output. In this case, you should first split your String:
temphosts.split("\n").each do |x|
精彩评论