Post

Logon Sessions and Access Tokens

What LSASS creates at the end of every logon: the logon session, identified by a LUID, and the access tokens that reference it. Their contents (SIDs, group attributes, privileges, integrity level), the UAC split token, the well-known and virtual-account sessions found on every system, and how defenders use logon IDs to correlate telemetry.

Logon Sessions and Access Tokens

Introduction

The LSASS article ended with the last step of a successful logon: LSASS creates a logon session and an access token. These two objects are the link between authentication and authorization. Authentication packages such as NTLM and Kerberos answer the question who is this?. From then on, every access check made by the Security Reference Monitor in the kernel answers the question what may this process do? using only the token.1

This article describes both objects, how they relate to each other, how User Account Control (UAC) splits them, and how they appear in the telemetry a defender collects.

Logon sessions

When they are created

A logon session is created every time a security principal logs on, interactively or not. A user at the console, an RDP connection, a service starting under its account, a scheduled task, and a network connection to a file share each produce one. The session is created by LSASS when LsaLogonUser succeeds, and it lasts until the last token that references it is closed.2

A logon session holds the identity established by the authentication:

Field Content
Logon ID A locally unique identifier (LUID), unique on the system until the next reboot
User name and SID The authenticated principal
Groups The group SIDs resolved at logon
Logon type How the logon happened: interactive, network, service and so on
Authentication package The package that validated it: Negotiate, Kerberos, NTLM, CloudAP
Logon time, logon server When, and against which authority
Session The terminal (Remote Desktop) session the logon belongs to

The authentication packages also attach their credential material to the logon session, which is what enables single sign-on for the processes running in it.3

Logon session is not terminal session. The Session column of tools such as Process Explorer is the terminal session (session 0 for services, 1 and above for interactive desktops). A single terminal session contains many logon sessions: the user’s, those of Desktop Window Manager and font driver host, and those created by every runas or network logon.

Logon types

Type Name Example
2 Interactive Console logon
3 Network Access to a file share or another network resource
4 Batch Scheduled task
5 Service Service started under an account
7 Unlock Workstation unlock
8 NetworkCleartext Network logon with the password sent to the server, for example IIS basic authentication
9 NewCredentials runas /netonly: local identity unchanged, new credentials for outbound connections
10 RemoteInteractive Remote Desktop
11 CachedInteractive Interactive logon with cached domain credentials, no DC reachable

The logon type is recorded in every logon event.4

Many sessions on a single system

It is normal for a system to host dozens of logon sessions. Some of them have well-known LUIDs and exist from boot:5

LUID Account SID
0x3E7 NT AUTHORITY\SYSTEM (shown as the computer account, e.g. WORKGROUP\HOST$) S-1-5-18
0x3E4 NT AUTHORITY\NETWORK SERVICE (network identity: the computer account) S-1-5-20
0x3E5 NT AUTHORITY\LOCAL SERVICE S-1-5-19
0x3E6 Anonymous logon S-1-5-7

Others belong to virtual accounts, which the system creates on demand for specific components:6

Account SID prefix Created for
Window Manager\DWM-n S-1-5-90-0 The Desktop Window Manager of terminal session n
Font Driver Host\UMFD-n S-1-5-96-0 The user-mode font driver host of terminal session n
NT VIRTUAL MACHINE\{VM GUID} S-1-5-83-1 Each Hyper-V virtual machine worker process
NT SERVICE\name S-1-5-80 Services running with a service SID or as a virtual account

An interactive user with administrative rights typically appears twice, with two different LUIDs and the same SID. The reason is UAC, described below.

Access tokens

Tokens and logon sessions

An access token is a kernel object that describes the security context of a process or a thread. Every token records the LUID of the logon session it belongs to (the AuthenticationId), and a single logon session is usually referenced by many tokens (Figure 1).1 When the user’s shell starts a program, the new process receives a copy of the parent’s primary token, and so every process the user runs points back to the same logon session.

flowchart TB
    subgraph LS["Logon session"]
        direction LR
        LID["Logon ID (LUID)"]
        USR["User name"]
        SID["SID"]
        GRP["Groups"]
    end
    LS --> T1["Token: explorer.exe<br/>privileges"]
    LS --> T2["Token: notepad.exe<br/>privileges"]
    LS --> T3["Token: browser<br/>privileges"]
    LS --> T4["Impersonation token<br/>of a server thread"]

Figure 1. One logon session referenced by several access tokens.

Tokens come in two kinds:

  • A primary token is attached to a process and defines its security context.
  • An impersonation token is attached to a thread, typically in a server, so that it can act on behalf of a client. Its impersonation level (Anonymous, Identification, Impersonation, Delegation) limits what the server can do with the client’s identity.7

Token contents

The most relevant fields of a token are:1

Field Content
User The SID of the user
Groups Group SIDs, each with attributes (see below)
Privileges System-wide rights, each enabled or disabled
Integrity level A mandatory label: Low, Medium, High or System
Owner, primary group, default DACL Defaults applied to objects the process creates
AuthenticationId The LUID of the logon session
Session ID The terminal session
Type, impersonation level Primary or impersonation token
Elevation type, linked token UAC information

Group attributes control how a SID takes part in access checks:

Attribute Meaning
Mandatory Always enabled, cannot be disabled
Enabled / Enabled by default Considered when granting access
Deny only Considered only to deny access, never to grant it
Logon ID The logon SID (S-1-5-5-X-Y), unique to the logon session
Integrity The SID is the mandatory integrity label of the token

Privileges are separate from object permissions. They authorize system-wide operations such as shutting down the system (SeShutdownPrivilege), debugging any process (SeDebugPrivilege) or impersonating a client (SeImpersonatePrivilege). A privilege can be present in a token but disabled: the process must enable it explicitly before it takes effect. A privilege that is absent cannot be enabled.8

Experiment: reading the token of a process

The Security tab of Process Explorer shows the token of any process: user and SID, terminal session, logon session LUID, groups with their flags, and privileges.9 For a standard explorer.exe of an administrator it shows, among others:

  • BUILTIN\Administrators with the flag Deny;
  • Mandatory Label\Medium Mandatory Level with the flag Integrity;
  • a short list of privileges, only SeChangeNotifyPrivilege enabled by default.

The same information for the current process is available from the command line:10

1
2
whoami /all          # user, groups with attributes, privileges
whoami /logonid      # logon SID of the current logon session

All logon sessions on the system, with their logon type and authentication package, can be listed with klist sessions or with the Sysinternals LogonSessions tool (run elevated):11

1
2
klist sessions
logonsessions.exe -p    # also lists the processes in each session

UAC and the split token

When a member of the Administrators group logs on interactively with UAC enabled, LSASS creates two logon sessions and two tokens, linked to each other (Figure 2).12

flowchart TB
    L["Interactive logon of an administrator"] --> F
    L --> E
    subgraph F["Logon session A: filtered token"]
        direction TB
        F1["Administrators: deny only"]
        F2["Medium integrity"]
        F3["Reduced privileges"]
    end
    subgraph E["Logon session B: elevated token"]
        direction TB
        E1["Administrators: enabled"]
        E2["High integrity"]
        E3["Full privileges"]
    end
    F <-.->|"linked token"| E
    F --> X["explorer.exe and the processes it starts"]
    E --> Y["Processes started after a consent prompt"]

Figure 2. The UAC split token: two linked logon sessions for one logon.

  • The filtered token is used for the user’s shell and for every process started normally. The Administrators SID is present but marked deny only, the administrative privileges are removed and the integrity level is Medium.
  • The elevated token has the Administrators group enabled, the full set of privileges and High integrity. It is used only when the user approves an elevation prompt; the elevated process therefore runs in a different logon session from its non-elevated parent.

This explains the two entries with the same user and SID in a list of logon sessions. The filtered and elevated tokens are retrievable from each other through the TokenLinkedToken information class, and their status is exposed as the elevation type (Default, Limited, Full).13

The integrity level adds a mandatory check on top of the DACL: a process cannot obtain write access to an object with a higher integrity label, and cannot open processes of a higher integrity level with most access rights. This is what isolates a Medium process from the elevated processes of the same user.14

Telemetry

The logon ID is the key that ties together the security events of a logon, from authentication to the processes it runs.

Event Logged when Fields of interest
46244 A logon session is created Logon ID, Linked Logon ID, Logon Type, Elevated Token, Authentication Package, Impersonation Level, Virtual Account, source address
467215 A new logon received sensitive privileges Logon ID, list of privileges; marks administrative logons
468816 A process is created Logon ID of the subject, Token Elevation Type, Mandatory Label
4634 / 464717 A logon session ends / a user initiated logoff Logon ID, Logon Type
Sysmon 118 A process is created LogonId, LogonGuid, IntegrityLevel, parent process

Analytics worth building:

  • Logon-to-process correlation. Join 4624 and 4688 (or Sysmon 1) on the logon ID to attribute every process to the logon, the source address and the authentication package that produced it.
  • Sensitive privileges. 4672 for accounts that are not expected to be administrators, or administrative logons of type 3 or 10 from unusual sources.
  • Unexpected token context. A process whose logon ID, user or integrity level differs from its parent’s without a corresponding elevation or runas is a sign of token manipulation, catalogued by MITRE ATT&CK as T1134.19
  • Logon type 9. NewCredentials logons are rare in normal administration and keep alternate credentials in the logon session; they deserve review.

Hardening

Control Effect
Least privilege Users and services hold only the group memberships and privileges they need
UAC in Admin Approval Mode Administrators run with a filtered token by default; elevation is explicit and logged12
User Rights Assignment review Restrict sensitive privileges such as SeDebugPrivilege, SeImpersonatePrivilege, SeTcbPrivilege and SeBackupPrivilege to the accounts that require them20
Virtual accounts and service SIDs Run services under dedicated, low-privilege identities instead of SYSTEM or shared accounts
End idle sessions Disconnected but not logged-off RDP sessions keep their logon session and its credential material in LSASS
Protected Users Members’ logon sessions keep no reusable NTLM credentials and have short-lived Kerberos tickets21

Summary

Every logon handled by LSASS produces a logon session, identified by a LUID and carrying the user’s identity, logon type, authentication package and credential material. Access tokens reference the logon session and describe the security context of processes and threads: user and group SIDs with their attributes, privileges, integrity level and UAC information. One logon session is referenced by many tokens, and a system normally hosts many logon sessions: the well-known SYSTEM, LOCAL SERVICE and NETWORK SERVICE sessions, virtual accounts for DWM, font drivers, services and virtual machines, and the users’ own. For administrators, UAC creates two linked logon sessions: a filtered, Medium-integrity token for everyday work and an elevated, High-integrity token used only after consent. For defenders, the logon ID is the thread that links 4624, 4672, 4688 and Sysmon events into a single, attributable story.

References

This post is licensed under CC BY 4.0 by the author.