The script below, test.php, is intended to be placed in a specific directory of all my wordpress sites. Its purpose is to grab the file at the $source address below and extract it to the directory in which it resides. That's all its intended to do.
For example, I will have a dashboard interface on my central server that lists all my sites in which this script is present. I will then execute a cURL routine that iterates over every site and performs a call on this script, effectively sending the update file to all of them at once.
The call is made like so...
...processing site 1 update...
http://targetsite1.com/somedeepdirectory/test.php?query=updates.zip
...processing site 2 update...
http://targetsite2.com/somedeepdirectory/test.php?query=updates.zip
...etc until all my sites have been updated.
My question is (1) how secure (hardened) is this script, as is. and (2) what checks should I put in place to make more so...
I'm thinking that at a minimum I would restrict the character count for myquery as well as check the payload in myquery for malicious, unexpected filetypes?
<?php
// TEST.PHP
$source = 'http://mycentralserver.com/protected/'.$_GET['myquery'];
$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();
}
?>