X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=compile%2Fvmware-detect.c;h=c99e36ff05e67911839177a562088a1b47ad8d3f;hb=34819b81d79e260d1fca486316806bc1b2e33896;hp=d242a388d52d59839c9a39a4022e1c4eb8102665;hpb=e720deae78f1eda5e6f62629606c194f16796762;p=grml-scripts.git diff --git a/compile/vmware-detect.c b/compile/vmware-detect.c index d242a38..c99e36f 100644 --- a/compile/vmware-detect.c +++ b/compile/vmware-detect.c @@ -1,13 +1,143 @@ -#include -int main() { - unsigned char idtr[6]; - asm("sidt %0" : "=m" (idtr)); - if(0xff==idtr[5]) - { - return 0; - } - else - { - return 1; - } +/* 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 i; + for(i=0; i