Th3-822 / rapidleech

http://rapidleech.com/forum/
590 stars 522 forks source link

ZIP file with password now in PHP 7 #151

Open MegaBedder opened 5 years ago

MegaBedder commented 5 years ago

Reading password protected zip files is possible from PHP 7.2.

ZIP extension registers zip wrapper zip://. As of PHP 7.2.0, support for the passwords for encrypted achives were added, allowing passwords to be supplied by stream contexts. Passwords can be set using the 'password' stream context option.

This also solves the problem of requiring the use of program execution functions, which are usually disabled in shared hosting.

Example - Basic password usage example

<?php
// Read encrypted archive
$opts = array(
    'zip' => array(
        'password' => 'secret',
    ),
);

// create the context...
$context = stream_context_create($opts);

// ...and use it to fetch the data
echo file_get_contents('zip://test.zip#test.txt', false, $context);

?>

Example - for extraction of files from password protected ZIP archives:

<?php
$zip = new ZipArchive();
$zip_status = $zip->open("test.zip");

if ($zip_status === true){
  if ($zip->setPassword('secret')){
    if (!$zip->extractTo(__DIR__))
      echo "Extraction failed (wrong password?)";
  }

  $zip->close();
} else {
  die("Failed opening archive: ". $zip->getStatusString() . " (code: ". $zip_status .")");
}
?>

Example - Archive and encrypt a file

<?php
$zip = new ZipArchive();
if ($zip->open('test.zip', ZipArchive::CREATE) === TRUE) {
    $zip->setPassword('secret');
    $zip->addFile('text.txt');
    #$zip->setEncryptionName('text.txt', ZipArchive::EM_AES_256);
    $zip->close();
    echo "OK\n";
} else {
    echo "FAILED\n";
}
?>

With reference to what is said here: #60

andykimpe commented 5 years ago

rapidleech is not intended for php 7 but for php 5 please use only php 5