0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excelのパスワードを総当たり解析!文字列PWも解読

Last updated at Posted at 2023-12-15

概要

  • Excel VBAで「パスワードのかかったExcelファイル」を開くためのコードを作成しました。以下の2種類のコードを記載しています。
    • 数字3桁のパスワードを生成し、解析するコード
    • 数字と英字の組み合わせの3桁パスワードを生成し、解析するコード

コードに関する動画

  • 以下の動画でこのコードを使いました。

実行環境

以下の環境で動作確認をしました。

  • Windows11でのExcel 2021

注意点

  • プログラムの実行については、すべて自己責任で行ってください。実行により発生した、いかなる直接的または間接的被害について、作者はその責任を負いません。

実行前の設定

  • 実行する前に、Const FilePath As String = "Your_File_Path_Here"に、該当のExcelファイルのフルパスを設定してください。
数字のみ3桁パスワード
Const FilePath As String = _
"Your_File_Path_Here" ' ファイルのパスを設定

Sub PasswordAnalysis()
    ' 数字のみの3桁パスワードを生成し、解析するサブルーチン
    Dim counter As Long
    Dim password As String
    Dim i As Integer, j As Integer, k As Integer

    ' 3重のループですべての3桁の数字を生成
    For i = 0 To 9
        For j = 0 To 9
            For k = 0 To 9
                ' 3桁の数字を生成
                password = Format(i, "0") & Format(j, "0") & Format(k, "0")

                ' エラーハンドリングを利用してパスワードを試す
                On Error Resume Next
                Workbooks.Open filepath, , , , password

                ' 結果をデバッグウィンドウに表示
                Debug.Print password & ":" & Err.Description
                DoEvents
'                counter = counter + 1
                ' エラーナンバーが0ならば、パスワードが解析されたとして処理を終了
                If Err.number = 0 Then
                    Debug.Print "Completed"
                    Exit Sub
                End If
            Next k
        Next j
    Next i
    Stop
End Sub
英数字3桁パスワード
Const FilePath As String = _
"Your_File_Path_Here" ' ファイルのパスを設定

Sub PasswordAnalysisAlphanumeric()
    ' 数字と英字の組み合わせの3桁パスワードを生成し、解析するサブルーチン
    Dim counter As Long
    Dim password As String
    Dim i As Integer, j As Integer, k As Integer

    ' 3重のループですべての3桁の数字と英字の組み合わせを生成
    For i = 48 To 122 ' 数字 0-9, 小文字 a-z, 大文字 A-Z
        If (i >= 58 And i <= 64) Or (i >= 91 And i <= 96) Then
            ' スキップする文字例: [ \ ] ^ _ ` { | } ~
            GoTo Next_i
        End If

        For j = 48 To 122 ' 数字 0-9, 小文字 a-z, 大文字 A-Z
            If (j >= 58 And j <= 64) Or (j >= 91 And j <= 96) Then
                GoTo Next_j
            End If

            For k = 48 To 122 ' 数字 0-9, 小文字 a-z, 大文字 A-Z
                If (k >= 58 And k <= 64) Or (k >= 91 And k <= 96) Then
                    GoTo Next_k
                End If

                ' 3桁の英数字を生成
                password = Chr(i) & Chr(j) & Chr(k)

                ' エラーハンドリングを利用してパスワードを試す
                On Error Resume Next
                
                Workbooks.Open filepath, , , , password
'                counter = counter + 1
                ' 結果をデバッグウィンドウに表示
                Debug.Print password & ":" & Err.Description
                DoEvents

                ' エラーナンバーが0ならば、パスワードが解析されたとして処理を終了
                If Err.number = 0 Then
                    Debug.Print "Completed"
                    Exit Sub
                End If
Next_k:
            Next k
Next_j:
        Next j
Next_i:
    Next i
End Sub
0
4
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
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?