31 typedef struct _PHSVCP_CAPTURED_RUNAS_SERVICE_PARAMETERS
70 return STATUS_SUCCESS;
76 _Out_ PHANDLE ReplyPortHandle
82 Payload->ApiNumber == 0 ||
87 Payload->ReturnStatus = STATUS_INVALID_SYSTEM_SERVICE;
88 *ReplyPortHandle = Client->PortHandle;
93 Payload->ReturnStatus = status;
95 *ReplyPortHandle = Client->PortHandle;
108 if ((ULONG_PTR)address + String->Length < (ULONG_PTR)address ||
110 (ULONG_PTR)address + String->Length > (ULONG_PTR)client->
ClientViewLimit)
115 if ((ULONG_PTR)address & (Alignment - 1))
125 _In_ ULONG Alignment,
126 _In_ BOOLEAN AllowNull,
132 if (String->Offset != 0)
137 return STATUS_ACCESS_VIOLATION;
144 return STATUS_ACCESS_VIOLATION;
149 return STATUS_SUCCESS;
154 _In_ BOOLEAN AllowNull,
155 _Out_ PVOID *CapturedBuffer
161 if (String->Offset != 0)
166 return STATUS_ACCESS_VIOLATION;
171 return STATUS_NO_MEMORY;
173 memcpy(buffer, address, String->Length);
174 *CapturedBuffer = buffer;
179 return STATUS_ACCESS_VIOLATION;
181 *CapturedBuffer = NULL;
184 return STATUS_SUCCESS;
189 _In_ BOOLEAN AllowNull,
195 if (String->Length & 1)
196 return STATUS_INVALID_BUFFER_SIZE;
197 if (String->Length > 0xfffe)
198 return STATUS_INVALID_BUFFER_SIZE;
200 if (String->Offset != 0)
205 return STATUS_ACCESS_VIOLATION;
207 if (String->Length != 0)
215 return STATUS_ACCESS_VIOLATION;
217 *CapturedString = NULL;
220 return STATUS_SUCCESS;
225 _In_ BOOLEAN AllowNull,
226 _Out_ PSID *CapturedSid
237 if (String->Length < FIELD_OFFSET(
struct _SID, IdentifierAuthority) ||
242 return STATUS_INVALID_SID;
252 return STATUS_SUCCESS;
257 _In_ BOOLEAN AllowNull,
258 _In_ SECURITY_INFORMATION RequiredInformation,
259 _Out_ PSECURITY_DESCRIPTOR *CapturedSecurityDescriptor
263 PSECURITY_DESCRIPTOR securityDescriptor;
269 if (securityDescriptor)
273 PhFree(securityDescriptor);
274 return STATUS_INVALID_SECURITY_DESCR;
277 bufferSize = String->Length;
280 if (status == STATUS_BUFFER_TOO_SMALL)
284 newBuffer = PhAllocate(bufferSize);
285 memcpy(newBuffer, securityDescriptor, String->Length);
286 PhFree(securityDescriptor);
287 securityDescriptor = newBuffer;
294 PhFree(securityDescriptor);
298 *CapturedSecurityDescriptor = securityDescriptor;
302 *CapturedSecurityDescriptor = NULL;
305 return STATUS_SUCCESS;
313 return STATUS_NOT_IMPLEMENTED;
334 request.
InBuffer = Payload->u.Plugin.i.Data;
335 request.
InLength =
sizeof(Payload->u.Plugin.i.Data);
336 request.
OutBuffer = Payload->u.Plugin.o.Data;
337 request.
OutLength =
sizeof(Payload->u.Plugin.o.Data);
348 status = STATUS_NOT_FOUND;
383 Parameters->ProcessId = Payload->u.ExecuteRunAsCommand.i.ProcessId;
384 Parameters->UserName =
PhGetString(CapturedParameters->UserName);
385 Parameters->Password =
PhGetString(CapturedParameters->Password);
386 Parameters->LogonType = Payload->u.ExecuteRunAsCommand.i.LogonType;
387 Parameters->SessionId = Payload->u.ExecuteRunAsCommand.i.SessionId;
388 Parameters->CurrentDirectory =
PhGetString(CapturedParameters->CurrentDirectory);
389 Parameters->CommandLine =
PhGetString(CapturedParameters->CommandLine);
390 Parameters->FileName =
PhGetString(CapturedParameters->FileName);
391 Parameters->DesktopName =
PhGetString(CapturedParameters->DesktopName);
392 Parameters->UseLinkedToken = Payload->u.ExecuteRunAsCommand.i.UseLinkedToken;
393 Parameters->ServiceName =
PhGetString(CapturedParameters->ServiceName);
402 if (CapturedParameters->UserName)
405 if (CapturedParameters->Password)
407 RtlSecureZeroMemory(CapturedParameters->Password->Buffer, CapturedParameters->Password->Length);
411 if (CapturedParameters->CurrentDirectory)
413 if (CapturedParameters->CommandLine)
415 if (CapturedParameters->FileName)
417 if (CapturedParameters->DesktopName)
419 if (CapturedParameters->ServiceName)
427 if ((!Parameters->UserName || !Parameters->Password) && !Parameters->ProcessId)
428 return STATUS_INVALID_PARAMETER_MIX;
429 if (!Parameters->FileName && !Parameters->CommandLine)
430 return STATUS_INVALID_PARAMETER_MIX;
431 if (!Parameters->ServiceName)
432 return STATUS_INVALID_PARAMETER;
434 return STATUS_SUCCESS;
483 HANDLE processHandle;
485 processId = Payload->u.ControlProcess.i.ProcessId;
487 switch (Payload->u.ControlProcess.i.Command)
493 NtClose(processHandle);
500 NtClose(processHandle);
507 NtClose(processHandle);
516 priorityClass.
PriorityClass = (UCHAR)Payload->u.ControlProcess.i.Argument;
517 status = NtSetInformationProcess(processHandle, ProcessPriorityClass, &priorityClass,
sizeof(
PROCESS_PRIORITY_CLASS));
519 NtClose(processHandle);
526 NtClose(processHandle);
530 status = STATUS_INVALID_PARAMETER;
544 SC_HANDLE serviceHandle;
545 SERVICE_STATUS serviceStatus;
549 switch (Payload->u.ControlService.i.Command)
557 if (!StartService(serviceHandle, 0, NULL))
560 CloseServiceHandle(serviceHandle);
570 SERVICE_PAUSE_CONTINUE
573 if (!ControlService(serviceHandle, SERVICE_CONTROL_CONTINUE, &serviceStatus))
576 CloseServiceHandle(serviceHandle);
586 SERVICE_PAUSE_CONTINUE
589 if (!ControlService(serviceHandle, SERVICE_CONTROL_PAUSE, &serviceStatus))
592 CloseServiceHandle(serviceHandle);
605 if (!ControlService(serviceHandle, SERVICE_CONTROL_STOP, &serviceStatus))
608 CloseServiceHandle(serviceHandle);
621 if (!DeleteService(serviceHandle))
624 CloseServiceHandle(serviceHandle);
632 status = STATUS_INVALID_PARAMETER;
656 SC_HANDLE scManagerHandle;
657 SC_HANDLE serviceHandle;
674 if (scManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE))
676 if (serviceHandle = CreateService(
680 SERVICE_CHANGE_CONFIG,
681 Payload->u.CreateService.i.ServiceType,
682 Payload->u.CreateService.i.StartType,
683 Payload->u.CreateService.i.ErrorControl,
686 Payload->u.CreateService.i.TagIdSpecified ? &tagId : NULL,
692 Payload->u.CreateService.o.TagId = tagId;
693 CloseServiceHandle(serviceHandle);
700 CloseServiceHandle(scManagerHandle);
710 RtlSecureZeroMemory(password->
Buffer, password->
Length);
738 SC_HANDLE serviceHandle;
757 if (ChangeServiceConfig(
759 Payload->u.ChangeServiceConfig.i.ServiceType,
760 Payload->u.ChangeServiceConfig.i.StartType,
761 Payload->u.ChangeServiceConfig.i.ErrorControl,
764 Payload->u.ChangeServiceConfig.i.TagIdSpecified ? &tagId : NULL,
771 Payload->u.ChangeServiceConfig.o.TagId = tagId;
778 CloseServiceHandle(serviceHandle);
790 RtlSecureZeroMemory(password->
Buffer, password->
Length);
805 _In_ PVOID CapturedBuffer,
807 _Out_ PVOID *ValidatedBuffer
810 if (Length > PackedData->Length)
811 return STATUS_ACCESS_VIOLATION;
813 *ValidatedBuffer = CapturedBuffer;
815 return STATUS_SUCCESS;
820 _In_ PVOID CapturedBuffer,
821 _In_ PVOID *OffsetInBuffer,
823 _In_ ULONG Alignment,
824 _In_ BOOLEAN AllowNull
829 offset = (SIZE_T)*OffsetInBuffer;
834 return STATUS_SUCCESS;
836 return STATUS_ACCESS_VIOLATION;
839 if (offset + Length < offset)
840 return STATUS_ACCESS_VIOLATION;
841 if (offset + Length > PackedData->Length)
842 return STATUS_ACCESS_VIOLATION;
843 if (offset & (Alignment - 1))
844 return STATUS_DATATYPE_MISALIGNMENT;
846 *OffsetInBuffer = (PVOID)((ULONG_PTR)CapturedBuffer + offset);
848 return STATUS_SUCCESS;
853 _In_ PVOID CapturedBuffer,
854 _In_ PVOID *OffsetInBuffer,
856 _In_ BOOLEAN AllowNull
865 offset = (SIZE_T)*OffsetInBuffer;
870 return STATUS_SUCCESS;
872 return STATUS_ACCESS_VIOLATION;
875 if (offset >= PackedData->Length)
876 return STATUS_ACCESS_VIOLATION;
878 return STATUS_DATATYPE_MISALIGNMENT;
880 start = (PWCHAR)((ULONG_PTR)CapturedBuffer + offset);
881 end = (PWCHAR)((ULONG_PTR)CapturedBuffer + (PackedData->Length & -2));
882 remainingPart.
Buffer = start;
883 remainingPart.
Length = (end - start) *
sizeof(WCHAR);
887 SIZE_T validatedLength = 0;
891 validatedLength += firstPart.
Length +
sizeof(WCHAR);
893 if (firstPart.
Length == 0)
895 *OffsetInBuffer = start;
897 return STATUS_SUCCESS;
905 *OffsetInBuffer = start;
907 return STATUS_SUCCESS;
911 return STATUS_ACCESS_VIOLATION;
922 SC_HANDLE serviceHandle = NULL;
924 PVOID unpackedInfo = NULL;
925 ACCESS_MASK desiredAccess = SERVICE_CHANGE_CONFIG;
932 packedData = Payload->u.ChangeServiceConfig2.i.Info;
934 switch (Payload->u.ChangeServiceConfig2.i.InfoLevel)
936 case SERVICE_CONFIG_FAILURE_ACTIONS:
938 LPSERVICE_FAILURE_ACTIONS failureActions;
946 if (!
NT_SUCCESS(status =
PhSvcpUnpackBuffer(&packedData, info, &failureActions->lpsaActions, failureActions->cActions *
sizeof(SC_ACTION), __alignof(SC_ACTION),
TRUE)))
949 if (failureActions->lpsaActions)
953 for (i = 0; i < failureActions->cActions; i++)
955 if (failureActions->lpsaActions[i].Type == SC_ACTION_RESTART)
957 desiredAccess |= SERVICE_START;
963 unpackedInfo = failureActions;
966 case SERVICE_CONFIG_DELAYED_AUTO_START_INFO:
967 status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_DELAYED_AUTO_START_INFO), &unpackedInfo);
969 case SERVICE_CONFIG_FAILURE_ACTIONS_FLAG:
970 status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_FAILURE_ACTIONS_FLAG), &unpackedInfo);
972 case SERVICE_CONFIG_SERVICE_SID_INFO:
973 status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_SID_INFO), &unpackedInfo);
975 case SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO:
977 LPSERVICE_REQUIRED_PRIVILEGES_INFO requiredPrivilegesInfo;
979 if (!
NT_SUCCESS(status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_REQUIRED_PRIVILEGES_INFO), &requiredPrivilegesInfo)))
984 unpackedInfo = requiredPrivilegesInfo;
987 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
988 status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_PRESHUTDOWN_INFO), &unpackedInfo);
990 case SERVICE_CONFIG_TRIGGER_INFO:
992 PSERVICE_TRIGGER_INFO triggerInfo;
994 PSERVICE_TRIGGER trigger;
996 PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM dataItem;
1001 if (!
NT_SUCCESS(status =
PhSvcpUnpackBuffer(&packedData, info, &triggerInfo->pTriggers, triggerInfo->cTriggers *
sizeof(SERVICE_TRIGGER), __alignof(SERVICE_TRIGGER),
TRUE)))
1004 if (triggerInfo->pTriggers)
1006 for (i = 0; i < triggerInfo->cTriggers; i++)
1008 trigger = &triggerInfo->pTriggers[i];
1012 if (!
NT_SUCCESS(status =
PhSvcpUnpackBuffer(&packedData, info, &trigger->pDataItems, trigger->cDataItems *
sizeof(SERVICE_TRIGGER_SPECIFIC_DATA_ITEM), __alignof(SERVICE_TRIGGER_SPECIFIC_DATA_ITEM),
TRUE)))
1015 if (trigger->pDataItems)
1017 for (j = 0; j < trigger->cDataItems; j++)
1019 dataItem = &trigger->pDataItems[j];
1022 switch (dataItem->dwDataType)
1024 case SERVICE_TRIGGER_DATA_TYPE_BINARY:
1025 case SERVICE_TRIGGER_DATA_TYPE_LEVEL:
1026 alignment =
sizeof(CHAR);
1028 case SERVICE_TRIGGER_DATA_TYPE_STRING:
1029 alignment =
sizeof(WCHAR);
1031 case SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ANY:
1032 case SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ALL:
1033 alignment =
sizeof(ULONG64);
1044 unpackedInfo = triggerInfo;
1047 case SERVICE_CONFIG_LAUNCH_PROTECTED:
1048 status =
PhSvcpUnpackRoot(&packedData, info,
sizeof(SERVICE_LAUNCH_PROTECTED_INFO), &unpackedInfo);
1051 status = STATUS_INVALID_PARAMETER;
1057 assert(unpackedInfo);
1065 if (!ChangeServiceConfig2(
1067 Payload->u.ChangeServiceConfig2.i.InfoLevel,
1077 CloseServiceHandle(serviceHandle);
1091 static PVOID setTcpEntry = NULL;
1093 ULONG (__stdcall *localSetTcpEntry)(PVOID TcpRow);
1104 localSetTcpEntry = setTcpEntry;
1106 if (!localSetTcpEntry)
1108 HMODULE iphlpapiModule;
1110 iphlpapiModule = LoadLibrary(L
"iphlpapi.dll");
1114 localSetTcpEntry = (PVOID)GetProcAddress(iphlpapiModule,
"SetTcpEntry");
1116 if (localSetTcpEntry)
1122 FreeLibrary(iphlpapiModule);
1128 if (!localSetTcpEntry)
1129 return STATUS_NOT_SUPPORTED;
1131 tcpRow.dwState = Payload->u.SetTcpEntry.i.State;
1132 tcpRow.dwLocalAddr = Payload->u.SetTcpEntry.i.LocalAddress;
1133 tcpRow.dwLocalPort = Payload->u.SetTcpEntry.i.LocalPort;
1134 tcpRow.dwRemoteAddr = Payload->u.SetTcpEntry.i.RemoteAddress;
1135 tcpRow.dwRemotePort = Payload->u.SetTcpEntry.i.RemotePort;
1136 result = localSetTcpEntry(&tcpRow);
1138 return NTSTATUS_FROM_WIN32(result);
1148 HANDLE threadHandle;
1150 threadId = Payload->u.ControlThread.i.ThreadId;
1152 switch (Payload->u.ControlThread.i.Command)
1158 NtClose(threadHandle);
1165 NtClose(threadHandle);
1172 NtClose(threadHandle);
1179 NtClose(threadHandle);
1183 status = STATUS_INVALID_PARAMETER;
1198 LSA_HANDLE policyHandle;
1208 status = LsaAddAccountRights(policyHandle, accountSid, &userRightUs, 1);
1209 LsaClose(policyHandle);
1250 status = NtSetSystemInformation(
1252 &Payload->u.IssueMemoryListCommand.i.Command,
1265 Payload->u.PostMessage.i.hWnd,
1266 Payload->u.PostMessage.i.Msg,
1267 Payload->u.PostMessage.i.wParam,
1268 Payload->u.PostMessage.i.lParam
1271 return STATUS_SUCCESS;
1285 Payload->u.PostMessage.i.hWnd,
1286 Payload->u.PostMessage.i.Msg,
1287 Payload->u.PostMessage.i.wParam,
1288 Payload->u.PostMessage.i.lParam
1291 return STATUS_SUCCESS;
1310 status = STATUS_UNSUCCESSFUL;
1325 PSECURITY_DESCRIPTOR securityDescriptor;
1326 ACCESS_MASK desiredAccess;
1327 SC_HANDLE serviceHandle;
1335 if ((Payload->u.SetServiceSecurity.i.SecurityInformation & OWNER_SECURITY_INFORMATION) ||
1336 (Payload->u.SetServiceSecurity.i.SecurityInformation & GROUP_SECURITY_INFORMATION))
1338 desiredAccess |= WRITE_OWNER;
1341 if (Payload->u.SetServiceSecurity.i.SecurityInformation & DACL_SECURITY_INFORMATION)
1343 desiredAccess |= WRITE_DAC;
1346 if (Payload->u.SetServiceSecurity.i.SecurityInformation & SACL_SECURITY_INFORMATION)
1348 desiredAccess |= ACCESS_SYSTEM_SECURITY;
1356 Payload->u.SetServiceSecurity.i.SecurityInformation,
1359 CloseServiceHandle(serviceHandle);
1366 PhFree(securityDescriptor);
1380 static BOOLEAN alreadyLoaded;
1386 return STATUS_SOME_NOT_MAPPED;
1392 alreadyLoaded =
TRUE;
1404 UlongToHandle(Payload->u.WriteMiniDumpProcess.i.LocalProcessHandle),
1405 UlongToHandle(Payload->u.WriteMiniDumpProcess.i.ProcessId),
1406 UlongToHandle(Payload->u.WriteMiniDumpProcess.i.LocalFileHandle),
1407 Payload->u.WriteMiniDumpProcess.i.DumpType,
1413 return STATUS_SUCCESS;
1419 error = GetLastError();
1421 if (error == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER))
1422 return STATUS_INVALID_PARAMETER;
1424 return STATUS_UNSUCCESSFUL;