- GRAYBYTE UNDETECTABLE CODES -

403Webshell
Server IP : 184.154.167.98  /  Your IP : 18.188.92.6
Web Server : Apache
System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
User : puertode ( 1767)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/local/ddos/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/local/ddos/loadmonitor
#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl

# Path to sendmail
$mailprog = '/usr/sbin/sendmail';

# Set these variables
# If you get too many emails, you may want to increase one or more of these
# maximum values or add processes to the commands to ignore list.

# Maximum %CPU per process
$maxcpu = 10;

# Maximum %CPU - top 10 processes total
$maxcputotal = 40;

# Number of CPU's on server
$CPUs = 1;

# Maximum load average
# Generally around 2 to 3 times the number of CPU's
# Only watches the 5 and 15 minute averages. The 1 minute
# average would send far too many warning emails.
$maxloadave = 2;

# Maximum %Memory per process
$maxmem = 10;

# Maximum %Memory - top 10 processes total
$maxmemtotal = 40;

# Email to send message to
$email = 'MRH <mrhhosting@gmail.com>';

# Email to use as message sender
# Change this one if you like
$sender = 'root <root@mason.dnsnetservice.com>';

# Any name to let you know which server this came from
$servername = "mason.dnsnetservice.com";

# When you are emailed about your server load, you can also have the
# current "top" output sent in the email. If you do want it included,
# change this option to Y.
$includetop = "N";



#**************************
#   No further editing
#**************************

$cputotal = 0;
$memtotal = 0;
$messagecount = 0;
$multicpu = "";
@messages = "";
$allprocesses = "";


&docheck;

exit;


sub docheck {

@top = `top -n1 -bc`;

foreach (@top) {
  chomp ($_);
  $_ =~ s/\r/\n/gs;
  $count++;
  if ($_ =~ /load average/) {
    $tmp = $_;
    $tmp =~ s/.*load average://;
    $tmp =~ s/ +//g;
    ($oneminuteave,$fiveminuteave,$fifteenminuteave) = split(/,/,$tmp);
  }
  if ($_ =~ /PID/ && $_ =~ /USER/ && $_ =~ /COMMAND/) {
    $commandline = $_;
    $commandline =~ s/^ +//g;
    $commandline =~ s/ +/\|/g;
    $line1 = $count;
    $line2 = $count + 11;
  }
  if ($count > $line1 && $count < $line2) {
    push(@processes,$_);
  }
}

$oneminuteavepercpu = $oneminuteave / $CPUs;
$fiveminuteavepercpu = $fiveminuteave / $CPUs;
$fifteenminuteavepercpu = $fifteenminuteave / $CPUs;

if ($fiveminuteave > $maxloadave || $fifteenminuteave > $maxloadave) {
    $messagecount++;
  }
  else {
}

foreach (@processes) {
  chomp ($_);
  $_ =~ s/^ +//;

  $tmp2 = $_;
  $tmp = $_;

  $PID = $tmp;
  $PID =~ s/\s.*//;
  $tmp =~ s/^$PID\s+//;

  $USER = $tmp;
  $USER =~ s/\s.*//;
  $tmp =~ s/^$USER\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\D+//;

  $CPU = $tmp;
  $CPU =~ s/\s.*//;
  $tmp =~ s/^$CPU\s+//;

  $MEM = $tmp;
  $MEM =~ s/\s.*//;
  $tmp =~ s/^$MEM\s+//;

  $TIME = $tmp;
  $TIME =~ s/\s.*//;
  $tmp =~ s/^$TIME\s+//;

  if ($CPUs > 1) {
      $whichCPU = $tmp;
      $whichCPU =~ s/\s.*//;
      $tmp =~ s/^$whichCPU\s+//;
      $COMMAND = $tmp;
      $multicpu = " on CPU #" . $whichCPU;
    }
    else {
      $COMMAND = $tmp;
  }

  # Just in case the output wasn't read correctly
  if ($PID =~ /\D/) {
    $error = $error . "Process ID not read correctly\n";
  }
  if ($CPU !~ /\d+\.?\d*/) {
    $error = $error . "CPU percentage not read correctly\n";
  }
  if ($MEM !~ /\d+\.\d+/) {
    $error = $error . "Memory percentage not read correctly\n";
  }
  if ($TIME =~ /\d+:\d+\.?\d*/) {
      ($minutes,$seconds) = split(/:/,$TIME);
      $running_time = "$minutes minutes and $seconds seconds";
    }
    elsif ($TIME =~ /\d+m/) {
      $minutes =~ $TIME;
      $minutes =~ s/m$//;
      $running_time = "$minutes minutes";
      if ($minutes > 999) {
        $running_time = $running_time . ", which may be a long time for a process to be running";
        $messagecount++;
      }
    }
    else {
      $error = $error . "Time not read correctly\n";
  }

  if ($error) {&sendmailerror;}

  $cputotal = $cputotal + $CPU;
  $memtotal = $memtotal + $MEM;

  $tmpmessage = "- The process ID #$PID under the user $USER is using $CPU\% CPU and $MEM\% Memory with the command $COMMAND which has been running$multicpu for $running_time.\n\n";

  $allprocesses = $allprocesses . $tmpmessage;

  $CPUequiv = $CPU / $CPUs;

  if ($CPUequiv > $maxcpu || $MEM > $maxmem) {
    push (@messages,$tmpmessage);
    $messagecount++;
  }
}


$cputotalequiv = $cputotal / $CPUs;

if ($cputotalequiv > $maxcputotal || $memtotal > $maxmemtotal) {
  push (@messages,"\n#####################################\n\nThe top 10 processes are using a total of $cputotal\% CPU and a total of $memtotal\% Memory. The process list will follow.\n\n");
  push (@messages,"Here are the top 10 processes:\n\n$allprocesses\n\n");
  $messagecount++;
}

if ($messagecount > 0) {

  open(MAIL,"|$mailprog -t");

  print MAIL "To: $email\n";
  print MAIL "From: $sender\n";

  print MAIL "Subject: High server load warning notice at server $servername\n";

  print MAIL "Your server, $servername, appears to have a high load.\n\n";
  print MAIL "The load averages are:\n";
  print MAIL "1 minute: $oneminuteave ($oneminuteavepercpu per CPU)\n";
  print MAIL "5 minutes: $fiveminuteave ($fiveminuteavepercpu per CPU)\n";
  print MAIL "15 minutes: $fifteenminuteave ($fifteenminuteavepercpu per CPU)\n\n";
  if (@messages) {
      print MAIL "Here is what was just recorded as the current load.\n";
      print MAIL "If blank, it means you have no current processes with a high load.\n\n";
    print MAIL "@messages\n\n";
  }
  if ($includetop eq "Y") {
    print MAIL "Here is your recent output from top:\n\n";
      foreach (@top) {
        print MAIL "$_\n";
      }
  }

  close (mail);
}

}


sub sendmailerror {

open(MAIL,"|$mailprog -t");

print MAIL "To: $email\n";
print MAIL "From: $sender\n";

print MAIL "Subject: Incorrect reading from TOP output on server $servername\n";

print MAIL "Your server, $servername, appears to have a different output for TOP. The data could not be read properly.\n\n";
print MAIL "Please help me make adjustments for your servers output by issuing the command top in shell and sending the output to me at scripts\@premierwebsitesolutions.com.\n\n";
print MAIL "Also, please forward the following messages to me.\n\n";
print MAIL "-" x 20;
print MAIL "\nThe error is:\n$error\n";
print MAIL "PID: $PID\n";
print MAIL "USER: $USER\n";
print MAIL "CPU: $CPU\n";
print MAIL "MEM: $MEM\n";
print MAIL "TIME: $TIME\n";
print MAIL "process line: -$tmp2-\n";
print MAIL "-" x 20;
print MAIL "\n\nOnce I have the modifications finished I will let you know.\n\n";
print MAIL "Mike\n";

close (mail);
exit;
}



Youez - 2016 - github.com/yon3zu
LinuXploit