gpt4 book ai didi

windows - 如何正确调用 LsaLogonUser 进行交互式登录?

转载 作者:可可西里 更新时间:2023-11-01 13:30:30 25 4
gpt4 key购买 nike

我正在尝试使用 LsaLogonUser 创建交互式登录 session ,但它总是返回 STATUS_INVALID_INFO_CLASS (0xc0000003)。根据我在网上搜索发现的内容,KERB_INTERACTIVE_LOGON 结构的内存布局很棘手,但我很确定我做对了。

我也尝试过使用 MSV1.0 而不是 Kerberos,使用 MSV1_0_INTERACTIVE_LOGON 作为身份验证结构,使用 MSV1_0_PACKAGE_NAME 作为程序包名称,但是失败了 STATUS_BAD_VALIDATION_CLASS (0xc00000a7)。

谁能告诉我这里做错了什么?这是代码,其中删除了大部分错误处理。显然这不是生产质量;我只是想获得一个工作样本。


// see below for definitions of these
size_t wcsByteLen( const wchar_t* str );
void InitUnicodeString( UNICODE_STRING& str, const wchar_t* value, BYTE* buffer, size_t& offset );

int main( int argc, char * argv[] )
{
// connect to the LSA
HANDLE lsa;
LsaConnectUntrusted( &lsa );

const wchar_t* domain = L"mydomain";
const wchar_t* user = L"someuser";
const wchar_t* password = L"scaryplaintextpassword";

// prepare the authentication info
ULONG authInfoSize = sizeof(KERB_INTERACTIVE_LOGON) +
wcsByteLen( domain ) + wcsByteLen( user ) + wcsByteLen( password );
BYTE* authInfoBuf = new BYTE[authInfoSize];
KERB_INTERACTIVE_LOGON* authInfo = (KERB_INTERACTIVE_LOGON*)authInfoBuf;
authInfo->MessageType = KerbInteractiveLogon;
size_t offset = sizeof(KERB_INTERACTIVE_LOGON);
InitUnicodeString( authInfo->LogonDomainName, domain, authInfoBuf, offset );
InitUnicodeString( authInfo->UserName, user, authInfoBuf, offset );
InitUnicodeString( authInfo->Password, password, authInfoBuf, offset );

// find the Kerberos security package
char packageNameRaw[] = MICROSOFT_KERBEROS_NAME_A;
LSA_STRING packageName;
packageName.Buffer = packageNameRaw;
packageName.Length = packageName.MaximumLength = (USHORT)strlen( packageName.Buffer );
ULONG packageId;
LsaLookupAuthenticationPackage( lsa, &packageName, &packageId );

// create a dummy origin and token source
LSA_STRING origin = {};
origin.Buffer = _strdup( "TestAppFoo" );
origin.Length = (USHORT)strlen( origin.Buffer );
origin.MaximumLength = origin.Length;
TOKEN_SOURCE source = {};
strcpy( source.SourceName, "foobar" );
AllocateLocallyUniqueId( &source.SourceIdentifier );

void* profileBuffer;
DWORD profileBufLen;
LUID luid;
HANDLE token;
QUOTA_LIMITS qlimits;
NTSTATUS subStatus;
NTSTATUS status = LsaLogonUser( lsa, &origin, Interactive, packageId,
&authInfo, authInfoSize, 0, &source, &profileBuffer, &profileBufLen,
&luid, &token, &qlimits, &subStatus );
if( status != ERROR_SUCCESS )
{
ULONG err = LsaNtStatusToWinError( status );
printf( "LsaLogonUser failed: %x\n", status );
return 1;
}
}

size_t wcsByteLen( const wchar_t* str )
{
return wcslen( str ) * sizeof(wchar_t);
}

void InitUnicodeString( UNICODE_STRING& str, const wchar_t* value,
BYTE* buffer, size_t& offset )
{
size_t size = wcsByteLen( value );
str.Length = str.MaximumLength = (USHORT)size;
str.Buffer = (PWSTR)(buffer + offset);
memcpy( str.Buffer, value, size );
offset += size;
}

最佳答案

您弄错了 LsaLogonUser() 的其中一个参数;而不是 &authInfo 你应该只传递 authInfo。发生在每个人身上:)

关于windows - 如何正确调用 LsaLogonUser 进行交互式登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7627750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com