Module: Msf::Payload::Ruby

Defined in:
lib/msf/core/payload/ruby.rb

Instance Method Summary collapse

Instance Method Details

#initialize(info = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/msf/core/payload/ruby.rb', line 5

def initialize(info = {})
  super(info)

  register_advanced_options(
    [
      # Since space restrictions aren't really a problem, default this to
      # true.
      Msf::OptBool.new('PrependFork', [ false, "Start the payload in its own process via fork or popen", true ])
    ]
  )
end

#prepends(buf) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/core/payload/ruby.rb', line 17

def prepends(buf)
  if datastore['PrependFork']
    buf = %Q^
      code = %(#{ Rex::Text.encode_base64(buf) }).unpack(%(m0)).first
      if RUBY_PLATFORM =~ /mswin|mingw|win32/
        inp = IO.popen(%(ruby), %(wb)) rescue nil
        if inp
          inp.write(code)
          inp.close
        end
      else
        if ! Process.fork()
          eval(code) rescue nil
        end
      end
    ^.strip.split(/\n/).map{|line| line.strip}.join("\n")
  end

  buf
end