@@ -286,7 +286,7 @@ def cmd_kill(*args)
286
286
args . uniq!
287
287
diff = args - valid_pids . map { |e | e . to_s }
288
288
if not diff . empty? # then we had an invalid pid
289
- print_error ( "The following pids are not valid:#{ diff . join ( ", " ) . to_s } , quitting " )
289
+ print_error ( "The following pids are not valid: #{ diff . join ( ", " ) . to_s } . Quitting " )
290
290
return false
291
291
end
292
292
@@ -300,26 +300,27 @@ def cmd_kill(*args)
300
300
# help for the kill command
301
301
#
302
302
def cmd_kill_help
303
- print_line ( "Usage: kill pid1 pid2 pid3 ...\n \n Terminate one or more processes." )
303
+ print_line ( "Usage: kill pid1 pid2 pid3 ..." )
304
+ print_line ( "Terminate one or more processes." )
304
305
end
305
306
306
307
#
307
308
# validates an array of pids against the running processes on target host
308
- # behavior can be controlled to allow/deny proces 0 and the session's process
309
- # the pids:
310
- # - are converted to integers
311
- # - have had pid 0 removed unless allow_pid_0
312
- # - have had current session pid removed unless allow_session_pid (to protect the session)
313
- # - have redundant entries removed
309
+ # behavior can be controlled to allow/deny proces 0 and the session's process
310
+ # the pids:
311
+ # - are converted to integers
312
+ # - have had pid 0 removed unless allow_pid_0
313
+ # - have had current session pid removed unless allow_session_pid (to protect the session)
314
+ # - have redundant entries removed
314
315
#
315
316
# @param pids [Array<String>] The pids to validate
316
317
# @param allow_pid_0 [Boolean] whether to consider a pid of 0 as valid
317
318
# @param allow_session_pid [Boolean] whether to consider a pid = the current session pid as valid
318
319
# @return [Array] Returns an array of valid pids
319
320
320
- def validate_pids ( arr_pids , allow_pid_0 = false , allow_session_pid = false )
321
+ def validate_pids ( pids , allow_pid_0 = false , allow_session_pid = false )
321
322
322
- return [ ] if ( arr_pids . class != Array or arr_pids . empty? )
323
+ return [ ] if ( pids . class != Array or pids . empty? )
323
324
valid_pids = [ ]
324
325
# to minimize network traffic, we only get host processes once
325
326
host_processes = client . sys . process . get_processes
@@ -339,7 +340,7 @@ def validate_pids(arr_pids, allow_pid_0 = false, allow_session_pid = false)
339
340
end
340
341
clean_pids . each do |pid |
341
342
# find the process with this pid
342
- theprocess = host_processes . select { |x | x [ "pid" ] == pid } . first
343
+ theprocess = host_processes . find { |x | x [ "pid" ] == pid }
343
344
if ( theprocess . nil? )
344
345
next
345
346
else
@@ -734,9 +735,9 @@ def cmd_shutdown(*args)
734
735
735
736
#
736
737
# Suspends or resumes a list of one or more pids
737
- # args can optionally be -c to continue on error or -r to resume instead of suspend,
738
- # followed by a list of one or more valid pids
739
- # A suspend which will accept process names will be added later
738
+ # args can optionally be -c to continue on error or -r to resume instead of suspend,
739
+ # followed by a list of one or more valid pids
740
+ # TODO: A suspend which will accept process names, much of that code is done
740
741
#
741
742
# @param args [Array] List of one of more pids
742
743
# @return [Boolean] Returns true if command was successful, else false
@@ -756,7 +757,7 @@ def cmd_suspend(*args)
756
757
args . uniq!
757
758
diff = args - valid_pids . map { |e | e . to_s }
758
759
if not diff . empty? # then we had an invalid pid
759
- print_error ( "The following pids are not valid:#{ diff . join ( ", " ) . to_s } " )
760
+ print_error ( "The following pids are not valid: #{ diff . join ( ", " ) . to_s } . " )
760
761
if continue
761
762
print_status ( "Continuing. Invalid args have been removed from the list." )
762
763
else
@@ -769,40 +770,28 @@ def cmd_suspend(*args)
769
770
targetprocess = nil
770
771
if resume
771
772
print_status ( "Resuming: #{ valid_pids . join ( ", " ) . to_s } " )
772
- begin
773
- valid_pids . each do |pid |
774
- print_status ( "Targeting process with PID #{ pid } ..." )
775
- targetprocess = client . sys . process . open ( pid , PROCESS_ALL_ACCESS )
776
- targetprocess . thread . each_thread do |x |
777
- targetprocess . thread . open ( x ) . resume
778
- end
779
- end
780
- rescue ::Rex ::Post ::Meterpreter ::RequestError => e
781
- print_error "Error resuming the process threads: #{ e . to_s } . " +
782
- "Try migrating to a process with the same owner as the target process"
783
- "Also consider running the win_privs post module and confirm SeDebug priv."
784
- ensure
785
- targetprocess . close if targetprocess
786
- return false unless continue
787
- end
788
- else # suspend
773
+ else
789
774
print_status ( "Suspending: #{ valid_pids . join ( ", " ) . to_s } " )
790
- begin
791
- valid_pids . each do |pid |
792
- print_status ( "Targeting process with PID #{ pid } ..." )
793
- targetprocess = client . sys . process . open ( pid , PROCESS_ALL_ACCESS )
794
- targetprocess . thread . each_thread do |x |
795
- targetprocess . thread . open ( x ) . suspend
796
- end
775
+ end
776
+ begin
777
+ valid_pids . each do |pid |
778
+ print_status ( "Targeting process with PID #{ pid } ..." )
779
+ targetprocess = client . sys . process . open ( pid , PROCESS_ALL_ACCESS )
780
+ targetprocess . thread . each_thread do |x |
781
+ if resume
782
+ targetprocess . thread . open ( x ) . resume
783
+ else
784
+ targetprocess . thread . open ( x ) . suspend
785
+ end
797
786
end
798
- rescue ::Rex ::Post ::Meterpreter ::RequestError => e
799
- print_error "Error suspending the process threads: #{ e . to_s } . " +
800
- "Try migrating to a process with the same owner as the target process"
801
- "Also consider running the win_privs post module and confirm SeDebug priv."
802
- ensure
803
- targetprocess . close if targetprocess
804
- return false unless continue
805
787
end
788
+ rescue ::Rex ::Post ::Meterpreter ::RequestError => e
789
+ print_error "Error acting on the process: #{ e . to_s } . " +
790
+ "Try migrating to a process with the same owner as the target process"
791
+ "Also consider running the win_privs post module and confirm SeDebug priv."
792
+ return false unless continue
793
+ ensure
794
+ targetprocess . close if targetprocess
806
795
end
807
796
return true
808
797
end
@@ -811,7 +800,8 @@ def cmd_suspend(*args)
811
800
# help for the suspend command
812
801
#
813
802
def cmd_suspend_help
814
- print_line ( "Usage: suspend [options] pid1 pid2 pid3 ...\n \n Suspend one or more processes." )
803
+ print_line ( "Usage: suspend [options] pid1 pid2 pid3 ..." )
804
+ print_line ( "Suspend one or more processes." )
815
805
print @@suspend_opts . usage
816
806
end
817
807
0 commit comments