Skip to content

Commit 2076db2

Browse files
committed
DRY up common stager and payload http and retry options
1 parent 1fd7f7c commit 2076db2

File tree

11 files changed

+114
-85
lines changed

11 files changed

+114
-85
lines changed

lib/msf/core/handler/reverse_tcp.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ def initialize(info = {})
4545
# XXX: Not supported by all modules
4646
register_advanced_options(
4747
[
48-
OptInt.new(
49-
'StagerRetryCount',
50-
[ true, 'The number of connection attempts to try before exiting the process', 10 ],
51-
aliases: ['ReverseConnectRetries']
52-
),
53-
OptFloat.new(
54-
'StagerRetryWait',
55-
[ false, 'Number of seconds to wait for the stager between reconnect attempts', 5.0 ]
56-
),
5748
OptAddress.new(
5849
'ReverseListenerBindAddress',
5950
[ false, 'The specific IP address to bind to on the local system' ]
@@ -62,7 +53,8 @@ def initialize(info = {})
6253
'ReverseListenerThreaded',
6354
[ true, 'Handle every connection in a new thread (experimental)', false ]
6455
)
65-
],
56+
] +
57+
Msf::Opt::stager_retry_options,
6658
Msf::Handler::ReverseTcp
6759
)
6860

lib/msf/core/opt.rb

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,77 @@ def self.ssl_supported_options
5959

6060
# @return [OptEnum]
6161
def self.SSLVersion
62-
Msf::OptEnum.new('SSLVersion',
62+
Msf::OptEnum.new(
63+
'SSLVersion',
6364
'Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate)',
6465
enums: self.ssl_supported_options
6566
)
6667
end
6768

69+
def self.stager_retry_options
70+
[
71+
OptInt.new(
72+
'StagerRetryCount',
73+
'The number of times the stager should retry if the first connect fails',
74+
default: 10,
75+
aliases: ['ReverseConnectRetries']
76+
),
77+
OptInt.new(
78+
'StagerRetryWait',
79+
'Number of seconds to wait for the stager between reconnect attempts',
80+
default: 5
81+
)
82+
]
83+
end
84+
85+
def self.http_proxy_options
86+
[
87+
OptString.new(
88+
'HttpProxyHost',
89+
'An optional proxy server IP address or hostname',
90+
aliases: ['PayloadProxyHost']
91+
),
92+
OptPort.new(
93+
'HttpProxyPort',
94+
'An optional proxy server port',
95+
aliases: ['PayloadProxyPort']
96+
),
97+
OptString.new(
98+
'HttpProxyUser',
99+
'An optional proxy server username',
100+
aliases: ['PayloadProxyUser']
101+
),
102+
OptString.new(
103+
'HttpProxyPass',
104+
'An optional proxy server password',
105+
aliases: ['PayloadProxyPass']
106+
),
107+
OptEnum.new(
108+
'HttpProxyType',
109+
'The type of HTTP proxy',
110+
enums: ['HTTP', 'SOCKS'],
111+
aliases: ['PayloadProxyType']
112+
)
113+
]
114+
end
115+
116+
def self.http_header_options
117+
[
118+
OptString.new(
119+
'HttpHeaderHost',
120+
'An optional value to use for the Host HTTP header'
121+
),
122+
OptString.new(
123+
'HttpHeaderCookie',
124+
'An optional value to use for the Cookie HTTP header'
125+
),
126+
OptString.new(
127+
'HttpHeaderReferer',
128+
'An optional value to use for the Referer HTTP header'
129+
)
130+
]
131+
end
132+
68133
CHOST = CHOST()
69134
CPORT = CPORT()
70135
LHOST = LHOST()

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ module Payload::Android::ReverseHttp
2323
#
2424
def initialize(*args)
2525
super
26-
register_advanced_options([
27-
OptString.new('HttpHeaderHost', [false, 'An optional value to use for the Host HTTP header']),
28-
OptString.new('HttpHeaderCookie', [false, 'An optional value to use for the Cookie HTTP header']),
29-
OptString.new('HttpHeaderReferer', [false, 'An optional value to use for the Referer HTTP header'])
30-
], self.class)
26+
register_advanced_options(Msf::Opt::http_header_options)
3127
end
3228

3329
#

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ module Payload::Java::ReverseHttp
2323
#
2424
def initialize(*args)
2525
super
26-
register_advanced_options([
27-
OptInt.new('Spawn', [true, 'Number of subprocesses to spawn', 2]),
28-
OptInt.new('StagerURILength', [false, 'The URI length for the stager (at least 5 bytes)']),
29-
OptString.new('HttpHeaderHost', [false, 'An optional value to use for the Host HTTP header']),
30-
OptString.new('HttpHeaderCookie', [false, 'An optional value to use for the Cookie HTTP header']),
31-
OptString.new('HttpHeaderReferer', [false, 'An optional value to use for the Referer HTTP header']),
32-
])
26+
register_advanced_options(
27+
[
28+
OptInt.new('Spawn', [true, 'Number of subprocesses to spawn', 2]),
29+
OptInt.new('StagerURILength', [false, 'The URI length for the stager (at least 5 bytes)']),
30+
] +
31+
Msf::Opt::http_header_options
32+
)
3333
end
3434

3535
#

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ module Payload::Multi::ReverseHttp
2222
#
2323
def initialize(*args)
2424
super
25-
register_advanced_options([
26-
OptInt.new('StagerURILength', 'The URI length for the stager (at least 5 bytes)'),
27-
OptInt.new('StagerRetryCount', 'The number of times the stager should retry if the first connect fails', default: 10, aliases: ['ReverseConnectRetries']),
28-
OptString.new('HttpProxyHost', 'An optional proxy server IP address or hostname', aliases: ['PayloadProxyHost']),
29-
OptPort.new('HttpProxyPort', 'An optional proxy server port', aliases: ['PayloadProxyPort']),
30-
OptString.new('HttpProxyUser', 'An optional proxy server username', aliases: ['PayloadProxyUser']),
31-
OptString.new('HttpProxyPass', 'An optional proxy server password', aliases: ['PayloadProxyPass']),
32-
OptEnum.new('HttpProxyType', 'The type of HTTP proxy (HTTP or SOCKS)', enums: ['HTTP', 'SOCKS'], aliases: ['PayloadProxyType'])
33-
])
25+
register_advanced_options(
26+
[ OptInt.new('StagerURILength', 'The URI length for the stager (at least 5 bytes)') ] +
27+
Msf::Opt::stager_retry_options +
28+
Msf::Opt::http_header_options +
29+
Msf::Opt::http_proxy_options
30+
)
3431
end
3532

3633
#

lib/msf/core/payload/python/meterpreter_loader.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ def initialize(info = {})
2828
'Stager' => {'Payload' => ""}
2929
))
3030

31-
register_advanced_options([
32-
OptBool.new('MeterpreterTryToFork', [ true, 'Fork a new process if the functionality is available', true ]),
33-
OptBool.new('PythonMeterpreterDebug', [ true, 'Enable debugging for the Python meterpreter', false ]),
34-
OptString.new('HttpHeaderHost', [false, 'An optional value to use for the Host HTTP header']),
35-
OptString.new('HttpHeaderCookie', [false, 'An optional value to use for the Cookie HTTP header']),
36-
OptString.new('HttpHeaderReferer', [false, 'An optional value to use for the Referer HTTP header'])
37-
], self.class)
31+
register_advanced_options(
32+
[
33+
OptBool.new(
34+
'MeterpreterTryToFork',
35+
'Fork a new process if the functionality is available',
36+
default: true
37+
),
38+
OptBool.new(
39+
'PythonMeterpreterDebug',
40+
'Enable debugging for the Python meterpreter'
41+
),
42+
] +
43+
Msf::Opt::http_header_options
44+
)
3845
end
3946

4047
def stage_payload(opts={})

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ module Payload::Python::ReverseHttp
1111

1212
def initialize(info = {})
1313
super(info)
14-
register_options(
15-
[
16-
OptString.new('HttpProxyHost', [ false, "The proxy server's IP address" ], aliases: ['PayloadProxyHost']),
17-
OptPort.new('HttpProxyPort', [ true, "The proxy port to connect to", 8080 ], aliases: ['PayloadProxyHost']),
18-
OptString.new('HttpHeaderHost', [false, 'An optional value to use for the Host HTTP header']),
19-
OptString.new('HttpHeaderCookie', [false, 'An optional value to use for the Cookie HTTP header']),
20-
OptString.new('HttpHeaderReferer', [false, 'An optional value to use for the Referer HTTP header'])
21-
], self.class)
14+
register_advanced_options(
15+
Msf::Opt::http_header_options +
16+
Msf::Opt::http_proxy_options
17+
)
2218
end
2319

2420
#

lib/msf/core/payload/python/reverse_tcp.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ module Payload::Python::ReverseTcp
1818

1919
def initialize(*args)
2020
super
21-
register_advanced_options([
22-
OptInt.new('StagerRetryCount', [false, 'The number of times the stager should retry if the first connect fails', 10],
23-
aliases: ['ReverseConnectRetries']),
24-
OptInt.new('StagerRetryWait', [false, 'Number of seconds to wait for the stager between reconnect attempts', 5])
25-
], self.class)
21+
register_advanced_options(Msf::Opt::stager_retry_options)
2622
end
2723

2824
#

lib/msf/core/payload/python/reverse_tcp_ssl.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ module Payload::Python::ReverseTcpSsl
1717
include Msf::Payload::Python::ReverseTcp
1818
def initialize(*args)
1919
super
20-
register_advanced_options([
21-
OptInt.new('StagerRetryCount', [false, 'The number of times the stager should retry if the first connect fails', 10],
22-
aliases: ['ReverseConnectRetries']),
23-
OptInt.new('StagerRetryWait', [false, 'Number of seconds to wait for the stager between reconnect attempts', 5])
24-
], self.class)
20+
register_advanced_options(Msf::Opt::stager_retry_options)
2521
end
2622

2723
#

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,12 @@ module Payload::Windows::ReverseHttp
2727
#
2828
def initialize(*args)
2929
super
30-
register_advanced_options([
31-
OptInt.new('StagerURILength', [false, 'The URI length for the stager (at least 5 bytes)']),
32-
OptInt.new('StagerRetryCount', [false, 'The number of times the stager should retry if the first connect fails', 10],
33-
aliases: ['ReverseConnectRetries']),
34-
OptInt.new('StagerRetryWait', [false, 'Number of seconds to wait for the stager between reconnect attempts', 5]),
35-
OptString.new('HttpProxyHost', 'An optional proxy server IP address or hostname', aliases: ['PayloadProxyHost']),
36-
OptPort.new('HttpProxyPort', 'An optional proxy server port', aliases: ['PayloadProxyPort']),
37-
OptString.new('HttpProxyUser', 'An optional proxy server username', aliases: ['PayloadProxyUser']),
38-
OptString.new('HttpProxyPass', 'An optional proxy server password', aliases: ['PayloadProxyPass']),
39-
OptEnum.new('HttpProxyType', 'The type of HTTP proxy (HTTP or SOCKS)', enums: ['HTTP', 'SOCKS'], aliases: ['PayloadProxyType']),
40-
OptString.new('HttpHeaderHost', 'An optional value to use for the Host HTTP header'),
41-
OptString.new('HttpHeaderCookie', 'An optional value to use for the Cookie HTTP header'),
42-
OptString.new('HttpHeaderReferer', 'An optional value to use for the Referer HTTP header')
43-
], self.class)
30+
register_advanced_options(
31+
[ OptInt.new('StagerURILength', 'The URI length for the stager (at least 5 bytes)') ] +
32+
Msf::Opt::stager_retry_options +
33+
Msf::Opt::http_header_options +
34+
Msf::Opt::http_proxy_options
35+
)
4436
end
4537

4638
#

0 commit comments

Comments
 (0)