what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

phpAV Code Auditing Tool 1.0

phpAV Code Auditing Tool 1.0
Posted Jan 5, 2010
Authored by Milos Zivanovic

phpAV is a script designed to work as antivirus for malicious PHP scripts. It will search a given directory and related files for dangerous functions and provide a report.

tags | web, php
SHA-256 | 52ba58c54f23247b703f406196191b4b06961a14a63f73da8e5e630962be128a

phpAV Code Auditing Tool 1.0

Change Mirror Download
#!/usr/bin/php
<?php
ini_set("max_execution_time", 0);
/**
* Title: phpAV
* Version: 1.0
* Author: Milos Zivanovic
* Email: milosz.security@gmail.com
* Date: January 2010.
*
* About: PHP script designed to work as antivirus for malicious
php scripts. phpAV search
* given directory an search in files with predefined
extension for dangerous
* functions such as system() and others. phpAV is
designed so it can be easily
* configured and look in more file types in search for
more functions.
*
* Usage: phpAV.php /var/www/
* file called Log.txt will appear in the same dir as
phpAV.php IF dangerous functions
* are found, else the file won't be there.
*
* Configuring: Array functions is used for storing functions you want
script to search in files.
* Array file_types is used for storing file types you
want phpAV to scan (it will
* only open files with those extensions).
* log_file is variable used for storing file name where
logs will be saved (script
* will create that file and write logs in it).
*
* Thanks: Special thanks to Teo Manojlovic, idea for this
originated in his mind.
* Note: Script tested on linux (ubuntu karmic koala (9.10))
**/

// CONFIGURATION SECTION
$functions = array('shell_exec', 'system', 'passthru', 'exec', 'eval',
'ftp_connect');
$file_types = array('php', 'php3', 'php4', 'php5', 'phps', 'ph3',
'ph4', 'html', 'htm', 'phtml');
$log_file = "Log.txt";
// END OF CONFIGURATION SECTION

$dir = $argv[1];

if($argc != 1) {
echo "Usage: ".$argv[0]." [DIR PATH]";
exit();
}
if(substr($dir, -1) != "/") $dir .= "/";

search_dir($dir);

function search_dir($path) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != "..") {
if(is_dir($path.$file))
search_dir($path.$file."/");
else if(is_readable($path.$file) && is_file_ext($path.$file))
search_in_file($path.$file);
}
}
}
}

function is_file_ext($file) {
global $file_types;
for($i=0;$i<count($file_types);$i++)
if(substr($file, -strlen($file_types[$i])) == $file_types[$i])
return 1;
return 0;
}

function search_in_file($file) {
global $functions;
$lines = array();
$found_str = array();
$found_line = array();
$content = file_get_contents($file);
$lines = explode("\n", $content);
for($i=0;$i<count($functions);$i++) {
for($j=0;$j<count($lines);$j++) {
if(strstr($lines[$j], " ".$functions[$i]."(") ||
strstr($lines[$j], "(".$functions[$i]."(") ||
strstr($lines[$j], ".".$functions[$i]."(") ||
strstr($lines[$j], "=".$functions[$i]."(") ||
strstr($lines[$j], "{".$functions[$i]."(") ||
strstr($lines[$j], ">".$functions[$i]."(") ||
strstr($lines[$j], "\t".$functions[$i]."(") ||
strstr($lines[$j], " ".$functions[$i]." (") ||
strstr($lines[$j], "=".$functions[$i]." (") ||
strstr($lines[$j], "{".$functions[$i]." (") ||
strstr($lines[$j], ".".$functions[$i]." (") ||
strstr($lines[$j], "(".$functions[$i]." (") ||
strstr($lines[$j], ">".$functions[$i]." (") ||
strstr($lines[$j], "\t".$functions[$i]." (") ||
substr($lines[$j], 0, strlen($functions[$i])) ==
$functions[$i]) {
$found_str[] = $lines[$j];
$found_line[] = $j+1;
}
}
}
if(!empty($found_str)) _log($file, $found_str, $found_line);
}

function _log($path, $line, $linenum) {
global $log_file;
file_put_contents($log_file, "File: ".$path."\n", FILE_APPEND);
for($i=0;$i<count($line);$i++) {
file_put_contents($log_file, "Line: ".$linenum[$i]." |
".$line[$i]."\n", FILE_APPEND);
}
}
?>
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    60 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    44 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close