1
0

More than 1 year has passed since last update.

SHA-1をJohn the ripperで突破する

Last updated at Posted at 2022-02-20

せっかくハッシュ化のGASを作って、Kaliの環境も整えたので、ちょっと遊んでみたくなりました。
ということで、SHA-1でハッシュ化したデータを元に戻してみたいと思います

ちなみに言うまでもないですが、悪用は厳禁です。

ハッシュ化関数のSHA-1は、簡単に突破できてしまうので現在は非推奨となっています。
非推奨と言われれば使いたくなってしまうのが、僕と言う人間なので
前回作成したコードを流用して、しょぼいパスワード群をSHA-1でハッシュ化しました

SHA1_GAS
function myFunction() {
  var currrentSheet = SpreadsheetApp.getActiveSheet();
  var targetSheet = SpreadsheetApp.openById("*************************").getActiveSheet();
  var targetLastRow = targetSheet.getLastRow();
  var currentValues = currrentSheet.getDataRange().getValues();

  var hashedRow; //ハッシュ化結果を保存

  for(var i=1;i<currentValues.length;i++){
    //ハッシュ化(SHA_1)
    var raw = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, currentValues[i][0], Utilities.Charset.UTF_8); 
    hashedRow = mySHA1(raw);

    currrentSheet.getRange(i+1,2).setValue(hashedRow); //元シートにハッシュ値を出力
    targetSheet.getRange(targetLastRow+1,1).setValue(hashedRow); //別シートにハッシュ値を出力

    targetLastRow = targetSheet.getLastRow(); //最終行の更新
  }
}

function mySHA1(raw){
  var strHash = ''; //ハッシュ値の文字列
  var numHash = 0;  //ハッシュ値の数値

  for (i = 0; i < raw.length; i++) {
    numHash = raw[i];
    if (numHash < 0) { //ゼロ未満だったら
      numHash += 256;  //マイナスの除去
    }
    if (numHash.toString(16).length == 1) { 
      strHash += '0'; //1桁なら0をくっつける
    }
    strHash += numHash.toString(16); //16進数表記の文字列に変換
  }
  return strHash;
}

上記を実行することで、以下のようなハッシュ値が得られました。
スクリーンショット 2022-02-20 20.38.48.png

上記のハッシュ値をコピーして、Kali上のテキストファイルに記述します。
記述方法はなんでもいいですが、今回はviを用いました。

Kali側での操作①
└─# mkdir test
└─# cd test
└─# vi 
vimの記載内容(ハッシュ値)
7c4a8d09ca3762af61e59520943dc26494f8941b
5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
c984aed014aec7623a54f0591da07a85fd4b762d
c6922b6ba9e0939583f973bc1682493351ad4fe8
7c222fb2927d828af22f592134e8932480637c0d
f7c3bc1d808e04732adf679965ccc34ca7ae3441
3d4f2bf07dc1be38b20cd6e46949a1071f9d0e3d
6435f683ab44dc5a30afa7a4523115585991eb42
b2309b10dc07f29664283983eaf677a5e719c35f
8cb2237d0679ca88db6464eac60da96345513964

ハッシュ値を記載後は、「test001.txt」として保存します。
そしてここからJohn the ripperを使って解析します。一瞬で突破できるので本当にびっくりしますよ。

Kali側での操作_JohnTheRipper
└─# john test001.txt

Warning: detected hash type "Raw-SHA1", but the string is also recognized as "Raw-SHA1-AxCrypt"
Use the "--format=Raw-SHA1-AxCrypt" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "Raw-SHA1-Linkedin"
Use the "--format=Raw-SHA1-Linkedin" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "ripemd-160"
Use the "--format=ripemd-160" option to force loading these as that type instead
Warning: detected hash type "Raw-SHA1", but the string is also recognized as "has-160"
Use the "--format=has-160" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 10 password hashes with no different salts (Raw-SHA1 [SHA1 128/128 NEON 4x])
Remaining 9 password hashes with no different salts
Warning: no OpenMP support for this hash type, consider --fork=4
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst

12345            (?)     
password         (?)     
123456789        (?)     
12345678         (?)     
111111           (?)     
sakura           (?)     
000000           (?)     
1qaz2wsx         (?)     

Proceeding with incremental:ASCII
8g 0:00:00:33  3/3 0.2408g/s 672165p/s 672165c/s 672298C/s tk1k16..tk1k19
Use the "--show --format=Raw-SHA1" options to display all of the cracked passwords reliably
Session aborted

意図的に改行している8つのパスワードが解析結果です。
「dropbox」は突破されずに生き残った(?)ようですが、それ以外は解析されましたね。
ちなみに激ショボラズパイでも一瞬で解析できたので、SHA-1が以下に脆弱なものかわかりました

間違ってもSHA-1でハッシュ化するのはやめましょうね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0