Skip to content

Commit 6011e8b

Browse files
committed
Land rapid7#4918, Rework how payload prepends work
2 parents 75b2ef8 + 744b1a6 commit 6011e8b

31 files changed

+48
-33
lines changed

lib/msf/core/encoded_payload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def generate(raw = nil)
9494
#
9595
# @return [String] The raw, unencoded payload.
9696
def generate_raw
97-
self.raw = (reqs['Prepend'] || '') + pinst.generate + (reqs['Append'] || '')
97+
self.raw = (reqs['Prepend'] || '') + pinst.generate_complete + (reqs['Append'] || '')
9898

9999
# If an encapsulation routine was supplied, then we should call it so
100100
# that we can get the real raw payload.

lib/msf/core/payload.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ def generate
311311
internal_generate
312312
end
313313

314+
#
315+
# Generates the payload and returns the raw buffer to the caller,
316+
# handling any post-processing tasks, such as prepended code stubs.
317+
def generate_complete
318+
apply_prepends(generate)
319+
end
320+
314321
#
315322
# Substitutes variables with values from the module's datastore in the
316323
# supplied raw buffer for a given set of named offsets. For instance,
@@ -465,6 +472,13 @@ def compatible_nops
465472
return nops
466473
end
467474

475+
#
476+
# A placeholder stub, to be overriden by mixins
477+
#
478+
def apply_prepends(raw)
479+
raw
480+
end
481+
468482
##
469483
#
470484
# Event notifications.

lib/msf/core/payload/linux.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def initialize(info = {})
9191
#
9292
# Overload the generate() call to prefix our stubs
9393
#
94-
def generate(*args)
95-
# Call the real generator to get the payload
96-
buf = super(*args)
94+
def apply_prepends(buf)
9795
pre = ''
9896
app = ''
9997

lib/msf/core/payload/windows.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ module Msf::Payload::Windows
3838
'none' => 0x5DE2C5AA, # GetLastError
3939
}
4040

41-
42-
def generate
43-
return prepends(super)
41+
#
42+
# Implement payload prepends for Windows payloads
43+
#
44+
def apply_prepends(raw)
45+
apply_prepend_migrate(raw)
4446
end
4547

4648
#

lib/msf/core/payload/windows/prepend_migrate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def prepend_migrate?
3434
#
3535
# Overload the generate() call to prefix our stubs
3636
#
37-
def prepends(buf)
37+
def apply_prepend_migrate(buf)
3838
pre = ''
3939

4040
test_arch = [ *(self.arch) ]

lib/msf/core/payload/windows/reverse_http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Msf
1616

1717
module Payload::Windows::ReverseHttp
1818

19+
include Msf::Payload::Windows
1920
include Msf::Payload::Windows::BlockApi
2021
include Msf::Payload::Windows::Exitfunk
2122

modules/payloads/singles/linux/x64/exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
module Metasploit3
1010

11-
CachedSize = 209
11+
CachedSize = 40
1212

1313
include Msf::Payload::Single
1414
include Msf::Payload::Linux

modules/payloads/singles/linux/x64/shell_bind_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module Metasploit3
1313

14-
CachedSize = 255
14+
CachedSize = 86
1515

1616
include Msf::Payload::Single
1717
include Msf::Payload::Linux

modules/payloads/singles/linux/x64/shell_bind_tcp_random_port.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module Metasploit3
99

10-
CachedSize = 226
10+
CachedSize = 57
1111

1212
include Msf::Payload::Single
1313
include Msf::Payload::Linux

modules/payloads/singles/linux/x64/shell_reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module Metasploit3
1313

14-
CachedSize = 243
14+
CachedSize = 74
1515

1616
include Msf::Payload::Single
1717
include Msf::Payload::Linux

0 commit comments

Comments
 (0)