2012-06-29 00:18:28 -05:00
|
|
|
# -*- 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
|
2011-05-02 21:39:09 +00:00
|
|
|
def put(str, opts={})
|
2010-11-23 01:23:24 +00:00
|
|
|
return super if not str
|
2011-05-02 21:39:09 +00:00
|
|
|
super(str.strip + "\r\n", opts)
|
2010-11-23 01:23:24 +00:00
|
|
|
end
|
2011-05-02 21:39:09 +00:00
|
|
|
def write(str, opts={})
|
2011-05-01 23:56:57 +00:00
|
|
|
return super if not str
|
2011-05-02 21:39:09 +00:00
|
|
|
super(str.strip + "\r\n", opts)
|
2011-05-01 23:56:57 +00:00
|
|
|
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
|
|
|
|
2021-11-10 16:52:10 -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
|
2021-11-10 16:52:10 -05:00
|
|
|
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)
|
2021-10-22 17:24:26 -04:00
|
|
|
|
|
|
|
|
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)
|
2021-10-22 17:24:26 -04:00
|
|
|
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
|