@@ -23,49 +23,49 @@ def initialize(info = {})
23
23
[
24
24
false ,
25
25
"Prepend a stub that executes the setresuid(0, 0, 0) system call" ,
26
- " false"
26
+ false
27
27
]
28
28
) ,
29
29
Msf ::OptBool . new ( 'PrependSetreuid' ,
30
30
[
31
31
false ,
32
32
"Prepend a stub that executes the setreuid(0, 0) system call" ,
33
- " false"
33
+ false
34
34
]
35
35
) ,
36
36
Msf ::OptBool . new ( 'PrependSetuid' ,
37
37
[
38
38
false ,
39
39
"Prepend a stub that executes the setuid(0) system call" ,
40
- " false"
40
+ false
41
41
]
42
42
) ,
43
43
Msf ::OptBool . new ( 'PrependSetresgid' ,
44
44
[
45
45
false ,
46
46
"Prepend a stub that executes the setresgid(0, 0, 0) system call" ,
47
- " false"
47
+ false
48
48
]
49
49
) ,
50
50
Msf ::OptBool . new ( 'PrependSetregid' ,
51
51
[
52
52
false ,
53
53
"Prepend a stub that executes the setregid(0, 0) system call" ,
54
- " false"
54
+ false
55
55
]
56
56
) ,
57
57
Msf ::OptBool . new ( 'PrependSetgid' ,
58
58
[
59
59
false ,
60
60
"Prepend a stub that executes the setgid(0) system call" ,
61
- " false"
61
+ false
62
62
]
63
63
) ,
64
64
Msf ::OptBool . new ( 'AppendExit' ,
65
65
[
66
66
false ,
67
67
"Append a stub that executes the exit(0) system call" ,
68
- " false"
68
+ false
69
69
]
70
70
) ,
71
71
] , Msf ::Payload ::Bsd )
@@ -74,95 +74,157 @@ def initialize(info = {})
74
74
end
75
75
76
76
77
- #
78
- # Overload the generate() call to prefix our stubs
79
- #
80
- def generate ( *args )
81
- # Call the real generator to get the payload
82
- buf = super ( *args )
77
+ def apply_prepends ( buf )
78
+ test_arch = [ *( self . arch ) ]
83
79
pre = ''
84
80
app = ''
85
81
86
- test_arch = [ *( self . arch ) ]
87
-
88
- # Handle all x86 code here
89
82
if ( test_arch . include? ( ARCH_X86 ) )
83
+ handle_x86_bsd_opts ( pre , app )
84
+ elsif ( test_arch . include? ( ARCH_X86_64 ) )
85
+ handle_x64_bsd_opts ( pre , app )
86
+ end
87
+
88
+ pre + buf + app
89
+ end
90
+
91
+ def handle_x86_bsd_opts ( pre , app )
92
+ if ( datastore [ 'PrependSetresuid' ] )
93
+ # setresuid(0, 0, 0)
94
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
95
+ "\x50 " +# pushl %eax #
96
+ "\x50 " +# pushl %eax #
97
+ "\x50 " +# pushl %eax #
98
+ "\x50 " +# pushl %eax #
99
+ "\x66 \xb8 \x37 \x01 " +# movw $0x0137,%ax #
100
+ "\xcd \x80 " # int $0x80 #
101
+ end
102
+
103
+ if ( datastore [ 'PrependSetreuid' ] )
104
+ # setreuid(0, 0)
105
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
106
+ "\x50 " +# pushl %eax #
107
+ "\x50 " +# pushl %eax #
108
+ "\x50 " +# pushl %eax #
109
+ "\xb0 \x7e " +# movb $0x7e,%al #
110
+ "\xcd \x80 " # int $0x80 #
111
+ end
112
+
113
+ if ( datastore [ 'PrependSetuid' ] )
114
+ # setuid(0)
115
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
116
+ "\x50 " +# pushl %eax #
117
+ "\x50 " +# pushl %eax #
118
+ "\xb0 \x17 " +# movb $0x17,%al #
119
+ "\xcd \x80 " # int $0x80 #
120
+ end
121
+
122
+ if ( datastore [ 'PrependSetresgid' ] )
123
+ # setresgid(0, 0, 0)
124
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
125
+ "\x50 " +# pushl %eax #
126
+ "\x50 " +# pushl %eax #
127
+ "\x50 " +# pushl %eax #
128
+ "\x50 " +# pushl %eax #
129
+ "\x66 \xb8 \x38 \x01 " +# movw $0x0138,%ax #
130
+ "\xcd \x80 " # int $0x80 #
131
+ end
90
132
91
- # Prepend
92
-
93
- if ( datastore [ 'PrependSetresuid' ] )
94
- # setresuid(0, 0, 0)
95
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
96
- "\x50 " +# pushl %eax #
97
- "\x50 " +# pushl %eax #
98
- "\x50 " +# pushl %eax #
99
- "\x50 " +# pushl %eax #
100
- "\x66 \xb8 \x37 \x01 " +# movw $0x0137,%ax #
101
- "\xcd \x80 " # int $0x80 #
102
- end
103
-
104
- if ( datastore [ 'PrependSetreuid' ] )
105
- # setreuid(0, 0)
106
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
107
- "\x50 " +# pushl %eax #
108
- "\x50 " +# pushl %eax #
109
- "\x50 " +# pushl %eax #
110
- "\xb0 \x7e " +# movb $0x7e,%al #
111
- "\xcd \x80 " # int $0x80 #
112
- end
113
-
114
- if ( datastore [ 'PrependSetuid' ] )
115
- # setuid(0)
116
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
117
- "\x50 " +# pushl %eax #
118
- "\x50 " +# pushl %eax #
119
- "\xb0 \x17 " +# movb $0x17,%al #
120
- "\xcd \x80 " # int $0x80 #
121
- end
122
-
123
- if ( datastore [ 'PrependSetresgid' ] )
124
- # setresgid(0, 0, 0)
125
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
126
- "\x50 " +# pushl %eax #
127
- "\x50 " +# pushl %eax #
128
- "\x50 " +# pushl %eax #
129
- "\x50 " +# pushl %eax #
130
- "\x66 \xb8 \x38 \x01 " +# movw $0x0138,%ax #
131
- "\xcd \x80 " # int $0x80 #
132
- end
133
-
134
- if ( datastore [ 'PrependSetregid' ] )
135
- # setregid(0, 0)
136
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
137
- "\x50 " +# pushl %eax #
138
- "\x50 " +# pushl %eax #
139
- "\x50 " +# pushl %eax #
140
- "\xb0 \x7f " +# movb $0x7f,%al #
141
- "\xcd \x80 " # int $0x80 #
142
- end
143
-
144
- if ( datastore [ 'PrependSetgid' ] )
145
- # setgid(0)
146
- pre << "\x31 \xc0 " +# xorl %eax,%eax #
147
- "\x50 " +# pushl %eax #
148
- "\x50 " +# pushl %eax #
149
- "\xb0 \xb5 " +# movb $0xb5,%al #
150
- "\xcd \x80 " # int $0x80 #
151
- end
152
- # Append
153
-
154
- if ( datastore [ 'AppendExit' ] )
155
- # exit(0)
156
- app << "\x31 \xc0 " +# xorl %eax,%eax #
157
- "\x50 " +# pushl %eax #
158
- "\xb0 \x01 " +# movb $0x01,%al #
159
- "\xcd \x80 " # int $0x80 #
160
- end
133
+ if ( datastore [ 'PrependSetregid' ] )
134
+ # setregid(0, 0)
135
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
136
+ "\x50 " +# pushl %eax #
137
+ "\x50 " +# pushl %eax #
138
+ "\x50 " +# pushl %eax #
139
+ "\xb0 \x7f " +# movb $0x7f,%al #
140
+ "\xcd \x80 " # int $0x80 #
141
+ end
161
142
143
+ if ( datastore [ 'PrependSetgid' ] )
144
+ # setgid(0)
145
+ pre << "\x31 \xc0 " +# xorl %eax,%eax #
146
+ "\x50 " +# pushl %eax #
147
+ "\x50 " +# pushl %eax #
148
+ "\xb0 \xb5 " +# movb $0xb5,%al #
149
+ "\xcd \x80 " # int $0x80 #
162
150
end
163
151
164
- return ( pre + buf + app )
152
+ if ( datastore [ 'AppendExit' ] )
153
+ # exit(0)
154
+ app << "\x31 \xc0 " +# xorl %eax,%eax #
155
+ "\x50 " +# pushl %eax #
156
+ "\xb0 \x01 " +# movb $0x01,%al #
157
+ "\xcd \x80 " # int $0x80 #
158
+ end
165
159
end
166
160
161
+ def handle_x64_bsd_opts ( pre , app )
162
+ if ( datastore [ 'PrependSetresuid' ] )
163
+ # setresuid(0, 0, 0)
164
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
165
+ "\x48 \x83 \xc8 \x4d " +# or rax, 77 (setgid=311>>2=77)
166
+ "\x48 \xc1 \xe0 \x02 " +# shl rax, 2
167
+ "\x48 \x83 \xf0 \x03 " +# xor rax, 3 (311&3=3)
168
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
169
+ "\x48 \x31 \xf6 " +# xor rsi, rsi 0
170
+ "\x48 \x31 \xd2 " +# xor rdx, rdx 0
171
+ "\x0f \x05 " # syscall
172
+ end
173
+
174
+ if ( datastore [ 'PrependSetreuid' ] )
175
+ # setreuid(0, 0)
176
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
177
+ "\x48 \x83 \xc8 \x7e " +# or rax, 126 (setreuid=126)
178
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
179
+ "\x48 \x31 \xf6 " +# xor rsi, rsi 0
180
+ "\x0f \x05 " # syscall
181
+ end
182
+
183
+ if ( datastore [ 'PrependSetuid' ] )
184
+ # setuid(0)
185
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
186
+ "\x48 \x83 \xc8 \x17 " +# or rax, 23 (setuid=23)
187
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
188
+ "\x0f \x05 " # syscall
189
+ end
190
+
191
+ if ( datastore [ 'PrependSetresgid' ] )
192
+ # setresgid(0, 0, 0)
193
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
194
+ "\x48 \x83 \xc8 \x4e " +# or rax, 78 (setgid=312>>2=78)
195
+ "\x48 \xc1 \xe0 \x02 " +# shl rax, 2 (78<<2=312)
196
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
197
+ "\x48 \x31 \xf6 " +# xor rsi, rsi 0
198
+ "\x48 \x31 \xd2 " +# xor rdx, rdx 0
199
+ "\x0f \x05 " # syscall
200
+ end
201
+
202
+ if ( datastore [ 'PrependSetregid' ] )
203
+ # setregid(0, 0)
204
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
205
+ "\x48 \x83 \xc8 \x7f " +# or rax, 127 (setuid=127)
206
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
207
+ "\x48 \x31 \xf6 " +# xor rsi, rsi 0
208
+ "\x0f \x05 " # syscall
209
+ end
210
+
211
+ if ( datastore [ 'PrependSetgid' ] )
212
+ # setgid(0)
213
+ pre << "\x48 \x31 \xc0 " +# xor rax, rax
214
+ "\x48 \x83 \xc8 \x5a " +# or rax, 90 (setgid=181>>1=90)
215
+ "\x48 \xd1 \xe0 " +# shl rax, 1
216
+ "\x48 \x83 \xc8 \x01 " +# or rax, 1 (setgid=181&1=1)
217
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
218
+ "\x0f \x05 " # syscall
219
+ end
220
+
221
+ if ( datastore [ 'AppendExit' ] )
222
+ # exit(0)
223
+ app << "\x48 \x31 \xc0 " +# xor rax, rax
224
+ "\x48 \x83 \xc8 \x01 " +# or rax, 1 (exit=1)
225
+ "\x48 \x31 \xff " +# xor rdi, rdi 0
226
+ "\x0f \x05 " # syscall
227
+ end
228
+ end
167
229
168
230
end
0 commit comments