Jump to content

CredUIPromptForWindowsCredentialsW problem


Recommended Posts

Hi everyone,

I have AutoIt 3.3.6.0 and I'm trying to execute this script:

$pUiInfo=DllStructCreate("dword cbSize;hwnd hwndParent;wchar pszMessageText[2048];wchar pszCaptionText[2048];handle hbmBanner")
DllStructSetData($pUiInfo,"pszCaptionText","CaptionText")
DllStructSetData($pUiInfo,"pszMessageText","MessageText")
DllStructSetData($pUiInfo,"hwndParent",0)
DllStructSetData($pUiInfo,"cbSize",DllStructGetSize($pUiInfo))
$dwAuthError=0
$pulAuthPackage=0
$defuser="test-user"
$defpass="test-pass"
$ret0=DllCall("credui.dll","dword","CredPackAuthenticationBufferW","dword",0,"wstr",$defuser,"wstr",$defpass,"ptr",0,"dword*",0)
$pPackedCredentials=DllStructCreate("byte["&$ret0[5]&"]")
$ret1=DllCall("credui.dll","dword","CredPackAuthenticationBufferW","dword",0,"wstr",$defuser,"wstr",$defpass,"ptr",DllStructGetPtr($pPackedCredentials),"dword*",DllStructGetSize($pPackedCredentials))
$pfSave=0
$dwFlags=0x10001010
$ret2=DllCall("credui.dll","dword","CredUIPromptForWindowsCredentialsW","ptr*",DllStructGetPtr($pUiInfo),"uint",$dwAuthError,"ulong*",$pulAuthPackage,"ptr",DllStructGetPtr($pPackedCredentials),"ulong",DllStructGetSize($pPackedCredentials),"ptr*",0,"ulong*",0,"boolean*",$pfSave,"uint",$dwFlags)
MsgBox(64,"CredUIPromptForWindowsCredentialsW return value",$ret2[0]) ; here it returns 160
$pPackedCredentialsOut=DllStructCreate("byte["&$ret2[7]&"]",$ret2[6])
$ret3=DllCall("credui.dll","bool","CredUnPackAuthenticationBufferW","dword",0,"ptr",DllStructGetPtr($pPackedCredentialsOut),"dword",DllStructGetSize($pPackedCredentialsOut),"ptr","","dword*",0,"ptr","","dword*",0,"ptr","","dword*",0)
$username=DllStructCreate("wchar["&$ret3[5]*2&"]")
$domain=DllStructCreate("wchar["&$ret3[7]*2&"]")
$password=DllStructCreate("wchar["&$ret3[9]*2&"]")
$ret4=DllCall("credui.dll","bool","CredUnPackAuthenticationBufferW","dword",0,"ptr",DllStructGetPtr($pPackedCredentialsOut),"dword",DllStructGetSize($pPackedCredentialsOut),"ptr",DllStructGetPtr($username),"dword*",DllStructGetSize($username),"ptr",DllStructGetPtr($domain),"dword*",DllStructGetSize($domain),"ptr",DllStructGetPtr($password),"dword*",DllStructGetSize($password))
MsgBox(64,"Results","Username: "&DllStructGetData($username,1)&@CRLF&"Domain: "&DllStructGetData($domain,1)&@CRLF&"Password: "&DllStructGetData($password,1))

It should ask for credentials, but there is no password dialog and the function CredUIPromptForWindowsCredentialsW is returning 160 (ERROR_BAD_ARGUMENTS). I'm running Windows Server 2008 Enterprise Service Pack 2 32-bit.

Can anyone help me? Thanks.

VittGam

Link to comment
Share on other sites

First three steps:

;STEP 1
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$tCREDUI_INFO = DllStructCreate("dword Size;" & _
        "hwnd Parent;" & _
        "ptr MessageText;" & _
        "ptr CaptionText;" & _
        "handle Banner")

$tMessageText = DllStructCreate("wchar[32767]")
DllStructSetData($tMessageText, 1, "And this is MessageText")

$tCaptionText = DllStructCreate("wchar[32767]")
DllStructSetData($tCaptionText, 1, "This is CaptionText")

DllStructSetData($tCREDUI_INFO, "MessageText", DllStructGetPtr($tMessageText))
DllStructSetData($tCREDUI_INFO, "CaptionText", DllStructGetPtr($tCaptionText))
DllStructSetData($tCREDUI_INFO, "Parent", 0)
DllStructSetData($tCREDUI_INFO, "Size", DllStructGetSize($tCREDUI_INFO))
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


$pfSave = 0
$dwFlags = 0x10001010
$dwAuthError = 0
$pulAuthPackage = 0
$defuser = "test-user"
$defpass = "test-pass"

; STEP 2
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$aCall = DllCall("credui.dll", "dword", "CredPackAuthenticationBufferW", _
        "dword", 0, _
        "wstr", $defuser, _
        "wstr", $defpass, _
        "ptr", 0, _
        "dword*", 0)

$iRequiredSize = $aCall[5]
Local $tBuffer = DllStructCreate("byte[" & $iRequiredSize & "]")

$aCall = DllCall("credui.dll", "dword", "CredPackAuthenticationBufferW", _
        "dword", 0, _
        "wstr", $defuser, _
        "wstr", $defpass, _
        "ptr", DllStructGetPtr($tBuffer), _
        "dword*", $iRequiredSize)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


; STEP 3
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$Call = DllCall("credui.dll", "dword", "CredUIPromptForWindowsCredentialsW", _
        "ptr", DllStructGetPtr($tCREDUI_INFO), _
        "dword", $dwAuthError, _
        "dword*", $pulAuthPackage, _
        "ptr", DllStructGetPtr($tBuffer), _
        "ulong", DllStructGetSize($tBuffer), _
        "ptr*", 0, _
        "dword*", 0, _
        "bool*", $pfSave, _
        "dword", $dwFlags)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



MsgBox(64, "CredUIPromptForWindowsCredentialsW return value", $Call[0])


; STEP 4
;...

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

wow! it works. Thank you very much!!!

First three steps:

;STEP 1
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$tCREDUI_INFO = DllStructCreate("dword Size;" & _
        "hwnd Parent;" & _
        "ptr MessageText;" & _
        "ptr CaptionText;" & _
        "handle Banner")

$tMessageText = DllStructCreate("wchar[32767]")
DllStructSetData($tMessageText, 1, "And this is MessageText")

$tCaptionText = DllStructCreate("wchar[32767]")
DllStructSetData($tCaptionText, 1, "This is CaptionText")

DllStructSetData($tCREDUI_INFO, "MessageText", DllStructGetPtr($tMessageText))
DllStructSetData($tCREDUI_INFO, "CaptionText", DllStructGetPtr($tCaptionText))
DllStructSetData($tCREDUI_INFO, "Parent", 0)
DllStructSetData($tCREDUI_INFO, "Size", DllStructGetSize($tCREDUI_INFO))
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


$pfSave = 0
$dwFlags = 0x10001010
$dwAuthError = 0
$pulAuthPackage = 0
$defuser = "test-user"
$defpass = "test-pass"

; STEP 2
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$aCall = DllCall("credui.dll", "dword", "CredPackAuthenticationBufferW", _
        "dword", 0, _
        "wstr", $defuser, _
        "wstr", $defpass, _
        "ptr", 0, _
        "dword*", 0)

$iRequiredSize = $aCall[5]
Local $tBuffer = DllStructCreate("byte[" & $iRequiredSize & "]")

$aCall = DllCall("credui.dll", "dword", "CredPackAuthenticationBufferW", _
        "dword", 0, _
        "wstr", $defuser, _
        "wstr", $defpass, _
        "ptr", DllStructGetPtr($tBuffer), _
        "dword*", $iRequiredSize)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


; STEP 3
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$Call = DllCall("credui.dll", "dword", "CredUIPromptForWindowsCredentialsW", _
        "ptr", DllStructGetPtr($tCREDUI_INFO), _
        "dword", $dwAuthError, _
        "dword*", $pulAuthPackage, _
        "ptr", DllStructGetPtr($tBuffer), _
        "ulong", DllStructGetSize($tBuffer), _
        "ptr*", 0, _
        "dword*", 0, _
        "bool*", $pfSave, _
        "dword", $dwFlags)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



MsgBox(64, "CredUIPromptForWindowsCredentialsW return value", $Call[0])


; STEP 4
;...

Link to comment
Share on other sites

So, what now? You will worship me and stuff? :(

xD

But the secure password isn't decoded from the secure desktop ($dwFlags = 0x10001010), only when the screen is not in the secure desktop ($dwFlags = 0x10000010)... and I even changed "CredUnPackAuthenticationBufferW","dword",0 to "CredUnPackAuthenticationBufferW","dword",1

edit: 1 should be the value for CRED_PACK_PROTECTED_CREDENTIALS, right?

Edited by VittGam
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...