Skip to content

Commit 0206663

Browse files
committed
feat: add stdapi_ui extension
1 parent 02995f2 commit 0206663

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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/mic/mic'
9+
require 'rex/post/meterpreter/extensions/stdapi/audio_output/audio_output'
10+
require 'rex/post/meterpreter/extensions/stdapi/webcam/webcam'
11+
require 'rex/post/meterpreter/extensions/stdapi/sys/config'
12+
require 'rex/post/meterpreter/extensions/stdapi/sys/process'
13+
require 'rex/post/meterpreter/extensions/stdapi/sys/registry'
14+
require 'rex/post/meterpreter/extensions/stdapi/sys/event_log'
15+
require 'rex/post/meterpreter/extensions/stdapi/sys/power'
16+
require 'rex/post/meterpreter/extensions/stdapi/ui'
17+
18+
module Rex
19+
module Post
20+
module Meterpreter
21+
module Extensions
22+
module Stdapi_Ui
23+
module AudioOutput
24+
include Rex::Post::Meterpreter::Extensions::Stdapi::AudioOutput
25+
end
26+
27+
module Mic
28+
include Rex::Post::Meterpreter::Extensions::Stdapi::Mic
29+
end
30+
31+
module Webcam
32+
include Rex::Post::Meterpreter::Extensions::Stdapi::Webcam
33+
end
34+
35+
module Sys
36+
include Rex::Post::Meterpreter::Extensions::Stdapi::Sys
37+
end
38+
include Rex::Post::Meterpreter::Extensions::Stdapi
39+
40+
###
41+
#
42+
# Standard ruby interface to remote entities for meterpreter. It provides
43+
# basic access to files, network, system, and other properties of the remote
44+
# machine that are fairly universal.
45+
#
46+
###
47+
class Stdapi_Ui < Extension
48+
49+
def self.extension_id
50+
Rex::Post::Meterpreter::Extensions::Stdapi::EXTENSION_ID_STDAPI
51+
end
52+
53+
#
54+
# Initializes an instance of the standard API extension.
55+
#
56+
def initialize(client)
57+
super(client, 'stdapi_ui')
58+
59+
# Alias the following things on the client object so that they
60+
# can be directly referenced
61+
client.register_extension_aliases(
62+
[
63+
{
64+
'name' => 'audio_output',
65+
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi_Ui::AudioOutput::AudioOutput.new(client)
66+
},
67+
{
68+
'name' => 'mic',
69+
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Mic::Mic.new(client)
70+
},
71+
{
72+
'name' => 'sys',
73+
'ext' => ObjectAliases.new(
74+
{
75+
'config' => Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Sys::Config.new(client),
76+
'process' => process,
77+
'registry' => registry,
78+
'eventlog' => eventlog,
79+
'power' => power
80+
}
81+
)
82+
},
83+
{
84+
'name' => 'ui',
85+
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi::UI.new(client)
86+
},
87+
{
88+
'name' => 'webcam',
89+
'ext' => Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Webcam::Webcam.new(client)
90+
},
91+
]
92+
)
93+
end
94+
95+
#
96+
# Sets the client instance on a duplicated copy of the supplied class.
97+
#
98+
def brand(klass)
99+
klass = klass.dup
100+
klass.client = client
101+
return klass
102+
end
103+
104+
#
105+
# Returns a copy of the Process class.
106+
#
107+
def process
108+
brand(Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Sys::Process)
109+
end
110+
111+
#
112+
# Returns a copy of the Registry class.
113+
#
114+
def registry
115+
brand(Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Sys::Registry)
116+
end
117+
118+
#
119+
# Returns a copy of the EventLog class.
120+
#
121+
def eventlog
122+
brand(Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Sys::EventLog)
123+
end
124+
125+
#
126+
# Returns a copy of the Power class.
127+
#
128+
def power
129+
brand(Rex::Post::Meterpreter::Extensions::Stdapi_Ui::Sys::Power)
130+
end
131+
end
132+
end
133+
end
134+
end
135+
end
136+
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: binary -*-
2+
3+
require 'rex/post/meterpreter'
4+
5+
module Rex
6+
module Post
7+
module Meterpreter
8+
module Ui
9+
###
10+
#
11+
# Standard API extension.
12+
#
13+
###
14+
class Console::CommandDispatcher::Stdapi_Ui
15+
require 'rex/post/meterpreter/ui/console/command_dispatcher/stdapi'
16+
require 'rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui'
17+
18+
Klass = Console::CommandDispatcher::Stdapi_Ui
19+
20+
Dispatchers =
21+
[
22+
Console::CommandDispatcher::Stdapi::Ui,
23+
]
24+
25+
include Console::CommandDispatcher
26+
27+
def self.has_command?(name)
28+
Dispatchers.any? { |klass| klass.has_command?(name) }
29+
end
30+
31+
#
32+
# Initializes an instance of the stdapi command interaction.
33+
#
34+
def initialize(shell)
35+
super
36+
37+
Dispatchers.each do |d|
38+
shell.enstack_dispatcher(d)
39+
end
40+
str_dispatchers = []
41+
uniq_dispatchers = []
42+
idx = 0
43+
while idx < shell.dispatcher_stack.length
44+
unless str_dispatchers.include?(shell.dispatcher_stack[idx].class.to_s)
45+
str_dispatchers.push(shell.dispatcher_stack[idx].class.to_s)
46+
uniq_dispatchers.push(shell.dispatcher_stack[idx])
47+
end
48+
idx += 1
49+
end
50+
shell.dispatcher_stack = uniq_dispatchers
51+
end
52+
53+
#
54+
# List of supported commands.
55+
#
56+
def commands
57+
{}
58+
end
59+
60+
#
61+
# Name for this dispatcher
62+
#
63+
def name
64+
'Standard Ui extension'
65+
end
66+
67+
end
68+
end
69+
end
70+
end
71+
end

0 commit comments

Comments
 (0)