• [^] # Re: Outil intéressant mais...

    Posté par . En réponse au journal [PHP] Apache Check, première release. Évalué à 4. Dernière modification le 04 août 2021 à 15:34.

    Voici ton code avec une erreur très peu visible introduite (il me semble qu'il s'exécute, même, mais pas sûr), tel qu'écrit à ta façon.

    Combien de temps vas-tu mettre à la trouver sans comparer au code initial ?

    // search for the pid with this inode in /proc/<pid>/fd (need to be root)
    $pid = "";
    $process_name = "";
    $process_cmdline = "";
    if ($h1 = @opendir("/proc")) {
     $found = false;
     while (false !== ($file1 = readdir($h1))) {
     if (! $found) {
     if (is_numeric($file1)) {
     if ($h2 = @opendir("/proc/$file1/fd")) {
     while (false !== ($file2 = readdir($h2))) {
     if (! $found) {
     if (is_link("/proc/$file1/fd/$file2")) {
     $file3 = readlink("/proc/$file1/fd/$file2");
     if (strpos($file3, "socket:[$inode]") !== false) {
     display("[..] Found inode for port $port in $file3 in /proc/$file1/fd");
     $status = file_get_contents("/proc/$file1/status");
     $status_ppid = "";
     $status_pid = "";
     $status_lines = explode("\n", $status);
     foreach ($status_lines as $line) {
     if (substr($line, 0, 4) == "Pid:") {
     $status_pid = trim(substr($line, 4));
     }
     if (substr($line, 0, 5) == "PPid:") {
     $status_ppid = trim(substr($line, 5));
     }
     if (substr($line, 0, 5) == "Name:") {
     $process_name = trim(substr($line, 5));
     }
     }
     if ($status_ppid == 1) {
     $pid = $status_pid;
     } else {
     $pid = $status_ppid;
     }
     $process_cmdline = readlink("/proc/$file1/exe");
     $found = true;
     }
     }
     }
     }
     }
     closedir($h2);
     }
     }
     }
     closedir($h1);
    }
    if ($pid == "") {
     display("[!!] Fatal error : unable to find the main apache process pid in /proc for inode $inode");
     exit();
    } else {
     display("[OK] Apache main process '$process_name' found : $process_cmdline (pid $pid)");
    }

    Matricule 23415