Fundacja Rozwoju Regionu Gołdapedukacja techniczno informatyczna
Access:

» Code injection using Windows GUI messages

Related categories: Windows | Generall | Tutorials | Exploits

Krzysztof Wilkos
Viewed: 11770 | Article date: 2006-07-31 15:53:45

Few could suspect that an innocuous GUI feature such as Windows messages could pose a danger to system security. We show why this seemingly innocent mechanism can be used to inject malicious code into another application and escalate an intruder's privileges.

Few could suspect that an innocuous GUI feature such as Windows messages could pose a danger to system security. However, this seemingly innocent mechanism can be used to inject malicious code into another application and escalate an intruder’s privileges.

About the author

Krzysztof Wilkos is a first-year student at the Faculty of Cybernetics at the Military Technical Academy in Warsaw. He has been working on computer security issues for several years now, and in his spare time he co-authors a security-related website.

GUI control and user interaction in Windows is based on events, which represent all supported user actions as well as calls sent between the various components. Event data is exchanged using messages – each event has its corresponding messages and application windows can identify messages and react to them.

You will learn...

  • what dangers can lurk within an innocent-looking user interface,

  • how to execute code in a vulnerable application.

You should know...

  • the basics of WinAPI programming,

  • how to use a debugger.

A message can therefore contain information about a mouse click or key press, but can also a window refresh request. The whole framework works and does the job it was designed for. Unfortunately, the mechanism was created in times when computer security was not a serious consideration, which can have grave consequences for Windows users today. The two crucial flaws are:

  • there is no way to identify the message sender,

  • some messages pass pointers to data structures and functions.

When a window receives a message, it has no way identifying the message sender – the messaging API simply provides no such functionality. In practice, this means that a system message is treated on par with a message from an application with the lowest possible privileges. While this is not a problem for a key press message, it becomes much more serious for messages that change application behaviour, for example by modifying its data or function addresses. We will see what opportunities this opens up for intruders, but first let’s have a look at some messaging basics.

How messages are sent

Messages can be sent by calling SendMessage(). Listing 1 shows the function prototype. The first argument is a handle to the window that will receive the message, while the second argument specifies the message type and therefore determines actual function behaviour. The last two parameters can be used to pass extra information, depending on the message type. The function return value also depends on the message type. Table 1 summarises the message types that will be useful for the purpose of this article.

Listing 1. SendMessage() prototype

 

LRESULT SendMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam );

Table 1. Selected message types

Message type

wParam

lParam

Return value

WM_PASTE

0

0

none

EM_SETREADONLY

True to set, False to unset

0

0 if unsuccessful

EM_SETLIMITTEXT

maximum text length

0

none

WM_SETTEXT

0

new text address

True if successful

EM_SETWORDBREAKPROC

0

function address

none

WM_LBUTTONDBLCLK

state information for mouse buttons and the Control and Shift keys

the less significant word specifies horizontal cursor position and the more significant word specifies vertical position

0 once processed by the application

Window handle

To send a message, we also need to know the handle for the target window. For the purpose of this article, we will use two functions to obtain the required handle. The first is FindWindow() – Listing 2 presents its prototype.

Listing 2. FindWindow() prototype

 

HWND FindWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName );

The function goes through all active application windows and returns a handle to the window specified by its parameters – a pointer to the window class name and a pointer to the window title. If NULL is specified as one of the arguments, then only the other argument is used to locate the window. The FindWindow() function is complemented by FindWindowEx(), shown in Listing 3.

A d v e r t i s e m e n t
Linux BSD Unix ranking vote

Page: 1 2 3 4 5
Buy article Buy subscription
Buy now add to cart
add to cart
Standard price: 2€/$3 Standard price: 25€/$30
Buy article for as little as (2€/$3) each allow access to individual articles. Buy a full access to our Hakin9 archive portal. You will be able to read the articles from all archive issues from year 2005 and 2006. For just 25€/$30 you get unrestricted access to the entire website for the whole year.
SDJhakin9

.SDJ Users:


.:Login
.:Password

[Register]
[Forgotten your password?]

...hakin9 StarterKit IT Practical Solutions for Newbies

...Shopping Cart

sum: 0 €
Choose currency:

...SUBSCRIBE TO
hakin9 Print Edition


...Advertisement



...Conferences

...Topics

...Advertisement

 

 

Subscribe | Contact Us | Newsletter | See all issues | About Hakin9
Copyright C 2006 by Software Developer's Journal. All rights reserved.