Module: PWN::Plugins::PS
- Defined in:
- lib/pwn/plugins/ps.rb
Overview
This plugin is a simple wrapper around the ps command.
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
-
0day Inc.
-
.cleanup_pids(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::PS.cleanup_pids( pids_arr: ‘required - array of pids to kill’ ).
-
.help ⇒ Object
Display Usage for this Module.
-
.list(opts = {}) ⇒ Object
- Supported Method Parameters
-
proc_list_arr = PWN::Plugins::PS.list.
Class Method Details
.authors ⇒ Object
- Author(s)
-
0day Inc. <[email protected]>
69 70 71 72 73 |
# File 'lib/pwn/plugins/ps.rb', line 69 public_class_method def self. "AUTHOR(S): 0day Inc. <[email protected]> " end |
.cleanup_pids(opts = {}) ⇒ Object
- Supported Method Parameters
-
PWN::Plugins::PS.cleanup_pids(
pids_arr: 'required - array of pids to kill'
)
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pwn/plugins/ps.rb', line 54 public_class_method def self.cleanup_pids(opts = {}) pids_arr = opts[:pids_arr] pids_arr.each do |pid_line| pid = pid_line[2].to_i Process.kill('TERM', pid) rescue Errno::ESRCH next end rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pwn/plugins/ps.rb', line 77 public_class_method def self.help puts "USAGE: proc_list_arr = #{self}.list #{self}.cleanup_pids( pids_arr: 'required - array of pids to kill' ) #{self}.authors " end |
.list(opts = {}) ⇒ Object
- Supported Method Parameters
-
proc_list_arr = PWN::Plugins::PS.list
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pwn/plugins/ps.rb', line 12 public_class_method def self.list(opts = {}) pid = opts[:pid] which_os = PWN::Plugins::DetectOS.type case which_os when :cygwin cmd = 'ps' params = "w -p #{pid}" params = 'waux' if pid.nil? when :freebsd, :linux, :netbsd, :openbsd, :osx cmd = 'ps' format = 'user,pcpu,pid,ppid,uid,group,gid,cpu,pmem,command' params = "w -p #{pid} -o #{format}" params = "wax -o #{format}" if pid.nil? else raise "Unsupported OS: #{which_os}" end full_cmd = "#{cmd} #{params}" stdout, _stderr, _status = Open3.capture3(full_cmd) proc_list_arr = [] stdout_arr = stdout.split("\n") stdout_arr.each do |line| column_len = format.split(',').length cmd_idx = column_len - 1 first_cols = line.split[0..(cmd_idx - 1)] cmd = [line.split[cmd_idx..].join(' ')] proc_line = first_cols + cmd proc_list_arr.push(proc_line) end proc_list_arr rescue StandardError => e raise e end |