一、破解軟體實作

以下實作軟體使用Visual Studio和C#,且必須安裝7-Zip軟體。

首先。開啟Visual Studio,建立新專案Windows Forms應用程式C#,照下圖設置視窗。

解密檔案為要破解的7z檔,解壓位置是破解成功後檔案存放位置,還可以設定密碼位數和密碼所包含的字元。

1.建立密碼字典

  private string[] SetPassword(int numeric, string[] includechars)
  {
      List<string> result = new List<string>();
      List<string> toplevelpws = new List<string>();
      List<string> nextlevelpws = new List<string>();
      //numeric=1
      foreach (string i in includechars)
          toplevelpws.Add(i);
      result.AddRange(toplevelpws);
      //numeric>1
      for (int d = 1; d < numeric; d++)
      {
          foreach (var t in toplevelpws)
              foreach (string i in includechars)
                  toplevelpws.Add(t+i);
          result.AddRange(nextlevelpws);
          toplevelpws = new List<string>(nextlevelpws);
          nextlevelpws.Clear();
      }
      return result.ToArray();
  }

輸入值numeric是密碼位數,includechars是密碼所包含的字元。可以參考以下字元所對應的數值。

char[] number = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
char[] littleeng = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
char[] largeeng = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
char[] mark = new char[] { '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' };
char[] space = new char[] { ' ' };

2.執行破解

private void backgroundWorker_CrackStart_DoWork(object sender, DoWorkEventArgs e)
  {
      BackgroundWorker worker = sender as BackgroundWorker;
      Process process = new Process();
      process.StartInfo.FileName = SevenzexePath;
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.RedirectStandardInput = true;
      process.StartInfo.RedirectStandardOutput = true;
      process.StartInfo.RedirectStandardError = true;
      process.StartInfo.CreateNoWindow = true;
      foreach (string s in password) // password=密碼字典
      {
          process.StartInfo.Arguments = "x -aoa -p" + s + " \"-o" + TargetPath + "\" \"" + SevenzfilePath + "\"";
          process.Start();
          if (worker.CancellationPending == true)
          {
              e.Cancel = true;
              break;
          }                
      }
  }

建立backgroundWorker_CrackStart物件後,執行backgroundWorker_CrackStart.RunWorkerAsync()。

SevenzexePath是7z.exe的位置,預設安裝位置為C:\Program Files\7-Zip\7z.exe

TargetPath是解壓位置,SevenzfilePath是解密檔案。

二、破解軟體實測

密碼字典愈大,理論所需時間愈久,不同速度的CUP所需時間也不一樣。

我目前使用的CPU是i9-13900K,速度大約5GHz。

密碼字典總數耗時(秒)每秒次數
數字,4位數1111053.2208.8
英文小寫&數字,3位數47988235.3203.9
英文大小寫&數字,3位數2422341225.9197.5

平均每秒200次,如果運行一週,大概可以處理「數字,8位數」(6.4天),「英文小寫&數字,5位數」(3.6天)

軟體本身沒有優化,實際使用的可行性不高,但是可以建立自己的密碼字典,用於部分已知的密碼進行猜測。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *