Code Monkey home page Code Monkey logo

gimmick's Introduction

Gimmick

A thread-safe, section-based payload obfuscation technique.

How it works

This technique allows safe, on-demand access to compile-time encrypted global variables and functions. How? Gimmick provides an API to allow sections to be dynamically decrypted and accessed at runtime in a thread-safe way. It also re-encrypts sections when no threads are using them. Depending on its usage, this technique introduces just a small window for your payload to exist fully decrypted in memory.

To decrypt a section, Gimmick checks for the following conditions:

  1. There are no other threads currently encrypting or decrypting the section simultaneously

To encrypt a section, Gimmick checks for the following conditions:

  1. There are no other threads currently encrypting or decrypting the section simultaneously
  2. There are no 'references' to the section

Extra features

  • PIC (Position Independent Code) friendly, with custom GetModuleHandle and GetProcAddress implementations
  • Dynamically loaded functions and modules that can be passed to a global instance at runtime.
  • Inbuilt RC4 implementation

Limitations

  • 64-bit only (for now)
  • If the executable is to be loaded by the OS, only sections that are untouched by Windows loader can be used to store data. This technique is best used with an rDLL or Shellcode.
  • All sections are marked as encrypted on initialisation, as Gimmick has no awareness of section states before they have been accessed. It will attempt to encrypt / decrypt any section referenced by the API. Only functions and variables designated a section with the SEC macro should be called, provided that the section will also be encrypted with crypt.py after. This really shouldn't be an issue provided that you only target the sections that you want to encrypt.
  • Section page protections are flipped to RW briefly during encryption and decryption.

Run

An example multithreaded application is set up for POC purposes. It is compiled with MinGW gcc.

  1. make build or make release
  2. ./gimmick.exe

Output

--- Starting threads
[*][.xdata] attempting to decrypt section
[*][.xdata] decrypting section
[+][.xdata] done! releasing mutex and restoring protection.
[+][.xdata] data is now available for use.
[*][00007FF6EAE64000] -- executing callee function
[*][.rodata] attempting to decrypt section
[*][.rodata] decrypting section
[*][.xdata] attempting to decrypt section
[!][.xdata] section is already decrypted
[*][00007FF6EAE64000] -- executing callee function
[+][.rodata] done! releasing mutex and restoring protection.
[+][.rodata] data is now available for use.
[*][.rodata] attempting to decrypt section
[!][.rodata] section is already decrypted
[*][.rodata] attempting to decrypt section
[!][.rodata] section is already decrypted
[*][.rodata] attempting to decrypt section
[!][.rodata] section is already decrypted
[*][.rodata] attempting to re-encrypt section
[!][.rodata] section is in use - no re-encryption was performed
[*][.rodata] attempting to re-encrypt section
[!][.rodata] section is in use - no re-encryption was performed
[*][00007FF6EAE64000] -- exited with code 0xdead
[*][.xdata] attempting to re-encrypt section
[!][.xdata] section is in use - no re-encryption was performed
[*][.rodata] attempting to re-encrypt section
[!][.rodata] section is in use - no re-encryption was performed
[*][.rodata] attempting to re-encrypt section
[*][.rodata] re-encrypting section
[+][.rodata] successfully re-encrypted section
[*][00007FF6EAE64000] -- exited with code 0xdead
[*][.xdata] attempting to re-encrypt section
[*][.xdata] re-encrypting section
[+][.xdata] successfully re-encrypted section

Usage

NOTE: This project is a Proof of Concept. It will likely be buggy, and I do NOT recommend using it as-is in production. You may open a PR to fix existing issues, or simply fix these yourself privately.

  1. Add gimmick.c, gimmick.h and ntdll.h to your project
  2. Assign objects to desired sections with the SEC macro, separating different types (e.g. functions and variables)
  3. Initialise Gimmick context with GkInitContext, and free with GkFreeSectionContext
  4. Use GkGet (+GkRelease), GkRun, or GkRunEx to run functions or access variables assigned to encrypted sections
  5. Compile the file with -Os and other desired flags
  6. Choose sections that contain data accessed with Gimmick to encrypt (crypt.py) and encrypt them with the same key used for Gimmick's context (edit in script)
  7. Run your executable

Disclaimer

This code is provided for educational and ethical purposes only. The authors and contributors are not responsible for any misuse of the code, including but not limited to the unlawful creation or distribution of malware. Use this code responsibly and in accordance with all applicable laws and regulations.

gimmick's People

Contributors

pygrum avatar

Stargazers

hirak0 avatar sodinokibi avatar  avatar Maulvi Alfansuri avatar xitan avatar BEWNIAC avatar MOHAMMED NUREDIN avatar Yeah9782 avatar mvinteuil avatar  avatar S3lrius avatar Itay Migdal avatar  avatar  avatar aweNousaku avatar Nate Subra avatar  avatar  avatar Max avatar V1rtu0l avatar Nicolas Vincent avatar djnn avatar clod avatar  avatar  avatar Solomon Sklash avatar Matthew Linney avatar 0乂ᐯ爪 avatar  avatar  avatar Erik avatar  avatar  avatar 18cm avatar Kr0ff avatar Prudhv! avatar  avatar Chiira avatar  avatar  avatar  avatar Hudson Seiler avatar 0xti2i avatar Eugene Dobrodeev avatar Dan avatar Ryota Sakai avatar D3Ext avatar  avatar  avatar  avatar Michael Eder avatar kleiton0x00 avatar Some random duck avatar /dev/null avatar  avatar

Watchers

 avatar

gimmick's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.