From c742a328a3239aec25b2a6671c7ccc884c52948b Mon Sep 17 00:00:00 2001 From: tofasthacker Date: Mon, 26 Feb 2024 19:15:09 -0500 Subject: [PATCH] programs --- log_sshd | 18 ++++++++++++++++++ log_stats | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 log_sshd create mode 100755 log_stats diff --git a/log_sshd b/log_sshd new file mode 100755 index 0000000..c97ba22 --- /dev/null +++ b/log_sshd @@ -0,0 +1,18 @@ +#!/bin/bash + +DATE=$(date +"%Y_%m_%d") +NUMBER="/nas/share/brickman/logs/sshd/ssh_attempts.log" +DAILY_FILE="/nas/share/brickman/logs/sshd/ssh_${DATE}.log" + + +echo -n "`date +"%b %e"`: " >> $NUMBER +ATTEMPTS=$(cat /var/log/auth.log /var/log/auth.log.1 | grep "`date +"%b %e"`" | zgrep sshd | grep rhost | sed -re 's/.*rhost=([^ ]+).*/\1/' | sort | wc -l) +echo $ATTEMPTS >> $NUMBER + +echo "-----$(date)-----" >> $DAILY_FILE +echo >> $DAILY_FILE +echo "Total Number of Failed Attempts: ${ATTEMPTS}" >> $DAILY_FILE +echo " COUNT | IP ADDRESS" >> $DAILY_FILE +cat /var/log/auth.log* | grep "`date +"%b %e"`" | zgrep sshd | grep rhost | sed -re 's/.*rhost=([^ ]+).*/\1/' | sort | uniq -c | sort -u >> $DAILY_FILE + +echo >> $DAILY_FILE diff --git a/log_stats b/log_stats new file mode 100755 index 0000000..604c364 --- /dev/null +++ b/log_stats @@ -0,0 +1,43 @@ +#!/bin/bash + + +DATE=$(date +"%Y_%m_%d") +FILE="/nas/share/brickman/logs/nginx/log_${DATE}_FULL.log" +FILE_M="/nas/share/brickman/logs/nginx/log_${DATE}_SHORT.log" + +# Complete file +echo "-----$(date)-----" >> $FILE +echo "" >> $FILE +# Short File +echo "-----$(date)-----" >> $FILE_M +echo "" >> $FILE_M + + +for IP in `grep -E -o "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" /var/log/nginx/access.log | sort | uniq` +do + REQ_NUM=$(grep $IP /var/log/nginx/access.log | wc -l) + + + echo "--------------------" >> $FILE + echo "IP: $IP" >> $FILE + echo "NUMBER OF REQUESTS: ${REQ_NUM}" >> $FILE + echo "HTTP Status Codes" >> $FILE + echo " COUNT | HTTP CODE" >> $FILE + grep $IP /var/log/nginx/access.log | grep -o " [1-5][0-9][0-9] "| sort | uniq -c >> $FILE + echo >> $FILE + + if [ $REQ_NUM -gt 25 ] + then + echo "--------------------" >> $FILE_M + echo "IP: $IP" >> $FILE_M + echo "NUMBER OF REQUESTS: ${REQ_NUM}" >> $FILE_M + echo "HTTP Status Codes" >> $FILE_M + echo " COUNT | HTTP CODE" >> $FILE_M + grep $IP /var/log/nginx/access.log | grep -o " [1-5][0-9][0-9] "| sort | uniq -c >> $FILE_M + echo >> $FILE_M + fi +done + + +echo "-----DONE-----" >> $FILE +echo "-----DONE-----" >> $FILE_M