# 用 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 檔案,也可以追加你自己覺得比較有可能的密碼,會更有效率。這邊推薦一個 [10萬組常用密碼字典檔清單](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/100k-most-used-passwords-NCSC.txt),點進去後選右上角的 ... ,再選 Download 即可下載。 > 小提醒:如果你覺得10萬組不夠,可以在上面的網址中找到更多的密碼字典檔 --- ## 修改 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語法 * 複製後在記事本貼上,將檔名改成 ```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" ``` --- ## 怎麼執行 powershell? 可以在檔案總管或桌面,任意空白位置**按住 shift 再按滑鼠右鍵**,會在新的視窗看看到 **在這裡開啟PowerShell 視窗**,點擊下去就會看到指令列視窗了  在 powershell 中,請貼上這一段指令,記得路徑**C:\pw\zippassword.ps1**這個部分要改成自己電腦路徑,按下 enter 執行後,要等他一會兒(大概10秒),之後就開始跑了 ```powershell -ExecutionPolicy Bypass -File C:\pw\zippassword.ps1``` --- ## 使用上的限制 1. 這個語法其實效率沒有很好,因為他的機制是打開7z>嘗試解壓縮>關閉,每解一條密碼大概要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: ``` --- ## 更新 借助 AI 的建議,改用 try 的方式進行解壓縮,速度更快,也可以輸出進度  ```=powershell # 指令範例: # powershell -ExecutionPolicy Bypass -File C:\Downloads\zippasswordSpeedUp.ps1 $stopWatch = [System.Diagnostics.Stopwatch]::StartNew() $7zipExec = "C:\Program Files\7-Zip\7z.exe" $input = "C:\Downloads\flag.zip" $output = "C:\Downloads\OutPut\" # 只有成功才會真正解壓用到 $passwordfile = "C:\Downloads\10_million_password_list_top_1000000.txt" [long]$counter = 0 $lastReport = [System.Diagnostics.Stopwatch]::StartNew() $lastPassword = "" # 用 StreamReader 逐行讀,避免 Get-Content 一次載入 $reader = [System.IO.StreamReader]::new($passwordfile) try { while (($password = $reader.ReadLine()) -ne $null) { $counter++ $lastPassword = $password # 用 t(test) 測試密碼,不解壓 # -bso0: 關標準輸出 # -bsp0: 關進度輸出 # -bse0: 關錯誤輸出 & $7zipExec ` "t" ` "-p$password" ` "-bso0" "-bsp0" "-bse0" ` $input *> $null # 把 stdout+stderr 全吃掉 if ($LASTEXITCODE -eq 0) { Write-Host "" Write-Host " ...OK!" Write-Host "Password is $password, found it after $counter tries." # 真正解壓(只做一次) & $7zipExec ` "x" ` "-o$output" ` "-p$password" ` "-aoa" ` $input | Out-Null break } # 每 5 秒輸出一次進度 if ($lastReport.Elapsed.TotalSeconds -ge 5) { $elapsed = $stopWatch.Elapsed $rate = if ($elapsed.TotalSeconds -gt 0) { [math]::Round($counter / $elapsed.TotalSeconds, 2) } else { 0 } Write-Host ("Tried {0} passwords | Last: {1} | Rate: {2}/sec | Elapsed: {3:hh\:mm\:ss}" -f ` $counter, $lastPassword, $rate, $elapsed) $lastReport.Restart() } } } finally { $reader.Close() } $stopWatch.Stop() Write-Host "" Write-Host ("Done in {0:hh\:mm\:ss}" -f $stopWatch.Elapsed) Read-Host -Prompt "Press Enter to exit" ``` --- ## 還能不能更快? 可以,使用 GPU 搭配 john the ripper / hash cat 一次冒出了兩個專有名詞,因為這些是更專業的軟體,但必須要使用顯示卡 cuda 的 gpu 運算,寫這篇是給任何人都能用家用windows電腦體會暴力破解密碼的感覺,不是真的要教學,專業工具會有其他知識點要補足,例如 hash 的概念,這篇就不特別介紹。 --- ## 參考來源 * danielmiessler SecLists https://github.com/danielmiessler/SecLists/tree/master/Passwords/Common-Credentials * 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
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.