Skip to content

Commit

Permalink
v2.0.4
Browse files Browse the repository at this point in the history
* Add more file extension and mime type.
* Add more security scan.
  • Loading branch information
ve3 committed Mar 8, 2019
1 parent 54c1ea5 commit 9d8abea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion Rundiz/Upload/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* PHP upload class that is able to validate requirements and limitations, real file's mime type check, detect the errors and report.
*
* @package Upload
* @version 2.0.3
* @version 2.0.4
* @author Vee W.
*/
class Upload
Expand Down Expand Up @@ -445,6 +445,31 @@ protected function securityScan()
return false;
}

// scan shell script
// reference: https://en.wikipedia.org/wiki/Shell_script
// https://stackoverflow.com/questions/10591086/shell-script-headers-bin-sh-vs-bin-csh
// https://www.shellscript.sh/
if (
stripos($file_content, '#!/') !== false &&
(
stripos($file_content, '/bin/sh') !== false ||
stripos($file_content, '/bin/bash') !== false ||
stripos($file_content, '/bin/csh') !== false ||
stripos($file_content, '/bin/tcsh') !== false
)
) {
// found shell script.
$this->setErrorMessage(
sprintf(static::__('Error! Found shell script embedded in the uploaded file. (%s).'), $this->files[$this->input_file_name]['name']),
'RDU_SEC_ERR_CGI',
$this->files[$this->input_file_name]['name'],
$this->files[$this->input_file_name]['name'],
$this->files[$this->input_file_name]['size'],
$this->files[$this->input_file_name]['type']
);
return false;
}

unset($file_content);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Rundiz/Upload/file-extensions-mime-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
'shtml' => array('text/html', 'text/x-server-parsed-html'),
'svg' => array('image/svg+xml'),
'tar' => array('application/x-tar'),
'text' => array('text/plain'),
'tgz' => array('application/x-gzip-compressed', 'application/x-tar'),
'tif' => array('image/tiff', 'image/x-tiff'),
'tiff' => array('image/tiff', 'image/x-tiff'),
'tar' => array('application/x-tar'),
'tgz' => array('application/x-gzip-compressed', 'application/x-tar'),
'text' => array('text/plain'),
'torrent' => array('application/x-bittorrent'),
'txt' => array('text/plain'),
'wav' => array('audio/wav', 'audio/wave', 'audio/x-wav'),
'wbmp' => array('image/vnd.wap.wbmp'),
Expand Down

0 comments on commit 9d8abea

Please sign in to comment.