Metasploit mailing list archives

Catching exploit exceptions in rc script


From: birchfresh <birchfresh () tormail org>
Date: Tue, 26 Jun 2012 15:46:09 +0000

Hello there.

I'm using msfconsole (newest git) to run a rc script that's essentially
something like:

  <ruby>
  run_single("use windows/smb/psexec")
  # [...]

  old_sessions = framework.sessions.keys.clone
  run_single("exploit -z") rescue nil    # script stops here after exception!

  new_session = (old_sessions - framework.sessions.keys).first
  do_something_with(new_session) if new_session
  </ruby>

My problem is that if the exploit raises an exception, the script refuses
continue until I press ^C. Shouldn't "rescue nil" catch the exception?

I tried to work around it by running the exploit as a background job
(exploit -z -j) and waiting for framework.jobs.length to be decremented,
but it's no good: If there's an exception, the job hangs around forever.

For context, I'm doing the following to a number of hosts, one by one:
Pivoted login with the psexec module, run a post module to gather some
data, kill the session, move on to the next host.

Is there a better way to open a session (and get its number) than to
run_single("exploit -z") and poke around in framework.sessions.keys for
newcomers?

Or, as a last resort: Is there a way to tell if the exploit at
framework.jobs[id] is dead?
_______________________________________________
https://mail.metasploit.com/mailman/listinfo/framework


Current thread: