Tidy code, remove regex and use comparison for platform checks

bug/bundler_fix
OJ 2016-10-29 13:41:20 +10:00
parent 9e3960f334
commit 0737d7ca12
No known key found for this signature in database
GPG Key ID: D5DC61FB93260597
6 changed files with 19 additions and 20 deletions

View File

@ -60,12 +60,13 @@ module MeterpreterOptions
session.load_session_info
end
if session.platform =~ /windows/i
# only load priv on native windows
if session.platform == 'windows' && [ARCH_X86, ARCH_64].include?(session.arch)
session.load_priv rescue nil
end
end
if session.platform =~ /android/i
if session.platform == 'android'
if datastore['AutoLoadAndroid']
session.load_android
end

View File

@ -104,7 +104,7 @@ module Exploit::FileDropper
# @param path [String] Remote filename to check
# @return [Boolean] True if the file exists, otherwise false.
def file_dropper_file_exist?(session, path)
if session.platform =~ /win/
if session.platform == 'windows'
normalized = file_dropper_win_file(path)
else
normalized = path
@ -115,7 +115,7 @@ module Exploit::FileDropper
return false unless stat
stat.file?
else
if session.platform =~ /win/
if session.platform == 'windows'
f = shell_command_token("cmd.exe /C IF exist \"#{normalized}\" ( echo true )")
if f =~ /true/
f = shell_command_token("cmd.exe /C IF exist \"#{normalized}\\\\\" ( echo false ) ELSE ( echo true )")
@ -142,7 +142,7 @@ module Exploit::FileDropper
# Meterpreter should do this automatically as part of
# fs.file.rm(). Until that has been implemented, remove the
# read-only flag with a command.
if session.platform =~ /win/
if session.platform == 'windows'
session.shell_command_token(%Q|attrib.exe -r #{win_file}|)
end
session.fs.file.rm(file)

View File

@ -27,7 +27,7 @@ module Msf::Post::File
if session.type == "meterpreter"
return session.fs.dir.getwd
else
if session.platform =~ /win/
if session.platform == 'windows'
# XXX: %CD% only exists on XP and newer, figure something out for NT4
# and 2k
return session.shell_command_token("echo %CD%")
@ -44,7 +44,7 @@ module Msf::Post::File
if session.type == 'meterpreter'
return session.fs.dir.entries(directory)
else
if session.platform =~ /win/
if session.platform == 'windows'
return session.shell_command_token("dir #{directory}").split(/[\r\n]+/)
else
return session.shell_command_token("ls #{directory}").split(/[\r\n]+/)
@ -64,7 +64,7 @@ module Msf::Post::File
return false unless stat
return stat.directory?
else
if session.platform =~ /win/
if session.platform == 'windows'
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\*\" ( echo true )")
else
f = session.shell_command_token("test -d \"#{path}\" && echo true")
@ -98,7 +98,7 @@ module Msf::Post::File
return false unless stat
return stat.file?
else
if session.platform =~ /win/
if session.platform == 'windows'
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
if f =~ /true/
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\\\\" ( echo false ) ELSE ( echo true )")
@ -124,7 +124,7 @@ module Msf::Post::File
stat = session.fs.file.stat(path) rescue nil
return !!(stat)
else
if session.platform =~ /win/
if session.platform == 'windows'
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
else
f = cmd_exec("test -e \"#{path}\" && echo true")
@ -260,7 +260,7 @@ module Msf::Post::File
if session.type == "meterpreter"
data = _read_file_meterpreter(file_name)
elsif session.type == "shell"
if session.platform =~ /win/
if session.platform == 'windows'
data = session.shell_command_token("type \"#{file_name}\"")
else
data = session.shell_command_token("cat \"#{file_name}\"")
@ -283,7 +283,7 @@ module Msf::Post::File
fd.write(data)
fd.close
elsif session.respond_to? :shell_command_token
if session.platform =~ /win/
if session.platform == 'windows'
session.shell_command_token("echo #{data} > \"#{file_name}\"")
else
_write_file_unix_shell(file_name, data)
@ -308,7 +308,7 @@ module Msf::Post::File
fd.write(data)
fd.close
elsif session.respond_to? :shell_command_token
if session.platform =~ /win/
if session.platform == 'windows'
session.shell_command_token("<nul set /p=\"#{data}\" >> \"#{file_name}\"")
else
_write_file_unix_shell(file_name, data, true)
@ -339,7 +339,7 @@ module Msf::Post::File
if session.type == "meterpreter"
session.fs.file.delete(remote) if exist?(remote)
else
if session.platform =~ /win/
if session.platform == 'windows'
cmd_exec("del /q /f \"#{remote}\"")
else
cmd_exec("rm -f \"#{remote}\"")
@ -359,7 +359,7 @@ module Msf::Post::File
if session.type == "meterpreter"
return (session.fs.file.mv(old_file, new_file).result == 0)
else
if session.platform =~ /win/
if session.platform == 'windows'
cmd_exec(%Q|move /y "#{old_file}" "#{new_file}"|) =~ /moved/
else
cmd_exec(%Q|mv -f "#{old_file}" "#{new_file}"|).empty?

View File

@ -10,7 +10,7 @@ module Eventlog
#
def eventlog_list
key = "HKLM\\SYSTEM\\CurrentControlSet\\Services\\"
if session.sys.config.sysinfo['OS'] =~ /Windows 2003|.Net|XP|2000/
if session.sys.config.sysinfo['OS'] =~ /Windows 2003|\.Net|XP|2000/
key = "#{key}Eventlog"
else
key = "#{key}eventlog"

View File

@ -29,7 +29,7 @@ class MetasploitModule < Msf::Exploit::Local
'TheWack0lian', # Issue discovery
'OJ Reeves' # exploit and msf module
],
'Arch' => [ ARCH_X64],
'Arch' => [ARCH_X64],
'Platform' => 'win',
'SessionTypes' => [ 'meterpreter' ],
'DefaultOptions' => {

View File

@ -132,9 +132,7 @@ class MetasploitModule < Msf::Post
def run
@token_stolen = false
os = get_target_os
case os
when Msf::Module::Platform::Windows.realname.downcase
if session.platform == 'windows'
windows_zip
else
linux_zip