Skip to content

Instantly share code, notes, and snippets.

@bka
Created March 16, 2011 10:04
Show Gist options
  • Save bka/872269 to your computer and use it in GitHub Desktop.
Save bka/872269 to your computer and use it in GitHub Desktop.
How to send commands to an existing metasploit framework instance
# init console with metasploit framwork
@console = Msf::Ui::Web::WebConsole.new(@framework,1)
# used to exec a command like it would be typed into msfconsole
def cmd_send_to_terminal cmd
@console.execute(cmd)
return @[email protected]
end
# used to interact with an open meterpreter session
def cmd_send_to_msfsession cmd, session_uuid
input = Rex::Ui::Text::Input::Readline.new
output = Rex::Ui::Text::Output::Buffer.new
session = get_session_by_uuid @framework.sessions, session_uuid
session.init_ui(input,output)
session.run_cmd(cmd)
return session.console.output.dump_buffer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment