scan files from php? can U

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
shyami
Forum Newbie
Posts: 4
Joined: Sun Aug 27, 2006 11:57 pm

scan files from php? can U

Post by shyami »

Hai,

Last one week onwards i am posting my question in most of the sites, and i read many books also, but i can't get anything.

here is my question


i am uploading some files through my PHP program, here i need to scan the files for virus information. I don't know how to scan the files from my coding

some sites refer clamav, i installed that but it is asking clamav database...


Is there any way to scan the files? Plz help me

Regards
Shyami
User avatar
mibocote
Forum Newbie
Posts: 18
Joined: Sun Aug 20, 2006 9:51 am
Contact:

Post by mibocote »

You will have to put the file in a temporary location and then run clamav on it, having only minimal experience with clamav all I can tell you is that you should: a) look at it's documentationand b) the bin program clamscan might be the easiest.

Edit: exec() is the way to run external programs.
shyami
Forum Newbie
Posts: 4
Joined: Sun Aug 27, 2006 11:57 pm

clamav

Post by shyami »

Thanks for u'r reply, It's very usefull to me

here is my code
----------------------
<?php
$e= "testphp.php";
echo "<br>";
$g=system("clamscan \"/$e\"");
echo "<br>";
echo "Res is : ", $g;
?>

Result is
------------


WARNING: Version mismatch (clamscan: 0.88.4, libclamav: 0.88.3) See the FAQ at http://www.clamav.net/faq.html /testphp.php: OK ----------- SCAN SUMMARY ----------- Known viruses: 60743 Engine version: 0.88.3 Scanned directories: 0 Scanned files: 1 Infected files: 0 Data scanned: 0.00 MB Time: 1.550 sec (0 m 1 s)
Res is : Time: 1.550 sec (0 m 1 s)


in $g some time is there
how i know the status of the file in my coding ?

with thanks
shyami
han866
Forum Newbie
Posts: 4
Joined: Sun Dec 04, 2005 8:25 pm

Post by han866 »

Hello

You can try to get the return value from clamscan. Looking at the man page, the following exit codes might be usefull...

Code: Select all

0 : No virus found.

1 : Virus(es) found.



Here is a list of available exit codes:

Code: Select all

0 : No virus found.

1 : Virus(es) found.

40: Unknown option passed.

50: Database initialization error.

52: Not supported file type.

53: Can't open directory.

54: Can't open file. (ofm)

55: Error reading file. (ofm)

56: Can't stat input file / directory.

57: Can't get absolute path name of current working directory.

58: I/O error, please check your file system.

59: Can't get information about current user from /etc/passwd.

60:  Can't  get  information  about  user  'clamav' (default name) from
       /etc/passwd.

61: Can't fork.

62: Can't initialize logger.

63: Can't create temporary files/directories (check permissions).

64: Can't write to temporary directory (please specify another one).

70: Can't allocate and clear memory (calloc).

71: Can't allocate memory (malloc).
I think all you need to do is add the $retVal to exec().

Code: Select all

<?php
$e= "testphp.php";
echo "<br>";
$g=system("clamscan \"/$e\"", $retVal);
if(!$retVal){
echo "clean";
}else{
echo $retVal;
}
?>
HTH
hanji
AlecH
Forum Commoner
Posts: 27
Joined: Fri Feb 24, 2006 4:22 pm
Location: New Hampshire

Post by AlecH »

Also note though that when switching hosts, make sure they dont disable those functions because I know alot of them do.
Post Reply