2013-04-12 17:35:03 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
module Msf::Payload::Dalvik
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# Fix the dex header checksum and signature
|
|
|
|
# http://source.android.com/tech/dalvik/dex-format.html
|
|
|
|
#
|
|
|
|
def fix_dex_header(dexfile)
|
|
|
|
dexfile = dexfile.unpack('a8LH40a*')
|
|
|
|
dexfile[2] = Digest::SHA1.hexdigest(dexfile[3])
|
|
|
|
dexfile[1] = Zlib.adler32(dexfile[2..-1].pack('H40a*'))
|
|
|
|
dexfile.pack('a8LH40a*')
|
|
|
|
end
|
2013-04-25 18:57:54 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# We could compile the .class files with dx here
|
|
|
|
#
|
|
|
|
def generate_stage
|
|
|
|
end
|
2013-04-12 17:35:03 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
|
|
|
# Used by stagers to construct the payload jar file as a String
|
|
|
|
#
|
|
|
|
def generate
|
|
|
|
generate_jar.pack
|
|
|
|
end
|
2013-04-25 18:57:54 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def java_string(str)
|
|
|
|
[str.length].pack("N") + str
|
|
|
|
end
|
2013-04-25 18:57:54 +00:00
|
|
|
|
2014-03-03 04:54:56 +00:00
|
|
|
def string_sub(data, placeholder="", input="")
|
|
|
|
data.gsub!(placeholder, input + ' ' * (placeholder.length - input.length))
|
|
|
|
end
|
|
|
|
|
2014-03-04 03:54:31 +00:00
|
|
|
def generate_cert
|
|
|
|
x509_name = OpenSSL::X509::Name.parse(
|
|
|
|
"C=Unknown/ST=Unknown/L=Unknown/O=Unknown/OU=Unknown/CN=Unknown"
|
|
|
|
)
|
|
|
|
key = OpenSSL::PKey::RSA.new(1024)
|
|
|
|
cert = OpenSSL::X509::Certificate.new
|
|
|
|
cert.version = 2
|
|
|
|
cert.serial = 1
|
|
|
|
cert.subject = x509_name
|
|
|
|
cert.issuer = x509_name
|
|
|
|
cert.public_key = key.public_key
|
|
|
|
|
|
|
|
# Some time within the last 3 years
|
|
|
|
cert.not_before = Time.now - rand(3600*24*365*3)
|
|
|
|
|
|
|
|
# From http://developer.android.com/tools/publishing/app-signing.html
|
|
|
|
# """
|
|
|
|
# A validity period of more than 25 years is recommended.
|
|
|
|
#
|
|
|
|
# If you plan to publish your application(s) on Google Play, note
|
|
|
|
# that a validity period ending after 22 October 2033 is a
|
|
|
|
# requirement. You can not upload an application if it is signed
|
|
|
|
# with a key whose validity expires before that date.
|
|
|
|
# """
|
|
|
|
cert.not_after = cert.not_before + 3600*24*365*20 # 20 years
|
|
|
|
return cert, key
|
|
|
|
end
|
2013-04-12 17:35:03 +00:00
|
|
|
end
|
|
|
|
|