Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are my options to check for viruses on a PHP upload?

Tags:

I am looking to see how I can go about checking if an uploaded file has a virus or not via PHP. What options exist, pros and cons of each, etc.

like image 797
Carl Avatar asked May 18 '12 22:05

Carl


People also ask

How do I scan PHP for malicious code?

PHP Antimalware Scanner is a free tool to scan PHP files and analyze your project to find any malicious code inside it. It provides an interactive text terminal console interface to scan a file, or all files in a given directory, and find PHP code files that seem to contain malicious code.

Can you get a virus from uploading a file?

Server-side attacksExploiting file upload vulnerabilities also allows hackers to place trojan horses, viruses, and other malicious files on your website.

Is PHP virus free?

Unfortunately, Php is undecryptable ransomware and there are no tools capable of cracking the RSA algorithm and restoring data free of charge.


2 Answers

ClamAV is a free anti virus commonly used on server applications.

php-clamav is an extension for binding ClamAV to PHP. You can check their documentation.

I've found a tutorial on how to use clamav as a Zend Framework Validator which already includes instructions on how to verify upload files. The tutorial should also help you on using it on another frameworks or architectures.

You can also call clamav by its command line interface with clamscan. This requires clamav to be installed but not the PHP extension. In the PHP side, you can shell_exec('clamscan myuploadedfile.zip'); then parse the output. Lines ending with OK are safe files, lines ending with FOUND are malicious files.

like image 136
alganet Avatar answered Oct 21 '22 14:10

alganet


You can use VirusTotal.com, they have an API which you can use to upload files and they will scan them using multiple virus scanners.

https://www.virustotal.com/

(unfortunately, their website is currently under maintenance, but I expect it to be back up soon enough)

like image 36
Jeroen Avatar answered Oct 21 '22 12:10

Jeroen