emails for all denied network activity using ufw












0















I have ufw configured to deny all incoming and outgoing traffic except input for SSH:



ufw default deny outgoing
ufw default deny incoming
ufw limit in ssh


Is it possible to get e-mails of denied traffic? Something that says/shows traffic was denied, from who, to who, what port, to port, etc...



I feel the e-mails should be digest or something because if all of a sudden there are hundreds of denies in a short amount of time, it should send one e-mail instead of hundreds.










share|improve this question























  • I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

    – heynnema
    Feb 6 at 19:01











  • It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

    – IMTheNachoMan
    Feb 6 at 19:04













  • You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

    – heynnema
    Feb 6 at 19:17











  • That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

    – IMTheNachoMan
    Feb 6 at 20:13
















0















I have ufw configured to deny all incoming and outgoing traffic except input for SSH:



ufw default deny outgoing
ufw default deny incoming
ufw limit in ssh


Is it possible to get e-mails of denied traffic? Something that says/shows traffic was denied, from who, to who, what port, to port, etc...



I feel the e-mails should be digest or something because if all of a sudden there are hundreds of denies in a short amount of time, it should send one e-mail instead of hundreds.










share|improve this question























  • I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

    – heynnema
    Feb 6 at 19:01











  • It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

    – IMTheNachoMan
    Feb 6 at 19:04













  • You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

    – heynnema
    Feb 6 at 19:17











  • That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

    – IMTheNachoMan
    Feb 6 at 20:13














0












0








0








I have ufw configured to deny all incoming and outgoing traffic except input for SSH:



ufw default deny outgoing
ufw default deny incoming
ufw limit in ssh


Is it possible to get e-mails of denied traffic? Something that says/shows traffic was denied, from who, to who, what port, to port, etc...



I feel the e-mails should be digest or something because if all of a sudden there are hundreds of denies in a short amount of time, it should send one e-mail instead of hundreds.










share|improve this question














I have ufw configured to deny all incoming and outgoing traffic except input for SSH:



ufw default deny outgoing
ufw default deny incoming
ufw limit in ssh


Is it possible to get e-mails of denied traffic? Something that says/shows traffic was denied, from who, to who, what port, to port, etc...



I feel the e-mails should be digest or something because if all of a sudden there are hundreds of denies in a short amount of time, it should send one e-mail instead of hundreds.







email firewall ufw






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 6 at 18:54









IMTheNachoManIMTheNachoMan

257212




257212













  • I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

    – heynnema
    Feb 6 at 19:01











  • It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

    – IMTheNachoMan
    Feb 6 at 19:04













  • You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

    – heynnema
    Feb 6 at 19:17











  • That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

    – IMTheNachoMan
    Feb 6 at 20:13



















  • I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

    – heynnema
    Feb 6 at 19:01











  • It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

    – IMTheNachoMan
    Feb 6 at 19:04













  • You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

    – heynnema
    Feb 6 at 19:17











  • That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

    – IMTheNachoMan
    Feb 6 at 20:13

















I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

– heynnema
Feb 6 at 19:01





I don't quite understand the need to lock down your system like this. It's totally crippled your system. Any emails, digest or otherwise, would be constant, and huge. Please explain.

– heynnema
Feb 6 at 19:01













It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

– IMTheNachoMan
Feb 6 at 19:04







It's a home server I use to play around with and learn on. I have a lot of ports explicitly opened like HTTP and HTTPS out so apt works. I want to know everything going in and out of the system that I haven't explicitly allowed.

– IMTheNachoMan
Feb 6 at 19:04















You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

– heynnema
Feb 6 at 19:17





You can just start with a simple grep -i ufw /var/log/syslog or more /var/log/ufw.log to see what you're getting into. Then, if you're convinced that you REALLY want to see all of this noise, pipe either output into a mail message.

– heynnema
Feb 6 at 19:17













That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

– IMTheNachoMan
Feb 6 at 20:13





That is what I was thinking of doing but thought maybe UFW has a built in way to do it. I can set a daily cron job to create a report and send me email.

– IMTheNachoMan
Feb 6 at 20:13










1 Answer
1






active

oldest

votes


















0














I could not find an answer I liked so per @heynnema's advice, I am capturing what I want from /var/log/ufw.log and formatting into a table for e-mail.



echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
echo '<html>';
echo '<head>';
echo '<title></title>';
echo '<style>table, th, td { border: 1px solid black; border-collapse: collapse; padding: 2px;}</style>';
echo '</head>';
echo '<body>';
echo '<table>';
echo '<tr><th>count</th><th>in or out</th><th>source IP</th><th>destination IP</th><th>source port</th><th>destination port</th></tr>';

# get all lines from yesterday
# capture the relevant data: IN, OUT, SRC, DST, SPT, and DPT
# send to awk
# get hostname for SRC and DST
# print everything as a table
sed -r "s/^$(date --date=yesterday +"%b %_d").*?[UFW BLOCK].*?IN=([^ ]*) OUT=([^ ]*) .*?SRC=([^ ]*) DST=([^ ]*) .*?SPT=([^ ]*) DPT=([^ ]*).*$/,1,2,3,4,5,6/;t;d" /var/log/ufw.log | sort | uniq -c | sort -nr | awk -F"," '{
inOrOut=$2==""?($3==""?"unknown":"out"):"in"

cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $4)
cmd | getline sourceName
close(cmd)

cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $5)
cmd | getline destinationName
close(cmd)

printf "<tr><td>%s</td><td>%s</td><td>%s (%s)</td><td>%s (%s)</td><td>%s</td><td>%s</td></tr>n", $1, inOrOut, $4, sourceName, $5, destinationName, $6, $7
}';

echo '</table>';
echo '<br>';
echo '<br>';

echo '</body>';
echo '</html>';


I have a daily cron job that runs this script and sends as HTML email.



This results in a table like so:



| count | in or out | source IP             | destination IP        | source port | destination port |
|-------|-----------|-----------------------|-----------------------|-------------|------------------|
| 3 | out | 192.168.1.100 (host1) | 192.168.1.101 (host2) | 100 | 400 |
| 1 | in | 192.168.1.101 (host2) | 192.168.1.100 (host1) | 200 | 500 |
| 1 | out | 192.168.1.100 (host1) | 192.168.1.100 (host1) | 300 | 600 |





share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1116181%2femails-for-all-denied-network-activity-using-ufw%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I could not find an answer I liked so per @heynnema's advice, I am capturing what I want from /var/log/ufw.log and formatting into a table for e-mail.



    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
    echo '<html>';
    echo '<head>';
    echo '<title></title>';
    echo '<style>table, th, td { border: 1px solid black; border-collapse: collapse; padding: 2px;}</style>';
    echo '</head>';
    echo '<body>';
    echo '<table>';
    echo '<tr><th>count</th><th>in or out</th><th>source IP</th><th>destination IP</th><th>source port</th><th>destination port</th></tr>';

    # get all lines from yesterday
    # capture the relevant data: IN, OUT, SRC, DST, SPT, and DPT
    # send to awk
    # get hostname for SRC and DST
    # print everything as a table
    sed -r "s/^$(date --date=yesterday +"%b %_d").*?[UFW BLOCK].*?IN=([^ ]*) OUT=([^ ]*) .*?SRC=([^ ]*) DST=([^ ]*) .*?SPT=([^ ]*) DPT=([^ ]*).*$/,1,2,3,4,5,6/;t;d" /var/log/ufw.log | sort | uniq -c | sort -nr | awk -F"," '{
    inOrOut=$2==""?($3==""?"unknown":"out"):"in"

    cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $4)
    cmd | getline sourceName
    close(cmd)

    cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $5)
    cmd | getline destinationName
    close(cmd)

    printf "<tr><td>%s</td><td>%s</td><td>%s (%s)</td><td>%s (%s)</td><td>%s</td><td>%s</td></tr>n", $1, inOrOut, $4, sourceName, $5, destinationName, $6, $7
    }';

    echo '</table>';
    echo '<br>';
    echo '<br>';

    echo '</body>';
    echo '</html>';


    I have a daily cron job that runs this script and sends as HTML email.



    This results in a table like so:



    | count | in or out | source IP             | destination IP        | source port | destination port |
    |-------|-----------|-----------------------|-----------------------|-------------|------------------|
    | 3 | out | 192.168.1.100 (host1) | 192.168.1.101 (host2) | 100 | 400 |
    | 1 | in | 192.168.1.101 (host2) | 192.168.1.100 (host1) | 200 | 500 |
    | 1 | out | 192.168.1.100 (host1) | 192.168.1.100 (host1) | 300 | 600 |





    share|improve this answer




























      0














      I could not find an answer I liked so per @heynnema's advice, I am capturing what I want from /var/log/ufw.log and formatting into a table for e-mail.



      echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
      echo '<html>';
      echo '<head>';
      echo '<title></title>';
      echo '<style>table, th, td { border: 1px solid black; border-collapse: collapse; padding: 2px;}</style>';
      echo '</head>';
      echo '<body>';
      echo '<table>';
      echo '<tr><th>count</th><th>in or out</th><th>source IP</th><th>destination IP</th><th>source port</th><th>destination port</th></tr>';

      # get all lines from yesterday
      # capture the relevant data: IN, OUT, SRC, DST, SPT, and DPT
      # send to awk
      # get hostname for SRC and DST
      # print everything as a table
      sed -r "s/^$(date --date=yesterday +"%b %_d").*?[UFW BLOCK].*?IN=([^ ]*) OUT=([^ ]*) .*?SRC=([^ ]*) DST=([^ ]*) .*?SPT=([^ ]*) DPT=([^ ]*).*$/,1,2,3,4,5,6/;t;d" /var/log/ufw.log | sort | uniq -c | sort -nr | awk -F"," '{
      inOrOut=$2==""?($3==""?"unknown":"out"):"in"

      cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $4)
      cmd | getline sourceName
      close(cmd)

      cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $5)
      cmd | getline destinationName
      close(cmd)

      printf "<tr><td>%s</td><td>%s</td><td>%s (%s)</td><td>%s (%s)</td><td>%s</td><td>%s</td></tr>n", $1, inOrOut, $4, sourceName, $5, destinationName, $6, $7
      }';

      echo '</table>';
      echo '<br>';
      echo '<br>';

      echo '</body>';
      echo '</html>';


      I have a daily cron job that runs this script and sends as HTML email.



      This results in a table like so:



      | count | in or out | source IP             | destination IP        | source port | destination port |
      |-------|-----------|-----------------------|-----------------------|-------------|------------------|
      | 3 | out | 192.168.1.100 (host1) | 192.168.1.101 (host2) | 100 | 400 |
      | 1 | in | 192.168.1.101 (host2) | 192.168.1.100 (host1) | 200 | 500 |
      | 1 | out | 192.168.1.100 (host1) | 192.168.1.100 (host1) | 300 | 600 |





      share|improve this answer


























        0












        0








        0







        I could not find an answer I liked so per @heynnema's advice, I am capturing what I want from /var/log/ufw.log and formatting into a table for e-mail.



        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
        echo '<html>';
        echo '<head>';
        echo '<title></title>';
        echo '<style>table, th, td { border: 1px solid black; border-collapse: collapse; padding: 2px;}</style>';
        echo '</head>';
        echo '<body>';
        echo '<table>';
        echo '<tr><th>count</th><th>in or out</th><th>source IP</th><th>destination IP</th><th>source port</th><th>destination port</th></tr>';

        # get all lines from yesterday
        # capture the relevant data: IN, OUT, SRC, DST, SPT, and DPT
        # send to awk
        # get hostname for SRC and DST
        # print everything as a table
        sed -r "s/^$(date --date=yesterday +"%b %_d").*?[UFW BLOCK].*?IN=([^ ]*) OUT=([^ ]*) .*?SRC=([^ ]*) DST=([^ ]*) .*?SPT=([^ ]*) DPT=([^ ]*).*$/,1,2,3,4,5,6/;t;d" /var/log/ufw.log | sort | uniq -c | sort -nr | awk -F"," '{
        inOrOut=$2==""?($3==""?"unknown":"out"):"in"

        cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $4)
        cmd | getline sourceName
        close(cmd)

        cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $5)
        cmd | getline destinationName
        close(cmd)

        printf "<tr><td>%s</td><td>%s</td><td>%s (%s)</td><td>%s (%s)</td><td>%s</td><td>%s</td></tr>n", $1, inOrOut, $4, sourceName, $5, destinationName, $6, $7
        }';

        echo '</table>';
        echo '<br>';
        echo '<br>';

        echo '</body>';
        echo '</html>';


        I have a daily cron job that runs this script and sends as HTML email.



        This results in a table like so:



        | count | in or out | source IP             | destination IP        | source port | destination port |
        |-------|-----------|-----------------------|-----------------------|-------------|------------------|
        | 3 | out | 192.168.1.100 (host1) | 192.168.1.101 (host2) | 100 | 400 |
        | 1 | in | 192.168.1.101 (host2) | 192.168.1.100 (host1) | 200 | 500 |
        | 1 | out | 192.168.1.100 (host1) | 192.168.1.100 (host1) | 300 | 600 |





        share|improve this answer













        I could not find an answer I liked so per @heynnema's advice, I am capturing what I want from /var/log/ufw.log and formatting into a table for e-mail.



        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
        echo '<html>';
        echo '<head>';
        echo '<title></title>';
        echo '<style>table, th, td { border: 1px solid black; border-collapse: collapse; padding: 2px;}</style>';
        echo '</head>';
        echo '<body>';
        echo '<table>';
        echo '<tr><th>count</th><th>in or out</th><th>source IP</th><th>destination IP</th><th>source port</th><th>destination port</th></tr>';

        # get all lines from yesterday
        # capture the relevant data: IN, OUT, SRC, DST, SPT, and DPT
        # send to awk
        # get hostname for SRC and DST
        # print everything as a table
        sed -r "s/^$(date --date=yesterday +"%b %_d").*?[UFW BLOCK].*?IN=([^ ]*) OUT=([^ ]*) .*?SRC=([^ ]*) DST=([^ ]*) .*?SPT=([^ ]*) DPT=([^ ]*).*$/,1,2,3,4,5,6/;t;d" /var/log/ufw.log | sort | uniq -c | sort -nr | awk -F"," '{
        inOrOut=$2==""?($3==""?"unknown":"out"):"in"

        cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $4)
        cmd | getline sourceName
        close(cmd)

        cmd=sprintf("nslookup %s 2>/dev/null | sed -r -e "s/^.*name = (.*).$/\1/;t;d"", $5)
        cmd | getline destinationName
        close(cmd)

        printf "<tr><td>%s</td><td>%s</td><td>%s (%s)</td><td>%s (%s)</td><td>%s</td><td>%s</td></tr>n", $1, inOrOut, $4, sourceName, $5, destinationName, $6, $7
        }';

        echo '</table>';
        echo '<br>';
        echo '<br>';

        echo '</body>';
        echo '</html>';


        I have a daily cron job that runs this script and sends as HTML email.



        This results in a table like so:



        | count | in or out | source IP             | destination IP        | source port | destination port |
        |-------|-----------|-----------------------|-----------------------|-------------|------------------|
        | 3 | out | 192.168.1.100 (host1) | 192.168.1.101 (host2) | 100 | 400 |
        | 1 | in | 192.168.1.101 (host2) | 192.168.1.100 (host1) | 200 | 500 |
        | 1 | out | 192.168.1.100 (host1) | 192.168.1.100 (host1) | 300 | 600 |






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 8 at 14:00









        IMTheNachoManIMTheNachoMan

        257212




        257212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1116181%2femails-for-all-denied-network-activity-using-ufw%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Human spaceflight

            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

            張江高科駅