facing a strange problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabanita
    New Member
    • Mar 2010
    • 9

    facing a strange problem...

    in order to scan the complete C drive i wrote a code it is scanning almost all the folders completely however it is leaving out some which can be easily (seperately) opened and sacnned using the same code........... ............... ...........

    the code used is pasted below, please suggest me how to rectify my code to solve the problem and go through all the folders not some!




    Code:
    <?php 
    function DirDisply($p) 
    { 
             $TrackDir=opendir($p); 
             while ($file = readdir($TrackDir)) 
             { 
                         if ($file == "." || $file == "..") { } 
                         else  
                         {
                                //print "<table><tr><td>$file</td>";
                                //print "<td>  ".filetype($file)."</td></tr></table>"; 
                                $n=$p."\\".$file; //echo"<br>$n<br>";        
                                if( opendir($n) ) {@ DirDisply($n);}                     
                                else 
                                {
                                   if(is_executable($file) )
                                   {
                                     $handle=fopen($file, "rb");
                                     echo("$file");
                                     $convert=bin2hex( fread( $handle, filesize($file) ) );
                                     $pattern="/a900003000000040/";
                                     if(preg_match($pattern, $convert))
                                     {
                                            echo"<b><i>VIRUS DETECTED<br></b></i>";
                                     }
                                     else
                                            echo"YOUR COMPUTER IS RUNNING FREE OF VIRUSES";
                                    
                                     pack( "H*", $convert );
                                     fclose($handle); 
                                   }
                                }
                         } 
             } 
             closedir($TrackDir); 
             return; 
    } 
    ?>
    
    <b><font face="Verdana, Arial, Helvetica, sans-serif">Current Directory Contain 
    Following files and Sub Directories...</font></b> 
    <p> 
    
    <?php 
    
    $p="C:";
    @ DirDisply($p); 
    ?>
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Do you have error_reporting set so that it displays errors? (See Turn on PHP Debugging Messages.)

    You should also remove the @ on line 13. It could be hiding the error that is causing this.

    Comment

    • philipwayne
      New Member
      • Mar 2010
      • 50

      #3
      I believe your problem is

      Code:
      $n=$p."\\".$file;
       if( opendir($n) ) {@ DirDisply($n);}
      When going through the file system use forward slashes as there native to most if not all machines. /
      I wouldn't use opendir( ) to test it, use is_dir( ).

      But the reason this is failing is that PHP probably doesn't have permission to access folders like System32 or even Windows.
      Correct permissions and probably correct the problem.
      Just navigate to the php.exe [right click->properties-> compatibility-> privilege level->run as administrator], Note HUGE risk

      Also I wanted to point out a few things.

      1: your reverting the hexadecimal content but doing nothing with it?
      Code:
      pack( "H*", $convert );
      2: Your evaluating an expression for no reason other then wasting time.
      Instead of
      Code:
      if ($file == "." || $file == "..") { } 
      else {
      Use
      Code:
      if ($file != "." && $file != "..") {
      3: You function uses the return statement but nothing is returned. The only time this really should be done if you need to break out of the function return; is still wasting resources theres no need for it.

      Comment

      Working...