Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/scanner/classes/Archiver.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ public function __construct($filename, $mode = 'r')
$archive = new ZipArchive;
if ($this->mode === 'r') {
$result = $archive->open($this->filename, ZipArchive::OPEN);
if (!$result) die(PS_ERR_ARCHIVE_OPENING);
} else if ($this->mode === 'w' || $this->mode === 'a') {
if (!$result) {
die(PS_ERR_ARCHIVE_OPENING);
}
} elseif ($this->mode === 'w' || $this->mode === 'a') {
$result = $archive->open($this->filename, ZipArchive::CREATE);
if (!$result) die(sprintf(PS_ERR_ARCHIVE_CREATION, $this->filename));
if (!$result) {
die(sprintf(PS_ERR_ARCHIVE_CREATION, $this->filename));
}
} else {
die(PS_ERR_WRONG_ARCHIVE_MODE);
}
Expand All @@ -26,7 +30,9 @@ public function __construct($filename, $mode = 'r')

public function addFile($filename, $targetFilename = null)
{
if ($this->mode === 'r') die(PS_ERR_ARCHIVE_WRITE_INCORRECT_MODE);
if ($this->mode === 'r') {
die(PS_ERR_ARCHIVE_WRITE_INCORRECT_MODE);
}
if (!$targetFilename) {
$this->archive->addFile($filename);
} else {
Expand All @@ -44,4 +50,3 @@ public function close()
$this->archive->close();
}
}

3 changes: 1 addition & 2 deletions src/scanner/classes/Auth.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Auth
{
function __construct()
public function __construct()
{
global $projectTmpDir;
$this->passwordHashFilepath = $projectTmpDir . '/password_hash.php';
Expand Down Expand Up @@ -125,4 +125,3 @@ public function auth()
return $result;
}
}

13 changes: 5 additions & 8 deletions src/scanner/classes/CmsVersionDetector.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,29 @@ public function __construct($rootPath = '.')
if ($this->checkPhpShopScript($version)) {
$this->addCms(CMS_SHOPSCRIPT, $version);
}

}

function getCmsList()
public function getCmsList()
{
return $this->types;
}

function getCmsVersions()
public function getCmsVersions()
{
return $this->versions;
}

function getCmsNumber()
public function getCmsNumber()
{
return count($this->types);
}

function getCmsName($index = 0)
public function getCmsName($index = 0)
{
return $this->types[$index];
}

function getCmsVersion($index = 0)
public function getCmsVersion($index = 0)
{
return $this->versions[$index];
}
Expand All @@ -139,7 +138,6 @@ private function checkBitrix(&$version)
if (preg_match('|define\("SM_VERSION","(.+?)"\)|smi', $tmpContent, $tmpVer)) {
$version = $tmpVer[1];
}

}

return $res;
Expand Down Expand Up @@ -394,4 +392,3 @@ public function getXMLNode()
return $dom->getElementsByTagName('cms_list')->item(0);
}
}

2 changes: 0 additions & 2 deletions src/scanner/classes/DownloadController.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,4 @@ public function start()
$this->startDownload();
}
}

}

11 changes: 5 additions & 6 deletions src/scanner/classes/ExecutorController.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ private function startExecutor()
$validator = new XmlValidator();
global $projectRootDir;

if (get_magic_quotes_gpc()) $xmlRecipe = stripslashes($xmlRecipe);
if (get_magic_quotes_gpc()) {
$xmlRecipe = stripslashes($xmlRecipe);
}

//TODO: implement proper XXE prevention or switch to JSON instead
if (strpos(strtoupper($xmlRecipe), '<!ENTITY') !== false) {
Expand Down Expand Up @@ -65,7 +67,7 @@ private function startExecutor()
define('PS_EXECUTE_TOTAL_Q', count($quarantineFiles));

$view->display('executor_changes.tpl');
} else if (isset($_POST['a']) && ($_POST['a'] === 'apply')) {
} elseif (isset($_POST['a']) && ($_POST['a'] === 'apply')) {
$deleteTotal = (int)$_POST['total_d'];
$quarantineTotal = (int)$_POST['total_q'];

Expand All @@ -91,9 +93,7 @@ private function startExecutor()
define('PS_QUARANTINE_URL', $quarantineUrl);

$view->display('executor_done.tpl');

} else if (isset($_REQUEST['a']) && ($_REQUEST['a'] == 'selfDelete')) {

} elseif (isset($_REQUEST['a']) && ($_REQUEST['a'] == 'selfDelete')) {
global $projectRootDir, $projectTmpDir;
if ($projectTmpDir == sys_get_temp_dir()) {
@unlink($projectTmpDir . '/scan_log.xml');
Expand Down Expand Up @@ -136,4 +136,3 @@ public function start()
}
}
}

2 changes: 0 additions & 2 deletions src/scanner/classes/FileInfo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,3 @@ public function __toString()
return implode(';', $data);
}
}


28 changes: 13 additions & 15 deletions src/scanner/classes/FileList.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class FileList
{
function __construct()
public function __construct()
{
global $projectTmpDir;

Expand Down Expand Up @@ -42,7 +42,6 @@ function __construct()
#For creating temprorary queue for further antimalware/whitelist scan
$this->GENERATE_FILE_QUEUE = true;
$this->tmpQueueFilename = $projectTmpDir . '/scan_queue.manul.tmp.txt';

}

private function throwTimeout()
Expand All @@ -65,7 +64,7 @@ private function fileExecutor($filePath, $type, $actionType)

$this->dom->documentElement->appendChild($this->dom->importNode($fileinfoNode, true));
$this->filesFound++;
} else if ($actionType === $this->ACTION_SKIP) {
} elseif ($actionType === $this->ACTION_SKIP) {
// TODO: Do something with skipped item
// fputs($file_handle, "* SKIPPED *************************************** " . $file_path);
}
Expand All @@ -81,11 +80,9 @@ public function getXMLFilelist()

private function finalizeRound()
{

global $php_errormsg;

if ($fHandle = fopen($this->AJAX_TMP_FILE, 'a')) {

$nodeList = $this->filesNode->childNodes;
$num = $nodeList->length;

Expand All @@ -98,9 +95,7 @@ private function finalizeRound()
$response['data'] = array();
$report = json_encode($response);
return $report;

} else {

ob_end_clean();
// output result for ajax processing
$response['meta'] = array('type' => 'error', 'phpError' => $php_errormsg);
Expand All @@ -117,7 +112,7 @@ private function cleanUp()
@unlink($this->AJAX_TMP_FILE);
}

function setUp()
public function setUp()
{
}

Expand All @@ -127,23 +122,25 @@ public function performScanning()

$dirs = '.';

if (file_exists($this->DIRLIST_TMP_FILENAME))
if (file_exists($this->DIRLIST_TMP_FILENAME)) {
$dirs = file_get_contents($this->DIRLIST_TMP_FILENAME);
}

$dirList = explode("\n", $dirs);
$startTime = time();

while (true) {
$dirList = array_merge($this->folderWalker(array_shift($dirList), $this->filesFound), $dirList);
$currentTime = time();
if (($currentTime - $startTime >= $this->MAX_EXECUTION_DURATION) || (count($dirList) < 1)) break;
if (($currentTime - $startTime >= $this->MAX_EXECUTION_DURATION) || (count($dirList) < 1)) {
break;
}
}

$result = $this->finalizeRound();


if (!$this->filesFound) {

$response['meta'] = array('type' => 'getFileList', 'status' => 'finished', 'phpError' => $php_errormsg);
$response['data'] = array();
$report = json_encode($response);
Expand All @@ -167,14 +164,17 @@ public function setInterval($val)

private function folderWalker($path, &$files_found)
{
if ($path === '.')
if ($path === '.') {
$path = $_SERVER['DOCUMENT_ROOT'];
}

$dirList = array();

if ($currentDir = opendir($path)) {
while ($file = readdir($currentDir)) {
if ($file === '.' || $file === '..' || is_link($path) || $file === basename($this->homedir)) continue;
if ($file === '.' || $file === '..' || is_link($path) || $file === basename($this->homedir)) {
continue;
}
$name = $file;
$file = $path . '/' . $file;
// skip path entries from the list
Expand All @@ -192,7 +192,6 @@ private function folderWalker($path, &$files_found)
$fileType = $this->TYPE_FOLDER;
}
$this->fileExecutor($file, $fileType, $this->ACTION_PROCESS);

}
closedir($currentDir);
}
Expand All @@ -206,4 +205,3 @@ private function folderWalker($path, &$files_found)
return $dirList;
}
} // End of class

11 changes: 7 additions & 4 deletions src/scanner/classes/Healer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private function parseXmlRecipe($xmlRecipe)

private function quarantineFile($filename)
{

if (!is_file($filename)) {
$this->log .= '<div class="err">' . sprintf(PS_ERR_QUARANTINE_NOT_EXISTS, $filename) . '</div>';
return false;
Expand Down Expand Up @@ -80,9 +79,13 @@ private function deleteFile($filename)

public function deleteDir($dirname)
{
if (!is_dir($dirname) || is_link($dirname)) return unlink($dirname);
if (!is_dir($dirname) || is_link($dirname)) {
return unlink($dirname);
}
foreach (scandir($dirname) as $file) {
if ($file === '.' || $file === '..') continue;
if ($file === '.' || $file === '..') {
continue;
}
if (!$this->deleteDir($dirname . DIRECTORY_SEPARATOR . $file)) {
chmod($dirname . DIRECTORY_SEPARATOR . $file, 0777);
$this->deleteDir($dirname . DIRECTORY_SEPARATOR . $file);
Expand Down Expand Up @@ -127,7 +130,7 @@ public function executeXmlRecipe($deleteFiles, $quarantineFiles, &$numQuarantine

$this->archiver->close();

//Put malicious files to backup archive and delete them
//Put malicious files to backup archive and delete them
foreach ($deleteFiles as $filename) {
$this->archiver = new Archiver($this->backupFilepath, 'a');

Expand Down
1 change: 0 additions & 1 deletion src/scanner/classes/Initialization.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ function escapedOctDec($escaped)
{
return chr(octdec($escaped[1]));
}

1 change: 0 additions & 1 deletion src/scanner/classes/Localization.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,3 @@
define('PS_CHECKER_FIX', 'Як виправити');
define('PS_CHECKER_MESSAGE', 'Будь ласка, виправте зазначені проблеми та перезапустіть Manul.');
}

Loading