|
| 1 | +#!/bin/bash |
| 2 | +## Author: Michael Ramsey |
| 3 | +## Objective Find A Cyberpanel/cPanel Users Dom/Access logs Stats for last 5 days for all of their domains. v2 |
| 4 | +## https://gitlab.com/mikeramsey/access-log-parser |
| 5 | +## How to use. |
| 6 | +# ./access-logparser.sh username |
| 7 | +#./access-logparser.sh exampleuserbob |
| 8 | +# |
| 9 | +##bash <(curl -s https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.sh || wget -qO - https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.sh) exampleuserbob; |
| 10 | +## |
| 11 | +Username=$1 |
| 12 | + |
| 13 | +#Detect Control panel |
| 14 | +if [ -f /usr/local/cpanel/cpanel ]; then |
| 15 | + # Cpanel check for /usr/local/cpanel/cpanel -V |
| 16 | + ControlPanel="cpanel" |
| 17 | + datetimeDcpumon=$(date +"%Y/%b/%d") # 2019/Feb/15 |
| 18 | + #Current Dcpumon file |
| 19 | + DcpumonCurrentLOG="/var/log/dcpumon/${datetimeDcpumon}" # /var/log/dcpumon/2019/Feb/15 |
| 20 | + #Setup datetimeDcpumonLast5_array |
| 21 | + declare -a datetimeDcpumonLast5_array=($(date +"%Y/%b/%d") $(date --date='1 day ago' +"%Y/%b/%d") $(date --date='2 days ago' +"%Y/%b/%d") $(date --date='3 days ago' +"%Y/%b/%d") $(date --date='4 days ago' +"%Y/%b/%d")); #for DATE in "${datetimeDcpumonLast5_array[@]}"; do echo $DATE; done; |
| 22 | + |
| 23 | + user_homedir="/home/${Username}" |
| 24 | + user_accesslogs="/home/${Username}/logs/" |
| 25 | + domlogs_path="/usr/local/apache/domlogs/${Username}/" |
| 26 | + acesslog_sed="-ssl_log" |
| 27 | + |
| 28 | +elif [ -f /usr/bin/cyberpanel ]; then |
| 29 | + # CyberPanel check /usr/bin/cyberpanel |
| 30 | + ControlPanel="cyberpanel" |
| 31 | + |
| 32 | + #Get users homedir path |
| 33 | + user_homedir=$(sudo egrep "^${Username}:" /etc/passwd | cut -d: -f6) |
| 34 | + domlogs_path="${user_homedir}/logs/" |
| 35 | + acesslog_sed=".access_log" |
| 36 | + |
| 37 | +else |
| 38 | + echo "Not able to detect Control panel. Unsupported Control Panel exiting now" |
| 39 | + exit 1; |
| 40 | + fi |
| 41 | +echo "============================================================="; |
| 42 | +echo "$ControlPanel Control Panel Detected" |
| 43 | +echo "User Homedirectory: ${user_homedir}" |
| 44 | +echo "User Domlogs Path: ${domlogs_path}" |
| 45 | +echo "============================================================="; |
| 46 | +echo ""; |
| 47 | +#Domlog Date array for past 5 days |
| 48 | +declare -a datetimeDomLast5_array=($(date +"%d/%b/%Y") $(date --date='1 day ago' +"%d/%b/%Y") $(date --date='2 days ago' +"%d/%b/%Y") $(date --date='3 days ago' +"%d/%b/%Y") $(date --date='4 days ago' +"%d/%b/%Y")); #for DATE in "${datetimeDomLast5_array[@]}"; do echo $DATE; done; |
| 49 | + |
| 50 | + |
| 51 | +Now=$(date +"%Y-%m-%d_%T") |
| 52 | + |
| 53 | +user_Snapshot="${Username}-Snapshot_${Now}.txt"; |
| 54 | + |
| 55 | +#create logfile in user's homedirectory. |
| 56 | +#sudo touch "$user_CyberpanelSnapshot" |
| 57 | + |
| 58 | +#chown logfile to user |
| 59 | +#sudo chown ${Username}:${Username} "$user_CyberpanelSnapshot"; |
| 60 | + |
| 61 | + |
| 62 | +main_function() { |
| 63 | + |
| 64 | +if [ "${ControlPanel}" == "cpanel" ] ; |
| 65 | + |
| 66 | +then |
| 67 | + for DATE in "${datetimeDcpumonLast5_array[@]}"; do |
| 68 | + echo "============================================================="; |
| 69 | + echo "Find $Username user's highest CPU use processes via Dcpumon Logs for $DATE"; |
| 70 | + sudo grep "$Username" /var/log/dcpumon/"${DATE}"; |
| 71 | + done; echo ""; |
| 72 | + echo "For more information about Dcpumon(Daily Process Logs) see https://docs.cpanel.net/whm/server-status/daily-process-log/82/" |
| 73 | + echo "=============================================================" |
| 74 | + echo ""; |
| 75 | + else |
| 76 | + #echo "The DcpumonCurrentLOG '$DcpumonCurrentLOG' was not found. Not running Dcpumon stats" |
| 77 | + echo ""; |
| 78 | + fi |
| 79 | + |
| 80 | +echo "" |
| 81 | +echo "Web Traffic Stats Check"; |
| 82 | + |
| 83 | +echo ""; |
| 84 | +for DATE in "${datetimeDomLast5_array[@]}"; do |
| 85 | +echo "============================================================="; |
| 86 | +echo "HTTP Dom Logs POST Requests for ${DATE} for $Username"; |
| 87 | + |
| 88 | + sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head |
| 89 | + echo "" |
| 90 | + echo "HTTP Dom Logs GET Requests for ${DATE} for $Username" |
| 91 | + sudo grep -r "$DATE" ${domlogs_path} | grep GET | awk '{print $1}' | cut -d: -f1 |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head |
| 92 | + echo "" |
| 93 | + echo "HTTP Dom Logs Top 10 bot/crawler requests per domain name for ${DATE}" |
| 94 | + sudo grep -r "$DATE" ${domlogs_path} | grep -Ei 'crawl|bot|spider|yahoo|bing|google'| awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head |
| 95 | + echo "" |
| 96 | + echo "HTTP Dom Logs top ten IPs for ${DATE} for $Username" |
| 97 | + |
| 98 | + command=$(sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}'|sed -e 's/^[^=:]*[=:]//' -e 's|"||g' | sort | uniq -c | sort -rn | head| column -t);readarray -t iparray < <( echo "${command}" | tr '/' '\n'); echo ""; for IP in "${iparray[@]}"; do echo "$IP"; done; echo ""; echo "Show unique IP's with whois IP, Country,and ISP"; echo ""; for IP in "${iparray[@]}"; do IP=$(echo "$IP" |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-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*)'); whois -h whois.cymru.com " -c -p $IP"|cut -d"|" -f 2,4,5|grep -Ev 'IP|whois.cymru.com'; done |
| 99 | + |
| 100 | + echo "" |
| 101 | + echo "Checking the IPs that Have Hit the Server Most and What Site they were hitting:" |
| 102 | + sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t |
| 103 | + echo "" |
| 104 | + echo "Checking the Top Hits Per Site Per IP:" |
| 105 | + sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1,$6,$7'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t |
| 106 | + echo "" |
| 107 | + echo "HTTP Dom Logs find the top number of uri's being requested for ${DATE}" |
| 108 | + sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $7}' | cut -d: -f2 |sed "s|$domlogs_path||g"| sort | uniq -c | sort -rn | head| column -t |
| 109 | + echo "" |
| 110 | + echo ""; |
| 111 | + echo "View HTTP requests per hour for $Username"; |
| 112 | + sudo grep -r "$DATE" ${domlogs_path} | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c| column -t |
| 113 | + echo "" |
| 114 | + echo "CMS Checks" |
| 115 | + echo "" |
| 116 | + echo "Wordpress Checks" |
| 117 | + echo "Wordpress Login Bruteforcing checks for wp-login.php for ${DATE} for $Username" |
| 118 | + sudo grep -r "$DATE" ${domlogs_path} | grep wp-login.php | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 119 | + echo "" |
| 120 | + echo "Wordpress Cron wp-cron.php(virtual cron) checks for ${DATE} for $Username" |
| 121 | + sudo grep -r "$DATE" ${domlogs_path} | grep wp-cron.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 122 | + echo "" |
| 123 | + echo "Wordpress XMLRPC Attacks checks for xmlrpc.php for ${DATE} for $Username" |
| 124 | + sudo grep -r "$DATE" ${domlogs_path} | grep xmlrpc.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 125 | + echo "" |
| 126 | + echo "Wordpress Heartbeat API checks for admin-ajax.php for ${DATE} for $Username" |
| 127 | + sudo grep -r "$DATE" ${domlogs_path} | grep admin-ajax.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn; |
| 128 | + echo "" |
| 129 | + echo "CMS Bruteforce Checks" |
| 130 | + echo "Drupal Login Bruteforcing checks for user/login/ for ${DATE} for $Username" |
| 131 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "user/login/" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 132 | + echo "" |
| 133 | + echo "Magento Login Bruteforcing checks for admin pages /admin_xxxxx/admin/index/index for ${DATE} for $Username" |
| 134 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "admin_[a-zA-Z0-9_]*[/admin/index/index]" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 135 | + echo "" |
| 136 | + echo "Joomla Login Bruteforcing checks for admin pages /administrator/index.php for ${DATE} for $Username" |
| 137 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "/administrator/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 138 | + echo "" |
| 139 | + echo "vBulletin Login Bruteforcing checks for admin pages admincp for ${DATE} for $Username" |
| 140 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "admincp" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 141 | + echo "" |
| 142 | + echo "Opencart Login Bruteforcing checks for admin pages /admin/index.php for ${DATE} for $Username" |
| 143 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 144 | + echo "" |
| 145 | + echo "Prestashop Login Bruteforcing checks for admin pages /adminxxxx for ${DATE} for $Username" |
| 146 | + sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin[a-zA-Z0-9_]*$" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn |
| 147 | + echo "" |
| 148 | + |
| 149 | + |
| 150 | +done; |
| 151 | +echo "=============================================================" |
| 152 | + |
| 153 | + |
| 154 | +echo "Contents have been saved to ${user_Snapshot}" |
| 155 | +} |
| 156 | + |
| 157 | +# log everything, but also output to stdout |
| 158 | +main_function 2>&1 | tee -a "${user_Snapshot}" |
0 commit comments