Class: Ronin::PostExploitation::Resources::Shell

Inherits:
Ronin::PostExploitation::Resource show all
Defined in:
lib/ronin/post_exploitation/resources/shell.rb

Overview

Controls the resources of a Shell.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from Ronin::PostExploitation::Resource

#controller

Instance Method Summary collapse

Methods inherited from Ronin::PostExploitation::Resource

#requires_method!, resource_method, resource_methods, #supports, #supports?

Constructor Details

#initialize(controller) ⇒ Shell

Initializes the Shell resource.

Since:

  • 1.0.0


47
48
49
50
51
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 47

def initialize(controller)
  super(controller)

  @paths = {}
end

Instance Attribute Details

#pathsObject (readonly)

Since:

  • 1.0.0


39
40
41
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 39

def paths
  @paths
end

Instance Method Details

#cat(*arguments, &block) ⇒ Object

Reads the contents of one or more files.

See Also:

Since:

  • 1.0.0


262
263
264
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 262

def cat(*arguments,&block)
  exec('cat',*arguments,&block)
end

#cc(*arguments, &block) ⇒ Object

Compiles some C source-code with cc.

See Also:

Since:

  • 1.0.0


863
864
865
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 863

def cc(*arguments,&block)
  exec('cc',*arguments,&block)
end

#cd(path) ⇒ String

Changes the current working directory in the shell.

Since:

  • 1.0.0


128
129
130
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 128

def cd(path)
  command('cd',path).first
end

#command(program, *arguments) ⇒ Command

Creates a command to later execute.

Since:

  • 1.0.0


65
66
67
68
69
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 65

def command(program,*arguments)
  program = (@paths[program.scan(/^[^\s]+/).first] || program)

  return Command.new(@controller,program,*arguments)
end

#consoleObject

Starts an interactive Shell console.

Since:

  • 1.0.0


918
919
920
921
922
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 918

def console
  UI::Shell.start(prompt: '$') do |shell,line|
    command(line).each_block { |block| shell.write(block) }
  end
end

#cp(*arguments) ⇒ String

Copies one or more files or directories.

Since:

  • 1.0.0


441
442
443
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 441

def cp(*arguments)
  command('cp',*arguments).first
end

#cp_a(*arguments) ⇒ Object

Runs cp -a.

See Also:

Since:

  • 1.0.0


461
462
463
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 461

def cp_a(*arguments)
  cp('-a',*arguments)
end

#cp_r(*arguments) ⇒ Object

Runs cp -r.

See Also:

Since:

  • 1.0.0


451
452
453
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 451

def cp_r(*arguments)
  cp('-r',*arguments)
end

#curl(*arguments) ⇒ Object

Runs the curl.

See Also:

Since:

  • 1.0.0


523
524
525
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 523

def curl(*arguments)
  exec('curl','-s',*arguments)
end

#curl_out(path, *arguments) ⇒ Object

Runs curl -O.

See Also:

Since:

  • 1.0.0


536
537
538
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 536

def curl_out(path,*arguments)
  curl('-O',path,*arguments)
end

#dateDate

Gets the current time and date from the shell.

Since:

  • 1.0.0


594
595
596
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 594

def date
  Date.parse(exec('date'))
end

#egrep(*arguments, &block) ⇒ Object

Runs grep -E.

See Also:

Since:

  • 1.0.0


361
362
363
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 361

def egrep(*arguments,&block)
  grep('-E',*arguments,&block)
end

#exec(program, *arguments) {|line| ... } ⇒ String?

Executes a command and reads the resulting output.

Yields:

  • (line)

    If a block is given, it will be passed each line of output from the command.

Yield Parameters:

  • line (String)

    A line of output from the command.

Since:

  • 1.0.0


92
93
94
95
96
97
98
99
100
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 92

def exec(program,*arguments)
  cmd = command(program,*arguments)

  if block_given?
    cmd.each { |line| yield line.chomp }
  else
    cmd.read
  end
end

#exitObject

Exits the shell.

Since:

  • 1.0.0


910
911
912
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 910

def exit
  exec('exit')
end

#faillog(*arguments, &block) ⇒ Object

Shows login failures.

See Also:

Since:

  • 1.0.0


712
713
714
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 712

def faillog(*arguments,&block)
  exec('faillog',*arguments,&block)
end

#fgrep(*arguments, &block) ⇒ Object

Runs grep -F.

See Also:

Since:

  • 1.0.0


371
372
373
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 371

def fgrep(*arguments,&block)
  grep('-F',*arguments,&block)
end

#file(*arguments) ⇒ String

Determines the format of a file.

Examples:

exploit.shell.file('data.db')
# => "data.db: SQLite 3.x database"

Since:

  • 1.0.0


235
236
237
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 235

def file(*arguments)
  command('file',*arguments).first
end

#find(*arguments) {|path| ... } ⇒ Array<String>?

Searches for files or directories.

Yields:

  • (path)

    If a block is given, it will be passed each path found.

Yield Parameters:

  • path (String)

    A path found by the find command.

Since:

  • 1.0.0


213
214
215
216
217
218
219
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 213

def find(*arguments)
  if block_given?
    exec('find',*arguments) { |line| yield line.chomp }
  else
    enum_for(__method__,*arguments).to_a
  end
end

#gcc(*arguments, &block) ⇒ Object

Compiles some C source-code with gcc.

See Also:

Since:

  • 1.0.0


850
851
852
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 850

def gcc(*arguments,&block)
  exec('gcc',*arguments,&block)
end

#gidInteger

The GID of the current user.

Since:

  • 1.0.0


646
647
648
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 646

def gid
  exec('id','-g').to_i
end

#grep(*arguments) {|path, line| ... } ⇒ Array<String>?

Searches one or more files for a given pattern.

Yields:

  • (path, line)

    If a block is given, it will be passed the paths and lines within files that matched the given pattern.

Yield Parameters:

  • path (String)

    The path of a file that contains matching lines.

  • line (String)

    A line that matches the given pattern.

Since:

  • 1.0.0


345
346
347
348
349
350
351
352
353
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 345

def grep(*arguments,&block)
  if block_given?
    exec('grep',*arguments) do |line|
      yield(*line.split(':',2))
    end
  else
    enum_for(__method__,*arguments).to_a
  end
end

#head(*arguments, &block) ⇒ Object

Reads the first n lines of one or more files.

See Also:

Since:

  • 1.0.0


275
276
277
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 275

def head(*arguments,&block)
  exec('head',*arguments,&block)
end

#head_n(lines, *arguments, &block) ⇒ Object

Reads the first n lines of one or more files.

See Also:

Since:

  • 1.0.0


291
292
293
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 291

def head_n(lines,*arguments,&block)
  head('-n',lines,*arguments,&block)
end

#idHash{Symbol => String}

The ID information of the current user.

Since:

  • 1.0.0


616
617
618
619
620
621
622
623
624
625
626
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 616

def id
  hash = {}

  exec('id').split(' ').each do |name_value|
    name, value = name_value.split('=',2)

    hash[name.to_sym] = value
  end

  return hash
end

#ifconfig(*arguments, &block) ⇒ Object

Shows information about network interfaces.

See Also:

Since:

  • 1.0.0


762
763
764
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 762

def ifconfig(*arguments,&block)
  exec('ifconfig',*arguments,&block)
end

#kill(*arguments) ⇒ String

Kills a current running process.

Since:

  • 1.0.0


749
750
751
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 749

def kill(*arguments)
  command('kill',*arguments).first
end

#lastlog(*arguments, &block) ⇒ Object

Shows when users last logged in.

See Also:

Since:

  • 1.0.0


699
700
701
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 699

def lastlog(*arguments,&block)
  exec('lastlog',*arguments,&block)
end

#ls(*arguments, &block) ⇒ Object

Lists the files or directories.

See Also:

Since:

  • 1.0.0


152
153
154
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 152

def ls(*arguments,&block)
  exec('ls',*arguments,&block)
end

#ls_a(*arguments, &block) ⇒ Object

Lists all files or directories.

See Also:

Since:

  • 1.0.0


165
166
167
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 165

def ls_a(*arguments,&block)
  exec('ls','-a',*arguments,&block)
end

#ls_l(*arguments, &block) ⇒ Object

Lists information about files or directories.

See Also:

Since:

  • 1.0.0


178
179
180
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 178

def ls_l(*arguments,&block)
  exec('ls','-l',*arguments,&block)
end

#ls_la(*arguments, &block) ⇒ Object Also known as: ls_al

Lists information about all files or directories.

See Also:

Since:

  • 1.0.0


191
192
193
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 191

def ls_la(*arguments,&block)
  exec('ls','-la',*arguments,&block)
end

#mkdir(*arguments) ⇒ String

Creates a new directory.

Since:

  • 1.0.0


427
428
429
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 427

def mkdir(*arguments)
  command('mkdir',*arguments).first
end

#mktemp(*arguments) ⇒ String

Creates a tempfile.

Since:

  • 1.0.0


399
400
401
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 399

def mktemp(*arguments)
  command('mktemp',*arguments).first.chomp
end

#mktempdir(*arguments) ⇒ String

Creates a tempdir.

Since:

  • 1.0.0


413
414
415
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 413

def mktempdir(*arguments)
  mktemp('-d',*arguments)
end

#nc(*arguments, &block) ⇒ Object

Runs net-cat.

See Also:

Since:

  • 1.0.0


811
812
813
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 811

def nc(*arguments,&block)
  exec('nc',*arguments,&block)
end

#nc_connect(host, port, *arguments, &block) ⇒ Object

Connects to a host using net-cat.

See Also:

Since:

  • 1.0.0


837
838
839
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 837

def nc_connect(host,port,*arguments,&block)
  nc(host,port,*arguments,&block)
end

#nc_listen(port, *arguments, &block) ⇒ Object

Runs nc -l.

See Also:

Since:

  • 1.0.0


821
822
823
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 821

def nc_listen(port,*arguments,&block)
  nc('-l',port,*arguments,&block)
end

#netstat(*arguments, &block) ⇒ Object

Shows network connections.

See Also:

Since:

  • 1.0.0


775
776
777
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 775

def netstat(*arguments,&block)
  exec('netstat',*arguments,&block)
end

#netstat_anp(*arguments, &block) ⇒ Object

Runs netstat -anp.

See Also:

Since:

  • 1.0.0


785
786
787
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 785

def netstat_anp(*arguments,&block)
  netstat('-anp',*arguments,&block)
end

#perl(*arguments, &block) ⇒ Object

Runs a PERL script.

See Also:

Since:

  • 1.0.0


876
877
878
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 876

def perl(*arguments,&block)
  exec('perl',*arguments,&block)
end

#ping(*arguments, &block) ⇒ Object

Pings an IP address.

See Also:

Since:

  • 1.0.0


798
799
800
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 798

def ping(*arguments,&block)
  exec('ping',*arguments,&block)
end

#ps(*arguments, &block) ⇒ Object

Shows the current running processes.

See Also:

Since:

  • 1.0.0


725
726
727
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 725

def ps(*arguments,&block)
  exec('ps',*arguments,&block)
end

#ps_aux(*arguments, &block) ⇒ Object

Runs ps aux.

See Also:

Since:

  • 1.0.0


735
736
737
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 735

def ps_aux(*arguments,&block)
  ps('aux',*arguments,&block)
end

#pwdString

Gets the current working directory.

Since:

  • 1.0.0


139
140
141
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 139

def pwd
  exec('pwd').chomp
end

#python(*arguments, &block) ⇒ Object

Runs a Python script.

See Also:

Since:

  • 1.0.0


889
890
891
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 889

def python(*arguments,&block)
  exec('python',*arguments,&block)
end

#rm(*arguments, &block) ⇒ Object

Removes one or more files or directories.

See Also:

Since:

  • 1.0.0


563
564
565
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 563

def rm(*arguments,&block)
  exec('rm',*arguments,&block)
end

#rm_r(*arguments, &block) ⇒ Object

Runs rm -r.

See Also:

Since:

  • 1.0.0


573
574
575
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 573

def rm_r(*arguments,&block)
  rm('-r',*arguments,&block)
end

#rm_rf(*arguments, &block) ⇒ Object

Runs rm -rf.

See Also:

Since:

  • 1.0.0


583
584
585
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 583

def rm_rf(*arguments,&block)
  rm('-rf',*arguments,&block)
end

#rmdir(*arguments) ⇒ String

Removes a directory.

Since:

  • 1.0.0


550
551
552
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 550

def rmdir(*arguments)
  command('rmdir',*arguments).first
end

#rsync(*arguments, &block) ⇒ Object

Runs rsync.

See Also:

Since:

  • 1.0.0


474
475
476
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 474

def rsync(*arguments,&block)
  exec('rsync',*arguments,&block)
end

#rsync_a(*arguments, &block) ⇒ Object

Runs rsync -a.

See Also:

Since:

  • 1.0.0


484
485
486
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 484

def rsync_a(*arguments,&block)
  rsync('-a',*arguments,&block)
end

#ruby(*arguments, &block) ⇒ Object

Runs a Ruby script.

See Also:

Since:

  • 1.0.0


902
903
904
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 902

def ruby(*arguments,&block)
  exec('ruby',*arguments,&block)
end

#system(command, *arguments) ⇒ nil

Executes a command and prints the resulting output.

Since:

  • 1.0.0


114
115
116
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 114

def system(command,*arguments)
  exec(command,*arguments) { |line| puts line }
end

#tail(*arguments, &block) ⇒ Object

Reads the last n lines of one or more files.

See Also:

Since:

  • 1.0.0


304
305
306
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 304

def tail(*arguments,&block)
  exec('tail',*arguments,&block)
end

#tail_n(lines, *arguments, &block) ⇒ Object

Reads the last n lines of one or more files.

See Also:

Since:

  • 1.0.0


320
321
322
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 320

def tail_n(lines,*arguments,&block)
  tail('-n',lines,*arguments,&block)
end

#timeTime

Gets the current time from the shell.

Since:

  • 1.0.0


605
606
607
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 605

def time
  date.to_time
end

#touch(*arguments) ⇒ String

Touches a file.

Since:

  • 1.0.0


385
386
387
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 385

def touch(*arguments)
  command('touch',*arguments).first
end

#uidInteger

The UID of the current user.

Since:

  • 1.0.0


635
636
637
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 635

def uid
  exec('id','-u').to_i
end

#w(*arguments, &block) ⇒ Object

Similar to #who but runs the w command.

See Also:

Since:

  • 1.0.0


686
687
688
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 686

def w(*arguments,&block)
  exec('w',*arguments,&block)
end

#wget(*arguments) ⇒ Object

Runs wget.

See Also:

Since:

  • 1.0.0


497
498
499
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 497

def wget(*arguments)
  exec('wget','-q',*arguments)
end

#wget_out(path, *arguments) ⇒ Object

Runs wget -O.

See Also:

Since:

  • 1.0.0


510
511
512
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 510

def wget_out(path,*arguments)
  wget('-O',path,*arguments)
end

#which(*arguments) ⇒ String

Finds a program available to the shell.

Since:

  • 1.0.0


249
250
251
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 249

def which(*arguments)
  command('which',*arguments).first
end

#who(*arguments, &block) ⇒ Object

Shows who is currently logged in.

See Also:

Since:

  • 1.0.0


673
674
675
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 673

def who(*arguments,&block)
  exec('who',*arguments,&block)
end

#whoami(*arguments) ⇒ String

The name of the current user.

Since:

  • 1.0.0


660
661
662
# File 'lib/ronin/post_exploitation/resources/shell.rb', line 660

def whoami(*arguments)
  exec('whoami',*arguments).chomp
end