Module: Msf::Util::EXE::Windows::ClassMethods

Included in:
Msf::Util::EXE::Windows
Defined in:
lib/msf/util/exe/windows.rb

Instance Method Summary collapse

Instance Method Details

#to_executable_windows(framework, arch, code, fmt = 'exe', opts = {}) ⇒ String?

Construct a Windows executable for the requested architecture and format.

Parameters:

  • framework (Msf::Framework) —

    The Metasploit framework instance.

  • arch (#index) —

    Architecture collection containing an ARCH_* constant.

  • code (String) —

    The shellcode to embed.

  • fmt (String) (defaults to: 'exe') —

    The executable format.

  • opts (Hash) (defaults to: {}) —

    Additional generation options.

Returns:

  • (String, nil) —

    The constructed executable, or nil when the format is unsupported.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/util/exe/windows.rb', line 23

def to_executable_windows(framework, arch, code, fmt = 'exe', opts = {})
  exe_formats = ['exe', 'exe-service', 'dll', 'dll-dccw-gdiplus']

  exe_fmt ||= 'exe-small' if ['vba-exe', 'vbs', 'loop-vbs', 'asp', 'aspx-exe'].include?(fmt)
  exe_fmt = 'exe'

  exe_fmt = fmt if exe_formats.include?(fmt)

  exe = nil
  exe = to_executable_windows_x86(framework, code, exe_fmt, opts) if arch.index(ARCH_X86)
  exe = to_executable_windows_x64(framework, code, exe_fmt, opts) if arch.index(ARCH_X64)
  exe = to_executable_windows_aarch64(framework, code, exe_fmt, opts) if arch.index(ARCH_AARCH64)
  return exe if exe_formats.include?(fmt) # Returning only the exe
end

#to_executable_windows_aarch64(framework, code, fmt = 'exe', opts = {}) ⇒ String?

Construct a Windows AArch64 executable in the requested format.

Parameters:

  • framework (Msf::Framework) —

    The Metasploit framework instance.

  • code (String) —

    The shellcode to embed.

  • fmt (String) (defaults to: 'exe') —

    The executable format.

  • opts (Hash) (defaults to: {}) —

    Additional generation options.

Returns:

  • (String, nil) —

    The constructed executable, or nil when the format is unsupported.



45
46
47
48
# File 'lib/msf/util/exe/windows.rb', line 45

def to_executable_windows_aarch64(framework, code, fmt = 'exe', opts = {})
  return to_winaarch64pe(framework, code, opts) if fmt == 'exe'
  return to_winaarch64pe_dll(framework, code, opts) if fmt == 'dll'
end

#to_executable_windows_x64(framework, code, fmt = 'exe', opts = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/msf/util/exe/windows.rb', line 50

def to_executable_windows_x64(framework, code, fmt = 'exe', opts = {})
  return to_win64pe(framework, code, opts) if fmt == 'exe'
  return to_win64pe(framework, code, opts) if fmt == 'exe-small'
  return to_win64pe_service(framework, code, opts) if fmt == 'exe-service'
  return to_win64pe_dll(framework, code, opts) if fmt == 'dll'
  return to_win64pe_dccw_gdiplus_dll(framework, code, opts) if fmt == 'dll-dccw-gdiplus'
end

#to_executable_windows_x86(framework, code, fmt = 'exe', opts = {}) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/msf/util/exe/windows.rb', line 58

def to_executable_windows_x86(framework, code, fmt = 'exe', opts = {})
  return to_win32pe(framework, code, opts) if fmt == 'exe'
  return to_win32pe_service(framework, code, opts) if fmt == 'exe-servsice'
  return to_win32pe_dll(framework, code, opts) if fmt == 'dll'
  return to_winpe_only(framework, code, opts, ARCH_X86) if fmt == 'exe-only'
  return to_win32pe_old(framework, code, opts) if fmt == 'exe-small'
end