Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change powershell platform to windows and add powershell support to some methods #15403

Merged
Merged
2 changes: 1 addition & 1 deletion lib/msf/base/sessions/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.type
# Returns the session platform.
#
def platform
"win"
"windows"
end

#
Expand Down
12 changes: 11 additions & 1 deletion lib/msf/core/post/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def cd(path)
def pwd
if session.type == "meterpreter"
return session.fs.dir.getwd
elsif session.type == 'powershell'
return cmd_exec('(Get-Location).Path').strip
else
if session.platform == 'windows'
# XXX: %CD% only exists on XP and newer, figure something out for NT4
Expand Down Expand Up @@ -159,6 +161,8 @@ def file?(path)
stat = session.fs.file.stat(path) rescue nil
return false unless stat
return stat.file?
elsif session.type == 'powershell'
return cmd_exec("Test-Path \"#{path}\" -PathType leaf")&.include?("True")
else
if session.platform == 'windows'
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
Expand Down Expand Up @@ -245,6 +249,8 @@ def exist?(path)
if session.type == 'meterpreter'
stat = session.fs.file.stat(path) rescue nil
return !!(stat)
elsif session.type == 'powershell'
return cmd_exec("Test-Path \"#{path}\"")&.include?("True")
else
if session.platform == 'windows'
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
Expand Down Expand Up @@ -469,7 +475,9 @@ def exploit_data(data_directory, file)
def rm_f(*remote_files)
remote_files.each do |remote|
if session.type == "meterpreter"
smcintyre-r7 marked this conversation as resolved.
Show resolved Hide resolved
session.fs.file.delete(remote) if exist?(remote)
session.fs.file.delete(remote) if file?(remote)
elsif session.type == 'powershell'
cmd_exec("Remove-Item \"#{remote}\" -Force") if file?(remote)
else
if session.platform == 'windows'
cmd_exec("del /q /f \"#{remote}\"")
Expand All @@ -490,6 +498,8 @@ def rm_rf(*remote_dirs)
remote_dirs.each do |remote|
if session.type == "meterpreter"
session.fs.dir.rmdir(remote) if exist?(remote)
elsif session.type == 'powershell'
cmd_exec("Remove-Item -Path \"#{remote}\" -Force -Recurse")
else
if session.platform == 'windows'
cmd_exec("rd /s /q \"#{remote}\"")
Expand Down
12 changes: 3 additions & 9 deletions lib/msf/core/post/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,15 @@ def has_pid?(pid)
# Gets the `pid` and `name` of the processes on the remote system
#
def get_processes
if session_has_process_ext
if session.type == 'meterpreter'
meterpreter_get_processes
elsif session.type == 'powershell'
shell_get_processes
else
shell_get_processes
end
end

def session_has_process_ext
begin
return !!(session.sys and session.sys.process)
rescue NoMethodError
return false
end
end

def meterpreter_get_processes
begin
return session.sys.process.get_processes.map { |p| p.slice('name', 'pid') }
Expand Down