tags:

views:

80

answers:

2

In my previous question on this topic, what would the implications be if I removed the dynamic variable and instead replaced it with a static one like you see below...

    $source = 'http://mycentralserver.com/protected/myupdater.zip';

I've included the code below for convenience...

<?php
// TEST.PHP

$source = 'http://mycentralserver.com/protected/myupdater.zip';
$target = '.';

$out_file = fopen(basename($source), 'w');
$in_file = fopen($source, 'r');
while ($chunk = fgets($in_file)) {
    fputs($out_file, $chunk);
}
fclose($in_file);
fclose($out_file);

$zip = new ZipArchive();
$result = $zip->open(basename($source));
if ($result) {
    $zip->extractTo($target);
    $zip->close();
}

?>
+1  A: 

You should at least be hashing the zip with SHA-1 and checking it against a digest to ensure it hasn't changed. These digests should be extremely hard to replace.

I still think automated updates are a bit iffy.

Xorlev
Thanks for the tip Xorlev. So at the point I update the zip on my central server, I would then update the digest. Then I'd place some code in the test.php to look up the digest value and confirm the received zip is a match. Do I understand it correctly?
Scott B
Why iffy on auto updates?
Scott B
Then you have the problem of updating the digests. If possible, install pgp (or gpg) on the server and create detached signatures for each updated zip file. Download both the zip file and the signature and verify the signature before unzipping.
MadCoder
Interesting, but this exact use of sha-1 is frowned upon because sha-1 is vulnerable to hash collisions. Sha-1 os only good for 2^52 bits and people have generated collisions. Any member of the sha-2 great choice, SHA-256 isn't getting broken any time soon.
Rook
SHA-1 is good enough for digests, I wouldn't use it for anything important needing cryptographic security.
Xorlev
A: 

PHP 5.2.6 and older had a vulnerability that allowed writing to arbitrary locations via Zip's extractTo() -method.

See: http://www.securityfocus.com/bid/32625

So, if the contents of the zip are untrustworthy, you must use PHP 5.2.7 or newer (or use your own Zip parser).

rFactor