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








Flag: Tornado! Hurricane!

 Forums >>  Target Specific - General  >>  RE'ing Windows Thread Message Passing

Topic created on: September 2, 2006 20:35 CDT by spork .

I have a bit of spyware I am looking at and have done a fair amount of the basic RE already, but I ran into a problem debugging how the spyware hijacks explorer windows to display its content (which I believe is the main payload). I am stuck where the code sits in a GetMessage/TranslateMessage/DispatchMessage loop:

.text:100051E4 loc_100051E4:                           ; CODE XREF: STRANGE_MESSAGE_PASSING+A1j
.text:100051E4 lea     ecx, [esp+28h+Msg]
.text:100051E8 push    ecx                             ; lpMsg
.text:100051E9 call    edi ; TranslateMessage
.text:100051EB lea     edx, [esp+28h+Msg]
.text:100051EF push    edx                             ; lpMsg
.text:100051F0 call    ebx ; DispatchMessageA
.text:100051F2 push    0                               ; wMsgFilterMax
.text:100051F4 push    0                               ; wMsgFilterMin
.text:100051F6 push    0                               ; hWnd
.text:100051F8 lea     eax, [esp+34h+Msg]
.text:100051FC push    eax                             ; lpMsg
.text:100051FD call    esi ; GetMessageA
.text:100051FF test    eax, eax
.text:10005201 jnz     short loc_100051E4

I'm fairly new to RE'ing on Windows, so I've been reading up on this Windows event passing. From what I understand, when an action is done on the screen, a message is passed to the thread controlling the window and then the event is passed onto its stub function which designates what occurs when the action is performed.

So, my question is, is there an easy way to locate these stub functions within the code?

If what I said made no sense, my apologies.

Cheers!

  anonymouse     September 3, 2006 09:26.12 CDT
if you are conversant with ollydbg you can try the following

ollydbg natively has a windows window (which would enumerate all the windows that the application has in active state and would also list its wndproc and class proc
along with thier handles you can directly set break points
on thier wndprocs(you can also enable code injection to get the address of wndproc in options -> debugging options -> security (use it with caution as it may not function always
like when all the threads in an application are in WaitState
(WaitForSingle/MULTIPLE whatever apis)

or you can find one of the spy programs (spy++ from ms (ive never used it but ppl say its better than what i use WinSpy from catch22.net) and then point the window to it
it would get you the wndproc which then you can nanlyse to your hearts content
you can aslo find the wndprocs if you are using windbg
with ~ find the thread you want and set it to current with ~ index S the doing  !SdbgExt.Hwnd
sdbgext is a user mode extension written by skywing
that has got a few things to make sourceless binary reversing in windbg easier

but these all assume you are doing things dynamically
and not analysing statically with a disassembler

  PSUJobu     September 4, 2006 08:03.32 CDT
> anonymouse: but these all assume you are doing things dynamically
> and not analysing statically with a disassembler

If you are doing pure static analysis (which you are not "forced" to do on Windows as on many other platforms), you would look for calls to RegisterClass() and RegisterClassEx(). These functions take a WNDCLASS(EX) structure pointer, and that structure includes a WNDPROC pointer - the "window procedure" called by DispatchMessage() to handle a given message.

Of course, if you are looking at an MFC application, things get more difficult.  There is a single WNDPROC which uses per-C++-class tables ("message maps") to find the appropriate handler for a given message.  There is caching involved to further complicate matters (dynamically, anyway).  The biggest difficulty is that each version of MFC (and there are a number of versions out there) has slightly different structure formats.  While I have written IDC scripts that can find the MFC RTTI-ish stuff, including the message maps, it is highly MFC version-specific.  If I did more Wintel, I would probably maintain a set of RE scripts (now probably IDAPython instead of IDC) for each version of MFC I encounter.

  anonymouse     September 4, 2006 09:11.31 CDT
> PSUJobu: > If you are doing pure static analysis (which you are not \"forced\" to do on Windows as on many other platforms), you would look for calls to RegisterClass() and RegisterClassEx(). These functions take a WNDCLASS(EX) structure pointer, and that structure includes a WNDPROC pointer - the \"window procedure\" called by DispatchMessage() to handle a given message.


well even in pure application that doesnt use mfc and what not if the windows etc are subclassed,modified with GetWindowLong(GWL_WNDPROC) etc to make the wndproc point to somewhere else it becomes a little difficult to find them out yeah you can find them out statically too but what i meant to say was it takes a little more work and time to arrive there while doing them dynamically all it takes are a few clicks and no brain :)


btw by doing dynamically you can get deep into user32.dll
NtCallUserWhatever@20 and stop on NtContinue to find the
context.eip thats passed to Continue force a temp break
and then analyse it when you are in user code

Note: Registration is required to post to the forums.

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