> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-5/data-recovery/archive/trick-0275.md).

# Extract Password-Protected 7z Archives

***

Once you have recovered the password for a password-protected 7z archive, you can use the standard `7z` command-line tool to extract its contents.

Simply specify the extract command (`x`), the archive name, and provide the password directly using the `-p` flag. The `-p` option must be immediately followed by the password with no space.

```bash
7z x <archive_name>.7z -p<password>
```

For instance, if a password `doodleGrive2022Backup` was found for an archive located at `/var/www/backups/backup.7z`, you would extract it like this:

```bash
7z x /var/www/backups/backup.7z -pdoodleGrive2022Backup
```

You can also specify an output directory for the extracted files using the `-o` option. For example, to extract the contents of `backup.7z` to a directory named `extracted_backup`:

```bash
7z x /var/www/backups/backup.7z -pdoodleGrive2022Backup -oextracted_backup
```

The output directory will be created if it doesn't exist. The `-o` switch specifies the output directory.

To extract specific files from a password-protected archive, you still use the `-p` flag followed by the password, and then list the names of the files you want to extract:

```bash
7z x /var/www/backups/backup.7z -pdoodleGrive2022Backup file1.txt path/to/file2.pdf
```

This command extracts only `file1.txt` and `path/to/file2.pdf` from the `backup.7z` archive using the provided password.

For automating the extraction of multiple password-protected 7z or zip files, you can use a batch script. A script like the following will iterate through all `.zip` and `.7z` files in the current directory, extracting each one into a new folder named after the archive file (without the extension) using the specified password:

```batch
@echo off
for %%f in (*.zip *.7z) do (
    "C:\Program Files\7-Zip\7z.exe" x "%%f" -o"%%~nf" -pYOUR_PASSWORD
)
```

In this script, `%%f` represents the current archive file being processed. The `-o"%%~nf"` part tells 7-Zip to create an output directory (`-o`) named `%%~nf`, which is the filename (`%%f`) without the extension (`~n`). Remember to replace `YOUR_PASSWORD` with the actual password for the archives. This provides an efficient way to handle bulk extraction of password-protected archives.
