From b4de8b52767a5d16088fcaf72e1a2e6b2b10df13 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 8 Jul 2010 10:32:49 +0000 Subject: [PATCH] 2010-07-08 Miguel de Dios * include/functions_filemanager.php: added in source code lines to test hash of directories or files for give more security to filemanager. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2973 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 +- .../include/functions_filemanager.php | 189 ++++++++++++------ 2 files changed, 129 insertions(+), 67 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8dfbb66982..8494a0fb74 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,4 +1,9 @@ -2010-07-07 Miguel de Dios +2010-07-08 Miguel de Dios + + * include/functions_filemanager.php: added in source code lines to test + hash of directories or files for give more security to filemanager. + +2010-07-08 Miguel de Dios * include/functions_filemanager.php: added var global through $config to return status of operation. And clean messages of filemanager. diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index 1cbdaae177..f995ef3251 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -145,22 +145,29 @@ if ($upload_file) { $real_directory = (string) get_parameter('real_directory'); $directory = (string) get_parameter ('directory'); - // Copy file to directory and change name - if ($directory == '') { - $nombre_archivo = $real_directory .'/'. $filename; + $hash = get_parameter('hash', ''); + $testHash = md5($real_directory . $directory . $config['dbpass']); + + if ($hash != $testHash) { + echo "

".__('Security error.')."

"; } else { - $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; - } - if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) { - echo "

".__('attach_error')."

"; - } else { - $config['filemanager']['correct_upload_file'] = 1; - - // Delete temporal file - unlink ($_FILES['file']['tmp_name']); - } - + // Copy file to directory and change name + if ($directory == '') { + $nombre_archivo = $real_directory .'/'. $filename; + } + else { + $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; + } + if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) { + echo "

".__('attach_error')."

"; + } else { + $config['filemanager']['correct_upload_file'] = 1; + + // Delete temporal file + unlink ($_FILES['file']['tmp_name']); + } + } } } @@ -188,17 +195,25 @@ if ($create_text_file) { $real_directory = (string) get_parameter('real_directory'); $directory = (string) get_parameter ('directory'); - if ($directory == '') { - $nombre_archivo = $real_directory .'/'. $filename; + $hash = get_parameter('hash', ''); + $testHash = md5($real_directory . $directory . $config['dbpass']); + + if ($hash != $testHash) { + echo "

".__('Security error.')."

"; } else { - $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; - } - if (! @touch($nombre_archivo)) { - echo "

".__('Error create file.')."

"; - } - else { - $config['filemanager']['correct_upload_file'] = 1; + if ($directory == '') { + $nombre_archivo = $real_directory .'/'. $filename; + } + else { + $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; + } + if (! @touch($nombre_archivo)) { + echo "

".__('Error create file.')."

"; + } + else { + $config['filemanager']['correct_upload_file'] = 1; + } } } else { @@ -228,32 +243,39 @@ if ($upload_zip) { $real_directory = (string) get_parameter('real_directory'); $directory = (string) get_parameter ('directory'); - // Copy file to directory and change name - if ($directory == '') { - $nombre_archivo = $real_directory .'/'. $filename; - } - else { - $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; - } - if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) { - echo "

".__('attach_error')."

"; - } - else { - // Delete temporal file - unlink ($_FILES['file']['tmp_name']); - - //Extract the zip file - $zip = new ZipArchive; - $pathname = $config['homedir'].'/'.$directory.'/'; - - if ($zip->open($nombre_archivo) === true) { - $zip->extractTo($pathname); - unlink($nombre_archivo); - } - - $config['filemanager']['correct_upload_file'] = 1; - } + $hash = get_parameter('hash', ''); + $testHash = md5($real_directory . $directory . $config['dbpass']); + if ($hash != $testHash) { + echo "

".__('Security error.')."

"; + } + else { + // Copy file to directory and change name + if ($directory == '') { + $nombre_archivo = $real_directory .'/'. $filename; + } + else { + $nombre_archivo = $config['homedir'].'/'.$directory.'/'.$filename; + } + if (! @copy ($_FILES['file']['tmp_name'], $nombre_archivo )) { + echo "

".__('attach_error')."

"; + } + else { + // Delete temporal file + unlink ($_FILES['file']['tmp_name']); + + //Extract the zip file + $zip = new ZipArchive; + $pathname = $config['homedir'].'/'.$directory.'/'; + + if ($zip->open($nombre_archivo) === true) { + $zip->extractTo($pathname); + unlink($nombre_archivo); + } + + $config['filemanager']['correct_upload_file'] = 1; + } + } } } @@ -267,15 +289,23 @@ if ($create_dir) { $directory = (string) get_parameter ('directory', "/"); - $dirname = (string) get_parameter ('dirname'); - if ($dirname != '') { - @mkdir ($directory.'/'.$dirname); - echo '

'.__('Created directory %s', $dirname).'

'; - - $config['filemanager']['correct_create_dir'] = 1; + $hash = get_parameter('hash', ''); + $testHash = md5($directory . $config['dbpass']); + + if ($hash != $testHash) { + echo "

".__('Security error.')."

"; } else { - echo "

".__('Error create file with empty name.')."

"; + $dirname = (string) get_parameter ('dirname'); + if ($dirname != '') { + @mkdir ($directory.'/'.$dirname); + echo '

'.__('Created directory %s', $dirname).'

'; + + $config['filemanager']['correct_create_dir'] = 1; + } + else { + echo "

".__('Error create file with empty name.')."

"; + } } } @@ -288,13 +318,22 @@ if ($delete_file) { $config['filemanager']['delete'] = 0; $filename = (string) get_parameter ('filename'); - echo "

".__('Deleting')." ".$filename."

"; - if (is_dir ($filename)) { - rmdir ($filename); - $config['filemanager']['delete'] = 1; - } else { - unlink ($filename); - $config['filemanager']['delete'] = 1; + + $hash = get_parameter('hash', ''); + $testHash = md5($filename . $config['dbpass']); + + if ($hash != $testHash) { + echo "

".__('Security error.')."

"; + } + else { + echo "

".__('Deleting')." ".$filename."

"; + if (is_dir ($filename)) { + rmdir ($filename); + $config['filemanager']['delete'] = 1; + } else { + unlink ($filename); + $config['filemanager']['delete'] = 1; + } } } @@ -338,6 +377,8 @@ function delete_directory($dir) * @param boolean $editor The flag to set the edition of text files. */ function file_explorer($real_directory, $relative_directory, $url, $father = '', $editor = false) { + global $config; + ?>