1] Abstract. 2] Anatomy of Svchost Process. 3] Dissecting Working Stature of Service Host. 4] IDAG Cross Structural Dissection of Svchost. 5] Disassembling Svchost Registry Paradigm. 6] Calling Kernel Land Modular Functions. 7] Disseminating Svchost Critical Section Object Usage. 8] Dependency Walking of a RPC Svchost Process. 9] Mapping EPMapper Endpoints: RPC Svchost Inheritance. 10] Tokens Anatomy in RPC svchost process. 11] Conclusion.
ntkrnlpa.exe!KiUnexpectedInterrupt+0xf0 ntkrnlpa.exe!ZwYieldExecution+0x1900 ntkrnlpa.exe!ZwYieldExecution+0x196c ntkrnlpa.exe!NtWriteFile+0x2b00 ntkrnlpa.exe!NtReadFile+0x580 ntkrnlpa.exe!KeReleaseInStackQueuedSpinLockFromDpcLevel+0xb14 ntdll.dll!KiFastSystemCallRet ADVAPI32.dll!SetServiceStatus+0x238 ADVAPI32.dll!SetServiceStatus+0xcc ADVAPI32.dll!StartServiceCtrlDispatcherW+0x8b svchost.exe+0x2585
ntkrnlpa.exe!KiUnexpectedInterrupt+0xf0 ntkrnlpa.exe!ZwYieldExecution+0x1900 ntkrnlpa.exe!ZwYieldExecution+0x196c ntkrnlpa.exe!KeReleaseInStackQueuedSpinLockFromDpcLevel+0xb14 ntdll.dll!KiFastSystemCallRet rpcss.dll!ServiceMain+0x453b kernel32.dll!GetModuleFileNameA+0x1b4
void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv) { // register our service control handler: sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl); if (!sshStatusHandle) goto cleanup; // SERVICE_STATUS members that don't change in example ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ssStatus.dwServiceSpecificExitCode = 0; // report the status to the service control manager. if (!ReportStatusToSCMgr( SERVICE_START_PENDING, // service state NO_ERROR, // exit code 3000)) // wait hint goto cleanup; ServiceStart( dwArgc, lpszArgv ); cleanup: if (sshStatusHandle) (VOID)ReportStatusToSCMgr( SERVICE_STOPPED, dwErr, 0);return;} }
void __cdecl main(int argc, char **argv) { char opt; SERVICE_TABLE_ENTRY dispatchTable[] = { { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main}, { NULL, NULL} }; // Code if (!StartServiceCtrlDispatcher(dispatchTable)) AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed.")); }
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint) { static DWORD dwCheckPoint = 1; BOOL fResult = TRUE; if ( !bDebug ) // when debugging we don't report to the SCM { if (dwCurrentState == SERVICE_START_PENDING) ssStatus.dwControlsAccepted = 0; else ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; ssStatus.dwCurrentState = dwCurrentState; ssStatus.dwWin32ExitCode = dwWin32ExitCode; ssStatus.dwWaitHint = dwWaitHint; if ( ( dwCurrentState == SERVICE_RUNNING ) || ( dwCurrentState == SERVICE_STOPPED ) ) ssStatus.dwCheckPoint = 0; else ssStatus.dwCheckPoint = dwCheckPoint++; if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) { AddToMessageLog(TEXT("SetServiceStatus")); } }return fResult; }
.text:010011DE mov edi, edi .text:010011E0 push ebp ; ulOptions .text:010011E1 mov ebp, esp .text:010011E3 push ecx ; lpSubKey .text:010011E4 push ecx ; hKey X .text:010011E5 push esi .text:010011E6 mov esi, ds:__imp__RegOpenKeyExW@20 ;RegOpenKeyExW(x,x,x,x,x) .text:010011EC push edi ; hKey .text:010011ED lea eax, [ebp+hKey] .text:010011F0 push eax ; phkResult .text:010011F1 mov edi, 20019h .text:010011F6 push edi ; samDesired .text:010011F7 push 0 ; ulOptions .text:010011F9 push offset SubKey ; "System\\CurrentControlSet\\Services" .text:010011FE push 80000002h ; hKey .text:01001203 call esi ; RegOpenKeyExW(x,x,x,x,x) ; RegOpenKeyExW(x,x,x,x,x) .text:01001205 test eax, eax .text:01001207 mov [ebp+var_4], eax .text:0100120A jnz short loc_1001247 .text:0100120C push ebx .text:0100120D lea eax, [ebp+phkResult] .text:01001210 push eax ; phkResult .text:01001211 push edi ; samDesired .text:01001212 push 0 ; ulOptions .text:01001214 push [ebp+phkResult] ; lpSubKey .text:01001217 push [ebp+hKey] ; hKey .text:0100121A call esi ; RegOpenKeyExW(x,x,x,x,x) ; RegOpenKeyExW(x,x,x,x,x) .text:0100121C test eax, eax .text:0100121E mov ebx, ds:__imp__RegCloseKey@4 ; RegCloseKey(x) .text:01001224 mov [ebp+var_4], eax .text:01001227 jnz short loc_1001241 .text:01001229 push [ebp+arg_4] ; phkResult .text:0100122C push edi ; samDesired .text:0100122D push 0 ; ulOptions .text:0100122F push offset aParameters ; "Parameters" .text:01001234 push [ebp+phkResult] ; hKey .text:01001237 call esi ; RegOpenKeyExW(x,x,x,x,x) ; RegOpenKeyExW(x,x,x,x,x) .text:01001239 push [ebp+phkResult] ; hKey .text:0100123C mov [ebp+var_4], eax .text:0100123F call ebx ; RegCloseKey(x) ; RegCloseKey(x) .text:01001241 .text:01001241 loc_1001241: ; CODE XREF: OpenServiceParametersKey(x,x)+49#j .text:01001241 push [ebp+hKey] ; hKey .text:01001244 call ebx ; RegCloseKey(x) ; RegCloseKey(x) .text:01001246 pop ebx
.text:010011F9 push offset SubKey ; "System\\CurrentControlSet\\Services" .text:010011FE push 80000002h ; hKey .text:01001203 call esi ; RegOpenKeyExW(x,x,x,x,x) ; RegOpenKeyExW(x,x,x,x,x) .text:01001205 test eax, eax
1] rpcss 2] dcom 3] imgsvc 4] Local service 5] termsvc
SERVICE_NAME: rpcss TYPE : 20 WIN32_SHARE_PROCESS STATE : 4 RUNNING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 Another Example of Dcom XII C:\tools>sc query dcomlaunch SERVICE_NAME: dcomlaunch TYPE : 20 WIN32_SHARE_PROCESS STATE : 4 RUNNING (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0
.text:01001483 ; FUNCTION CHUNK AT .text:010029E2 SIZE 00000023 BYTES .text:01001483 .text:01001483 mov edi, edi .text:01001485 push ebp .text:01001486 mov ebp, esp .text:01001488 push esi .text:01001489 mov esi, [ebp+arg_0] .text:0100148C mov eax, [esi+8] .text:0100148F test eax, eax .text:01001491 jnz short loc_10014AA .text:01001493 push 8 ; dwFlags .text:01001495 push eax ; hFile .text:01001496 push dword ptr [esi+0Ch] ; lpLibFileName .text:01001499 call ds:__imp__LoadLibraryExW@12 ; LoadLibraryExW(x,x,x) .text:0100149F test eax, eax .text:010014A1 jz loc_10029EF .text:010014A7 mov [esi+8], eax .text:010014AA .text:010014AA loc_10014AA: ; CODE XREF: GetServiceDllFunction(x,x,x)+E#j .text:010014AA push edi .text:010014AB push [ebp+lpProcName] ; lpProcName .text:010014AE push eax ; hModule .text:010014AF call ds:__imp__GetProcAddress@8 ; GetProcAddress(x,x) .text:010014B5 mov edi, eax .text:010014B7 .test edi, edi .text:010014B9 jz short loc_10014E1 .text:010014BB .text:010014BB loc_10014BB: ; CODE XREF: GetServiceDllFunction(x,x,x)+63#j .text:010014BB ; GetServiceDllFunction(x,x,x)+1567#j .text:010014BB mov eax, edi .text:010014BD pop edi .text:010014BE .text:010014BE loc_10014BE: ; CODE XREF: GetServiceDllFunction(x,x,x)+157D#j .text:010014BE pop esi .text:010014BF pop ebp .text:010014C0 retn 0Ch .text:010014C0 _GetServiceDllFunction@12 endp
// Global variable CRITICAL_SECTION CriticalSection; void main() { // Initialize the critical section one time only. if (!InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x80000400) ) return;.. // Release resources used by the critical section object. DeleteCriticalSection(&CriticalSection) } DWORD WINAPI ThreadProc( LPVOID lpParameter ) { . // Request ownership of the critical section. EnterCriticalSection(&CriticalSection); // Access the shared resource. // Release ownership of the critical section. LeaveCriticalSection(&CriticalSection); } }
77E945FA > 8BFF MOV EDI,EDI 77E945FC 55 PUSH EBP 77E945FD 8BEC MOV EBP,ESP 77E945FF 83EC 28 SUB ESP,28 77E94602 A1 ACA2EF77 MOV EAX,DWORD PTR DS:[77EFA2AC] 77E94607 8B55 10 MOV EDX,DWORD PTR SS:[EBP+10] 77E9460A 53 PUSH EBX 77E9460B 8945 FC MOV DWORD PTR SS:[EBP-4],EAX 77E9460E 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] 77E94611 56 PUSH ESI 77E94612 8B75 14 MOV ESI,DWORD PTR SS:[EBP+14] 77E94615 85F6 TEST ESI,ESI 77E94617 8945 E0 MOV DWORD PTR SS:[EBP-20],EAX 77E9461A 8B45 0C MOV EAX,DWORD PTR SS:[EBP+C] 77E9461D 57 PUSH EDI 77E9461E 8945 E4 MOV DWORD PTR SS:[EBP-1C],EAX 77E94621 8D5D D8 LEA EBX,DWORD PTR SS:[EBP-28] 77E94624 C645 EB 00 MOV BYTE PTR SS:[EBP-15],0 77E94628 75 03 JNZ SHORT RPCRT4.77E9462D 77E9462A 8D75 EB LEA ESI,DWORD PTR SS:[EBP-15] 77E9462D 8BC6 MOV EAX,ESI 77E9462F 8D78 01 LEA EDI,DWORD PTR DS:[EAX+1] 77E94632 8A08 MOV CL,BYTE PTR DS:[EAX] 7 7E94634 40 INC EAX 77E94635 84C9 TEST CL,CL 77E94637 ^75 F9 JNZ SHORT RPCRT4.77E94632 77E94639 2BC7 SUB EAX,EDI 77E9463B 83F8 40 CMP EAX,40 77E9463E 0F83 1A880100 JNB RPCRT4.77EACE5E 77E94644 837D E4 00 CMP DWORD PTR SS:[EBP-1C],0 77E94648 0F84 1A880100 JE RPCRT4.77EACE68 77E9464E 85D2 TEST EDX,EDX 77E94650 0F85 1C880100 JNZ RPCRT4.77EACE72 77E94656 33C0 XOR EAX,EAX 77E94658 8D7D EC LEA EDI,DWORD PTR SS:[EBP-14] 77E9465B AB STOS DWORD PTR ES:[EDI] 77E9465C AB STOS DWORD PTR ES:[EDI] 77E9465D AB STOS DWORD PTR ES:[EDI] 77E9465E AB STOS DWORD PTR ES:[EDI] 77E9465F 8D45 EC LEA EAX,DWORD PTR SS:[EBP-14] 77E94662 C745 D8 01000000 MOV DWORD PTR SS:[EBP-28],1 77E94669 8945 DC MOV DWORD PTR SS:[EBP-24],EAX 77E9466C E8 0F3FFEFF CALL RPCRT4.77E78580
There are 31,323 total registered users.
[+] expand