Einzelnen Beitrag anzeigen

Benutzerbild von Remko
Remko

Registriert seit: 10. Okt 2006
Ort: 's-Hertogenbosch, Die Niederlande
222 Beiträge
 
RAD-Studio 2010 Arc
 
#5

Re: Password hash in RDP files

  Alt 20. Mär 2007, 12:18
I watched what MSTSC does with a debugger, the description is always psw.

Here's the cleaned up function:
Delphi-Quellcode:
uses JwaWinCrypt;

function CryptRDPPassword(sPassword: string): string;
var DataIn: DATA_BLOB;
    DataOut: DATA_BLOB;
    pwDescription: PWideChar;
    P: PByte;
    I: Integer;
    PwdHash: string;
begin
  PwdHash := '';

  DataOut.cbData := 0;
  DataOut.pbData := nil;

  // RDP uses UniCode
  DataIn.pbData := Pointer(WideString(sPassword));
  DataIn.cbData := Length(sPassword) * SizeOf(WChar);

  // RDP always sets description to psw
  pwDescription := WideString('psw');

  if CryptProtectData(@DataIn,
                      pwDescription,
                      nil,
                      nil,
                      nil,
                      CRYPTPROTECT_UI_FORBIDDEN, // Never show interface
                      @DataOut) then
  begin
    // Convert the DataBlob to Hex String
    P := DataOut.pbData;
    I := DataOut.cbData;

    PwdHash := '';
    while (I > 0) do begin
      Dec(I);
      PwdHash := PwdHash + IntToHex(P^, 2);
      Inc(P);
    end;
  end;

  Result := PwdHash;

  // Cleanup
  pwDescription := nil;
  LocalFree(Cardinal(DataOut.pbData));
  LocalFree(Cardinal(DataIn.pbData));

end;
  Mit Zitat antworten Zitat