Odczytywanie MD5 Przy zbiorze A.Z nie dziala

0

Mam taki oto program:

unit MD5HackerfMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Spin, StdCtrls, DCPcrypt2, DCPmd5;

type
  TfMain = class(TForm)
    GroupBox1: TGroupBox;
    lHash: TLabel;
    eHash: TEdit;
    lMinLength: TLabel;
    seMinLength: TSpinEdit;
    lMaxLength: TLabel;
    seMaxLength: TSpinEdit;
    GroupBox2: TGroupBox;
    eHackedText: TEdit;
    Button1: TButton;
    cbUpperCaseAZ: TCheckBox;
    cbLowerCaseAZ: TCheckBox;
    cbNumbers: TCheckBox;
    cbSpecialChars: TCheckBox;
    lInfo: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure seMinLengthChange(Sender: TObject);
    procedure seMaxLengthChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CreateASCIITable;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  UCAZ: array[0..25] of Byte = (Ord('A'), Ord('B'), Ord('C'), Ord('D'), Ord('E'),
                                Ord('F'), Ord('G'), Ord('H'), Ord('I'), Ord('J'),
                                Ord('K'), Ord('L'), Ord('M'), Ord('N'), Ord('O'),
                                Ord('P'), Ord('Q'), Ord('R'), Ord('S'), Ord('T'),
                                Ord('U'), Ord('V'), Ord('W'), Ord('X'), Ord('Y'),
                                Ord('Z'));

  LCAZ: array[0..25] of Byte = (Ord('a'), Ord('b'), Ord('c'), Ord('d'), Ord('e'),
                                Ord('f'), Ord('g'), Ord('h'), Ord('i'), Ord('j'),
                                Ord('k'), Ord('l'), Ord('m'), Ord('n'), Ord('o'),
                                Ord('p'), Ord('q'), Ord('r'), Ord('s'), Ord('t'),
                                Ord('u'), Ord('v'), Ord('w'), Ord('x'), Ord('y'),
                                Ord('z'));

  NUMB: array[0..9] of Byte = (Ord('0'), Ord('1'), Ord('2'), Ord('3'), Ord('4'),
                               Ord('5'), Ord('6'), Ord('7'), Ord('8'), Ord('9'));

var
  ASCII: array[0..193] of Byte;


  fMain: TfMain;

implementation

{$R *.dfm}

procedure TfMain.CreateASCIITable;
var
  i, j: Integer;
  tmp: string;
begin
  j := 0;
  for i := 0 to 255 do
    if not (Chr(i) in ['A'..'Z']) and not (Chr(i) in ['a'..'z']) and not (Chr(i) in ['0'..'9']) then
    begin
      ASCII[j] := i;
      Inc(j);
    end;          {
  tmp := '';
  for i := 0 to 193 do
  begin
    Tmp := Tmp + IntToStr(ASCII[i]) + ' ';
    if (i mod 10) = 0 then
      Tmp := Tmp + #13;
  end;
  ShowMessage(tmp);        }
end;

function MaxIndex: integer;
begin
  Result := -1;
  if fMain.cbLowerCaseAZ.Checked then
    Result := Result + 26;
  if fMain.cbUpperCaseAZ.Checked then
    Result := Result + 26;
  if fMain.cbNumbers.Checked then
    Result := Result + 10;
  if fMain.cbSpecialChars.Checked then
    Result := Result + 194;
end;

function IndexToByte(Index: integer): Byte;
var
  i: integer;
  actIndex: integer;
  aValues: array[0..255] of Byte;
begin
  for i := 0 to 255 do
    aValues[i] := 0;
  with fMain do
  begin
    actIndex := 0;
    if cbUpperCaseAZ.Checked then
      for i := actIndex to actIndex + 25 do
      begin
        aValues[actIndex] := UCAZ[i];
        actIndex := actIndex + 1;
      end;
    if cbLowerCaseAZ.Checked then
      for i := actIndex to actIndex + 25 do
      begin
        aValues[actIndex] := LCAZ[i];
        actIndex := actIndex + 1;
      end;
    if cbNumbers.Checked then
      for i := actIndex to actIndex + 9 do
      begin
        aValues[actIndex] := NUMB[i];
        actIndex := actIndex + 1;
      end;
    if cbSpecialChars.Checked then
      for i := actIndex to actIndex + 193 do
      begin
        aValues[actIndex] := ASCII[i];
        actIndex := actIndex + 1;
      end;
  end;
  Result := aValues[Index];      
end;

procedure BruteForce(Hash: string; var HackedText: string);
var
  TmpHash, TmpTxt: string;
  tHash: TDCP_md5;
  Digest: array[0..15] of Byte;
  actLength, i: integer;
  Index: array of integer;
begin
  actLength := fMain.seMinLength.Value - 1;
  HackedText := '';
  while HackedText = '' do
  begin
    SetLength(Index, actLength + 1);
    for i := 0 to actLength do
      Index[i] := 0;
    while True do
    begin
      TmpTxt := '';
      for i := 0 to actLength do
        TmpTxt := TmpTxt + Chr(IndexToByte(Index[i]));
      tHash := TDCP_md5.Create(fMain);
      tHash.Init;
      tHash.UpdateStr(TmpTxt);
      tHash.Final(Digest);
      tHash.Free;
      TmpHash := '';
      for i := 0 to 15 do
        TmpHash := TmpHash + IntToHex(Digest[i], 2);
      if LowerCase(TmpHash) = LowerCase(Hash) then
      begin
        HackedText := TmpTxt;
        Break;
      end;
      if Index[Low(Index)] = MaxIndex then
        Break;
      Index[High(Index)] := Index[High(Index)] + 1;
      for i := High(Index) downto 0 do
        if Index[i] > MaxIndex then
        begin
          Index[i] := 0;
          Index[i - 1] := Index[i - 1] + 1;
        end;
    end;
    if HackedText = '' then
      actLength := actLength + 1;
    if actLength > fMain.seMaxLength.Value - 1 then
    begin
      MessageBox(fMain.Handle, 'Nie można odczytac HASH''a', 'MD5 HACKER - BRUTE FORCE (BRUTALNY ATAK)', MB_OK + MB_ICONERROR);
      Exit;
    end;
  end;
  MessageBox(fMain.Handle, 'Gotowe! Hash zostal odczytany :)', 'MD5 HACKER - BRUTE FORCE (BRUTALNY ATAK)', MB_OK + MB_ICONINFORMATION);
end;

procedure TfMain.FormCreate(Sender: TObject);
var
  tHash: TDCP_md5;
  Digest: array[0..15] of Byte;
  i: integer;
  Tmp: string;
begin

  Tmp := 'Z-A: ' + IntToStr(Ord('Z') - Ord('A')) + #13 +
         'A: ' + IntToStr(Ord('A')) + #13 +
         'Z: ' + IntToStr(Ord('Z')) + #13 +
         'Z-A: ' + IntToStr(Ord('z') - Ord('a')) + #13 +
         'A: ' + IntToStr(Ord('a')) + #13 +
         'Z: ' + IntToStr(Ord('z')) + #13 +
         '9-0: ' + IntToStr(Ord('9') - Ord('0')) + #13 +
         '0: ' + IntToStr(Ord('0')) + #13 +
         '9: ' + IntToStr(Ord('9')) + #13 + #13;

  for i := Ord('A') to Ord('Z') do
    Tmp := Tmp + Chr(i);
  Tmp := Tmp + #13;
  for i := Ord('a') to Ord('z') do
    Tmp := Tmp + Chr(i);
  Tmp := Tmp + #13;
  for i := Ord('0') to Ord('9') do
    Tmp := Tmp + Chr(i);

  MessageBox(Handle, PChar(Tmp), '', MB_OK + MB_ICONINFORMATION);

  CreateASCIITable;

    Tmp := IntToStr(Low(ASCII)) + '/' + IntToStr(High(ASCII)) + #13;
    for i := Low(ASCII) to High(ASCII) do
    begin
      Tmp := Tmp {+ Chr(ASCII[i]) + '/'} + IntToStr(ASCII[i]) + '; ';
      if (i mod 10) = 0 then
        Tmp := Tmp + #13;
    end;
    Tmp := Tmp + #13#13 + IntToStr(Ord('/'));
    MessageBox(Handle, PChar(Tmp), '', 0);

      tHash := TDCP_md5.Create(fMain);
      tHash.Init;
      tHash.UpdateStr('dupa');
      tHash.Final(Digest);

      Tmp := '';

      for i := 0 to 15 do
        Tmp := Tmp + IntToHex(Digest[i], 2);

      eHash.Text := Tmp;
end;

procedure TfMain.seMinLengthChange(Sender: TObject);
begin
  with seMinLength do
  begin
    if Value < 1 then
      Value := 1;
    if Value > seMaxLength.Value then
      seMaxLength.Value := Value;
  end;
end;

procedure TfMain.seMaxLengthChange(Sender: TObject);
begin
  with seMaxLength do
    if Value < seMinLength.Value then
      Value := seMinLength.Value;
end;

procedure TfMain.Button1Click(Sender: TObject);
var
  Tmp: string;
begin
  BruteForce(eHash.Text, Tmp);
  eHackedText.Text := Tmp;
end;

end.

I problem jest taki, że gdy aplikacja ma do listy mozliwych znaków dodany zbiór 'A'..'Z' to nie odczytuje zadnego hash. Pytanie jest takie: dlaczego?

0

Drobna uwaga, tego rodzaju atak nie przejdzie, sprawdzasz na chama hashe wszystkich możliwych zakresów. Kilka lat temu został ładnie opisany i udokumentowany algorytm generowania kolizji w bardzo krótkim czasie, na domowym PC poniżej godziny. Dokumentacja , implementacja w C - powinieneś dać sobie radę z jej przetłumaczeniem, wersji w Delphi nie widziałem.

0

Dzięki za odpowiedź, ale to nie zmienia faktu że program nie działa jak należy. Więc w dalszym ciągu będę wdzięczny za każdą pomoc.

1 użytkowników online, w tym zalogowanych: 0, gości: 1