Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. #!/usr/local/bin/php -q
  2. <?php
  3.   define('MAX_ALLOWED_INFECTED_FILES', 3);
  4.  
  5.   stream_set_blocking(STDIN, 0);
  6.   $stdin = fopen('php://stdin', 'r');
  7.   $data = stream_get_contents($stdin);
  8.   $json = json_decode(trim($data), true);
  9.  
  10.   switch ($json['event']) {
  11.     case 'malware-detected':
  12.                              // if it's infection?
  13.                              if ($json['subtype'] == 'critical') {
  14.                                  // retrieve the scanning report
  15.                                  $report = json_decode(file_get_contents($json['params']['tmp_filename']), true);
  16.                                  $by_users = array();
  17.  
  18.                                  // combine infected files by users
  19.                                  foreach ($report as $entry) {
  20.                                     if (!isset($by_users[$entry['username']])) {
  21.                                         $by_users[$entry['username']] = array();
  22.                                     }
  23.  
  24.                                     $by_users[$entry['username']][] = $entry['file'];
  25.                                  }
  26.  
  27.                                  // suspend all accounts, where number of infected files more than MAX_ALLOWED_INFECTED_FILES
  28.                                  foreach ($by_users as $user => $files) {
  29.                                     if (count($files) > MAX_ALLOWED_INFECTED_FILES) {
  30.                                        exec('/scripts/suspendacct ' . $user . ' "Reason" 1');
  31.                                     }
  32.                                  }
  33.  
  34.                              }                                                      
  35.                              break;
  36.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement