If a Windows username is created in a [email protected] email syntax, the System.Security.Principal.WindowsIdentity.GetCurrent().Name value returned is in the DOMAIN\UserName syntax.
How does Netplwiz retrieve and display usernames properly in their email syntax? Can that be done for the currently logged in user?
What classes/methods/fields are available for retrieval?
They're more formally referred to as User Principal Name, or UPN for short precisely to avoid confusion with identically-formatted SMTP e-mail addresses.
Nostalgia time!: Back in the days of Windows 2000 I remember the mood and expectation was that UPNs would eventually be mapped to a valid e-mail address and they'd replace NT's
DOMAIN\USERNAME-style logins long before Windows Server 2003 came out - well, that never happened, and despite Microsoft really pushing people to use UPNs in the early 2000s I think they realised it wasn't going to go anywhere by the time Windows 7 came out.(Ghidra speedrun time...)
I noticed that
netplwizuses COM to access and call-out into services that would be resolved at runtime and so it's possible thatnetplwizmay be using some hither-unknown COM interface/service to perform some aspects of name translation, so the function list here is not exhaustive.But moving on to what a straightforward static-analysis can tell us:
Looking at the Imports table, ``netplwiz.dll` directly references dozens of Win32 libraries, and from those I saw these imported funcs that can perform name translation (either searching by UPN or login-name and resolving it to a SID, or vice-versa; or translating between them).
API-MS-WIN-SECURITY-ACTIVEDIRECTORYCLIENT-L1-1-0.DLL::DsCrackNamesWAPI-MS-WIN-SECURITY-LSALOOKUP-L2-1-0.DLL::LookupAccountNameWAPI-MS-WIN-SECURITY-LSALOOKUP-L2-1-0.DLL::LookupAccountSidWAPI-MS-WIN-SECURITY-SDDL-L1-1-0.DLL::ConvertSidToStringSidWDSROLE.DLL::DsRoleGetPrimaryDomainInformationSAMCLI.DLL::NetLocalGroupEnumSAMCLI.DLL::NetLocalGroupGetMembersSAMCLI.DLL::NetUserGetInfoSECUR32.DLL::TranslateNameWThere are other parts of Win32 that can do this too, which
netplziwzdoesn't use, like:NetQueryDisplayInformation.NetUserEnumGetUserNameExWYes.
From the command-line, just run
whoami /upnI poked around in
whoami.exejust to be sure and it looks like it gets your username in UPN format usingGetUserNameExWby passingNameUserPrincipal(i.e. the integer value8) as the first argument: