This prints the user (in the form of "user @domain") for outgoing connections. This is C ++.
CredHandle credHandle; TimeStamp timeStamp; SECURITY_STATUS status = AcquireCredentialsHandle(0, L"Negotiate", SECPKG_CRED_OUTBOUND, 0, 0, 0, 0, &credHandle, &timeStamp); if (status == SEC_E_OK) { SecPkgCredentials_Names names; status = QueryCredentialsAttributes(&credHandle, SECPKG_CRED_ATTR_NAMES, &names); if (status == SEC_E_OK) { wprintf(L"%s\n", names.sUserName); status = FreeContextBuffer(names.sUserName); } status = FreeCredentialsHandle(&credHandle); }
Other information: I think runas uses CreateProcessWithLogonW with the LOGON_NETCREDENTIALS_ONLY flag. This creates a new login session based on an existing login session, with network credentials hidden inside it. GetTokenInformation and LsaGetLogonSessionData return information about the original user, not about the network user. One bit of Windows that a network user needs to know is SSPI so that it can send the username and domain to a remote server. Hence the code above.
source share