Windows 11 & Server 2022 Services Deep Dive: Part 1 - A Technical Journey

TechSavvyProductions
171 followers
17 Video Views·Oct 31, 2024
Windows Services are critical software carefully designed to provide the functionality to applications, network services, and the operating system. Windows Services are *.dll files often executed in a “service host” process called svchost.exe Windows services are vectors of attack by malicious actors attempting to gain privilege elevation on the operating system. We will look at how services are authenticated; privileges are restricted and run in a unique session environment. A review of the tools to interact with services, including GUI, command-line, and PowerShell. We will focus on security in part 1 and part 2 on practical concepts and troubleshooting.
Hello, my name is Lowell Vanderpool and this channel is dedicated to IT students,
IT professionals, and anyone who enjoys learning technical subjects.
Our presentation and demonstration today is going to be covering Windows Services.
We're going to look at Windows 11 and Server 2022 and we're going to look at this diverse
set of modular software that sits on top of the kernel. It provides this very broad set of
functions to applications, to network, to just about everything that we need our operating
system to do. Now, I just finished a video comparing Windows 11 and Server 22 and we
looked at the fact that Windows 11, which is a thick client, has over 200 reinstalled services
compared to its server side 2016, 2019, 2022. And we'll talk about server core has plus or minus
56 services pre-installed, quite a bit different, almost one-fourth of the amount of services on a
server versus on a client. Now, on a server core, you don't have a GUI. So, with the command prompt,
as you see in the graphic, I'm using the command sequery and then I'm using the redirect, the
greater than symbol, and redirecting that query output to a text file called service-list.txt.
And I'm just putting in the administrator's folder. And that allows you to quickly look at
any services on your Windows server core. Now, just because you have all these services
installed on your operating systems doesn't mean they're all running. So, you can use this very
nice little PowerShell that will quickly allow you to display all the services that are running
right now in your operating system. You can use this in Windows 11 and Server Core. And this
PowerShell is in our video notes that you can download in our video description. Running
services are really the ones that are impacting your system. Microsoft works hard at making sure
that unneeded services are not running on your operating system because they do impact the
system. So, I'm going to go to my Windows 11, use my Windows R to launch the run command,
and I'm going to type in services.msc, which is going to launch a GUI interface in my service
control manager. So, let's go ahead and do that. And this allows me to see all my services and
their status and how to configure and manage them. Most of these services, about 90 percent
on any one given box is probably going to be created and installed by Microsoft. You don't
have a lot of problem with those services. I won't say you won't have any, but most cases,
the Microsoft created and installed services are not so much your big problem. Now, as you add
applications, third parties also take advantage of this concept of services and they will also
install services. And it's important for us to be able to find those third party services and look
at them and troubleshoot them. So, let me show you a quick way to go and identify what services are
third party. So, I'm going to go back to my run command, Windows R, and this time I'm going to
type in msconfig. Now, the msconfig tool, we don't use it a lot, but under the services tab,
I can see all my services that are running or installed right now, and I can come down to hide
all Microsoft services. So, with one click, I now have all my third party services right before me.
So, I can go in and one at a time disable some of these third party services and see if they're
the problem for HP printing subsystem that's running on this, or possibly I've got Firefox
on there and something's going wrong with Firefox. This is a very handy tool to quickly get to those
third party services. So, I've taken my browser to Windows System Terminal site. This is a series
of utilities from Microsoft, and I'm going to download Process Explorer. Now, I've downloaded
the entire suite here in my downloads folder, and I'm going to right mouse click, and I'm going to
run this tool as an administrator. And we're going to look at the Service Control Manager.
I've launched Process Explorer so that we can look at the relationships between processes that are
running in user mode. Process Explorer is now showing me my operating system, and this is all
user mode. Process Explorer reveals user mode to the tech, and I can see my critical services at
the top. And down here, I see my WinInit, which is my Windows initiation process. It launched a child
process called services.exe. This is my Service Control Manager, and we have lots of tools that
interact with this process so that we can manage all the services that are installed on our Windows
operating system. Now, Mark Russinovich, who wrote this tool, chose in his options, we can configure
colors. And in Process Explorer, all services will be this pinkish color. You'll see we have a lot
of services, and we can quickly identify them because they're a color pink. So, this is really
nice and easy for us to quickly identify what processes are services and which are not. So,
Microsoft provides a variety of tools to interface with your Service Control Manager, your services.exe
process. It has a GUI interface, the one you're seeing right now on the slide, and that is
services.msc. That gives us a GUI interface to configure and work with our services. There's also
a command line tool called sc, pretty simple to remember that one. And then there's some PowerShell
commandlets that we can also use to work with our services. Now, the sc command is very powerful,
but make sure you've got elevated credentials in a command prompt before you try to use the sc
command. It basically allows you to do just about anything you can do in the GUI you can do at the
command prompt. And of course, Microsoft provides a good support through PowerShell to also do the
same thing, so that you can automate your management of services using PowerShell.
Now, Mark Rusanovich, who also wrote those system internal tools, wrote a tool called PSService. It
has additional features that the sc command does not provide. It enables you to log on to a remote
system using a different user account. It allows a unique service search capability. It also displays
and configures and shows dependencies, much like the sc command, but it does have additional
features. Now, if you look at this architectural diagram, you'll see that services and your
applications that you use and system processes are all in user space. But there's a big difference
between Microsoft Word that you launch and a browser that you run and services, even though
they're in user mode. Number one, services are controlled by the service control manager.
Services are launching early in the boot process. They do not require you to log on to your desktop
or log on to a server. Second of all, they have special mechanisms which they authenticate.
Another big difference is that most of those services are running in what's known as session
zero. That isolates them from your applications and those services that are running.
Let's briefly look at services and sessions. In the days of XP, this is the way it was done.
We created a session zero. These various developer concepts like Windows stations and desktops,
we would boot our services into a session zero and then the user would log on. He was in session
zero and his apps were in session zero. We had everybody in the same session. If malicious code
was downloaded in the browser, it could interact with services. We had privilege escalation and
we had problems. Microsoft, when it launched Vista, decided to make a clean break at Vista.
What they did was they created a session zero with the workstation, the desktop, and booted
all the services in session zero. Then when the user logged on, a new session was created.
They've got their Windows station, their desktop, and their apps were now in session one,
separated and isolated from session zero. Here's another picture of that same thing.
Here we have session zero and the services being launched under that session. Then we have session
one when the user logs on and we can see there's a separation between user applications versus
services. Services need accounts in order to run. Service accounts are special types of non-human
privileged accounts used to execute applications, automated services, virtual machine instances,
and other processes. We're going to look at a Windows 11. I'm going to the Start button and
right mouse click and go ahead and launch Task Manager. Let's say we're having a problem with
Clipboard. Clipboard keeps crashing. Of course, if you use Word and PowerPoint, you need Clipboard.
I'm going to come down here and look for the service that runs Clipboard. Here I see a svchost
and it has the Clipboard user service in it. Notice the services have this gear icon on them.
I have an arrow here and I'm going to open that up. Here I can see the svchost file that's actually
running the service. Down here is the name of the service. The first thing I can do is right
mouse click and go to Details tab and it takes me to the Details tab in Task Manager. That's my
svchost that's running my Clipboard service that crashes on me every time and it's process 8124.
I can also here go ahead and go to Services and it now takes me to the Service tab and I can see
the actual Clipboard service 8124 and it is running. If that still hasn't told me who's
logged on, so I'm going to right mouse click, go to Open Services. This launches the services.msc,
the GUI interface to Service Control Manager. I'm going to slide down and find my Clipboard
user service. Here I can see the Clipboard user service and you can come over here to the column
logged on as local system. That's a special account. Now I can maybe dig in and start
troubleshooting. That was a great example of why I don't like Task Manager as a tech. I prefer
either services.msc or Process Explorer. You saw it was real kludgy to work with services with
Task Manager. Every account in Windows has privileges assigned to that account and you can
see this is my, I'm logged on and at the command prompt I type in whoami forward slash priv or
privilege and I've shown you the list of privileges that I had as I logged on. It is very important to
understand the privileges and rights we give to services because that's the fundamental
construct for security in our operating system. Now most of us are familiar with the system account
which is a very high privileged account in the Windows operating system. The system account is
used by the OS and services that run in Windows. It's created when you install Windows 11 and
Server 2022. It has the capability to sign internally. It's an internal account. It does
not show up in User Manager. You can see the system account as you see in the graphic when
you're dealing with NTFS permissions. Now one of the special accounts that services use to
authenticate them is LocalSystem. It's a predefined local account used by the Service Control Manager.
It has extensive privileges on the local computer. So if I'm hacking a service, I want a service that
is logged on with LocalSystem. It acts as the computer on the network. The Service Control
Manager can modify the LocalSystem to have less rights such as network restricted rights. Here's
an example of a dialog box showing the LocalSystem account under the Logon tab. Now I've used Process
Explorer to look at the properties of my antivirus service and you can see it is running under System
Account or Service Control Manager calls it LocalSystem account. This account does not have
a password. The account is not associated with any logged on user. So here you see an example of
the Service Control Manager modifying the LocalSystem special account with these network
restricted rights. Another special account that we use to run services is called NetworkService.
This account is predefined by the local account and is used by the Service Control Manager.
The account is not recognized by the security subsystem at all. It has minimum privileges on
the local computer and acts as a computer on the network. Here's a dialog box showing network
services as the account used for that service. Now another special account that we use to run
services is called LocalService. It is used by the Service Control Manager as minimum privileges.
It presents anonymous credentials on the network. The Service Control Manager can modify this
account so that it has no network rights at all. It can also modify it so it has network restricted
rights. So here's a service in the logon tab and you can see LocalService. Here again I'm showing
you under Process Explorer I'm hovering, mousing over a particular svchost file and in it you can
see the LocalService no network. As you would expect these Windows Service accounts are a
preferred attack service for privilege escalation.
