Flag: Tornado! Hurricane!

 Forums >>  Brainstorms - General  >>  Microsoft VirtualPC 2004 (build 528) Detection

Topic created on: September 4, 2006 05:57 CDT by GynvaelColdwind .

Hi ;>

Recently I was codding a disassembler, and found something interesing. Mainly, the way that disassemblers treat REP/REPNE prefixes differs in every disassembler. It looks like it differs also in CPU -emulators- like VirtualPC.

If a real-life CPU executes the following code:
REP REP REP ... (15xREP total) ... REP MOVSB, an "Illegal Instruction" exception is generated. If there are 14xREP total, the exception is not generated. Well. It looks like VirtualPC 2004 does not generate the exception even if there are 15xREP. So this can be used to detect if the application is runned from VPC ;>

Could anyone check this on QEMU or Bochs, or on different build of VirtualPC ? VMWare behaves just like the real CPU.

proof of concept code follows:

binary:
http://www.openrce.org/repositories/users/GynvaelColdwind/vpcredpill.exe

source:

--vpcredpill.asm---
; masm32
; research & code by gynvael.coldwind//vx
; special thx to ReWolf (even more research ;>) & vul7ur3 (testing)
.386
.model flat, stdcall
option casemap :none   ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code

start:
  ; some strings
  jmp @F
    szDlgTitle    db "VirtualPC 2004 RedPill (by gynvael.coldwind//vx)",0
    szMsgOFF      db "VirtualPC was NOT detected",0
    szMsgON       db "VirtualPC DETECTED!",0
  @@:

  ; SEH
  xor eax, eax
  push offset detected
  db 064h ; FS
  push dword ptr [eax]
  db 064h ; FS
  mov dword ptr [eax], esp

  ; teh RedPill
  mov esi, esp
  mov edi, esp
  mov ecx, 1

  ; This is REP REP REP REP ... REP movsb
  ; 15 * REP generate 'Invalid Instruction' exception on real CPU (tested on both Intel and AMD)
  ; Microsoft Virtual PC 2004 does NOT generate this exception.
  db 0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h,0F3h;
  movsb    

  ; was found!
  invoke MessageBox, 0, ADDR szMsgON, ADDR szDlgTitle, MB_OK
  invoke ExitProcess, 0

detected:
  invoke MessageBox, 0, ADDR szMsgOFF, ADDR szDlgTitle, MB_OK
  invoke ExitProcess, 0
  
end start

  GynvaelColdwind     September 4, 2006 16:07.31 CDT
I've just checked it with qemu-0.8.2. Seems that qemu-0.8.2 can also be detected with this method.

  n4v4r4j   September 7, 2006 01:00.33 CDT
vmware not detected (;

  FX     September 7, 2006 09:08.07 CDT
> GynvaelColdwind: Hi ;>
>
> If a real-life CPU executes the following code:
> REP REP REP ... (15xREP total) ... REP MOVSB, an \"Illegal Instruction\" exception is
> generated. If there are 14xREP total, the exception is not generated.

If you look into the Intel IA-32 Manual, it states:

"2.2. INSTRUCTION PREFIXES
The instruction prefixes are divided into four groups, each with a set of allowable prefix codes:
- Group 1 Lock and repeat prefixes:
    - F0 HLOCK.
    - F2 HREPNE/REPNZ (used only with string instructions).
    - F3 HREP or REPE/REPZ (use only with string instructions).
- Group 2 Segment override prefixes:
[... and so on ...]

For each instruction, one prefix may be used from each of these groups and be placed in any order. Using redundant prefixes (more than one prefix from a group) is reserved and may cause unpredictable behavior."

The last bit about the redundant prefixes is the interesting bit. Now, one could think that using anything that the IA-32 Vol2 declares as "unpredictable behavior" is likely to identify virtual machine products. How about this, a few lines below in the same document:

"The branch hint prefixes allow a program to give a hint to the processor about the most likely code path that will be taken at a branch. These prefixes can only be used with the conditional branch instructions (Jcc). Use of these prefixes with other IA-32 instructions is reserved and may cause unpredictable behavior."

FX

  GynvaelColdwind     September 7, 2006 11:29.56 CDT
bochs was not detected

FX
"Now, one could think that using anything that the IA-32 Vol2 declares as "unpredictable behavior" is likely to identify virtual machine products."

That makes sense ;>

Note: Registration is required to post to the forums.

There are 28,212 total registered users.


Recently Created Topics
Reverse Engineering ...
Jan/23
Career: DoD Agency I...
Jan/22
"Disappearing&q...
Jan/17
Career: Software Sec...
Jan/11
Where is the call st...
Jan/07
IDA Pro 6.1 Breakpoi...
Jan/01
How to create data s...
Dec/30
can i search all mod...
Dec/23
IDA symbol table exp...
Dec/20
An anti-attach trick
Dec/17


Recent Forum Posts
Reverse Engineering ...
NirIzr
"Disappearing&q...
NirIzr
Reverse Engineering ...
charlie
"Disappearing&q...
charlie
An anti-attach trick
Bass
An anti-attach trick
waleeda...
An anti-attach trick
Bass
An anti-attach trick
waleeda...
An anti-attach trick
Bass
Looking for value in...
NirIzr


Recent Blog Entries
Ludwig
Feb/04
chi on sale

Ludwig
Feb/04
Monster In The Vicinity Of ...

Ludwig
Feb/04
Supra footwear Online

waleedassar
Jan/31
Yet Another Anti-Debug Trick

RolfRolles
Jan/22
Finding Bugs in VMs with a ...

More ...


Recent Blog Comments
waleedassar on:
Feb/01
Yet Another Anti-Debug Trick

NirIzr on:
Jan/31
Yet Another Anti-Debug Trick

jackchen on:
Jan/10
nike mercurial vapor iii

waleedassar on:
Dec/27
A new Anti-Olly trick.

PeterFerrie on:
Dec/27
A new Anti-Olly trick.

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit