CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/base/sessions/command_shell_options.rb
Views: 11784
1
# -*- coding: binary -*-
2
3
##
4
# This file is part of the Metasploit Framework and may be subject to
5
# redistribution and commercial restrictions. Please see the Metasploit
6
# Framework web site for more information on licensing and terms of use.
7
# https://metasploit.com/framework/
8
##
9
10
11
module Msf
12
module Sessions
13
module CommandShellOptions
14
15
def initialize(info = {})
16
super(info)
17
18
register_advanced_options(
19
[
20
OptString.new('InitialAutoRunScript', "An initial script to run on session creation (before AutoRunScript)"),
21
OptString.new('AutoRunScript', "A script to run automatically on session creation."),
22
OptString.new('CommandShellCleanupCommand', "A command to run before the session is closed"),
23
OptBool.new('AutoVerifySession', [true, 'Automatically verify and drop invalid sessions', true])
24
]
25
)
26
end
27
28
def on_session(session)
29
super
30
31
# Configure input/output to match the payload
32
session.user_input = self.user_input if self.user_input
33
session.user_output = self.user_output if self.user_output
34
35
platform = nil
36
if self.platform and self.platform.kind_of? Msf::Module::PlatformList
37
platform = self.platform.platforms.first.realname.downcase
38
end
39
if self.platform and self.platform.kind_of? Msf::Module::Platform
40
platform = self.platform.realname.downcase
41
end
42
43
44
# a blank platform is *all* platforms and used by the generic modules, in that case only set this instance if it was
45
# not previously set to a more specific value through some means
46
session.platform = platform unless platform.blank? && !session.platform.blank?
47
48
if self.arch
49
if self.arch.kind_of?(Array)
50
session.arch = self.arch.join('')
51
else
52
session.arch = self.arch
53
end
54
end
55
56
end
57
58
end
59
end
60
end
61
62