HEX
Server: Apache
System: Linux shared178.accountservergroup.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User: somesolu (2995)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //etc/cron.hourly/unsafe_root_procs
#! /usr/bin/env perl
use Sys::Hostname;
use strict;
use warnings;
my $problems = 0;

opendir my $d, '/proc';
while (defined(my $pid = readdir $d)) {
    next unless -o "/proc/$pid";
    check_exe($pid);
    check_cmdline($pid);
}
report($problems);

sub check_exe {
    my ($pid) = @_;
    my $script = readlink "/proc/$pid/exe" or return;
    return unless $script =~ m,^(/home\d*/[^/]+/),;
    my $homedir = $1;
    return if -o $homedir;
    print STDERR "root proc under user dir: $script\n" if -t \*STDERR;
    $problems++;
}

sub check_cmdline {
    my ($pid) = @_;
    open my $f, '<', "/proc/$pid/cmdline" or return;
    my @cmd = split /\0/, scalar(<$f>);
    close $f;
    return unless @cmd >= 2
        && $cmd[0] =~ m,(?:sh|bash|perl|ruby|php|python|lua|tclsh|awk)$,
        && $cmd[1] =~ m,^(/home\d*/[^/]+/),;
    my $homedir = $1;
    return if -o $homedir;
    print STDERR "root script under user dir: @cmd\n" if -t \*STDERR;
    $problems++;
}

sub report {
    my ($flag) = @_;
    exec "/usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -s '@{[hostname()]}' -k eig.user.root_process -o $flag >/dev/null 2>/dev/null";
}