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/plugins/sample.rb
Views: 11705
1
module Msf
2
###
3
#
4
# This class illustrates a sample plugin. Plugins can change the behavior of
5
# the framework by adding new features, new user interface commands, or
6
# through any other arbitrary means. They are designed to have a very loose
7
# definition in order to make them as useful as possible.
8
#
9
###
10
class Plugin::Sample < Msf::Plugin
11
12
###
13
#
14
# This class implements a sample console command dispatcher.
15
#
16
###
17
class ConsoleCommandDispatcher
18
include Msf::Ui::Console::CommandDispatcher
19
20
#
21
# The dispatcher's name.
22
#
23
def name
24
'Sample'
25
end
26
27
#
28
# Returns the hash of commands supported by this dispatcher.
29
#
30
def commands
31
{
32
'sample' => 'A sample command added by the sample plugin'
33
}
34
end
35
36
#
37
# This method handles the sample command.
38
#
39
def cmd_sample(*args)
40
print_line("You passed: #{args.join(' ')}")
41
end
42
end
43
44
#
45
# The constructor is called when an instance of the plugin is created. The
46
# framework instance that the plugin is being associated with is passed in
47
# the framework parameter. Plugins should call the parent constructor when
48
# inheriting from Msf::Plugin to ensure that the framework attribute on
49
# their instance gets set.
50
#
51
def initialize(framework, opts)
52
super
53
54
# If this plugin is being loaded in the context of a console application
55
# that uses the framework's console user interface driver, register
56
# console dispatcher commands.
57
add_console_dispatcher(ConsoleCommandDispatcher)
58
59
print_status('Sample plugin loaded.')
60
end
61
62
#
63
# The cleanup routine for plugins gives them a chance to undo any actions
64
# they may have done to the framework. For instance, if a console
65
# dispatcher was added, then it should be removed in the cleanup routine.
66
#
67
def cleanup
68
# If we had previously registered a console dispatcher with the console,
69
# deregister it now.
70
remove_console_dispatcher('Sample')
71
end
72
73
#
74
# This method returns a short, friendly name for the plugin.
75
#
76
def name
77
'sample'
78
end
79
80
#
81
# This method returns a brief description of the plugin. It should be no
82
# more than 60 characters, but there are no hard limits.
83
#
84
def desc
85
'Demonstrates using framework plugins'
86
end
87
88
end
89
end
90
91