X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=compile%2Fvmware-detect.c;h=8afe2d1dd18c5a39096085b50989e62cf80a82ae;hb=c07e10f95b370c9e59461f6e4369cf6c2eab395e;hp=c0964605d8e8c9b61314101046cb310a3cebba22;hpb=13ace677c0da840842913fd6bc45d3b02ab3f314;p=grml-scripts.git diff --git a/compile/vmware-detect.c b/compile/vmware-detect.c index c096460..8afe2d1 100644 --- a/compile/vmware-detect.c +++ b/compile/vmware-detect.c @@ -1,25 +1,143 @@ -#if defined (__i386__) -int checkVmware() +/* Filename: vmware-detect.c +* Purpose: Detect if running inside vmware +* Authors: grml-team (grml.org), (c) Michael Gebetsroither +* Bug-Reports: see http://grml.org/bugs/ +* License: This file is licensed under the GPL v2. +*******************************************************************************/ +// return 0 if running inside vmware, 1 otherwise + +#include "string.h" +#include "unistd.h" +#include "stdio.h" +#include "stdlib.h" +#include "signal.h" + +#define WRITE(x) write(1, x, strlen(x)) +#define DWRITE(x) do{ \ + if(debug) { \ + WRITE(x); \ + } \ +} while(0); +#define FALSE 0 +#define TRUE !FALSE + +/* doc: + * vmware IO backdoor: http://chitchat.at.infoseek.co.jp/vmware/backdoor.html + * http://www.honeynet.org/papers/bots/botnet-code.html + * http://www.codegurus.be/codegurus/Programming/virtualpc&vmware_en.htm + */ + +// from libowfat {{{ +static inline char tohex(char c) { + return c>=10?c-10+'a':c+'0'; +} + +unsigned int fmt_xlong(char *dest,unsigned long i) { + register unsigned long len,tmp; + /* first count the number of bytes needed */ + for (len=1, tmp=i; tmp>15; ++len) tmp>>=4; + if (dest) + for (tmp=i, dest+=len; ; ) { + *--dest = tohex(tmp&15); + if (!(tmp>>=4)) break; + } + return len; +} +// }}} + +void printIdtr(const unsigned char* idtr, unsigned size) { - unsigned char idtr[6]; - asm("sidt %0" : "=m" (idtr)); - return (0xff==idtr[5]) ? 0 : 1; + unsigned i; + for(i=0; i