Skip to content

Commit d0adc19

Browse files
committed
Land rapid7#2729 - Allow manual self-destruct via "kill -s"
2 parents e4c6413 + e90b764 commit d0adc19

File tree

1 file changed

+16
-8
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+16
-8
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,20 @@ def cmd_kill(*args)
329329
return true
330330
end
331331

332-
# validate all the proposed pids first so we can bail if one is bogus
333-
valid_pids = validate_pids(args)
334-
args.uniq!
335-
diff = args - valid_pids.map {|e| e.to_s}
336-
if not diff.empty? # then we had an invalid pid
337-
print_error("The following pids are not valid: #{diff.join(", ").to_s}. Quitting")
338-
return false
332+
self_destruct = args.include?("-s")
333+
334+
if self_destruct
335+
valid_pids = [client.sys.process.getpid.to_i]
336+
else
337+
valid_pids = validate_pids(args)
338+
339+
# validate all the proposed pids first so we can bail if one is bogus
340+
args.uniq!
341+
diff = args - valid_pids.map {|e| e.to_s}
342+
if not diff.empty? # then we had an invalid pid
343+
print_error("The following pids are not valid: #{diff.join(", ").to_s}. Quitting")
344+
return false
345+
end
339346
end
340347

341348
# kill kill kill
@@ -348,8 +355,9 @@ def cmd_kill(*args)
348355
# help for the kill command
349356
#
350357
def cmd_kill_help
351-
print_line("Usage: kill pid1 pid2 pid3 ...")
358+
print_line("Usage: kill [pid1 [pid2 [pid3 ...]]] [-s]")
352359
print_line("Terminate one or more processes.")
360+
print_line(" -s : Kills the pid associated with the current session.")
353361
end
354362

355363
#

0 commit comments

Comments
 (0)