Skip to content
EvanMcBroom edited this page Aug 10, 2023 · 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)

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

0x03

DeregisterLogonProcess

>=3.5

0x04

>=6.1

Not used

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

0x00

LookupPackage

>=6.1

0x01

CallPackage

>=6.1

0x02

DeregisterLogonProcess

>=6.1

0x03

>=6.1

Not used

CallPackage

Facilitates the LsaCallAuthenticationPackage API and is the primary API used by LSA Whisperer.

DeregisterLogonProcess

Facilitates the LsaDeregisterLogonProcess API.

LogonUser

Facilitates the LsaLogonUser API.

LookupPackage

Facilitates the LsaLookupAuthenticationPackage API.

SPM API

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

Later removed

0x17

EfsGenerateKey

>~5.2

0x18

EfsGenerateDirEfs

>~5.2

Replaced by EfsGenerateKey

0x19

EfsDecryptFek

>~5.2

Replaced by EfsGenerateKey

0x1A

EfsGenerateSessionKey

>~5.2

Replaced by EfsGenerateKey

0x1B

QueryContextAttr

>~5.2

Renamed to QueryContextAttributes

0x1C

Callback

>~5.2

0x1D

LsaPolicyChangeNotify

>~5.2

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

>~5.2

Not used

✏️
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

Named EfsGenerateFek in NT 6.1

0x0D

EfsGenerateKey

>=6.1

Named EfsGenerateFek in NT 6.1

0x0E

EfsGenerateKey

>=6.1

Named EfsGenerateFek in NT 6.1

0x0F

EfsGenerateKey

>=6.1

Named EfsGenerateFek in NT 6.1

0x10

Callback

>=6.1

0x11

QueryContextAttributes

>=6.1

0x12

LsaPolicyChangeNotify

>=6.1

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

>=6.1

Not used

AcceptContext

Facilitates the AcceptSecurityContext API.

AcquireCreds

…​

AddCredentials

…​

AddPackage

Facilitates the AddSecurityPackageW API.

ApplyToken

…​

Callback

…​

DeleteContext

Facilitates the FreeContextBuffer API. Not to be confused with the DeleteSecurityContext API which frees local data associated with a security context.

DeletePackage

Microsoft likely intended this to facilitate the DeleteSecurityPackageW API, but both that API and it’s SPM counterpart were never completed. That is likely why the API was removed from the SPM in the NT 6.1 update.

EfsDecryptFek

Decrypts or recovers an encrypted files system (EFS) File Encryption Key (FEK) for a provided $EFS attribute for a file.

EfsGenerateDirEfs

…​

EfsGenerateKey

Generate a File Encryption Key (FEK) and encrypted files system (EFS) stream for a file being encrypted.

EfsGenerateSessionKey

…​

EnumLogonSessions

Facilitates the LsaEnumerateLogonSessions API.

EnumPackages

Facilitates the `EnumerateSecurityPackagesW ` API.

EstablishCreds

…​

FindPackage

…​

FreeCredHandle

Frees and credential handle.

GetBinding

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

GetCreds

…​

GetLogonSessionData

Facilitates the LsaGetLogonSessionData API.

GetUserInfo

…​

GetUserNameX

Facilitates the GetUserNameExW API.

InitContext

Facilitates the InitializeSecurityContext API.

LookupAccountName

Stub to call LsarLookupNames3.

LookupAccountSidX

…​

LookupWellKnownSid

…​

LsaPolicyChangeNotify

Facilitates the LsaUnregisterPolicyChangeNotification API.

QueryContextAttributes

…​

QueryCredAttributes

…​

QueryPackage

Facilitates the QuerySecurityPackageInfoW API.

SaveCreds

…​

SetContextAttributes

…​

SetSession

…​

Clone this wiki locally