Indefinite Studies

Hitting bottom, and asking for more

Puppet Master… or how to poison Red Pill

with 6 comments

Today we’ve been working with Vincent Mussot on a way to prevent VMM detection with red pill. We implemented it as a simple pintool:

// see the PIN manual for compilation instructions
#include <iostream>
#include <string>
#include "pin.H"

unsigned long int fake_idt = 0;

VOID poison(unsigned int* m) {
    *(unsigned int*)((*m)+2) = fake_idt;
}

VOID Instruction(INS ins, VOID *v) {
    string dis = INS_Disassemble(ins);
    if (dis.substr(0,4)=="sidt") {       
        unsigned int rpill = INS_Address(ins);
        unsigned int* m = (unsigned int *)(((char *)rpill)+3);
        INS_InsertCall(ins, IPOINT_AFTER, (AFUNPTR)poison, IARG_PTR, m, IARG_END);
    }   
}

// omitted for brevity
// parses the command line and sets fakeidt
int parseArguments(int argc, char **argv);

int main(int argc, char * argv[]) {
    if(parseArguments(argc, argv)) {
        printf("Usage: pin -f <toolname> <fake_idt> -- <binary> [arguments]\n");
        exit(1);
    }
    PIN_Init(argc, argv);
    INS_AddInstrumentFunction(Instruction, 0);
    PIN_StartProgram();   
    return 0;
}

Definitely not easy to read, but we followed the red pill coding standards ;) It waits for red pill to execute the SIDT instruction and then overwrites the memory location containing the value of the interrupt descriptor table register (IDTR) with an arbitrary value, given on the command line.

> redpill.exe
idt base: 0xff03f400
Inside Matrix!

> pin -t puppetmaster.dll 0x2501 -- redpill.exe
idt base: 0x2501
Not in Matrix.

Written by dan

April 16, 2009 at 16:57

6 Responses

Subscribe to comments with RSS.

  1. Useless when redpill is in kernelland. It’s possible to do the same thing with ptrace (which is GPL :)).

    Pouik

    April 17, 2009 at 08:25

    • >Useless when redpill is in kernelland
      true

      >It’s possible to do the same thing with ptrace
      what about Windows systems ?

      dan

      April 17, 2009 at 08:37

  2. >what about Windows systems ?

    Use a hypervisor to prevent redpill on windows in kernelmode.

    Jeff

    April 17, 2009 at 16:15

  3. [...] Piotr Bania opublikował artykuł przedstawiający metodę rozpakowania samomodyfikujących się aplikacji (spakowanych) wykorzystując binarną instrumentację (patrz np. Pin i jego przykładowe wykorzystanie): [...]

  4. [...] 13 07 2009 Vincent Mussot and I implemented new virtualization counter-countermeasures in puppetmaster. This time we can detect and thwart 6 tests out of 7 in ScoopyNG. In addition to the SIDT test, we [...]

  5. good job… but… we need puppet master for PIN :)

    tokki2cut

    September 20, 2009 at 17:14


Leave a Reply