Skip to content
EvanMcBroom edited this page Mar 14, 2024 · 7 revisions

Security Package Manager

The security package manager (SPM) is an undocumented component of LSA. The SPM manages both the authentication package and security package DLLs that LSA loads. As far as I am aware, the SPM has not been previously written about.

As far back as NT 3.5, LSA has provided an API for interacting with authentication packages (e.g., the AU API) over LPC port \\LsaAuthenticationPort. Clients could interact with the API by either using an abstracted Win32 function (ex. LsaLookupAuthenticationPackage) or by submitting data to the port formatted as an LSAP_AU_API_MESSAGE structure. The ntoskrnl.exe has always provided Win32 function equivalents which are internally handled by the ksecdd.sys driver. The ksecdd.sys driver currently implements this functionality as an NTOS extension host (e.g., SepAuthExtensionHost).

Microsoft later added an SPM API which extends the AU API. The SPM API has been identified in NT 5.2 but may have existed as early as NT 5.0. Microsoft provides Win32 and ntoskrnl.exe exports for some SPM APIs but clients must submit data to the SPM directly to interact with all of the API’s functions.

Data for SPM API calls are formated as an SPM_LPC_MESSAGE structure. The first members of the LSAP_AU_API_MESSAGE and SPM_LPC_MESSAGE structures are binary compatible up until the structure member that identifies which API number is to be called. That allows the SPM to know which API is being requested and which structure definition should be used to interpret the remainder of the data.

Oddly, Microsoft continued to use the same LPC port for communication in NT 6.0 despite the introduction of ALPC. The APIs have only been updated in NT 6.1 when the SSPI RPC interface was added to LSA.

The LPC port was removed in NT 6.1 and clients must now use the SspirCallRpc operation of the SSPI RPC interface to send data directly to either API. Although the communication is now facilitated via RPC, the code for handling API requests has not been updated and still expects data to be formatted as an LSAP_AU_API_MESSAGE or SPM_LPC_MESSAGE structure. Additionally, some API functions were removed to become SSPI RPC operations while others were removed entirely. The only API function that was added was ChangeAccountPassword. Other than the API updates for NT 6.1 and slight name changes for functions over the years both APIs have remaned stable.

SPM Security

LsapGetClientInfo checks for:

  • userPrincipalName capability which is documented as required for GetUserNameEx.

Authentication API (AU API)

Each AU API is linked to the documentation for the Win32 API it facilitates.

Table 1. AU APIs Pre-NT 6.1
Id Message Type CLI Support NT Version Notes

0x00

LookupPackage

>=3.5

0x01

LogonUser

>=3.5

Moved to the SSPI RPC interface

0x02

CallPackage

>=3.5

The main API used by LSA whisperer

0x03

DeregisterLogonProcess

>=3.5

0x04

Reserved

>=6.1

Table 2. AU APIs Post-NT 6.1
Id Message Type CLI Support NT Version Notes

0x00

LookupPackage

>=6.1

0x01

CallPackage

>=6.1

The main API used by LSA whisperer

0x02

DeregisterLogonProcess

>=6.1

0x03

Reserved

>=6.1

SPM API

Each SPM API is linked to the documentation for the higher level API it facilitates (ex. Win32) if identified. The SPM APIs that are not implemented are marked by an ❌. The remainder are documented here.

Table 3. SPM APIs Pre-NT 6.1
Id Message Type CLI Support NT Version Notes

0x05

GetBinding

>~5.2

0x06

SetSession

>~5.2

0x07

FindPackage

>~5.2

0x08

EnumPackages

✔️

>~5.2

0x09

AcquireCreds

>~5.2

Moved to the SSPI RPC interface

0x0A

EstablishCreds

>~5.2

Later removed

0x0B

FreeCredHandle

>~5.2

Moved to the SSPI RPC interface

0x0C

InitContext

>~5.2

Later removed

0x0D

AcceptContext

>~5.2

Later removed

0x0E

ApplyToken

>~5.2

Moved to the SSPI RPC interface

0x0F

DeleteContext

>~5.2

Moved to the SSPI RPC interface

0x10

QueryPackage

>~5.2

0x11

GetUserInfo

✔️

>~5.2

0x12

GetCreds

>~5.2

Later removed

0x13

SaveCreds

>~5.2

Later removed

0x14

QueryCredAttributes

>~5.2

0x15

AddPackage

>~5.2

0x16

DeletePackage

>~5.2

Never implemented and later removed

0x17

EfsGenerateKey

>~5.2

0x18

EfsGenerateDirEfs

>~5.2

0x19

EfsDecryptFek

>~5.2

0x1A

EfsGenerateSessionKey

>~5.2

0x1B

QueryContextAttr

>~5.2

Renamed to QueryContextAttributes

0x1C

Callback

>~5.2

0x1D

LsaPolicyChangeNotify (2nd API)

>~5.2

Facilitates two Win32 APIs

0x1E

GetUserNameX

>~5.2

Moved to the SSPI RPC interface

0x1F

AddCredential

>~5.2

Renamed to AddCredentials

0x20

EnumLogonSession

✔️

>~5.2

Renamed to EnumLogonSessions

0x21

GetLogonSessionData

✔️

>~5.2

0x22

SetContextAttr

>~5.2

Renamed to SetContextAttributes

0x23

LookupAccountSidX

>~5.2

Moved to the SSPI RPC interface

0x24

LookupAccountNameX

>~5.2

Renamed to LookupAccountName

0x25

LookupWellKnownSid

>~5.2

0x26

Reserved

>~5.2

✏️
The SPM API has been identified in NT 5.2 but may have existed as early as NT 5.0.
Table 4. SPM APIs Post-NT 6.1
Id Message Type CLI Support NT Version Notes

0x04

GetBinding

>=6.1

0x05

SetSession

>=6.1

0x06

FindPackage

>=6.1

0x07

EnumPackages

✔️

>=6.1

0x08

QueryPackage

>=6.1

0x09

GetUserInfo

✔️

>=6.1

0x0A

QueryCredAttributes

>=6.1

0x0B

AddPackage

>=6.1

0x0C

EfsGenerateKey

>=6.1

0x0D

EfsGenerateDirEfs

>=6.1

0x0E

EfsDecryptFek

>=6.1

0x0F

EfsGenerateSessionKey

>=6.1

0x10

Callback

>=6.1

0x11

QueryContextAttributes

>=6.1

0x12

LsaPolicyChangeNotify (2nd API)

>=6.1

Facilitates two Win32 APIs

0x13

AddCredentials

>=6.1

0x14

EnumLogonSessions

✔️

>=6.1

0x15

GetLogonSessionData

✔️

>=6.1

0x16

SetContextAttributes

>=6.1

0x17

LookupAccountName

>=6.1

0x18

LookupWellKnownSid

>=6.1

0x19

SetCredAttributes

>=6.1

0x1A

ChangeAccountPassword

>=6.1

0x1B

Reserved

>=6.1

EfsDecryptFek

May only be called from kernel mode. Used by the EFS file system filter to recover the File Encryption Key (FEK) for a provided $EFS attribute for a file being decrypted.

EfsGenerateDirEfs

May only be called from kernel mode. Used by the EFS file system filter to generate an encrypted files system (EFS) stream for a directory being encrypted.

EfsGenerateKey

May only be called from kernel mode. Used by the EFS file system filter to generate a File Encryption Key (FEK) and encrypted files system (EFS) stream for a file being encrypted.

EfsGenerateSessionKey

May only be called from kernel mode. Generates and returns a random 8 byte value. The value was used by the EFS file system filter driver as a DES key that was used when decrypting FSCTL input buffers.

FindPackage

Resolves a package ID to a package name.

GetBinding

Returns the full path or DLL name for a specified package ID.

LookupWellKnownSid

Calls CreateWellKnownSid with the provided input and returns the result.

SetSession

Set an option for the LPC/ALPC session of the current client connection with LSA.

Id Option Description

0x1

Set status

Returns 0

0x2

Add workqueue

Originally added a workqueue to support threaded SPM calls. The option was later removed

0x3

Remove workqueue

Never implemented

0x4

Get dispatch

Returns the address of lsasrv!DispatchAPIDirect when called from LSA. Otherwise return access denied

Clone this wiki locally