grab the appropriate shell from mult-platform meterpreters and use /bin/sh instead of /bin/bash for linux to improve compatibility, fixes #5996

This commit is contained in:
James Lee 2011-12-26 14:41:24 -07:00
parent 05f3af1e77
commit 80603e03cb
1 changed files with 11 additions and 2 deletions

View File

@ -153,12 +153,21 @@ class Console::CommandDispatcher::Stdapi::Sys
# Drop into a system shell as specified by %COMSPEC% or
# as appropriate for the host.
def cmd_shell(*args)
if client.platform =~/win/
case client.platform
when /win/
path = client.fs.file.expand_path("%COMSPEC%")
path = (path and not path.empty?) ? path : "cmd.exe"
cmd_execute("-f", path, "-c", "-H", "-i", "-t")
when /linux/
# Don't expand_path() this because it's literal anyway
path = "/bin/sh"
cmd_execute("-f", path, "-c", "-i")
else
path = client.fs.file.expand_path("/bin/bash")
# Then this is a multi-platform meterpreter (php or java), which
# must special-case COMSPEC to return the system-specific shell.
path = client.fs.file.expand_path("%COMSPEC%")
# If that failed for whatever reason, guess it's unix
path = (path and not path.empty?) ? path : "/bin/sh"
cmd_execute("-f", path, "-c", "-i")
end
end