How to Unrar with a Password List

This guide explains how to extract a password-protected RAR archive using a text file containing a list of potential passwords. Because the standard unrar utility does not natively support reading a list of passwords from a file, this process is accomplished using a lightweight command-line script in Linux/macOS (Bash) or Windows (Batch/PowerShell) to test each password until the archive extracts successfully.


Understanding the Approach

The standard syntax to extract an archive with a specific password using unrar is:

unrar x -pYourPassword archive.rar

To test multiple passwords from a file (e.g., passwords.txt), a loop reads the file line by line, passes each entry to unrar using the test command (unrar t), and performs the actual extraction (unrar x) once a valid password is found. Using the test command first avoids partial or corrupted extractions from incorrect attempts.


Method 1: Linux and macOS (Bash Script)

On Linux or macOS, you can run a Bash loop directly in your terminal.

  1. Place archive.rar and passwords.txt in the same directory.
  2. Open your terminal and navigate to that directory.
  3. Run the following command:
while IFS= read -r pass; do
    if unrar t -inul -p"$pass" archive.rar; then
        echo "Password found: $pass"
        unrar x -p"$pass" archive.rar
        break
    fi
done < passwords.txt

Explanation of flags:

  • t: Tests archive files without extracting them.
  • -inul: Suppresses standard console output, keeping the terminal clean.
  • -p"$pass": Passes the current password variable.
  • x: Extracts files with full paths once the valid password is confirmed.
  • break: Stops the loop as soon as extraction succeeds.

Method 2: Windows (PowerShell)

On modern Windows systems, PowerShell provides a reliable way to iterate through a password list.

  1. Open PowerShell and navigate to the folder containing your archive and password list.
  2. Ensure unrar.exe is available in your system PATH (or use the full path to WinRAR.exe).
  3. Run the following script:
$passwords = Get-Content .\passwords.txt
foreach ($pass in $passwords) {
    & unrar t -inul -p"$pass" .\archive.rar
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Password found: $pass"
        & unrar x -p"$pass" .\archive.rar
        break
    }
}

Method 3: Windows Command Prompt (Batch)

If you prefer using the traditional Windows Command Prompt (cmd.exe):

  1. Create a file named extract.bat in the same folder as archive.rar and passwords.txt.
  2. Insert the following code:
@echo off
for /f "usebackq delims=" %%P in ("passwords.txt") do (
    unrar t -inul -p"%%P" archive.rar >nul 2>&1
    if not errorlevel 1 (
        echo Password found: %%P
        unrar x -p"%%P" archive.rar
        goto :found
    )
)
echo No valid password found in list.
:found
  1. Run extract.bat from the command line.