Skip to content

Commit f8f61e8

Browse files
committed
Basic shell of the MSF Powershell extension functionality
1 parent df0ff30 commit f8f61e8

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: binary -*-
2+
3+
require 'rex/post/meterpreter/extensions/powershell/tlv'
4+
5+
module Rex
6+
module Post
7+
module Meterpreter
8+
module Extensions
9+
module Powershell
10+
11+
###
12+
#
13+
# This meterpreter extensions a privilege escalation interface that is capable
14+
# of doing things like dumping password hashes and performing local
15+
# exploitation.
16+
#
17+
###
18+
class Powershell < Extension
19+
20+
21+
def initialize(client)
22+
super(client, 'powershell')
23+
24+
client.register_extension_aliases(
25+
[
26+
{
27+
'name' => 'powershell',
28+
'ext' => self
29+
},
30+
])
31+
end
32+
33+
34+
def execute_string(string)
35+
request = Packet.create_request('powershell_execute')
36+
37+
response = client.send_request(request)
38+
39+
return response
40+
end
41+
42+
end
43+
44+
end; end; end; end; end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: binary -*-
2+
module Rex
3+
module Post
4+
module Meterpreter
5+
module Extensions
6+
module Powershell
7+
8+
TLV_TYPE_POWERSHELL_CODE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 1)
9+
10+
end
11+
end
12+
end
13+
end
14+
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# -*- coding: binary -*-
2+
require 'rex/post/meterpreter'
3+
4+
module Rex
5+
module Post
6+
module Meterpreter
7+
module Ui
8+
9+
###
10+
#
11+
# Powershell extension - interact with a Powershell interpreter
12+
#
13+
###
14+
class Console::CommandDispatcher::Powershell
15+
16+
Klass = Console::CommandDispatcher::Powershell
17+
18+
include Console::CommandDispatcher
19+
20+
#
21+
# Name for this dispatcher
22+
#
23+
def name
24+
'Powershell'
25+
end
26+
27+
#
28+
# List of supported commands.
29+
#
30+
def commands
31+
{
32+
'powershell_execute' => 'Execute a Powershell command string',
33+
}
34+
end
35+
36+
@@powershell_execute_opts = Rex::Parser::Arguments.new(
37+
'-h' => [false, 'Help banner']
38+
)
39+
40+
def powershell_execute_usage
41+
print_line('Usage: powershell_execute <powershell code>')
42+
print_line
43+
print_line('Runs the given Powershell string on the target.')
44+
print_line(@@powershell_execute_opts.usage)
45+
end
46+
47+
#
48+
# Execute a simple Powershell command string
49+
#
50+
def cmd_powershell_execute(*args)
51+
if args.length == 0 || args.include?('-h')
52+
powershell_execute_usage
53+
return false
54+
end
55+
56+
code = args.shift
57+
58+
@@powershell_execute_opts.parse(args) { |opt, idx, val|
59+
#case opt
60+
#when '-r'
61+
# result_var = val
62+
#end
63+
}
64+
65+
client.powershell.execute_string(code)
66+
end
67+
68+
end
69+
70+
end
71+
end
72+
end
73+
end
74+

0 commit comments

Comments
 (0)