Module: Msf::Payload::Linux::Prepends

Included in:
Aarch64::Prepends, Armle::Prepends, Msf::Payload::Linux::Ppc::Prepends, X64::Prepends, X86::Prepends
Defined in:
lib/msf/core/payload/linux/prepends.rb

Overview

Linux Preprends shared logic.

Instance Method Summary collapse

Instance Method Details

#apply_prepends(buf) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/msf/core/payload/linux/prepends.rb', line 32

def apply_prepends(buf)
  pre = ''
  app = ''
  for name in prepends_order.each
    pre << prepends_map.fetch(name) if datastore[name]
  end
  for name in appends_order.each
    app << appends_map.fetch(name) if datastore[name]
  end
  pre.force_encoding('ASCII-8BIT') +
    buf.force_encoding('ASCII-8BIT') +
    app.force_encoding('ASCII-8BIT')
end

#initialize(info) ⇒ Object



5
6
7
8
# File 'lib/msf/core/payload/linux/prepends.rb', line 5

def initialize(info)
  super(info)
  register_prepend_options
end

#register_prepend_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/msf/core/payload/linux/prepends.rb', line 10

def register_prepend_options
  all_options = {
    'PrependFork' => [false, 'Prepend a stub that starts the payload in its own process via fork', 'false'],
    'PrependSetresuid' => [false, 'Prepend a stub that executes the setresuid(0, 0, 0) system call', 'false'],
    'PrependSetreuid' => [false, 'Prepend a stub that executes the setreuid(0, 0) system call', 'false'],
    'PrependSetuid' => [false, 'Prepend a stub that executes the setuid(0) system call', 'false'],
    'PrependSetresgid' => [false, 'Prepend a stub that executes the setresgid(0, 0, 0) system call', 'false'],
    'PrependSetregid' => [false, 'Prepend a stub that executes the setregid(0, 0) system call', 'false'],
    'PrependSetgid' => [false, 'Prepend a stub that executes the setgid(0) system call', 'false'],
    'PrependChrootBreak' => [false, 'Prepend a stub that will break out of a chroot (includes setreuid to root)', 'false'],
    'AppendExit' => [false, 'Prepend a stub that will break out of a chroot (includes setreuid to root)', 'false']
  }
  avaiable_options = []
  for prepend in prepends_order
    avaiable_options.append(Msf::OptBool.new(prepend, all_options.fetch(prepend)))
  end
  for append in appends_order
    avaiable_options.append(Msf::OptBool.new(append, all_options.fetch(append)))
  end
  register_advanced_options(avaiable_options, Msf::Payload::Linux)
end