peinjector – MITM PE file infector

peinjector

peinjector

The executable file format on the Windows platform is PE COFF. The peinjector provides different ways to infect these files with custom payloads without changing the original functionality. It creates patches, which are then applied seamlessly during file transfer. It is very performant, lightweight, modular and can be operated on embedded hardware.

Features

  • Full x86 and x64 PE file support.
  • Open Source
  • Fully working on Windows and Linux, including automated installation scripts.
  • Can be operated on embedded hardware, tested on a Rasperberry Pi 2.
  • On Linux, all servers will be automatically integrated as service, no manual configuration required.
  • Plain C, no external libraries required (peinjector).
  • MITM integration is available in C, Python, and Java. A sample Python MITM implementation is included.
  • Foolproof, mobile-ready web interface. Anyone who can configure a home router can configure the injector server.
  • Easy to use integrated shellcode factory, including reverse shells, meterpreter, … or own shellcode. Everything is available in 32 and 64 bit with optional automated encryption. Custom shellcode can be injected directly or as a new thread.
  • An awesome about page and much more, check it out.

libpefile

Provides PE file parsing, modification and reassembling capabilities, based on PE COFF specification. Also, works with many non-compliant and deliberately malformed files which the Windows Loader accepts.

libpetool

Provides more complex modifications (adding/resizing sections). Keeps header values PE COFF compliant.

libpeinfect

Provides different infection methods, removes integrity checks, certificates, etc. It can fully infect a file (statically, e.g. from disk) or generate a patch (for MITM infection. Connectors which work with these patches are available in C, Python, and Java). The infected file keeps its original functionality.

servers

peinjector

Provides PE file patching as a service. Just send the raw header of your PE file and you’ll receive a custom-made patch for it. Can be remotely controlled via a command protocol.

control

Web interface to configure and control a peinjector server. A small shellcode factory with some basic shellcodes, automatic encryption/obfuscation and thread generation is provided – alternatively, custom shellcode can be injected.

interceptor

Sample MITM integration. Based on Python and libmproxy, supports SSL interception, can act as transparent Proxy, HTTP Proxy, … Provides seamless PE patching capabilities.

Install

git clone https://github.com/JonDoNym/peinjector

Install peinjector-server (Provides PE file patching as a service)

  • The install script installs gcc (if not exist)
  • Compiles the source and copies the binary to /usr/bin/peinjector
  • Installs the server as a service with autostart! (sudo service peinjector start|stop)
  • CONFIG: /etc/peinjector
  • LOG: /var/log/peinjector/
  • HELP: sudo peinjector -h
    cd /tmp/peinjector/peinjector/install/
    sudo chmod a+x peinjector_install.sh
    sudo ./peinjector_install.sh

Install control (manages the peinjector server via webgui)

  • The install script installs python3 (if not exists)
  • Copies the controller to /etc/peinjector-control
  • Installs the python web server as a service with autostart! (sudo service peinjector-control start|stop)
  • CONFIG: /etc/peinjector-control
  • LOG: /var/log/peinjector-control
  • Web server listen on: https://{your_ip}:3333/
    cd /tmp/peinjector/pe-injector-control/install/
    sudo chmod a+x peinjector-control_install.sh
    sudo ./peinjector-control_install.sh

Install interceptor (the MitM-Proxy with peinjector connector)

  • The install script installs mitmproxy (if not exists)!
  • Copies the interceptor to /etc/peinjector-interceptor
  • Installs the interceptor as a service with autostart! (sudo service peinjector-interceptor start|stop)
  • CONFIG: /etc/peinjector-interceptor
  • LOG: /var/log/peinjector-interceptor
  • Proxy listens on 8080
    cd /tmp/peinjector/pe-injector-interceptor/install/
    sudo chmod a+x peinjector-interceptor_install.sh
    sudo ./peinjector-interceptor_install.sh

hardening

replace the webgui certificate with your own

sudo openssl req -new -x509 –keyout /etc/peinjector-control/cert_example_do_not_use_this.pem -out /etc/peinjector-control/cert_example_do_not_use_this.pem -days 365 -nodes
sudo service peinjector-control stop
sudo service peinjector-control start

set a password for the gui

  1. Go to https://{your_ip}:3333/settings.htm
  2. set a password (set password for user ‘admin’)
  3. activate the authentication (enable authentication)
  4. USER: admin; PASS: {your_pass}

binding the peinjector ports on localhost
if you do that, only the webgui and the proxy can connect to the injector server (recommend)

  1. Go to https://{your_ip}:3333/injector.htm
  2. click on the local button (control interface)
  3. click on the local button (data interface)
  4. click on the restart button to restart the peinjector

Usage

  1. Go to https://{your_ip}:3333
  2. Navigate to “shellcode
  3. Scroll to “demo (calc)
  4. Click on “create and send shellcode
  5. Set your Firefox proxy setting to {your_ip}:8080
  6. Download any PE-File (Example: putty.exe or hundreds of megabytes big AV setup to see the seamless infection in action)
  7. You will see, the program is infected!

Demo

Sourcehttps://github.com/JonDoNym/