the windows os’s Basic Terminology - on sessions, Processes, Services, etc.
The vast majority of computer users utilize the Windows OS. Many of these users however, do not realize the nuances and subtle distinctions of various terms their OS uses to identify their inner workings’ components.
It could be confusing for a novice to figure out the various mechanisms that Windows utilizes and the way they differ from one another.
You may have run into terms such as “tasks”, “processes”, “services” and “jobs” and failed to understand the distinctions between them.
The confusion’s root runs more deeply than the ambiguity of the terms however.
The terminology is derivative, and is the outcome, first and foremost, of the Windows OS’s mechanics, its basic principles of operation, and its underlying logic.
The average user’s lack of understanding of the terms, therefore, stems from his/her lack of understanding of the various Windows methods of operation. Again, the various terms are derived from these methods of operation.
For instance, have you ever wondered to yourself , “Suppose I log into a Windows host with my particular user account, run some processes on it and keep the session active/open while accessing the same host with the very same user remotely. Will the new remote session have all of the processes that have been running on the initial session running as well?”
On sessions
The answer is no, typically each session on a Windows OS operates independently. Processes running in one session won't automatically be visible or accessible on another session, even if it's the same user accessing the system remotely. Each session has its own environment and resources. Each session operates independently, and while they share certain aspects like user settings and preferences, they do not automatically share running processes.
One can however hijack an existing active session, meaning that if you’d left your previous session in a “live” state (basically, by not logging off) you could reconnect to it.
But how can one access an existing local session remotely? Won’t it necessarily be a new session?
Generally, that’s correct. When accessing a Windows session remotely, it typically creates a new session rather than accessing the existing local session. In that case, the new remote session won't have direct access to the processes running in the original local session.
But sessions that are not actively being used are not necessarily obsolete, and you could make use of them, and even reconnect to them
Many times, users will choose to lock their session (by pressing the windows key +L) instead of logging off. Also, when logging via RDP into a remote session, many people would simply close the session’s window once they are done working with it, not realizing that they are actually leaving the session in a live, reusable state. It is important to keep in mind that it is possible to close a session window without logging out of it, and to later reconnect to the very same live session, whether locally or remotely (with the TScon executable).
To terminate a session one must log off of it. Period.
If not logged out of, an active session would remain dormant on the computer, and is vulnerable to being hijacked by another active session
The procedure for doing so is as follows.
Sessions labeled as “active” are ones that are currently being used, however any other session labeled as “Disc” is in fact a live session, meaning that its owner-user hasn’t logged out of it, and could potentially be reactivated by connecting to it.
Syntax: tscon /session: <sessionID/session name> /dest:<your own session ID ie. the one you wish to attach the live, inactive session to>
Once reconnected to the same live session, you will find that:
Okay, so that is the case when reconnecting to an old session that hadn’t been logged out of. The next logical question one may ask might be, what persists on distinct sessions of the same user's account?
When logging into a whole new session with the same user account, what carries through?
Most people do know that a user’s permissions will remain the same on all of his/her sessions, but is that the only characterization separating one user’s account from the rest of the OS’s users’ sessions?
When accessing different sessions of the same user’s account on a Windows OS, certain aspects do persist:
However, it's important to stress that this applies to aspects of the user’s environment and settings, but not to individual processes.
Each session operates independently in terms of running processes, meaning that you won't see processes initiated in one session automatically appear in another session, even for the same user.
Processes
A process is basically an action performed or initiated on the OS. It has certain representations (such as a process ID) that can be accessed (for example by the task manager), and it uses up a certain amount of the hardwares resources.
As mentioned, processes running in the background within a user session will continue to run when accessing that session remotely, so in that sense, the state of those processes does persist.
However, new processes initiated in one session won't automatically be visible or accessible in another session of the same user.
Hiding processes
To make processes ( that are either run by a service or independently) more discreet, you can employ several techniques to enhance their privacy and security:
svchost.exe
svchost.exe is a legitimate system process on the Windows operating systems that hosts multiple Windows services. It's a common target for malware because it's an essential system process, and it's normal to see multiple instances of svchost.exe running simultaneously.
svchost.exe processes are a common occurrence and are often used to hide other processes.
Svchost.exe characteristics:
To mitigate the risks associated with svchost.exe and prevent abuse by malware, it's essential to:
On the flip side, if I want to create a service and have it run by the svchost.exe, thereby somewhat hiding it, how would I go about it?
if you want your service to run under svchost.exe, you would include it as a DLL. svchost.exe hosts services implemented as DLLs, so your service code would need to be compiled into a DLL format. Then, you would register your service DLL with the SCM, specifying the appropriate configuration settings and grouping information.
Creating a service to run under svchost.exe involves configuring the service appropriately and registering it with the Service Control Manager (SCM) to be hosted by svchost.exe. Here's a general outline of the steps involved:
It's important to note that while running a service under svchost.exe may provide some level of obscurity, it does not guarantee complete invisibility. Malware and security researchers are aware of this technique, and sophisticated monitoring tools can still detect and analyze services running under svchost.exe.
services
Certain situations do call for non-session dependent processes, processes that will carry through between separate sessions.
Moreover there are situations where you’d like processes to persist across all of the active sessions, regardless of the users’ accounts.
This is where services come into play.
The very definition of a service, as opposed to a process, is that it persists on different sessions
Services are designed to run in the background and can persist across different user sessions and system reboots. They are intended to provide functionality or perform tasks that operate independently of any particular session.
Once started, a non-user specific service will continue running until it is explicitly stopped or the system is shut down, regardless of which user is logged in or whether any user session is in an active state at all.
However, If a service is configured to run under a specific user account and is set to start automatically or manually, it will persist across different sessions for that user and any other logged in users, but under the configured user context and permissions, regardless of which user is currently logged in. . Once started, it will continue running until it is stopped or the system is restarted, regardless of which session is currently active nor of which user is currently logged on.
When a service is initialized, it typically spawns one or more processes to carry out its tasks. Each service can have one or more associated processes responsible for executing the service's code and handling its functionality
So the initialization of a service usually involves the creation of one or more processes to execute the service's code. These processes are spawned by the service manager (services.exe) when it starts the service.
To create a service on a Windows system, you would typically follow these steps:
By following these steps, you can create a service that operates in the context of a specific user account rather than a session. This allows the service to perform tasks on behalf of that user, even if the user is not currently logged in.
When creating a service with the sc command you can also specify arguments for the executable. These arguments are passed to the executable when the service is started and you include them after the executable's path in the binPath parameter when creating the service. Here's the general syntax:
sc create <SERVICE_NAME> binPath= <"EXECUTABLE_PATH> <”ARGUMENTS">
For example, if you want to create a service named "MyService" that runs my_executable.exe with the arguments -arg1 -arg2, you would use the following command:
sc create MyService binPath= "my_executable.exe -arg1 -arg2"
This command instructs the system to start my_executable.exe with the specified arguments when the "MyService" service is started. Make sure to enclose the executable path and arguments in double quotes if they contain spaces or special characters.
So to reiterate:
The way you'd limit a service to a specific user’s context and permissions is to assign it to a specific user or create it as said user.
When you create or configure a service, you can specify the user account under which the service should run. This is done during the service creation process or by modifying the service properties after it's created.
Here's how you can assign a service to a specific user account:
Syntax: sc create <ServiceName> binPath= <"C:\Path\to\Your\Service.exe"> obj= <"Domain\User"> password= <"UserPassword">
By assigning the service to a specific user account, you ensure that it runs in the context of that user, with the associated permissions and privileges.
Hiding services
You may want to run your own services discreetly without other users being able to query it or figure out what it's doing for various reasons.
If you want a service to run discreetly on your sessions you can take several measures to enhance its privacy and security:
This makes it less conspicuous to other users.
To configure a service to be hidden, you can set its service type to SERVICE_TYPE_NO_DISPLAY using the sc command-line tool. When a service is marked as "no display," it will not appear in the Services management console (services.msc) and will be hidden from most users. However, it may still be visible to users with administrative privileges and can be queried using certain command-line tools.
Syntax: sc config <ServiceName> type= own type= interact type= kernel start= demand
Explanation of parameters:
This configuration hides the service from the Services management console (services.msc). However, it may still be visible to certain command-line tools such as tasklist and sc query. To further conceal the service from these tools, additional measures may be required, such as modifying access permissions or employing advanced security techniques..
By implementing these measures, you can enhance the privacy and security of the service, making it more difficult for other users to query or discern its activities.