ronin-post_ex 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.document +6 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.rspec +1 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +1 -0
  8. data/API_SPEC.md +235 -0
  9. data/COPYING.txt +165 -0
  10. data/ChangeLog.md +23 -0
  11. data/Gemfile +36 -0
  12. data/README.md +245 -0
  13. data/Rakefile +34 -0
  14. data/examples/bind_shell.rb +19 -0
  15. data/gemspec.yml +25 -0
  16. data/lib/ronin/post_ex/cli/shell_shell.rb +66 -0
  17. data/lib/ronin/post_ex/cli/system_shell.rb +811 -0
  18. data/lib/ronin/post_ex/remote_dir.rb +190 -0
  19. data/lib/ronin/post_ex/remote_file/stat.rb +174 -0
  20. data/lib/ronin/post_ex/remote_file.rb +417 -0
  21. data/lib/ronin/post_ex/remote_process.rb +170 -0
  22. data/lib/ronin/post_ex/resource.rb +144 -0
  23. data/lib/ronin/post_ex/sessions/bind_shell.rb +60 -0
  24. data/lib/ronin/post_ex/sessions/remote_shell_session.rb +48 -0
  25. data/lib/ronin/post_ex/sessions/reverse_shell.rb +67 -0
  26. data/lib/ronin/post_ex/sessions/rpc_session.rb +779 -0
  27. data/lib/ronin/post_ex/sessions/session.rb +73 -0
  28. data/lib/ronin/post_ex/sessions/shell_session.rb +618 -0
  29. data/lib/ronin/post_ex/system/fs.rb +650 -0
  30. data/lib/ronin/post_ex/system/process.rb +422 -0
  31. data/lib/ronin/post_ex/system/shell.rb +1037 -0
  32. data/lib/ronin/post_ex/system.rb +191 -0
  33. data/lib/ronin/post_ex/version.rb +26 -0
  34. data/lib/ronin/post_ex.rb +22 -0
  35. data/ronin-post_ex.gemspec +61 -0
  36. data/spec/sessions/bind_shell_spec.rb +31 -0
  37. data/spec/sessions/remote_shell_session_spec.rb +28 -0
  38. data/spec/sessions/reverse_shell_spec.rb +49 -0
  39. data/spec/sessions/rpc_session_spec.rb +500 -0
  40. data/spec/sessions/session_spec.rb +61 -0
  41. data/spec/sessions/shell_session_spec.rb +482 -0
  42. data/spec/spec_helper.rb +9 -0
  43. data/spec/system_spec.rb +66 -0
  44. metadata +155 -0
@@ -0,0 +1,1037 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-post_ex - a Ruby API for Post-Exploitation.
4
+ #
5
+ # Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-post_ex is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-post_ex is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-post_ex. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/post_ex/resource'
22
+ require 'ronin/post_ex/cli/shell_shell'
23
+
24
+ require 'date'
25
+
26
+ module Ronin
27
+ module PostEx
28
+ class System < Resource
29
+ #
30
+ # Provides access to a system's shell and executing shell commands.
31
+ #
32
+ # ## Supported API Methods
33
+ #
34
+ # * `shell_exec(command : String) -> String`
35
+ #
36
+ class Shell < Resource
37
+
38
+ # Persistent environment variables for the shell.
39
+ #
40
+ # @return {Hash{String => String}]
41
+ attr_reader :env
42
+
43
+ #
44
+ # Initializes the Shell resource.
45
+ #
46
+ # @param [#shell_exec] session
47
+ # The {#session} object that defines the `shell_exec` method.
48
+ #
49
+ def initialize(session)
50
+ super(session)
51
+
52
+ @cwd = nil
53
+ @env = {}
54
+ end
55
+
56
+ #
57
+ # Executes a shell command and returns it's output.
58
+ #
59
+ # @param [String] command
60
+ # The shell command to execute.
61
+ #
62
+ # @param [Array<String>] arguments
63
+ # Additional arguments for the shell command.
64
+ #
65
+ # @example
66
+ # system.shell.run 'ls'
67
+ #
68
+ # @example with additional arguments:
69
+ # system.shell.run 'ls', '-l'
70
+ #
71
+ # @return [String]
72
+ # The output of the shell command.
73
+ #
74
+ def run(command,*arguments)
75
+ unless arguments.empty?
76
+ command = "#{command} #{Shellwords.shelljoin(arguments)}"
77
+ end
78
+
79
+ unless @env.empty?
80
+ env_vars = @env.map { |key,value|
81
+ "#{key}=#{Shellwords.shellescape(value)}"
82
+ }.join(' ')
83
+
84
+ command = "env #{env_vars} #{command}"
85
+ end
86
+
87
+ if @cwd
88
+ command = "cd #{@cwd} && #{command}"
89
+ end
90
+
91
+ return @session.shell_exec(command)
92
+ end
93
+ resource_method :run, [:shell_exec]
94
+
95
+ #
96
+ # Executes a command and prints the resulting output.
97
+ #
98
+ # @param [String] command
99
+ # The program name or path to execute.
100
+ #
101
+ # @param [Array<String>] arguments
102
+ # Additional arguments for the shell command.
103
+ #
104
+ # @return [nil]
105
+ #
106
+ def system(command,*arguments)
107
+ puts(run(command,*arguments))
108
+ end
109
+ resource_method :system, [:shell_exec]
110
+
111
+ #
112
+ # Changes the current working directory in the shell.
113
+ #
114
+ # @param [String] path
115
+ # The path for the new current working directory.
116
+ #
117
+ # @return [String]
118
+ # Any error messages.
119
+ #
120
+ def cd(path)
121
+ @pwd = File.expand_path(path,pwd)
122
+ end
123
+ resource_method :cd, [:shell_exec]
124
+
125
+ #
126
+ # Gets the current working directory.
127
+ #
128
+ # @return [String]
129
+ # The path of the current working directory.
130
+ #
131
+ def pwd
132
+ @pwd ||= run('pwd').chomp
133
+ end
134
+ resource_method :pwd, [:shell_exec]
135
+
136
+ #
137
+ # Lists the files or directories.
138
+ #
139
+ # @param [Array<String>] arguments
140
+ # Arguments to pass to the `ls` command.
141
+ #
142
+ # @return [String]
143
+ # The full output of the command.
144
+ #
145
+ # @see #exec
146
+ #
147
+ def ls(*arguments)
148
+ run('ls',*arguments)
149
+ end
150
+ resource_method :ls, [:shell_exec]
151
+
152
+ #
153
+ # Lists all files or directories.
154
+ #
155
+ # @param [Array<String>] arguments
156
+ # Additional arguments to pass to the `ls -a` command.
157
+ #
158
+ # @return [String]
159
+ # The full output of the command.
160
+ #
161
+ # @see #exec
162
+ #
163
+ def ls_a(*arguments)
164
+ run('ls','-a',*arguments)
165
+ end
166
+ resource_method :ls_a, [:shell_exec]
167
+
168
+ #
169
+ # Lists information about files or directories.
170
+ #
171
+ # @param [Array<String>] arguments
172
+ # Additional arguments to pass to the `ls -l` command.
173
+ #
174
+ # @return [String]
175
+ # The full output of the command.
176
+ #
177
+ # @see #exec
178
+ #
179
+ def ls_l(*arguments)
180
+ run('ls','-l',*arguments)
181
+ end
182
+ resource_method :ls_l, [:shell_exec]
183
+
184
+ #
185
+ # Lists information about all files or directories.
186
+ #
187
+ # @param [Array<String>] arguments
188
+ # Additional arguments to pass to the `ls -la` command.
189
+ #
190
+ # @return [String]
191
+ # The full output of the command.
192
+ #
193
+ # @see #exec
194
+ #
195
+ def ls_la(*arguments)
196
+ run('ls','-la',*arguments)
197
+ end
198
+ resource_method :ls_la, [:shell_exec]
199
+
200
+ alias ls_al ls_la
201
+
202
+ #
203
+ # Searches for files or directories.
204
+ #
205
+ # @param [Array<String>] arguments
206
+ # Additional arguments to pass to the `find` command.
207
+ #
208
+ # @yield [path]
209
+ # If a block is given, it will be passed each path found.
210
+ #
211
+ # @yieldparam [String] path
212
+ # A path found by the `find` command.
213
+ #
214
+ # @return [Array<String>, nil]
215
+ # If no block is given, all found paths will be returned.
216
+ #
217
+ def find(*arguments,&block)
218
+ if block
219
+ run('find',*arguments).each_line(chomp: true,&block)
220
+ else
221
+ enum_for(__method__,*arguments).to_a
222
+ end
223
+ end
224
+ resource_method :find, [:shell_exec]
225
+
226
+ #
227
+ # Determines the format of a file.
228
+ #
229
+ # @param [Array<String>] arguments
230
+ # Additional arguments to pass to the `file` command.
231
+ #
232
+ # @return [String]
233
+ # The output of the `file` command.
234
+ #
235
+ # @example
236
+ # system.shell.file('data.db')
237
+ # # => "data.db: SQLite 3.x database"
238
+ #
239
+ def file(*arguments)
240
+ run('file',*arguments)
241
+ end
242
+ resource_method :file, [:shell_exec]
243
+
244
+ #
245
+ # Finds a program available to the shell.
246
+ #
247
+ # @param [Array<String>] arguments
248
+ # Additional arguments to pass to the `which` command.
249
+ #
250
+ # @return [String]
251
+ # The output from the `which` command.
252
+ #
253
+ def which(*arguments)
254
+ run('which',*arguments)
255
+ end
256
+ resource_method :which, [:shell_exec]
257
+
258
+ #
259
+ # Reads the contents of one or more files.
260
+ #
261
+ # @param [Array<String>] arguments
262
+ # Additional arguments to pass to the `cat` command.
263
+ #
264
+ # @return [String]
265
+ # The full output of the command.
266
+ #
267
+ # @see #exec
268
+ #
269
+ def cat(*arguments)
270
+ run('cat',*arguments)
271
+ end
272
+ resource_method :cat, [:shell_exec]
273
+
274
+ #
275
+ # Reads the first `n` lines of one or more files.
276
+ #
277
+ # @param [Array<String>] arguments
278
+ # Additional arguments to pass to the `head` command.
279
+ #
280
+ # @return [String]
281
+ # The full output of the command.
282
+ #
283
+ # @see #exec
284
+ #
285
+ def head(*arguments)
286
+ run('head',*arguments)
287
+ end
288
+ resource_method :head, [:shell_exec]
289
+
290
+ #
291
+ # Reads the first `n` lines of one or more files.
292
+ #
293
+ # @param [Integer] lines
294
+ # The number of lines to read from one or more files.
295
+ #
296
+ # @param [Array<String>] arguments
297
+ # Additional arguments to pass to the `head` command.
298
+ #
299
+ # @return [String]
300
+ # The full output of the command.
301
+ #
302
+ # @see #exec
303
+ #
304
+ def head_n(lines,*arguments)
305
+ head('-n',lines,*arguments)
306
+ end
307
+ resource_method :head_n, [:shell_exec]
308
+
309
+ #
310
+ # Reads the last `n` lines of one or more files.
311
+ #
312
+ # @param [Array<String>] arguments
313
+ # Additional arguments to pass to the `tail` command.
314
+ #
315
+ # @return [String]
316
+ # The full output of the command.
317
+ #
318
+ # @see #exec
319
+ #
320
+ def tail(*arguments)
321
+ run('tail',*arguments)
322
+ end
323
+ resource_method :tail, [:shell_exec]
324
+
325
+ #
326
+ # Reads the last `n` lines of one or more files.
327
+ #
328
+ # @param [Integer] lines
329
+ # The number of lines to read from one or more files.
330
+ #
331
+ # @param [Array<String>] arguments
332
+ # Additional arguments to pass to the `tail` command.
333
+ #
334
+ # @return [String]
335
+ # The full output of the command.
336
+ #
337
+ # @see #exec
338
+ #
339
+ def tail_n(lines,*arguments)
340
+ tail('-n',lines,*arguments)
341
+ end
342
+ resource_method :tail_n, [:shell_exec]
343
+
344
+ #
345
+ # Searches one or more files for a given pattern.
346
+ #
347
+ # @param [Array<String>] arguments
348
+ # Additional arguments to pass to the `grep` command.
349
+ #
350
+ # @yield [path, line]
351
+ # If a block is given, it will be passed the paths and lines
352
+ # within files that matched the given pattern.
353
+ #
354
+ # @yieldparam [String] path
355
+ # The path of a file that contains matching lines.
356
+ #
357
+ # @yieldparam [String] line
358
+ # A line that matches the given pattern.
359
+ #
360
+ # @return [Array<String>, nil]
361
+ # If no block is given, all matching paths and lines will be
362
+ # returned.
363
+ #
364
+ def grep(*arguments)
365
+ if block_given?
366
+ run('grep',*arguments).each_line(chomp: true) do |line|
367
+ yield(*line.split(':',2))
368
+ end
369
+ else
370
+ enum_for(__method__,*arguments).to_a
371
+ end
372
+ end
373
+ resource_method :grep, [:shell_exec]
374
+
375
+ #
376
+ # Runs `grep -E`.
377
+ #
378
+ # @param [Array<String>] arguments
379
+ # Additional arguments for the `grep` command.
380
+ #
381
+ # @return [Array<String>, nil]
382
+ # If no block is given, all matching paths and lines will be
383
+ # returned.
384
+ #
385
+ # @see #grep
386
+ #
387
+ def egrep(*arguments,&block)
388
+ grep('-E',*arguments,&block)
389
+ end
390
+ resource_method :egrep, [:shell_exec]
391
+
392
+ #
393
+ # Runs `grep -F`.
394
+ #
395
+ # @param [Array<String>] arguments
396
+ # Additional arguments for the `grep` command.
397
+ #
398
+ # @return [Array<String>, nil]
399
+ # If no block is given, all matching paths and lines will be
400
+ # returned.
401
+ #
402
+ # @see #grep
403
+ #
404
+ def fgrep(*arguments,&block)
405
+ grep('-F',*arguments,&block)
406
+ end
407
+ resource_method :fgrep, [:shell_exec]
408
+
409
+ #
410
+ # Touches a file.
411
+ #
412
+ # @param [Array<String>] arguments
413
+ # Additional arguments to pass to the `touch` command.
414
+ #
415
+ # @return [String]
416
+ # Any error messages returned by the `touch` command.
417
+ #
418
+ def touch(*arguments)
419
+ run('touch',*arguments)
420
+ end
421
+ resource_method :touch, [:shell_exec]
422
+
423
+ #
424
+ # Creates a tempfile.
425
+ #
426
+ # @param [Array<String>] arguments
427
+ # Additional arguments to pass to `mktemp`.
428
+ #
429
+ # @return [String]
430
+ # The path of the new tempfile.
431
+ #
432
+ def mktemp(*arguments)
433
+ run('mktemp',*arguments).chomp
434
+ end
435
+ resource_method :mktemp, [:shell_exec]
436
+
437
+ #
438
+ # Creates a tempdir.
439
+ #
440
+ # @param [Array<String>] arguments
441
+ # Additional arguments to pass to `mktemp`.
442
+ #
443
+ # @return [String]
444
+ # The path of the new tempdir.
445
+ #
446
+ def mktempdir(*arguments)
447
+ mktemp('-d',*arguments)
448
+ end
449
+ resource_method :mktempdir, [:shell_exec]
450
+
451
+ #
452
+ # Creates a new directory.
453
+ #
454
+ # @param [Array<String>] arguments
455
+ # Additional arguments to pass to the `mkdir` command.
456
+ #
457
+ # @return [String]
458
+ # Any error messages returned by the `mkdir` command.
459
+ #
460
+ def mkdir(*arguments)
461
+ run('mkdir',*arguments)
462
+ end
463
+ resource_method :mkdir, [:shell_exec]
464
+
465
+ #
466
+ # Copies one or more files or directories.
467
+ #
468
+ # @param [Array<String>] arguments
469
+ # Additional arguments to pass to the `cp` command.
470
+ #
471
+ # @return [String]
472
+ # Any error messages returned by the `cp` command.
473
+ #
474
+ def cp(*arguments)
475
+ run('cp',*arguments)
476
+ end
477
+ resource_method :cp, [:shell_exec]
478
+
479
+ #
480
+ # Runs `cp -r`.
481
+ #
482
+ # @param [Array<String>] arguments
483
+ # Additional arguments for the `cp` command.
484
+ #
485
+ # @return [String]
486
+ # Any error messages returned by the `cp` command.
487
+ #
488
+ # @see #cp
489
+ #
490
+ def cp_r(*arguments)
491
+ cp('-r',*arguments)
492
+ end
493
+ resource_method :cp_r, [:shell_exec]
494
+
495
+ #
496
+ # Runs `cp -a`.
497
+ #
498
+ # @param [Array<String>] arguments
499
+ # Additional arguments for the `cp` command.
500
+ #
501
+ # @return [String]
502
+ # Any error messages returned by the `cp` command.
503
+ #
504
+ # @see #cp
505
+ #
506
+ def cp_a(*arguments)
507
+ cp('-a',*arguments)
508
+ end
509
+ resource_method :cp_a, [:shell_exec]
510
+
511
+ #
512
+ # Runs `rsync`.
513
+ #
514
+ # @param [Array<String>] arguments
515
+ # Additional arguments to pass to the `rsync` command.
516
+ #
517
+ # @return [String]
518
+ # The full output of the command.
519
+ #
520
+ # @see #exec
521
+ #
522
+ def rsync(*arguments)
523
+ run('rsync',*arguments)
524
+ end
525
+ resource_method :rsync, [:shell_exec]
526
+
527
+ #
528
+ # Runs `rsync -a`.
529
+ #
530
+ # @param [Array<String>] arguments
531
+ # Additional arguments for the `rsync` command.
532
+ #
533
+ # @return [String]
534
+ # The full output of the command.
535
+ #
536
+ # @see #rsync
537
+ #
538
+ def rsync_a(*arguments)
539
+ rsync('-a',*arguments)
540
+ end
541
+ resource_method :rsync_a, [:shell_exec]
542
+
543
+ #
544
+ # Runs `wget`.
545
+ #
546
+ # @param [Array<String>] arguments
547
+ # Additional arguments to pass to the `rsync` command.
548
+ #
549
+ # @return [String]
550
+ # The full output of the command.
551
+ #
552
+ # @see #exec
553
+ #
554
+ def wget(*arguments)
555
+ run('wget','-q',*arguments)
556
+ end
557
+ resource_method :wget, [:shell_exec]
558
+
559
+ #
560
+ # Runs `wget -O`.
561
+ #
562
+ # @param [String] path
563
+ # The path that `wget` will write to.
564
+ #
565
+ # @param [Array<String>] arguments
566
+ # Additional arguments for the `wget` command.
567
+ #
568
+ # @return [String]
569
+ # The full output of the command.
570
+ #
571
+ # @see #wget
572
+ #
573
+ def wget_out(path,*arguments)
574
+ wget('-O',path,*arguments)
575
+ end
576
+ resource_method :wget_out, [:shell_exec]
577
+
578
+ #
579
+ # Runs the `curl`.
580
+ #
581
+ # @param [Array<String>] arguments
582
+ # Additional arguments to pass to the `curl` command.
583
+ #
584
+ # @return [String]
585
+ # The full output of the command.
586
+ #
587
+ # @see #exec
588
+ #
589
+ def curl(*arguments)
590
+ run('curl','-s',*arguments)
591
+ end
592
+ resource_method :curl, [:shell_exec]
593
+
594
+ #
595
+ # Runs `curl -O`.
596
+ #
597
+ # @param [String] path
598
+ # The path that `curl` will write to.
599
+ #
600
+ # @param [Array<String>] arguments
601
+ # Additional arguments for the `curl` command.
602
+ #
603
+ # @return [String]
604
+ # The full output of the command.
605
+ #
606
+ # @see #curl
607
+ #
608
+ def curl_out(path,*arguments)
609
+ curl('-O',path,*arguments)
610
+ end
611
+ resource_method :curl_out, [:shell_exec]
612
+
613
+ #
614
+ # Removes a directory.
615
+ #
616
+ # @param [Array<String>] arguments
617
+ # Additional arguments to pass to the `rmdir` command.
618
+ #
619
+ # @return [String]
620
+ # Any error messages returned by the `rmdir` command.
621
+ #
622
+ def rmdir(*arguments)
623
+ run('rmdir',*arguments)
624
+ end
625
+ resource_method :rmdir, [:shell_exec]
626
+
627
+ #
628
+ # Removes one or more files or directories.
629
+ #
630
+ # @param [Array<String>] arguments
631
+ # Additional arguments to pass to the `rm` command.
632
+ #
633
+ # @yield [line]
634
+ # If a block is given, it will be passed each line of output
635
+ # from the command.
636
+ #
637
+ # @yieldparam [String] line
638
+ # A line of output from the command.
639
+ #
640
+ # @return [String]
641
+ # The full output of the command.
642
+ #
643
+ # @see #exec
644
+ #
645
+ def rm(*arguments)
646
+ run('rm',*arguments)
647
+ end
648
+ resource_method :rm, [:shell_exec]
649
+
650
+ #
651
+ # Runs `rm -r`.
652
+ #
653
+ # @param [Array<String>] arguments
654
+ # Additional arguments for the `rm` command.
655
+ #
656
+ # @return [String]
657
+ # The full output of the command.
658
+ #
659
+ # @see #rm
660
+ #
661
+ def rm_r(*arguments)
662
+ rm('-r',*arguments)
663
+ end
664
+ resource_method :rm_r, [:shell_exec]
665
+
666
+ #
667
+ # Runs `rm -rf`.
668
+ #
669
+ # @param [Array<String>] arguments
670
+ # Additional arguments for the `rm` command.
671
+ #
672
+ # @return [String]
673
+ # The full output of the command.
674
+ #
675
+ # @see #rm
676
+ #
677
+ def rm_rf(*arguments)
678
+ rm('-rf',*arguments)
679
+ end
680
+ resource_method :rm_rf, [:shell_exec]
681
+
682
+ #
683
+ # Gets the current time from the shell.
684
+ #
685
+ # @return [Time]
686
+ # The current time returned by the shell.
687
+ #
688
+ def time
689
+ Time.parse(run('date').chomp)
690
+ end
691
+ resource_method :time, [:shell_exec]
692
+
693
+ #
694
+ # Gets the current time and date from the shell.
695
+ #
696
+ # @return [Date]
697
+ # The current data returned by the shell.
698
+ #
699
+ def date
700
+ time.to_date
701
+ end
702
+ resource_method :date, [:shell_exec]
703
+
704
+ #
705
+ # The ID information of the current user.
706
+ #
707
+ # @return [Hash{Symbol => String}]
708
+ # The ID information returned by the `id` command.
709
+ #
710
+ def id
711
+ hash = {}
712
+
713
+ run('id').split.each do |name_value|
714
+ name, value = name_value.split('=',2)
715
+
716
+ hash[name.to_sym] = value
717
+ end
718
+
719
+ return hash
720
+ end
721
+ resource_method :id, [:shell_exec]
722
+
723
+ #
724
+ # The UID of the current user.
725
+ #
726
+ # @return [Integer]
727
+ # The UID of the current user.
728
+ #
729
+ def uid
730
+ run('id','-u').to_i
731
+ end
732
+ resource_method :uid, [:shell_exec]
733
+
734
+ #
735
+ # The GID of the current user.
736
+ #
737
+ # @return [Integer]
738
+ # The GID of the current user.
739
+ #
740
+ def gid
741
+ run('id','-g').to_i
742
+ end
743
+ resource_method :gid, [:shell_exec]
744
+
745
+ #
746
+ # The name of the current user.
747
+ #
748
+ # @param [Array<String>] arguments
749
+ # Additional arguments to pass to the `whoami` command.
750
+ #
751
+ # @return [String]
752
+ # The name of the current user returned by the `whoami` command.
753
+ #
754
+ def whoami(*arguments)
755
+ run('whoami',*arguments).chomp
756
+ end
757
+ resource_method :whoami, [:shell_exec]
758
+
759
+ #
760
+ # Shows who is currently logged in.
761
+ #
762
+ # @param [Array<String>] arguments
763
+ # Additional arguments to pass to the `who` command.
764
+ #
765
+ # @return [String]
766
+ # The full output of the command.
767
+ #
768
+ # @see #exec
769
+ #
770
+ def who(*arguments)
771
+ run('who',*arguments)
772
+ end
773
+ resource_method :who, [:shell_exec]
774
+
775
+ #
776
+ # Similar to {#who} but runs the `w` command.
777
+ #
778
+ # @param [Array<String>] arguments
779
+ # Additional arguments to pass to the `w` command.
780
+ #
781
+ # @return [String]
782
+ # The full output of the command.
783
+ #
784
+ # @see #exec
785
+ #
786
+ def w(*arguments)
787
+ run('w',*arguments)
788
+ end
789
+ resource_method :w, [:shell_exec]
790
+
791
+ #
792
+ # Shows when users last logged in.
793
+ #
794
+ # @param [Array<String>] arguments
795
+ # Additional arguments to pass to the `lastlog` command.
796
+ #
797
+ # @return [String]
798
+ # The full output of the command.
799
+ #
800
+ # @see #exec
801
+ #
802
+ def lastlog(*arguments)
803
+ run('lastlog',*arguments)
804
+ end
805
+ resource_method :lastlog, [:shell_exec]
806
+
807
+ #
808
+ # Shows login failures.
809
+ #
810
+ # @param [Array<String>] arguments
811
+ # Additional arguments to pass to the `faillog` command.
812
+ #
813
+ # @yield [line]
814
+ # If a block is given, it will be passed each line of output
815
+ # from the command.
816
+ #
817
+ # @yieldparam [String] line
818
+ # A line of output from the command.
819
+ #
820
+ # @return [String]
821
+ # The full output of the command.
822
+ #
823
+ # @see #exec
824
+ #
825
+ def faillog(*arguments)
826
+ run('faillog',*arguments)
827
+ end
828
+ resource_method :faillog, [:shell_exec]
829
+
830
+ #
831
+ # Shows the current running processes.
832
+ #
833
+ # @param [Array<String>] arguments
834
+ # Additional arguments to pass to the `ps` command.
835
+ #
836
+ # @return [String]
837
+ # The full output of the command.
838
+ #
839
+ # @see #exec
840
+ #
841
+ def ps(*arguments)
842
+ run('ps',*arguments)
843
+ end
844
+ resource_method :ps, [:shell_exec]
845
+
846
+ #
847
+ # Runs `ps aux`.
848
+ #
849
+ # @param [Array<String>] arguments
850
+ # Additional arguments for the `ps` command.
851
+ #
852
+ # @return [String]
853
+ # The full output of the command.
854
+ #
855
+ # @see #ps
856
+ #
857
+ def ps_aux(*arguments)
858
+ ps('aux',*arguments)
859
+ end
860
+ resource_method :ps_aux, [:shell_exec]
861
+
862
+ #
863
+ # Kills a current running process.
864
+ #
865
+ # @param [Array<String>] arguments
866
+ # Additional arguments to pass to the `kill` command.
867
+ #
868
+ # @return [String]
869
+ # Output from the `kill` command.
870
+ #
871
+ def kill(*arguments)
872
+ run('kill',*arguments)
873
+ end
874
+ resource_method :kill, [:shell_exec]
875
+
876
+ #
877
+ # Shows information about network interfaces.
878
+ #
879
+ # @param [Array<String>] arguments
880
+ # Additional arguments to pass to the `ifconfig` command.
881
+ #
882
+ # @return [String]
883
+ # The full output of the command.
884
+ #
885
+ # @see #exec
886
+ #
887
+ def ifconfig(*arguments)
888
+ run('ifconfig',*arguments)
889
+ end
890
+ resource_method :ifconfig, [:shell_exec]
891
+
892
+ #
893
+ # Shows network connections.
894
+ #
895
+ # @param [Array<String>] arguments
896
+ # Additional arguments to pass to the `netstat` command.
897
+ #
898
+ # @return [String]
899
+ # The full output of the command.
900
+ #
901
+ # @see #exec
902
+ #
903
+ def netstat(*arguments)
904
+ run('netstat',*arguments)
905
+ end
906
+ resource_method :netstat, [:shell_exec]
907
+
908
+ #
909
+ # Runs `netstat -anp`.
910
+ #
911
+ # @param [Array<String>] arguments
912
+ # Additional arguments for the `netstat` command.
913
+ #
914
+ # @return [String]
915
+ # The full output of the command.
916
+ #
917
+ # @see #netstat
918
+ #
919
+ def netstat_anp(*arguments)
920
+ netstat('-anp',*arguments)
921
+ end
922
+ resource_method :netstat_anp, [:shell_exec]
923
+
924
+ #
925
+ # Pings an IP address.
926
+ #
927
+ # @param [Array<String>] arguments
928
+ # Additional arguments to pass to the `ping` command.
929
+ #
930
+ # @yield [line]
931
+ # If a block is given, it will be passed each line of output
932
+ # from the command.
933
+ #
934
+ # @yieldparam [String] line
935
+ # A line of output from the command.
936
+ #
937
+ # @return [String]
938
+ # The full output of the command.
939
+ #
940
+ # @see #exec
941
+ #
942
+ def ping(*arguments)
943
+ run('ping',*arguments)
944
+ end
945
+ resource_method :ping, [:shell_exec]
946
+
947
+ #
948
+ # Compiles some C source-code with `gcc`.
949
+ #
950
+ # @param [Array<String>] arguments
951
+ # Additional arguments to pass to the `gcc` command.
952
+ #
953
+ # @return [String]
954
+ # The full output of the command.
955
+ #
956
+ # @see #exec
957
+ #
958
+ def gcc(*arguments)
959
+ run('gcc',*arguments)
960
+ end
961
+ resource_method :gcc, [:shell_exec]
962
+
963
+ #
964
+ # Compiles some C source-code with `cc`.
965
+ #
966
+ # @param [Array<String>] arguments
967
+ # Additional arguments to pass to the `cc` command.
968
+ #
969
+ # @return [String]
970
+ # The full output of the command.
971
+ #
972
+ # @see #exec
973
+ #
974
+ def cc(*arguments)
975
+ run('cc',*arguments)
976
+ end
977
+ resource_method :cc, [:shell_exec]
978
+
979
+ #
980
+ # Runs a PERL script.
981
+ #
982
+ # @param [Array<String>] arguments
983
+ # Additional arguments to pass to the `perl` command.
984
+ #
985
+ # @return [String]
986
+ # The full output of the command.
987
+ #
988
+ # @see #exec
989
+ #
990
+ def perl(*arguments)
991
+ run('perl',*arguments)
992
+ end
993
+ resource_method :perl, [:shell_exec]
994
+
995
+ #
996
+ # Runs a Python script.
997
+ #
998
+ # @param [Array<String>] arguments
999
+ # Additional arguments to pass to the `python` command.
1000
+ #
1001
+ # @return [String]
1002
+ # The full output of the command.
1003
+ #
1004
+ # @see #exec
1005
+ #
1006
+ def python(*arguments)
1007
+ run('python',*arguments)
1008
+ end
1009
+ resource_method :python, [:shell_exec]
1010
+
1011
+ #
1012
+ # Runs a Ruby script.
1013
+ #
1014
+ # @param [Array<String>] arguments
1015
+ # Additional arguments to pass to the `ruby` command.
1016
+ #
1017
+ # @return [String]
1018
+ # The full output of the command.
1019
+ #
1020
+ # @see #exec
1021
+ #
1022
+ def ruby(*arguments)
1023
+ run('ruby',*arguments)
1024
+ end
1025
+ resource_method :ruby, [:shell_exec]
1026
+
1027
+ #
1028
+ # Starts an interactive Shell console.
1029
+ #
1030
+ def interact
1031
+ CLI::ShellShell.start(self)
1032
+ end
1033
+
1034
+ end
1035
+ end
1036
+ end
1037
+ end