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/rex/post/meterpreter/extensions/stdapi/stdapi.rb
Views: 11791
1
# -*- coding: binary -*-
2
3
require 'rex/post/meterpreter/object_aliases'
4
require 'rex/post/meterpreter/extension'
5
require 'rex/post/meterpreter/extensions/stdapi/constants'
6
require 'rex/post/meterpreter/extensions/stdapi/tlv'
7
require 'rex/post/meterpreter/extensions/stdapi/command_ids'
8
require 'rex/post/meterpreter/extensions/stdapi/fs/dir'
9
require 'rex/post/meterpreter/extensions/stdapi/fs/file'
10
require 'rex/post/meterpreter/extensions/stdapi/fs/file_stat'
11
require 'rex/post/meterpreter/extensions/stdapi/fs/mount'
12
require 'rex/post/meterpreter/extensions/stdapi/net/resolve'
13
require 'rex/post/meterpreter/extensions/stdapi/net/config'
14
require 'rex/post/meterpreter/extensions/stdapi/net/socket'
15
require 'rex/post/meterpreter/extensions/stdapi/sys/config'
16
require 'rex/post/meterpreter/extensions/stdapi/sys/process'
17
require 'rex/post/meterpreter/extensions/stdapi/sys/registry'
18
require 'rex/post/meterpreter/extensions/stdapi/sys/event_log'
19
require 'rex/post/meterpreter/extensions/stdapi/sys/power'
20
require 'rex/post/meterpreter/extensions/stdapi/railgun/railgun'
21
require 'rex/post/meterpreter/extensions/stdapi/ui'
22
require 'rex/post/meterpreter/extensions/stdapi/webcam/webcam'
23
require 'rex/post/meterpreter/extensions/stdapi/mic/mic'
24
require 'rex/post/meterpreter/extensions/stdapi/audio_output/audio_output'
25
26
module Rex
27
module Post
28
module Meterpreter
29
module Extensions
30
module Stdapi
31
32
###
33
#
34
# Standard ruby interface to remote entities for meterpreter. It provides
35
# basic access to files, network, system, and other properties of the remote
36
# machine that are fairly universal.
37
#
38
###
39
class Stdapi < Extension
40
41
def self.extension_id
42
EXTENSION_ID_STDAPI
43
end
44
45
#
46
# Initializes an instance of the standard API extension.
47
#
48
def initialize(client)
49
super(client, 'stdapi')
50
51
# Alias the following things on the client object so that they
52
# can be directly referenced
53
client.register_extension_aliases(
54
[
55
{
56
'name' => 'fs',
57
'ext' => ObjectAliases.new(
58
{
59
'dir' => self.dir,
60
'file' => self.file,
61
'filestat' => self.filestat,
62
'mount' => Fs::Mount.new(client)
63
})
64
},
65
{
66
'name' => 'sys',
67
'ext' => ObjectAliases.new(
68
{
69
'config' => Sys::Config.new(client),
70
'process' => self.process,
71
'registry' => self.registry,
72
'eventlog' => self.eventlog,
73
'power' => self.power
74
})
75
},
76
{
77
'name' => 'net',
78
'ext' => ObjectAliases.new(
79
{
80
'config' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Config.new(client),
81
'socket' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Socket.new(client),
82
'resolve' => Rex::Post::Meterpreter::Extensions::Stdapi::Net::Resolve.new(client)
83
})
84
},
85
{
86
'name' => 'railgun',
87
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::Railgun.new(client)
88
},
89
{
90
'name' => 'webcam',
91
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Webcam::Webcam.new(client)
92
},
93
{
94
'name' => 'mic',
95
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::Mic::Mic.new(client)
96
},
97
{
98
'name' => 'audio_output',
99
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::AudioOutput::AudioOutput.new(client)
100
},
101
{
102
'name' => 'ui',
103
'ext' => UI.new(client)
104
}
105
106
])
107
end
108
109
#
110
# Sets the client instance on a duplicated copy of the supplied class.
111
#
112
def brand(klass)
113
klass = klass.dup
114
klass.client = self.client
115
return klass
116
end
117
118
#
119
# Returns a copy of the Dir class.
120
#
121
def dir
122
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Fs::Dir)
123
end
124
125
#
126
# Returns a copy of the File class.
127
#
128
def file
129
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Fs::File)
130
end
131
132
#
133
# Returns a copy of the FileStat class.
134
#
135
def filestat
136
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Fs::FileStat)
137
end
138
139
#
140
# Returns a copy of the Process class.
141
#
142
def process
143
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Process)
144
end
145
146
#
147
# Returns a copy of the Registry class.
148
#
149
def registry
150
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Registry)
151
end
152
153
#
154
# Returns a copy of the EventLog class.
155
#
156
def eventlog
157
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::EventLog)
158
end
159
160
#
161
# Returns a copy of the Power class.
162
#
163
def power
164
brand(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Power)
165
end
166
end
167
168
end; end; end; end; end
169
170