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/modules/post/windows/manage/exec_powershell.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
include Msf::Post::Windows::Powershell
8
9
def initialize(info = {})
10
super(
11
update_info(
12
info,
13
'Name' => 'Windows Powershell Execution Post Module',
14
'Description' => %q{
15
This module will execute a powershell script in a meterpreter session.
16
The user may also enter text substitutions to be made in memory before execution.
17
Setting VERBOSE to true will output both the script prior to execution and the results.
18
},
19
'License' => MSF_LICENSE,
20
'Platform' => ['windows'],
21
'SessionTypes' => ['meterpreter'],
22
'Author' => [
23
'Nicholas Nam (nick[at]executionflow.org)', # original meterpreter script
24
'RageLtMan <rageltman[at]sempervictus>' # post module and libs
25
]
26
)
27
)
28
29
register_options(
30
[
31
OptString.new('SCRIPT', [true, 'Path to the local PS script or command string to execute']),
32
]
33
)
34
35
register_advanced_options(
36
[
37
OptString.new('SUBSTITUTIONS', [false, 'Script subs in gsub format - original,sub;original,sub']),
38
]
39
)
40
end
41
42
def run
43
# Make sure we meet the requirements before running the script, note no need to return
44
# unless error
45
raise 'Powershell not available' if !have_powershell?
46
47
# Preprocess the Powershell::Script object with substitions from Exploit::Powershell
48
script = make_subs(read_script(datastore['SCRIPT']), process_subs(datastore['SUBSTITUTIONS']))
49
50
# Execute in session
51
print_status psh_exec(script)
52
print_good 'Finished!'
53
end
54
end
55
56