📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

Blogs >> c1de0x's Blog

Created: Monday, May 14 2007 12:28.20 CDT  
Printer Friendly ...
Kerberos API Tracing
Author: c1de0x # Views: 2892

Hi all,

I'm looking into API tracing, and heard about kerberos (Rustem Fasihov) in this thread: https://www.openrce.org/forums/posts/274.

As I've been grappling with my own hooking engine for a couple of days, I couldn't resist looking under the hood.

I discovered that at it's core, kerberos seems to use 5-byte hotpatch hooks, which isn't surprising, as it's the mechanism I was using and also - to some degree - that favored by Detours.

What is interesting is that there don't seem to be any 'trampoline' functions. In other words, in both my solution and Detours, it is necessary to generate a 'jump function' (which acts as the target of the 5-byte JMP patch) for each API being hooked. The 'jump'/'trampoline' function typically has the address of the instruction immediately following the patch hard-coded into a JMP so that execution can continue.

It seems that kerberos takes a different approach though, all patches, for all hooked functions, jump to the same method, which begins:

    pushf
spin:
    cmp    g_inHookSemaphore, 1
    jz     spin
    mov    g_inHookSemaphore, 1
    popf
    pop    data1
    pop    data2
    pushf
    pusha
    ...


Blog Comments
camus Posted: Tuesday, May 15 2007 13:16.42 CDT
Are you sure about that? It's hard to believe :S

Here you have an active wait:

spin:
  cmp    g_inHookSemaphore, 1
  jz     spin

wich is a processor consuming operation.
And this is a race condition:

    jz     spin
    mov    g_inHookSemaphore, 1

Aren't they?

jms Posted: Wednesday, May 16 2007 12:08.44 CDT
Well it could be that this function trying to determine whether it can use that semaphore, and if not it spinlocks. The next instruction appears to then set the semaphore as locked and continue the instructions, then the next thread comes in it will spin again.

Then again, what do I know?

anonymouse Posted: Wednesday, May 16 2007 13:10.31 CDT
g_whatever is a name that was given by you ?

supposedly looking if some other thread is executing the hook it seems
coz when the function finishes it sets the global dword to 0 before exiting

References in ke_core:.text to 10004000..10004003
Address    Disassembly                               Comment
10002547   CMP DWORD PTR DS:[10004000],1             DS:[10004000]=00000000
10002550   MOV DWORD PTR DS:[10004000],1             DS:[10004000]=00000000
10002696   MOV DWORD PTR DS:[10004000],0             DS:[10004000]=00000000



Add New Comment
Comment:









There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit