Files
metasploit-gs/lib/msf/core/auxiliary/command_shell.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.6 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2010-11-23 01:23:24 +00:00
module Msf
###
#
# This module provides methods for scanning modules that yield
# Command Shell sessions.
#
###
module Auxiliary::CommandShell
include Msf::Sessions::CommandShellOptions
2013-08-30 16:28:33 -05:00
2010-11-23 01:23:24 +00:00
#
# Ghetto
#
module CRLFLineEndings
def put(str, opts={})
2010-11-23 01:23:24 +00:00
return super if not str
super(str.strip + "\r\n", opts)
2010-11-23 01:23:24 +00:00
end
def write(str, opts={})
return super if not str
super(str.strip + "\r\n", opts)
end
2010-11-23 01:23:24 +00:00
end
2013-08-30 16:28:33 -05:00
2021-06-30 09:51:52 -04:00
def start_session(obj, info, ds_merge, crlf = false, sock = nil, sess = nil)
2010-11-23 01:23:24 +00:00
if crlf
# Windows telnet server requires \r\n line endings and it doesn't
# seem to affect anything else.
obj.sock.extend(CRLFLineEndings)
end
2013-08-30 16:28:33 -05:00
sock ||= obj.respond_to?(:sock) ? obj.sock : nil
2021-06-30 09:51:52 -04:00
sess ||= Msf::Sessions::CommandShell.new(sock)
2010-11-23 01:23:24 +00:00
sess.set_from_exploit(obj)
2013-08-30 16:28:33 -05:00
2010-11-23 01:23:24 +00:00
# Clean up the stored data
sess.exploit_datastore.merge!(ds_merge)
2013-08-30 16:28:33 -05:00
2010-11-23 01:23:24 +00:00
# Prevent the socket from being closed
obj.sockets.delete(sock) if sock
obj.sock = nil if obj.respond_to?(:sock)
2013-08-30 16:28:33 -05:00
2010-11-23 01:23:24 +00:00
framework.sessions.register(sess)
if sess.respond_to?(:bootstrap)
sess.bootstrap(datastore)
return unless sess.alive
end
2010-11-23 01:23:24 +00:00
sess.process_autoruns(datastore)
sess.info = info unless info.blank?
2013-08-30 16:28:33 -05:00
2021-04-07 11:59:22 -05:00
# Notify the framework that we have a new session opening up...
# Don't let errant event handlers kill our session
begin
framework.events.on_session_open(sess)
rescue ::Exception => e
wlog("Exception in on_session_open event handler: #{e.class}: #{e}")
wlog("Call Stack\n#{e.backtrace.join("\n")}")
end
2011-07-14 19:42:03 +00:00
sess
2010-11-23 01:23:24 +00:00
end
end
end