Warcraft PDF
Warcraft PDF
Greg Hoglund
Hacking World of Warcraft™ - an hoglund@hbgary.com
exercise in advanced rootkit design ©2006 Greg Hoglund
Why Games?
• Games are fun, we like them, and it’s a fresh
topic
• Games are complex online applications
• There is a healthy community of game hackers
(that is, those who write game hacks & discover the exploits)
• Computer Gaming is BIG BUSINESS
– Microsoft reports that gaming is the third most
common activity on their platforms, just after browsing
the Web and email
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Why cheat?
• It’s a challenge
• Because I suck at this game
• Because I like having an unfair advantage
• Because cheating makes the game more
fun to play
– Such as automating repetitive and boring
tasks
• Because cheating makes money $$$$ !
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
MassivelyMultiplayerOnline’s
(MMO)
• Think D&D mixed with IRC
• More than 50 active MMO’s in the world
• Over 10 million players of MMO’s
worldwide, and the number is doubling
every year (whoa!)
• 2.9 Million players of MMO’s actively
subscribed in the U.S. alone (IDG estimate)
• 6 million subscribers to WoW worldwide
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
http://mmogchart.com/Chart4_files/Subscriptions_21524_image001.gif
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
http://mmogchart.com/Chart7_files/Subscriptions_12473_image001.gif
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
MMO’s and Money
• There are real exchange rates between in-
game currency and real money
– The “wealth”in some MMO worlds is greater
than some small “real”countries
• There was a $600 million dollar real,
secondary market selling ‘virtual gold’in
2005 (estimates vary)
• Current calculations show that “farmers”
can make about $1.17 hour playing WoW
– This is good enough for China!
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The exchange
The exchange rate
rate isis
roughly 10
roughly 10 cents
cents to
to aa gold-
gold-
piece on
piece on WoW
WoW servers
servers
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
http://www.gameusd.com/
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
A video documentary on Chinese gold farmers can be found here:
http://youtube.com/watch?v=ho5Yxe6UVv4
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Two kinds of cheating
• “Exploits”- actual game bugs, which are
exploited to:
– Teleport
– Duplicate items or gold
– See stuff your not supposed to see
• Botting
– Both AFK and non-AFK
– Only performing legal inputs, but in an
automated fashion
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Botting
• People want to do this because
– Because ‘grinding’is really boring
• And WoW, in my opinion, has a big problem w/ this
– Because they are ‘farming’
• Running the game to farm a resource, possibly
running multiple accounts at once
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Combat bots
• Aimbotting
– Bots cannot be used for ‘aimbotting’in WoW –
it’s not a first person shooter
• PvP bots
– In WoW these are possible, but their
effectiveness has never been proven
– Possible advantage for optimized DPS
– Possible advantage to move behind enemy
player
• Orientation plays a big part of combat mechanics
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
How do bots work?
• MACRO’s & Scripts (most common)
• Memory read & write
• DLL Injection
• Debugging
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
MACRO’s
• Inject keystrokes and mouse movement
• Sample pixels and read memory locations
– Takes over the GUI
– You can’t use the computer
– Error prone
– Screen and controls must be preconfigured
exactly as required
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Example: ACTool
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Process manipulation
• Read & Write memory data
– Coordinates
– Speed
– Which direction your facing
• Can be used in conjunction w/ MACRO
– Data can be read directly instead of inferred
from pixel colors or text
• Can be used for exploits
– Map hacks, teleporting, speed hacks, etc
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Total Client Replacement
• Forget memory offsets and hiding – write
your own client
• Done in First Person Shooter games to
cheat
• Can we make WoW look a bit like Warcraft
3?
• Requires significantly more initial work
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
One Free WoW 0day
• Specify someone else's GUID in
CMSG_STANDSTATECHANGE
• Can make other players sit
• Makes for some fun PvP
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Thread Hijacking
• Hijack main system thread
– Eliminates thread safety issues
• Call internal functions within game client
directly
– You can minimize the game program
– It runs itself
– It doesn’t have errors in sampling
• Eliminates need for MACRO altogether
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Thread hijacking
• Used in a few WoW botting programs
WoW.EXE
INJECTED
MAIN DLL
THREAD
RenderWorld(..)
DETOUR PATCH
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoW!Bot
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Enter the Warden
• Absolutely brilliant countermeasure technology
to catch cheaters and AFK Botters
• Uses ‘fear of the unknown’to keep cheaters
down
– Code is downloaded from server on-the-fly
– Code can change at any time
• Scans for publicly available bot & cheat
programs
• Thousand of players have been banned!
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden
WoW.EXE
INJECTED
MAIN DLL
THREAD
RenderWorld(..)
DETOUR PATCH
WARDEN
CODE
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden
WoW.EXE
WARDEN
CODE
? ?
RenderWorld(..) INJECTED
DETOUR PATCH DLL
DLL
DLL
DLL
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden
WoW.EXE
WARDEN
MEMORY CODE WINDOW TEXT
? WINDOW TEXT
?
OTHER PROCESS
?
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
How to find the Warden in memory
• It gets called in response to a server
message
– If you hook or sniff the “NetClient”class in
WoW.EXE, you can locate the call into the
warden by tracing what happens after
message type “0x2E8”arrives. This is the
warden message*.
*of course, this information was obtained using publically available resources
that can be found using a well skilled google search.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Packet includes a type field
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Note: strings present in binary
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Thispage
This pagechanges
changesdynamically
dynamicallywith
witheach
each
Gamelaunch
Game launch
Thepage
The pagecontains
containscode
codewith
withstandard-looking
standard-lookingfunction
functionentry
entry
Andexit
And exitpoints
points
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Readand
Read andcompare
comparelocal
localprocess
processmemory
memory
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Readand
Read andcompare
comparelocal
localDLL
DLLnames
names
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Readand
Read andcompare
compareexternal
externalprocess
processnames
names
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Readand
Read andcompare
comparememory
memoryfrom
fromother
otherprocesses
processes
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden Deadlisting
Readwindow
Read windowtext
textfrom
fromall
allopen
openwindows
windows
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
End of cheating?
• Just turn off the warden?
– If the warden responses don’t come back,
server disconnects you within 15 seconds
• Forge responses?
– You need to crack their encryption
– Remember that it scans anything it wants to
– Remember it can change at any time
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Anti-warden
do you trust it?
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
RealmBot
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoWHelper
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoWSniffer
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoW!Bot / WoW!Sharp
a WoW botting program
• Written by Jerremy Koot
• Started development January 2005, went live in
May
• Was about 2 months of development for the bot
and 2 months of other work making a service out
of it
– Had a small subscription fee (2 euro’s a month)
– Users had code-patching offsets downloaded on-the-
fly when they logged in
• Closed shop in Sept 2005 due to the Warden
– Jerremy figures, with all the work, he only made about
2 bucks an hour for all his time
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoW!Sharp goes down
• Remember, this was a moonlighted business
without any funding or staff
• Sometime in August 2005, Wow!Sharp was put
into a “lockout”period since a new warden had
been released (this was common practice)
• The new warden was detecting WoW!Sharp and
reverse engineering was difficult and taking
weeks
• Paying customers were growing impatient and
putting on pressure to unlock WoW!Sharp.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoW!Kit
trying to save the day w/ a rootkit
• Written in August/September of 2005, but was
NEVER RELEASED to the public
• Development was started WAAAAY too late in
the game. It needed a few more weeks of
development.
– Memory cloaking was blue screening like crazy!
• Under pressure, a pre-release version (w/o
memory cloaking) was tested for a few days and
resulted in MASS-BAN of all developer accounts
– My own version had memory cloaking enabled, and I
was one of the few who did not get banned
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Warden works!
It cost hackers time and money
• Bannings were a very hard blow to the team
– Many used their level-60 accounts to test with!
• Prompted the open-source release of the whole
project (“we give up!”)
– Not enough time or money to make it all worth it.
• Prompted a detailed analysis of the Warden client
(how were we detected?)
– This lead subsequently to the “governor”release
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The endgame
• Ultimately, users created private versions of the
WoW!Bot w/ the source. Some of these remain
undetected to this day.
• The development of WoW!Kit continued in
private
• WoW!Sharp was released because of customer
pressure, not a failure in technology
• Without all the external pressure, WoW!Sharp
development would have had more time to
develop a working solution.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
What did we learn?
• The core weakness of Warden is that it’s
signature based
– KEEP YOUR BOTS PRIVATE!
• Software tamperproofing WORKS, the
warden proves that
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Introducing “The Supervisor”
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The Supervisor
• NO PROCESS!
• NO INJECTED DLL!
• NO INJECTED THREAD!
• NO ATTACHED DEBUGGER!
• NO SCANNABLE MEMORY!
• NO CODE PATCHES!
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Basics of the Supervisor
• Uses Shadow Branching, the technique
originally developed for WoW!Kit
• Injects “implant”code directly into a user-
mode memory page (yay, no injected DLL!)
• Command-and-control is via a kernel-
mode TCP/IP stack
– bot controller script can be on a separate
computer
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Overall architecture
WoW.EXE
IMPLANT
MSG
MSG
Botting
SUPER
Application
MSG
Kernel-land memory
User-land memory
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Summary of components
Antifreeze.EXE
Driven by LUA script
Botting
Communicates using standard winsock
Application
Potentially could drive more than one bot (a farm?)
Not exposed to warden for detection
Supervisor.sys rootkit
Can be loaded before launching game
SUPER Accepts commands over network
Message structure
Can be used to send commands and
MSG
also query for results
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Shadow Branching
• Instead of a detour, it uses hardware
breakpoints to hijack the main program
thread
– A hook on any number of points (i.e.,
PspGetContext) can protect the context from
being read from usermode
• Uses memory cloaking to protect injected
code
– Page table manipulations and/or timely
memory movements
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Injected code portion
WoW.EXE
MAIN THREAD
BREAKPOINT
UNCLOAK
INJECTED PAYLOAD
PAYLOAD
SUPER RECLOAK
RESTORE
MAIN THREAD
Kernel-land memory
User-land memory
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hardware Breakpoints
• Implemented via DR registers
• Requires address of breakpoint in DR0-3
and a corresponding modification to DR7
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Problems w/ NtSetContextThread
• Does not seem to allow DR register modification
• Attempted CONTEXT_DEBUG_REGISTERS
and no error occurs, but subsequent read of the
trap frame shows that no set occurred
• DR register values, clearly present in trap frame,
are zero’d out in context returned from
NtGetContextThread
• Attempting to set other types of context, such as
EIP, results in instant blue screen
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Context Conclusion?
• Throw the NtSet/GetContextThread
routines in the trash heap. Go straight to
the trap frame for your work.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Getting to the KTRAP_FRAME
FS:0
Initial
TIB
KTHREAD
Stack
(TCB) KTHREAD
KPCR InitialStack
DRxx
SelfPCR
EIP
ETHREAD KTRAP_
PRCB
FRAME
KPRCB
*CurrentThread
*NextThread
*IdleThread
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Kernel-mode APC’s
• We want to modify the kernel trap frame
while in the context of the target thread
• We can schedule a kernel-mode APC
against the target thread
• Unlike user-mode APC’s, the kernel-mode
APC does not have to wait for an alertable
state, it will execute immediately
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
WoW.EXE
INJECTED
MAIN CODE PAGE
THREAD
RenderWorld(..)
HARDWARE BP
? DR0
WARDEN
CODE
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Debug Interrupts
• Interrupt 1
– Called for single step, branch trace, ICEBP,
and hardware breakpoints
– We are only using it for hardware breakpoints
• Interrupt 3
– Called for embedded INT3 (0xCC) and INT-3
breakpoints
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Multiprocessor-safe interrupt
hooking
• We are using breakpoints so we need to
hook the debug interrupts
• Each CPU has it’s own IDT, so we need to
hook them all
• We can use a Deferred Procedure Call
(DPC) to schedule activity against a
particular CPU
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Proper interrupt hooking
• Use Deferred Procedure Calls scheduled
to each processor in the system
IDT 0
IDT 1
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
gDPCP_RemoveInterruptHandlers =
ExAllocatePool(NonPagedPool,sizeof(KDPC));
KeInitializeDpc( gDPCP_RemoveInterruptHandlers,
DpcRoutine_RemoveInterruptHooks, NULL );
KeInitializeEvent(&gEvent_Process_Set_Complete,
NotificationEvent, 0);
}
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Detect number of processors
KAFFINITY NumberOfProcessors; Bitmask
int n;
int pcount;
NumberOfProcessors = KeQueryActiveProcessors();
for(n=0; NumberOfProcessors; NumberOfProcessors >>= 1)
{
if (NumberOfProcessors & 1)
n++; Number of processors
}//end for
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
DPC function will set the waitable object when it’s done
KeWaitForSingleObject(
&gEvent_Process_Set_Complete,
Executive,
KernelMode,
FALSE,
NULL);
KeResetEvent(&gEvent_Process_Set_Complete);
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The DPC routine itself
VOID DpcRoutine_SetInterruptHooks ( … )
{
ULONG procnum = KeGetCurrentProcessorNumber();
logprintf("DpcRoutine_SetInterruptHooks called on processor %d", procnum);
// UNProtect memory
// REProtect memory
KeSetEvent(&gEvent_Process_Set_Complete, 1, FALSE);
}
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Saved EFlags
Hardware ESP
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Important things about interrupts
• Don’t hang around, you need to return
promptly
• Schedule DPC’s for any work you need to
do
• Any modifications made to the CPU and
trap frame immediately become context
after you iret
– This enables us to store/restore context and
alter things like the EIP
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Shadow Branching
• Through interrupt, cause immediate and
total change in execution context in thread
• On command, put it back just like it was
before the shadow branch
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Overview
• Based on interrupt hooks
– Interrupt 1
– Interrupt 3
• No requirement to hook page fault handler
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The interrupt handler
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Saving context
All registers, flags,
segment registers
Int 3
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
When rootkit code is done
All registers, flags,
segment registers
Int 3
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Our context structure
typedef struct _MyContext
{
ULONG eax; Read from processor
ULONG ebx; Read from processor
ULONG ecx; Read from processor
ULONG edx; Read from processor
ULONG esi; Read from processor
ULONG edi; Read from processor
ULONG eflags; Read from trap frame
ULONG ebp; Read from processor
ULONG esp; Read from trap frame
ULONG eip; Read from trap frame
ULONG segss; Read from trap frame
ULONG segcs; Read from trap frame
} MyContext, *PMyContext;
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Example ‘secret’command
__asm
{
pushad
mov eax, index
mov ebx, from_address
mov edx, to_address
int 3
56 push esi // this series of push/pops
pop esi // are a secret command key used
5E push esi // to tell the driver what it is we are
pop esi // trying to do
56 popad
}
5E
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
anAddress = trapframe->Eip;
__asm
{
push eax
push ebx
mov eax, anAddress
mov ebx, dword ptr [eax]
mov aSecretCode, ebx
pop ebx
pop eax
}
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Returning from the interrupt
• Passing the interrupt onto the original
handler
• Changing behavior depending on which
EIP threw the interrupt
• Setting arbitrary context before returning
• Setting the RF Bit to prevent recursion
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
mov eax, 0
mov g_already_handling, eax
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Restart Flag (RF)
• When set, it causes any debug fault to be
ignored during the next instruction
– This is a way to skip over a breakpoint w/o having it
fire a second time
• So, when we return w/ an IRET, we need to
make sure the saved EFlags value in the trap
frame has RF set
• Note: x86 documentation says that RF should
be set automatically, but on VMWare this may
not be the case. Be safe and set it yourself.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Modifying Context
• Anything, even including EIP!
– By modifying EIP, you can cause the thread to
‘hyperspace’to a new location
– All kinds of in-place modifications are possible
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
mov esp, eax Put pointer to trap frame in eax first
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Shadow branch part I
if(anAddress == g_det_0_src)
Thesource
The sourceofofthe
the
{
exception is the code
exception is the code
// we are performing a shadow branch. Save address
address wehave
we
the currenthavecontext
hardware
hardware
// so we can use it later when restoring this breakpointset
breakpoint
thread. set
CopyContext( &g_det_0_ctx, &gCurrentContextupon
);
upon
Wesave
We saveoff
offthe
thecurrent
currentcontext,
context,so
soititcan
canbe
berestored
restoredlater
later
Beforereturning
Before returningfrom
fromthe
theinterrupt,
interrupt,make
make
surethe
sure thetarget
targetmemory
memoryisisuncloaked
uncloaked
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Preventing recursion
• When our hardware BP fires, we are going
to shadow branch to a new code location
• When we are done w/ our new code, we
need to branch back to original location
• When original location executes, we
DON’T want to shadow branch again
– Else, we would be infinite ‘loop’
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Takenote
Take noteof
ofwhich
whichaddress
addresslast
lastcaused
causedaashadow
shadowbranch
branch
if(anAddress == g_det_0_src)
{
// set this so we don't repeat the same
// exception over and over
g_last_firing_detour = anAddress;
if(anAddress == g_last_firing_detour)
{
g_last_firing_detour = 0;
gCurrentContext.eflags |= 0x00010000; Set RF !!
__asm
{
mov eax, trapframe
call SetContext_and_IRET
}
} Whenthe
When theinterrupt
interruptfires
firesmake
makesure
surethat
thatyou
you
checktotosee
check seeififit’
it’
ssthe
theaddress
addressthat
thatlast
lastfired,
fired,
ififititis,
is,then
thenjust
justreturn
return
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Memory Cloaking
• Reading memory is required for integrity
analysis and scanning
• Virtual addresses must be translated into
physical address before memory can be
accessed
• The physical address is what controls the
view of memory
• You can alter this translation in several
places
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Page Table Manipulation
• Alter the physical base address for the
page
• Remap the virtual address to:
– Another resident page in the same process
– or, a page of NonPagedPool you allocate in
the driver
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
CR3
CPU
CPU
Virtual Address
RAM
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Exploit the conversion
CR3
CPU
CPU
Virtual Address
RAM
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
CR3 KPROCESS
Physical address
Non-PAE
Virtual Address
10 bits 10 bits 12 bits
Page Directory Index (1024) Page Table Index (1024) Byte Index (4096)
Page Frame
Page Dir
Individual
page table
PDE
PTE
1 per process
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
MS Windows: Getting the virtual addresses
of PDE entries (non-PAE)
Virtual Address
10 bits 10 bits 12 bits
Page Directory Index (1024) Page Table Index (1024) Byte Index (4096)
Page Directory Base
0xC0300000
10-bit address * 4
#define GetPDEAddress32(va)
( (PPDE32) ((((ULONG)va >> 22) << 2) + PROCESS_PAGE_DIR_BASE))
take top 10 bits --------^ ^-- leftshift 2 == *4 (32 bit entries)
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Virtual Address
10 bits 10 bits 12 bits
Page Directory Index (1024) Page Table Index (1024) Byte Index (4096)
Page Directory Base
0xC0000000
20-bit address * 4
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
PAE
• All entries in the page directory specify 64
bit physical addresses
• Virtual address is still 32 bits
• Enables a 32 bit virtual address to map
anywhere within a 64GB physical address
space
• CR4[PAE] = 1 (and CR4[PSE] = 0)
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
CR3 KPROCESS
Physical address
PAE
Virtual Address
2 bits 9 bits 9 bits 12 bits
Page Directory Index (512) Page Table Index (512) Byte Index (4096)
PDP index
Page Dir Pointers Page Tables Physical Memory
(4)
PDP
Page Frame
Individual
page table
Page Dir
PDE
PTE
4 per process
2048 per process
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
MS Windows: Getting the virtual addresses
of PDE entries (PAE)
Virtual Address
PDP index
(4) 2 bits 9 bits 9 bits 12 bits
Page Directory Index (512) Page Table Index (512) Byte Index (4096)
Page Directory Base
#define GetPDEAddress64(va)
( (PPDE64) ((((ULONG)va >> 21) << 3) + PROCESS_PAGE_DIR_BASE_PAE))
//take top 11 bits --------^ ^-- leftshift 3 == *8(64 bit entries)
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Virtual Address
PDP index
(4) 2 bits 9 bits 9bits 12 bits
Page Directory Index (512) Page Table Index (512) Byte Index (4096)
Page Directory Base
0xC0000000
20-bit address * 8
Base remains the same as
Non-PAE but entries are 64 bits
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
// remap existing virtual address to new physical address
// this can be read using readprocessmemory OK, but it BSoD's if the program
// tries to read the memory - there is a consistency check.
VOID RemapVirtualAddress( PVOID virtual_address, ULONG physical_address )
{
if(TRUE == IsPAE())
{
PPDE64 aPDE64 = GetPDEAddress64(virtual_address);
if(aPDE64->Present)
{
PPTE64 aPTE64 = GetPTEAddress64(virtual_address);
if(aPTE64->Present)
{
aPTE64->MemoryBasePhysicalAddress =
(physical_address >> 12);
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Memory cloaking via timely
memory movements
• Page table manipulations are both
complex and difficult to manage in regards
to paging and consistency checking
• A very simple and elegant solution is to
simply copy the memory in and out of a
“holding area”
- very stable
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
super
User-mode mapped memory
Allocate
Fill w/ AAAA
Uncloak
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The Implant
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The Implant
• Position independent, like shellcode
• Parses PE headers to find GetProcAddress and
LoadLibrary
• Subsequently loads a table of function pointers
• Sets up it’s own memory page for cloaking
• Sets up the primary function hook
• Implements the micro-kernel that is executed
when the primary function hook fires
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Based at bottom of page
The header & loader code runs only once.
header
Finds data section.
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
The “compilation”process
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
super
User-mode mapped memory
Allocate
Inject Code
Branch to it
Done executing
“Holding pen” Cloak
Fill w/ AAAA
Hook Fires
Uncloak
Branch to code
Done executing
Cloak
Process repeats whenever hook fires
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
super
MAIN
THREAD INJECTED
CODE PAGE
RenderWorld(..)
HARDWARE BP uncloak
MAIN
THREAD
branch
complete
CastSpellByID( .. )
ScriptExecute( .. )
ClearTarget( .. )
MSG
RenderWorld(..)
MAIN
THREAD recloak
restore
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Anti-Freeze
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Better tricks
• Check timing of operations
• Scan the stack
– Should be predictable for legitimate calls
– Anti-warden would need quite a lot of additional logic to work
around it
• Use better and variable encryption schemes
– Causes transparent proxy developers a great deal of headache
• Perform warden scans from within functions, not just
from one place – try to catch injected memory while it is
uncloaked
• Play games with exceptions to see if you can catch the
debugger
• Use up all the DR registers yourself
• GO TO THE KERNEL!
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
FOTU - FearOfTheUnknown
• On the fly detection program, updated at any
time
• Requires positive response
– Scans for stuff you know should be there
• Uses negative response
– Scans for stuff you know shouldn’t be there
• Puts the go/no-go decision on the server
– User cannot control a decision, only the presentation
of memory
• Disseminate multiple versions via user account,
physical location, and server
– R/E’s can never get their hands on all of them
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Applications to Tamper Proofing
• Use Supervisor-like technology to make
reverse engineering more difficult
– Effectively prevent user & kernel-mode
debugging against your active process
– Use memory techniques to decrypt code and
data for short periods, frustrating debugging &
reverse engineering efforts
– This is already being done commerically
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Applications against malware
• Use supervisor-like technology to debug
and trace malware that includes anti-
debugging tricks
• Monitor compromised systems covertly,
even when those systems contain anti-
forensics tools
• Monitor an attacker over time without
being detected
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
Covert monitoring can be used to
track and assess insider threats
-John Pescatore
Gartner Group
Hacking World of Warcraft™ - an exercise in advanced rootkit design ©2006 Greg Hoglund
UPCOMING BOOK!