我正在尝试在 apache 2.4、php 5.6 上使用 clamav 扫描文件(通常为 100MB+ zip),并使用 clamav-daemon 的套接字。我没有使用 PHP-FPM。(ps套接字工作,我可以发送一个PING并得到一个PONG)。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
if(socket_connect($socket, '/var/run/clamav/clamd.ctl')) {
$result = "";
$file = $_FILES['file']['tmp_name'];
socket_send($socket, "SCAN $file", strlen($file) + 5, 0);
socket_recv($socket, $result, 20000, 0);
var_dump($result);
}
socket_close($socket);
}
?>
<form method="post" enctype="multipart/form-data"><input type="file" name="file"><input type="submit"></form>
上传文件会产生:
string(65) "/tmp/phpxYBjyS: lstat() failed: No such file or directory. ERROR "
在我看来,这似乎是一个权限错误(即使 /tmp 是drwxrwxrwt 9 root root 4096 Dec 4 13:10 tmp
)。但我可能是错的。我不能轻易查看文件,因为在 php 进程完成后,文件被删除。
clamdscan
,在命令行,当然工作(例如/tmp/virus.txt: Eicar-Test-Signature FOUND
)。
我/etc/clamav/clamd.conf
的仍然是默认值。它看起来像这样:
LocalSocket /var/run/clamav/clamd.ctl
FixStaleSocket true
LocalSocketGroup clamav
LocalSocketMode 666
# TemporaryDirectory is not set to its default /tmp here to make overriding
# the default with environment variables TMPDIR/TMP/TEMP possible
User clamav
AllowSupplementaryGroups true
ScanMail true
ScanArchive true
ArchiveBlockEncrypted false
MaxDirectoryRecursion 15
FollowDirectorySymlinks false
FollowFileSymlinks false
ReadTimeout 180
MaxThreads 12
MaxConnectionQueueLength 15
LogSyslog false
LogRotate true
LogFacility LOG_LOCAL6
LogClean false
LogVerbose false
DatabaseDirectory /var/lib/clamav
OfficialDatabaseOnly false
SelfCheck 3600
Foreground false
Debug false
ScanPE true
MaxEmbeddedPE 10M
ScanOLE2 true
ScanPDF true
ScanHTML true
MaxHTMLNormalize 10M
MaxHTMLNoTags 2M
MaxScriptNormalize 5M
MaxZipTypeRcg 1M
ScanSWF true
DetectBrokenExecutables false
ExitOnOOM false
LeaveTemporaryFiles false
AlgorithmicDetection true
ScanELF true
IdleTimeout 30
CrossFilesystems true
PhishingSignatures true
PhishingScanURLs true
PhishingAlwaysBlockSSLMismatch false
PhishingAlwaysBlockCloak false
PartitionIntersection false
DetectPUA false
ScanPartialMessages false
HeuristicScanPrecedence false
StructuredDataDetection false
CommandReadTimeout 5
SendBufTimeout 200
MaxQueue 100
ExtendedDetectionInfo true
OLE2BlockMacros false
ScanOnAccess false
AllowAllMatchScan true
ForceToDisk false
DisableCertCheck false
DisableCache false
MaxScanSize 100M
MaxFileSize 25M
MaxRecursion 16
MaxFiles 10000
MaxPartitions 50
MaxIconsPE 100
PCREMatchLimit 10000
PCRERecMatchLimit 5000
PCREMaxFileSize 25M
ScanXMLDOCS true
ScanHWP3 true
MaxRecHWP3 16
StatsEnabled false
StatsPEDisabled true
StatsHostID auto
StatsTimeout 10
StreamMaxLength 25M
LogFile /var/log/clamav/clamav.log
LogTime true
LogFileUnlock false
LogFileMaxSize 0
Bytecode true
BytecodeSecurity TrustSigned
BytecodeTimeout 60000
/Edit 尝试使用exec而不是套接字。
if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
$path = escapeshellarg($_FILES['file']['tmp_name']);
$code = -1;
$result = '';
exec('clamdscan ' . $path, $result, $code);
if ($code !== 0) {
var_dump($result);
}
}
这也会产生类似的错误
array(6) {
[0]=>
string(64) "/tmp/php2hQTE8: lstat() failed: No such file or directory. ERROR"
[1]=>
string(0) ""
[2]=>
string(36) "----------- SCAN SUMMARY -----------"
[3]=>
string(17) "Infected files: 0"
[4]=>
string(15) "Total errors: 1"
[5]=>
string(25) "Time: 0.000 sec (0 m 0 s)"
}