Skip to content

Commit e835f2b

Browse files
committed
Rejig transport config into module
Adjust a few other things along the way, including tidying of code, removing of dead stuff.
1 parent 93bf995 commit e835f2b

27 files changed

+419
-407
lines changed

lib/msf/core/payload/linux/bind_tcp.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45

56
module Msf
67

@@ -14,6 +15,7 @@ module Msf
1415

1516
module Payload::Linux::BindTcp
1617

18+
include Msf::TransportConfig
1719
include Msf::Payload::Linux
1820

1921
#
@@ -44,14 +46,8 @@ def generate_bind_tcp(opts={})
4446
Metasm::Shellcode.assemble(Metasm::X86.new, asm).encode_string
4547
end
4648

47-
def generate_transport_config(opts={})
48-
{
49-
:scheme => 'tcp',
50-
:lport => datastore['LPORT'].to_i,
51-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
52-
:retry_total => datastore['SessionRetryTotal'].to_i,
53-
:retry_wait => datastore['SessionRetryWait'].to_i
54-
}
49+
def transport_config(opts={})
50+
transport_config_bind_tcp(opts)
5551
end
5652

5753
#

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45

56
module Msf
67

@@ -14,6 +15,7 @@ module Msf
1415

1516
module Payload::Linux::ReverseTcp
1617

18+
include Msf::TransportConfig
1719
include Msf::Payload::Linux
1820

1921
#
@@ -40,15 +42,8 @@ def generate
4042
generate_reverse_tcp(conf)
4143
end
4244

43-
def generate_transport_config(opts={})
44-
{
45-
:scheme => 'tcp',
46-
:lhost => datastore['LHOST'],
47-
:lport => datastore['LPORT'].to_i,
48-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
49-
:retry_total => datastore['SessionRetryTotal'].to_i,
50-
:retry_wait => datastore['SessionRetryWait'].to_i
51-
}
45+
def transport_config(opts={})
46+
transport_config_reverse_tcp(opts)
5247
end
5348

5449
#

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45
require 'msf/core/payload/windows/block_api'
56
require 'msf/core/payload/windows/exitfunk'
67

@@ -16,14 +17,11 @@ module Msf
1617

1718
module Payload::Windows::BindTcp
1819

20+
include Msf::TransportConfig
1921
include Msf::Payload::Windows
2022
include Msf::Payload::Windows::BlockApi
2123
include Msf::Payload::Windows::Exitfunk
2224

23-
def close_listen_socket
24-
datastore['StagerCloseListenSocket'].nil? || datastore['StagerCloseListenSocket'] == true
25-
end
26-
2725
#
2826
# Generate the first stage
2927
#
@@ -45,14 +43,8 @@ def generate
4543
generate_bind_tcp(conf)
4644
end
4745

48-
def generate_transport_config(opts={})
49-
{
50-
:scheme => 'tcp',
51-
:lport => datastore['LPORT'].to_i,
52-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
53-
:retry_total => datastore['SessionRetryTotal'].to_i,
54-
:retry_wait => datastore['SessionRetryWait'].to_i
55-
}
46+
def transport_config(opts={})
47+
transport_config_bind_tcp(opts)
5648
end
5749

5850
#
@@ -86,11 +78,6 @@ def required_space
8678
# Reliability checks add 4 bytes for the first check, 5 per recv check (2)
8779
space += 14
8880

89-
# if the payload doesn't need the listen socket closed then we save space. This is
90-
# the case for meterpreter payloads, as metsrv now closes the listen socket once it
91-
# kicks off (needed for more reliable shells).
92-
space -= 8 unless close_listen_socket
93-
9481
# The final estimated size
9582
space
9683
end
@@ -175,13 +162,11 @@ def asm_bind_tcp(opts={})
175162
push 0xE13BEC74 ; hash( "ws2_32.dll", "accept" )
176163
call ebp ; accept( s, 0, 0 );
177164
178-
push edi ; push the listening socket, either to close, or to pass on
165+
push edi ; push the listening socket
179166
xchg edi, eax ; replace the listening socket with the new connected socket for further comms
180167
push 0x614D6E75 ; hash( "ws2_32.dll", "closesocket" )
181168
call ebp ; closesocket( s );
182-
^
183169
184-
asm << %Q^
185170
recv:
186171
; Receive the size of the incoming second stage...
187172
push 0 ; flags

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
module Msf
77

8-
98
###
109
#
1110
# Common module stub for ARCH_X86 payloads that make use of Meterpreter.
1211
#
1312
###
1413

15-
1614
module Payload::Windows::MeterpreterLoader
1715

1816
include Msf::ReflectiveDLLLoader
@@ -34,7 +32,7 @@ def initialize(info = {})
3432
))
3533
end
3634

37-
def asm_invoke_dll(opts={})
35+
def asm_invoke_metsrv(opts={})
3836
asm = %Q^
3937
; prologue
4038
dec ebp ; 'M'
@@ -69,7 +67,7 @@ def stage_meterpreter
6967
:length => dll.length
7068
}
7169

72-
asm = asm_invoke_dll(asm_opts)
70+
asm = asm_invoke_metsrv(asm_opts)
7371

7472
# generate the bootstrap asm
7573
bootstrap = Metasm::Shellcode.assemble(Metasm::X86.new, asm).encode_string

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45
require 'msf/core/payload/windows/block_api'
56
require 'msf/core/payload/windows/exitfunk'
67

@@ -14,6 +15,7 @@ module Msf
1415

1516
module Payload::Windows::ReverseTcp
1617

18+
include Msf::TransportConfig
1719
include Msf::Payload::Windows
1820
include Msf::Payload::Windows::BlockApi
1921
include Msf::Payload::Windows::Exitfunk
@@ -42,15 +44,8 @@ def generate
4244
generate_reverse_tcp(conf)
4345
end
4446

45-
def generate_transport_config(opts={})
46-
{
47-
:scheme => 'tcp',
48-
:lhost => datastore['LHOST'],
49-
:lport => datastore['LPORT'].to_i,
50-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
51-
:retry_total => datastore['SessionRetryTotal'].to_i,
52-
:retry_wait => datastore['SessionRetryWait'].to_i
53-
}
47+
def transport_config(opts={})
48+
transport_config_reverse_tcp(opts)
5449
end
5550

5651
#

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45
require 'msf/core/payload/windows/block_api'
56
require 'msf/core/payload/windows/exitfunk'
67
require 'msf/core/payload/windows/reverse_http'
@@ -19,13 +20,6 @@ module Payload::Windows::ReverseWinHttp
1920

2021
include Msf::Payload::Windows::ReverseHttp
2122

22-
#
23-
# Register reverse_winhttp specific options
24-
#
25-
def initialize(*args)
26-
super
27-
end
28-
2923
#
3024
# Generate the first stage
3125
#
@@ -52,25 +46,8 @@ def generate
5246
generate_reverse_winhttp(conf)
5347
end
5448

55-
def generate_transport_config(opts={})
56-
# most cases we'll haev a URI already, but in case we don't
57-
# we should ask for a connect to happen given that this is
58-
# going up as part of the stage.
59-
uri = opts[:uri]
60-
unless uri
61-
sum = uri_checksum_lookup(:connect)
62-
uri = generate_uri_uuid(sum, opts[:uuid])
63-
end
64-
65-
{
66-
:scheme => 'http',
67-
:lhost => datastore['LHOST'],
68-
:lport => datastore['LPORT'].to_i,
69-
:uri => uri,
70-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
71-
:retry_total => datastore['SessionRetryTotal'].to_i,
72-
:retry_wait => datastore['SessionRetryWait'].to_i
73-
}
49+
def transport_config(opts={})
50+
transport_config_reverse_http(opts)
7451
end
7552
#
7653
# Generate and compile the stager

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'msf/core'
4+
require 'msf/core/transport_config'
45
require 'msf/core/payload/windows/reverse_winhttp'
56
require 'msf/core/payload/windows/verify_ssl'
67
require 'rex/payloads/meterpreter/uri_checksum'
@@ -17,6 +18,7 @@ module Msf
1718

1819
module Payload::Windows::ReverseWinHttps
1920

21+
include Msf::TransportConfig
2022
include Msf::Payload::Windows::ReverseWinHttp
2123
include Msf::Payload::Windows::VerifySsl
2224

@@ -83,14 +85,8 @@ def generate
8385
generate_reverse_winhttps(conf)
8486
end
8587

86-
def generate_transport_config(opts={})
87-
config = super
88-
89-
config[:scheme] = 'https'
90-
config[:ssl_cert_hash] = get_ssl_cert_hash(datastore['StagerVerifySSLCert'],
91-
datastore['HandlerSSLCert'])
92-
93-
config
88+
def transport_config(opts={})
89+
transport_config_reverse_https(opts)
9490
end
9591

9692
#

0 commit comments

Comments
 (0)