The script below, test.php, is intended to be placed in a specific directory of all my wordpress sites. Its purpose is to capture the file at $ source below and extract it into the directory in which it is located. That is all he intends to do.
For example, I will have a control panel interface on my central server, which lists all my sites on which this script is present. Then I execute the cURL procedure, which iterates through each site and calls this script, effectively sending the update file to all of them at once.
The call goes like this ...
...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 safe (hardened) is this script, as it is. and (2) what checks should I put in order to do more ...
I think that, at a minimum, I would limit the number of characters for myquery and also check the payload in myquery for malicious and unexpected file types?
<?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(); } ?>
source share