очередь sendmail - отображает количество сообщений на домен

Ну, потому что корень является действительным пользователем, и sshd делает это задание, позволяющее его. На OpenBSD (те же парни от OpenSSH), например, Вас не просят создать пользователя во время установки, таким образом, необходимо использовать корень для доступа к полю.

Некоторые основанные на рабочем столе дистрибутивы вынуждают Вас создать дополнительных пользователей, но для серверов Вам на самом деле не нужен тот.

Кроме того, этими аргументами, что sudo или su более безопасны, чем вход в систему как корень, является большой миф. На Ubuntu, например, пользователь может выполнить ЛЮБУЮ команду с помощью sudo по умолчанию, таким образом, любой взломщик, кто входит, может также выполнить ЛЮБУЮ команду как корень. Довольно бесполезный с точки зрения безопасности.

4
задан 19 September 2011 в 17:03
3 ответа

Well, if you are going to use perl, might as well go all the way.

The following is a fairly imperfect way of counting the number of messages per domain:

#!/usr/bin/perl

use strict;

my @mailq = `cat /home/users/rilindo/mailq`; #Had to simulate the output of the mail command here. Change this to the actual mailq path, e.g. /usr/bin/mailq
my %domains = ();

foreach my $m (@mailq) {
    $m =~ s/^\s+//;
    $m =~ s/\s+$//;
    $m =~ s/>//;
    next if $m =~ /Queue/;
    if ($m =~ /\d\d:\d\d:\d\d/) {
        $domains{(split(/@/,$m))[1]}++;
    }
    else {
        $domains{(split(/@/,$m))[1]}++;
    }
}

foreach my $d (keys %domains) {
    print $d . " has $domains{$d} message(s)" . "\n";
}

Essentially, we send an output of the mailq command into an array and iterate. For each record in the array, we strip the leading and trailing spaces/newlines, and then split at the "@" sign. Then we insert domain as a key (if it doesn't exist) and then increment it in a hash. On the next try, it will simply increment the value if the same domain was found. From there, we loop through the hash and then print out the domain with the total number of matches.

The result:

[rilindo@localhost ~]$ ./parsemail.pl 
domain.com has 6 message(s)
domain3.com has 2 message(s)
domain1.com has 2 message(s)

Like I said, its not perfect, but it does the job. If nothing else, it will give you an idea of where to go from here.

Incidentally, since it appears you know perl, review of Perl's hash data structures will prove to be very useful:

http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/

Or:

http://perldoc.perl.org/perldsc.html

2
ответ дан 3 December 2019 в 03:10

Попробуйте следующее:

# mailq -v | awk 'BEGIN { FS = "@" } \
!/^[a-zA-Z0-9-]|^[ \t]+(\(|\/|Total requests:)/ { print $2 }' | sort | uniq -c
3
ответ дан 3 December 2019 в 03:10

«простой» относительный. Анализировать вывод mailq очень сложно, но это можно сделать. Типичный подробный вывод mailq выглядит примерно так:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
637F5CFF9C*    1497 Sat Dec 18 21:40:34  sender@domain.com 
                                         recepient@domain.com

637F5CFF9d*    1497 Sat Dec 18 21:40:35  sender@domain.com 
                                         recepient@domain2.com

Некоторые творческие хакерские приемы могут дать вам то, что вам нужно:

Во-первых, вы хотите удалить эту верхнюю строку - это полезно для человека, но не имеет отношения к наши цели анализа.
Самый простой способ: mailq -v | egrep -v '^ -'

Теперь вы хотите получить информацию о получателе и извлечь имя домена. Perl - ваш друг - направьте вывод через этот удобный скрипт (назовем его get_domains.pl ):

#!/usr/bin/perl
$/ = "\n\n";                                    # Use a blank line as the separator.
while (<>) {
        ($x,$recip) = split(/\n/, $_);          # Extract the recipient line
        ($user,$domain) = split(/@/, $recip);   # Get the domain.
        print "$domain\n";                      # Print Recipient Domain
}

Остается только простая часть - подсчет доменов (конвейер через sort | uniq -c ).

Итак mailq -v | egrep -v '^ -' | get_domains.pl | сортировать | uniq -c выдаст что-то вроде:

    1 domain.com
    1 domain2.com
1
ответ дан 3 December 2019 в 03:10

Теги

Похожие вопросы