Files
Investidor-V2/tools/portal-audit-scanner.php
T
nala 6ddafc95ba
tests / ci (push) Canceled after 0s
oportunidades 4
2026-10-10 07:03:59 +02:00

44 lines
2.6 KiB
PHP

<?php
// No database connection or data writes; scan retained private QA source files only.
use App\Services\Malware\MalwareScanner;
use Illuminate\Contracts\Console\Kernel;
$root = dirname(__DIR__);
require $root.'/vendor/autoload.php';
$app = require $root.'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$scanner = app(MalwareScanner::class);
$health = $scanner->health();
$health['signatures_at'] = $health['signatures_at']?->format(DATE_ATOM);
$files = [];
if ($health['available']) {
foreach ([1, 2, 3] as $level) {
$path = $root.'/storage/app/private/investmoz-v2/portal-audit/moz-adm'.$level.'-ine-20190607.geojson';
$scan = $scanner->scan($path, filesize($path), $root.'/storage/app/private');
$scan['signatures_at'] = $scan['signatures_at']?->format(DATE_ATOM);
$files[] = ['file' => basename($path), 'sha256' => hash_file('sha256', $path), 'scan' => $scan];
}
}
// Standard harmless antivirus test string is streamed from memory, never written to disk.
$probe = null;
if ($health['available']) {
$socket = stream_socket_client('tcp://127.0.0.1:3310', $number, $message, 5);
if ($socket === false) {
throw new RuntimeException('ClamD probe connection failed.');
}
stream_set_timeout($socket, 10);
$content = base64_decode('WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5EQVJELUFOVElWSVJVUy1URVNULUZJTEUhJEgrSCo=');
fwrite($socket, "zINSTREAM\0".pack('N', strlen($content)).$content.pack('N', 0));
$reply = stream_get_contents($socket);
fclose($socket);
$probe = ['mode' => 'INSTREAM_memory', 'detected' => str_contains($reply, 'FOUND') && str_contains($reply, 'Eicar'), 'reply' => trim($reply, "\0\r\n")];
// Names are engine dependent and may contain EICAR in upper case.
$probe['detected'] = str_contains($reply, 'FOUND') && str_contains(strtolower($reply), 'eicar');
}
$result = ['captured_at' => gmdate('c'), 'health' => $health, 'files' => $files, 'standard_test_probe' => $probe, 'active_database_writes' => 0,
'binary_url' => 'https://www.clamav.net/downloads/production/clamav-1.5.4.win.x64.zip', 'binary_sha256' => hash_file('sha256', $root.'/storage/app/private/investmoz-v2/portal-audit/clamav/clamav-1.5.4.win.x64.zip'),
'runtime_scope' => 'Local portable daemon on loopback; startup after reboot and periodic signature maintenance still require configuration'];
file_put_contents($root.'/storage/app/private/investmoz-v2/portal-audit/clamd-lote2.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;