관리-도구
편집 파일: test_malware_deobfuscation.php
<?php /** * Test for malware sample that previously caused infinite recursion. * * This test ensures that the Deobfuscator can process the malware sample * from issue #XX without hanging or crashing. */ require_once __DIR__ . '/../src/Deobfuscator.php'; require_once __DIR__ . '/../src/CodeMatch.php'; use AMWScan\Deobfuscator; $malwareFile = __DIR__ . '/malware_sample_2308ba68.php'; if (!file_exists($malwareFile)) { echo "Error: Malware sample file not found at {$malwareFile}\n"; exit(1); } echo "Testing Deobfuscator with malware sample...\n\n"; // Read and strip the malware file $contentRaw = file_get_contents($malwareFile); echo "1. Reading malware sample... OK (" . strlen($contentRaw) . " bytes)\n"; $contentClean = @php_strip_whitespace($malwareFile); echo "2. Stripping whitespace... OK (" . strlen($contentClean) . " bytes)\n"; // Test deobfuscation with timeout $deobfuscator = new Deobfuscator(); $startTime = microtime(true); set_time_limit(5); // 5 second timeout - should complete in milliseconds try { $contentDeobfuscated = $deobfuscator->deobfuscate($contentClean); $elapsed1 = microtime(true) - $startTime; echo "3. Deobfuscating... OK (" . strlen($contentDeobfuscated) . " bytes, " . number_format($elapsed1 * 1000, 2) . "ms)\n"; $startTime = microtime(true); $contentDecoded = $deobfuscator->decode($contentDeobfuscated); $elapsed2 = microtime(true) - $startTime; echo "4. Decoding... OK (" . strlen($contentDecoded) . " bytes, " . number_format($elapsed2 * 1000, 2) . "ms)\n"; $totalTime = $elapsed1 + $elapsed2; // Check that it completed quickly (should be < 1 second) if ($totalTime < 1.0) { echo "\n✓ SUCCESS: Malware sample processed successfully in " . number_format($totalTime * 1000, 2) . "ms\n"; echo " This malware previously caused an infinite loop in the calc() method.\n"; exit(0); } else { echo "\n✗ WARNING: Processing took longer than expected (" . number_format($totalTime, 2) . "s)\n"; exit(1); } } catch (Exception $e) { echo "\n✗ FAIL: Exception during processing: " . $e->getMessage() . "\n"; exit(1); }