Module: Ronin::Payloads::Helpers::Shell

Included in:
BindShell
Defined in:
lib/ronin/payloads/helpers/shell.rb

Overview

Payload helper which implements Ronin::PostExploitation methods via shell commands.

Instance Method Summary collapse

Instance Method Details

#fs_chdir(path) ⇒ Object


35
36
37
38
# File 'lib/ronin/payloads/helpers/shell.rb', line 35

def fs_chdir(path)
  shell.cd(path)
  return shell.pwd
end

#fs_chgrp(group, path) ⇒ Object


86
87
88
# File 'lib/ronin/payloads/helpers/shell.rb', line 86

def fs_chgrp(group,path)
  shell.chgrp(group,path).empty?
end

#fs_chmod(mode, path) ⇒ Object


90
91
92
# File 'lib/ronin/payloads/helpers/shell.rb', line 90

def fs_chmod(mode,path)
  shell.chmod("%.4o" % mode,path).empty?
end

#fs_chown(user, path) ⇒ Object


82
83
84
# File 'lib/ronin/payloads/helpers/shell.rb', line 82

def fs_chown(user,path)
  shell.chown(user,path).empty?
end

#fs_copy(path, new_path) ⇒ Object


66
67
68
# File 'lib/ronin/payloads/helpers/shell.rb', line 66

def fs_copy(path,new_path)
  shell.cp(path,new_path).empty?
end

#fs_getcwdObject


31
32
33
# File 'lib/ronin/payloads/helpers/shell.rb', line 31

def fs_getcwd
  shell.pwd
end

#fs_glob(pattern, &block) ⇒ Object


44
45
46
# File 'lib/ronin/payloads/helpers/shell.rb', line 44

def fs_glob(pattern,&block)
  shell.find(pattern,&block)
end

#fs_mkdir(path) ⇒ Object


62
63
64
# File 'lib/ronin/payloads/helpers/shell.rb', line 62

def fs_mkdir(path)
  shell.mkdir(path)
end

#fs_mktemp(basename) ⇒ Object


58
59
60
# File 'lib/ronin/payloads/helpers/shell.rb', line 58

def fs_mktemp(basename)
  shell.mktemp(basename)
end

#fs_move(path, new_path) ⇒ Object


78
79
80
# File 'lib/ronin/payloads/helpers/shell.rb', line 78

def fs_move(path,new_path)
  shell.mv(path,new_path).empty?
end

#fs_read(path, pos) ⇒ Object


48
49
50
# File 'lib/ronin/payloads/helpers/shell.rb', line 48

def fs_read(path,pos)
  shell.exec('dd',"if=#{path}",'bs=1',"skip=#{pos}",'count=4096')
end

#fs_readdir(path) ⇒ Object


40
41
42
# File 'lib/ronin/payloads/helpers/shell.rb', line 40

def fs_readdir(path)
  shell.ls(path)
end

#fs_rmdir(path) ⇒ Object


74
75
76
# File 'lib/ronin/payloads/helpers/shell.rb', line 74

def fs_rmdir(path)
  shell.rmdir(path).empty?
end

#fs_stat(path) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ronin/payloads/helpers/shell.rb', line 94

def fs_stat(path)
  fields = shell.exec('stat','-t',path).strip.split(' ')

  return {
    path: path,
    size: fields[1].to_i,
    blocks: fields[2].to_i,
    uid: fields[4].to_i,
    gid: fields[5].to_i,
    inode: fields[7].to_i,
    links: fields[8].to_i,
    atime: Time.at(fields[11].to_i),
    mtime: Time.at(fields[12].to_i),
    ctime: Time.at(fields[13].to_i),
    blocksize: fields[14].to_i
  }
end

70
71
72
# File 'lib/ronin/payloads/helpers/shell.rb', line 70

def fs_unlink(path)
  shell.rm(path).empty?
end

#fs_write(path, pos, data) ⇒ Object


52
53
54
55
56
# File 'lib/ronin/payloads/helpers/shell.rb', line 52

def fs_write(path,pos,data)
  escaped = data.gsub('%','%%').dump

  shell.exec("printf #{escaped} | dd if=#{path} bs=1 skip=#{pos} count=4096")
end

#process_exitObject


146
147
148
# File 'lib/ronin/payloads/helpers/shell.rb', line 146

def process_exit
  shell.exit
end

#process_getenv(name) ⇒ Object


120
121
122
# File 'lib/ronin/payloads/helpers/shell.rb', line 120

def process_getenv(name)
  shell.exec('echo',"$#{name}")
end

#process_getgidObject


116
117
118
# File 'lib/ronin/payloads/helpers/shell.rb', line 116

def process_getgid
  shell.gid
end

#process_getuidObject


112
113
114
# File 'lib/ronin/payloads/helpers/shell.rb', line 112

def process_getuid
  shell.uid
end

#process_kill(pid) ⇒ Object


132
133
134
# File 'lib/ronin/payloads/helpers/shell.rb', line 132

def process_kill(pid)
  shell.kill(pid)
end

#process_setenv(name, value) ⇒ Object


124
125
126
# File 'lib/ronin/payloads/helpers/shell.rb', line 124

def process_setenv(name,value)
  shell.exec('export',"#{name}=#{value}")
end

#process_spawn(program, *arguments) ⇒ Object


140
141
142
143
144
# File 'lib/ronin/payloads/helpers/shell.rb', line 140

def process_spawn(program,*arguments)
  arguments += %w[2>&1 >/dev/null]

  shell.exec(program,*arguments)
end

#process_timeObject


136
137
138
# File 'lib/ronin/payloads/helpers/shell.rb', line 136

def process_time
  shell.time
end

#process_unsetenv(name) ⇒ Object


128
129
130
# File 'lib/ronin/payloads/helpers/shell.rb', line 128

def process_unsetenv(name)
  shell.exec('unset',name)
end