Class: Msf::RPC::RPC_Module

Inherits:
RPC_Base show all
Defined in:
lib/msf/core/rpc/v10/rpc_module.rb

Instance Attribute Summary

Attributes inherited from RPC_Base

#framework, #service, #tokens, #users

Instance Method Summary collapse

Methods inherited from RPC_Base

#error, #initialize

Constructor Details

This class inherits a constructor from Msf::RPC::RPC_Base

Instance Method Details

#rpc_auxiliaryObject


11
12
13
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 11

def rpc_auxiliary
  { "modules" => self.framework.auxiliary.keys }
end

#rpc_compatible_payloads(mname) ⇒ Object


77
78
79
80
81
82
83
84
85
86
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 77

def rpc_compatible_payloads(mname)
  m   = _find_module('exploit',mname)
  res = {}
  res['payloads'] = []
  m.compatible_payloads.each do |k|
    res['payloads'] << k[0]
  end

  res
end

#rpc_compatible_sessions(mname) ⇒ Object


88
89
90
91
92
93
94
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 88

def rpc_compatible_sessions(mname)
  m   = _find_module('post',mname)
  res = {}
  res['sessions'] = m.compatible_sessions

  res
end

#rpc_encode(data, encoder, options) ⇒ Object


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 154

def rpc_encode(data, encoder, options)
  # Load supported formats
  supported_formats = Msf::Simple::Buffer.transform_formats + Msf::Util::EXE.to_executable_fmt_formats

  if (fmt = options['format'])
    if not supported_formats.include?(fmt)
      error(500, "Invalid Format: #{fmt}")
    end
  end

  badchars = ''
  if options['badchars']
    badchars = options['badchars']
  end

  platform = nil
  if options['platform']
    platform = Msf::Module::PlatformList.transform(options['platform'])
  end

  arch = nil
  if options['arch']
    arch = options['arch']
  end

  ecount = 1
  if options['ecount']
    ecount = options['ecount'].to_i
  end

  exeopts = {
    :inject => options['inject'],
    :template => options['altexe'],
    :template_path => options['exedir']
  }

  # If we were given addshellcode for a win32 payload,
  # create a double-payload; one running in one thread, one running in the other
  if options['addshellcode']
    buf = Msf::Util::EXE.win32_rwx_exec_thread(buf,0,'end')
    file = ::File.new(options['addshellcode'])
    file.binmode
    buf << file.read
    file.close
  end

  enc = self.framework.encoders.create(encoder)

  begin
    # Imports options
    enc.datastore.update(options)

    raw  = data.unpack("C*").pack("C*")

    1.upto(ecount) do |iteration|
      # Encode it up
      raw = enc.encode(raw, badchars, nil, platform)
    end

    output = Msf::Util::EXE.to_executable_fmt(self.framework, arch, platform, raw, fmt, exeopts)

    if not output
      fmt ||= "ruby"
      output = Msf::Simple::Buffer.transform(raw, fmt)
    end

    # How to warn?
    #if exeopts[:fellback]
    # $stderr.puts(OutError + "Warning: Falling back to default template: #{exeopts[:fellback]}")
    #end

    { "encoded" => output.to_s }
  rescue => e
    error(500, "#{enc.refname} failed: #{e} #{e.backtrace}")
  end
end

#rpc_encode_formatsObject


149
150
151
152
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 149

def rpc_encode_formats
  # Supported formats
  Msf::Simple::Buffer.transform_formats + Msf::Util::EXE.to_executable_fmt_formats
end

#rpc_encodersObject


19
20
21
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 19

def rpc_encoders
  { "modules" => self.framework.encoders.keys }
end

#rpc_execute(mtype, mname, opts) ⇒ Object


134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 134

def rpc_execute(mtype, mname, opts)
  mod = _find_module(mtype,mname)
  case mtype
    when 'exploit'
      _run_exploit(mod, opts)
    when 'auxiliary'
      _run_auxiliary(mod, opts)
    when 'payload'
      _run_payload(mod, opts)
    when 'post'
      _run_post(mod, opts)
  end

end

#rpc_exploitsObject


7
8
9
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 7

def rpc_exploits
  { "modules" => self.framework.exploits.keys }
end

#rpc_info(mtype, mname) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 31

def rpc_info(mtype, mname)
  m = _find_module(mtype,mname)
  res = {}

  res['name'] = m.name
  res['description'] = m.description
  res['license'] = m.license
  res['filepath'] = m.file_path
  res['rank'] = m.rank.to_i

  res['references'] = []
  m.references.each do |r|
    res['references'] << [r.ctx_id, r.ctx_val]
  end

  res['authors'] = []
  m.each_author do |a|
    res['authors'] << a.to_s
  end

  if(m.type == "exploit")
    res['targets'] = {}
    m.targets.each_index do |i|
      res['targets'][i] = m.targets[i].name
    end

    if (m.default_target)
      res['default_target'] = m.default_target
    end
  end

  if(m.type == "auxiliary")
    res['actions'] = {}
    m.actions.each_index do |i|
      res['actions'][i] = m.actions[i].name
    end

    if (m.default_action)
      res['default_action'] = m.default_action
    end
  end

  res
end

#rpc_nopsObject


23
24
25
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 23

def rpc_nops
  { "modules" => self.framework.nops.keys }
end

#rpc_options(mtype, mname) ⇒ Object


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 108

def rpc_options(mtype, mname)
  m = _find_module(mtype,mname)
  res = {}

  m.options.each_key do |k|
    o = m.options[k]
    res[k] = {
      'type'     => o.type,
      'required' => o.required,
      'advanced' => o.advanced,
      'evasion'  => o.evasion,
      'desc'     => o.desc
    }

    if(not o.default.nil?)
      res[k]['default'] = o.default
    end

    if(o.enums.length > 1)
      res[k]['enums'] = o.enums
    end
  end

  res
end

#rpc_payloadsObject


15
16
17
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 15

def rpc_payloads
  { "modules" => self.framework.payloads.keys }
end

#rpc_postObject


27
28
29
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 27

def rpc_post
  { "modules" => self.framework.post.keys }
end

#rpc_target_compatible_payloads(mname, target) ⇒ Object


96
97
98
99
100
101
102
103
104
105
106
# File 'lib/msf/core/rpc/v10/rpc_module.rb', line 96

def rpc_target_compatible_payloads(mname, target)
  m   = _find_module('exploit',mname)
  res = {}
  res['payloads'] = []
  m.datastore['TARGET'] = target.to_i
  m.compatible_payloads.each do |k|
    res['payloads'] << k[0]
  end

  res
end