880 likes | 903 Views
Windows Internals 4th Chapter 4 (continued). Team 6 Service ~ Startup Errors 945002086 洪健惟 Accepting the Boot and Last Known Good ~ Service Control Program 945002089 李家豪 Windows Management Instrumentation ~ the Managed Object Format Language 945002101 張凱翔
E N D
Windows Internals 4thChapter 4 (continued) Team 6 Service ~ Startup Errors 945002086 洪健惟 Accepting the Boot and Last Known Good ~ Service Control Program 945002089 李家豪 Windows Management Instrumentation ~ the Managed Object Format Language945002101 張凱翔 The WMI Namespace ~ Conclusion 93502105 廖凡磊
Windows Internals 4thService ~ Startup Errors Service p.211 Service Applications p.212 Service Accounts p.217 The Service Control Manager p.223 Service Startup p.225 Startup Errors p.229
What is Service • Processes start at system startup time that provide services to any user • Include services and device drivers • Similar to UNIX daemon processes • Ex : Web Server
Service Component • Service Application • Consist of at least one executable that runs as a Windows service • Service Control Program ( SCP ) • Used to start , stop , or configure a service • Service Control Manager ( SCM ) • Manage Service Control Program ( SCP ) • \Windows\system32\services.exe
Service Component ( cont. ) Service Application Service Control Program ( SCP ) Service Control Manager ( SCM )
Service Accounts • It dictates what resources the process can access • In service’s registry , ObjectName value decide which account service use to run • Four types in Windows XP • Local System Account • Network Service Account • Local Service Account • Alternate Account ( User-defined )
Service Accounts ( cont. ) Windows NT series Windows 95 Windows 98 Windows Me Local System Account Domain User Account Local System Account Windows 2000 Windows XP Windows Server 2003 Local System Account Network Service Account Local Service Account
Local System Account • Most services run in this account • Core Windows user-mode operating system components use this account • Session Manager ( Smss.exe ) • Windows subsystem process ( Csrss.exe ) • local security authority subsystem ( Lsass.exe ) • Winlogon process ( Winlogon.exe ) • All in \Windows\system32\
Local System Account ( cont. ) • It is a member of the local administrators group ( Table 4-8 ) • It has the right to enable virtually every privilege ( Table 4-9 ) ( Chapter 8 describes the use of each privilege ) • Can full access most files and registry keys
Local System Account ( cont. ) • Run with the default user profile in HKU\.DEFAULT • When a system is a member of a Windows domain , the service will be automatically authenticated on other machines . • Can specify the shares and pipes on a particular computer that permit null sessions
Network Service Account • Is intended for used by services that wish to authenticate to other machines on the network • Difference to local system account : • Less privileges ( Ex : Can’t access device driver ) • Use the network service account’s profile in HKU\S-1-5-20 which is load from \Documents and Settings\NetworkService • Ex : DNS client
Local Service Account • Virtually identical to network service account • Difference to network service account : • Only can access network resources that allow anonymous access • Use the local service account’s profile in HKU\S-1-5-19 which is load from \Documents and Settings\LocalService • Ex : Remote Registry Service 、 Alerter Service 、 LmHost Service
Alternate Account • Because of the restrictions just outlined , some services need to run with the security credentials of a user account • Can configure in Windows Services MMC : Services snap-in → right-click on a service → select Properties → Log On tab → This Account option ( Figure 4-10 )
Interactive Services • Another restriction for services running under the local system , local service , and network service accounts is that they can’t display dialog boxes or windows on the interactive user’s desktop . • This limitation is a consequence of the way Windows subsystem assigns service processes to window stations.
Interactive Services ( cont. ) Terminal Service Environment
Interactive Services ( cont. ) Terminal Service Environment …… Console Session ( 0 ) Session 1 Session N
Interactive Services ( cont. ) Terminal Service Environment …… Console Session ( 0 ) Session 1 Session N Windows Station Windows Station Windows Station Windows Station
Interactive Services ( cont. ) Terminal Service Environment …… Console Session ( 0 ) Session 1 Session N Windows Station Windows Station Windows Station Windows Station Desktop
Interactive Services ( cont. ) Console Session ( Session 0 ) WinSta0 Service-0x0-3e7$ Service-0x0-X$ X is logon identifier Visible All interactive processes Invisible Service run with local system account Invisible Service run with other accounts
Interactive Services ( cont. ) • Since services aren’t running on the visible window station , they can’t receive input from a user or display windows on the console • Exception : • Special flag is set on MessageBox call : • MB_SERVICE_NOTIFICATION : message boxwill always display at interactive windows ( forced ) • MB_DEFAULT_DESKTOP_ONLY : message boxwill display on default desktop of the interactive window station
Interactive Services ( cont. ) • Set service Type registry value as 「SERVICE_INTERACTIVE_PROCESS」 : • It must be run without user-defined account • SCM will associate the service with WinSta0 rather than other non-interactive windows station • However , Microsoft discourages running interactive services , especially in the local system account
Install New Service Application call CreateService in Advapi32.dll and tell SCM
Install New Service ( cont. ) SC_HANDLE WINAPI CreateService ( __in SC_HANDLE hSCManager, __in LPCTSTR lpServiceName, __in_opt LPCTSTR lpDisplayName, __in DWORD dwDesiredAccess, __in DWORD dwServiceType, __in DWORD dwStartType, __in DWORD dwErrorControl, __in_opt LPCTSTR lpBinaryPathName, //error in textbook p.212 __in_opt LPCTSTR lpLoadOrderGroup, __out_opt LPDWORD lpdwTagId, __in_opt LPCTSTR lpDependencies, __in_opt LPCTSTR lpServiceStartName, __in_opt LPCTSTR lpPassword );
Install New Service Application call CreateService in Advapi32.dll and tell SCM
Install New Service ( cont. ) Application call CreateService in Advapi32.dll and tell SCM SCM create and define a new registry key under HKLM\SYSTEM\CurrentControlSet\Services
Install New Service ( cont. ) Application call CreateService in Advapi32.dll and tell SCM SCM create and define a new registry key under HKLM\SYSTEM\CurrentControlSet\Services
Install New Service ( cont. ) Application call CreateService in Advapi32.dll and tell SCM SCM create and define a new registry key under HKLM\SYSTEM\CurrentControlSet\Services Application use StartSevice function or ask user to reboot the system to initialize service when start-up
Install New Service ( cont. ) • If a service needs to store configuration information that is private to the service , the convention is to create a subkey named Parameters under its service key and then store the configuration information in values under that Parameters subkey • SCM only access Parameters when the service is to be deleted
SrvAny Tool • If you have a program that you want to run as a service , you need to modify the startup code to conform to the requirements for services • You can use the SrvAny tool in the Windows Resource Kits . SrvAny enables you to run any application as a service • SrvAny don’t have share-process Type value
SrvAny Tool ( cont. ) A program want to start as service through SrvAny
SrvAny Tool ( cont. ) A program want to start as service through SrvAny SrvAny start , tell SCM SrvAny is hosting a particular service
SrvAny Tool ( cont. ) A program want to start as service through SrvAny SrvAny start , tell SCM SrvAny is hosting a particular service SCM send start-up command to SrvAny
SrvAny Tool ( cont. ) A program want to start as service through SrvAny SrvAny start , tell SCM SrvAny is hosting a particular service SCM send start-up command to SrvAny SrvAny start program as child process , give program a copy of SrvAny’s access token and a reference to the same Windows Station
Start a Service • Install a new Service • Initialize the Service Control Manager ( SCM ) and Local Security Authority Subsystem ( LSASS ) • Service Control Manager ( SCM ) start a service
Initialize Service Control Manager I/O Manager load boot-start and system-start to \Driver
Initialize Service Control Manager ( cont. ) I/O Manager load boot-start and system-start to \Driver Winlogon.exe start SCM and LSASS
Initialize Service Control Manager ( cont. ) I/O Manager load boot-start and system-start to \Driver Winlogon.exe start SCM and LSASS SvcCtrlMain create non-signaled SvcCtrlEvent_A3752DX and call ScCreateServiceDB
Initialize Service Control Manager ( cont. ) I/O Manager load boot-start and system-start to \Driver Winlogon.exe start SCM and LSASS SvcCtrlMain create non-signaled SvcCtrlEvent_A3752DX and call ScCreateServiceDB ScCreateServiceDB load HKLM\SYSTEM \CurrentControllSet\Control\ServiceGroupOrder\List to service database
Initialize Service Control Manager ( cont. ) ScCreateServiceDB load HKLM\SYSTEM \CurrentControllSet\Control\ServiceGroupOrder\List to service database ScCreateServiceDB load and associate HKLM \SYSTEM\CurrentControllSet\Services to service database
Initialize Service Control Manager ( cont. ) ScCreateServiceDB load HKLM\SYSTEM \CurrentControllSet\Control\ServiceGroupOrder\List to service database ScCreateServiceDB load and associate HKLM \SYSTEM\CurrentControllSet\Services to service database SvcCtrlMain call ScGetBootAndSystemDriverState to save driver name to ScFailedDrivers by PnP_DeviceList
Initialize Service Control Manager ( cont. ) SvcCtrlMain call ScGetBootAndSystemDriverState to save driver name to ScFailedDrivers by PnP_DeviceList SCM register shutdown handler for console application and SCM itself