# 用 windows 內建指令暴力破解 zip 壓縮檔密碼 powershell ## 說明 有些人總覺得密碼破解需要很多駭客工具,其實不見得,這篇文章會介紹如何使用 windows 內建的 powershell 指令以及 7zip 解壓縮軟體,實作zip壓縮檔密碼暴力破解。 如果已經對 powershell 有一定熟悉程度,可以直接跳到 [完整 powershell 語法](#完整powershell語法) ,還不熟悉或是執行時遇到問題的話,請跟著以下步驟慢慢執行。 ## 使用前準備 1. 需要安裝 7zip 解壓縮軟體,請到[官方網站](https://www.developershome.com/7-zip/)下載 2. 安裝後(或是已經有安裝的人),找到 7zip 的安裝路徑,以我來說我的路徑是 ```C:\Program Files (x86)\7-Zip\7z.exe``` 3. 準備好密碼的字典檔,字典檔就是蒐集了一大堆的常見密碼的 txt 檔案,也可以追加你自己覺得比較有可能的密碼,會更有效率。這邊推薦一個 [1000萬組常用密碼字典檔清單](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt),點進去後選右上角的 ... ,再選 Download 即可下載。 ## 修改 powershell 內的參數 前面的東西準備差不多了,等下的 powershell 中有幾個要自己填入的資料 共4項,請依照自己電腦的路徑修改 1. $7zipExec = "C:\Program Files\7-Zip\7z.exe" 2. $input = "C:\Users\not\Desktop\有密碼保護的壓縮檔.zip" 3. $output = "C:\Users\not\Desktop\" 4. $passwordfile = "C:\Users\not\Desktop\10-million-password-list-top-1000000.txt" ## 怎麼執行 powershell? 可以在檔案總管或桌面,任意空白位置**按住 shift 再按滑鼠右鍵**,會在新的視窗看看到 **在這裡開啟PowerShell 視窗**,點擊下去就會看到指令列視窗了 ![](https://hackmd.io/_uploads/Sy52Jh4KC.png) 在 powershell 中,請貼上這一段指令,記得路徑**C:\pw\zippassword.ps1**這個部分要改成自己電腦路徑,按下 enter 執行後,要等他一會兒(大概10秒),之後就開始跑了 ```powershell -ExecutionPolicy Bypass -File C:\pw\zippassword.ps1``` --- ## 使用上的限制 1. 這個語法其實效率沒有很好,解一條密碼大概要1秒鐘,只是方便體驗暴力破解的感覺而已 2. 如果要增加效率,又沒有要大規模更改程式碼,可以把字典檔分成好幾份,同時開多個powershell 一起跑會更快 3. 暴力破解是從最上面的密碼開始一行行慢慢試,如果你有覺得特別有可能出現的密碼,可以擺在上面一點的地方。 以下是執行起來的樣子,最後一筆 **1234567** 就是被暴力破解試出來的密碼 ```cmd= PS C:\Users\not\Desktop> powershell -ExecutionPolicy Bypass -File C:\Users\not\Desktop\zippassword.ps1 Attempt #(1): 123456 ...wrong Attempt #(2): password ...wrong Attempt #(3): 12345678 ...wrong Attempt #(4): qwerty ...wrong Attempt #(5): 123456789 ...wrong Attempt #(6): 12345 ...wrong Attempt #(7): 1234 ...wrong Attempt #(8): 111111 ...wrong Attempt #(9): 1234567 ...OK! Password is 1234567, found it after 9 tries. Done in 0 hour(s), 0 minute(s) and 21 seconds(s) Press Enter to exit: ``` --- ## 完整powershell語法 * 複製後在記事本貼上,將檔名改成 ```zippassword.ps1```,副檔名最後一個字是數字one ```=cmd # 指令範例 powershell -ExecutionPolicy Bypass -File C:\pw\zippassword.ps1 # Stopwatch for measurement $stopWatch = [System.Diagnostics.Stopwatch]::startNew() $7zipExec = "C:\Program Files\7-Zip\7z.exe" $input = "C:\Users\not\Desktop\flag.zip" $output = "C:\Users\not\Desktop\" $passwordfile = "C:\Users\not\Desktop\10-million-password-list-top-1000000.txt" $windowStyle = "Hidden" [long] $counter = 0 # Correct password is 12341234 foreach ($password in (get-content $passwordfile)) { $counter++ Write-Host -NoNewLine "Attempt #($counter): $password" $arguments = "x -o$output -p$password -aoa $input" $p = Start-Process $7zipExec -ArgumentList $arguments -Wait -PassThru -WindowStyle $windowStyle if ($p.ExitCode -eq 0) { # Password OK Write-Host " ...OK!" Write-Host "" Write-Host "Password is $password, found it after $counter tries." break } elseif ($p.ExitCode -eq 2) { # Wrong password Write-Host " ...wrong" } else { # Unknown Write-Host " ...ERROR" } } # Halt the stopwatch and display the time spent for this process $stopWatch.Stop() Write-Host Write-Host "Done in $($stopWatch.Elapsed.Hours) hour(s), $($stopWatch.Elapsed.Minutes) minute(s) and $($stopWatch.Elapsed.Seconds) seconds(s)" Read-Host -Prompt "Press Enter to exit" ``` --- ## 參考來源 * danielmiessler/SecLists Passwords/Common-Credentials/10-million-password-list-top-1000000.txt https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt * Powershell: Brute-forcing password-protected .zip file (speeding up the process) https://stackoverflow.com/questions/39172934/powershell-brute-forcing-password-protected-zip-file-speeding-up-the-process