Facebook
From sundowndev, 2 Years ago, written in Bash.
Embed
Download Paste or View Raw
Hits: 172
  1. #!/usr/bin/env bash
  2.  
  3. LOGS_FILES=(
  4.         /var/log/messages # General message and system related stuff
  5.         /var/log/auth.log # Authenication logs
  6.         /var/log/kern.log # Kernel logs
  7.         /var/log/cron.log # Crond logs
  8.         /var/log/maillog # Mail server logs
  9.         /var/log/boot.log # System boot log
  10.         /var/log/mysqld.log # MySQL database server log file
  11.         /var/log/qmail # Qmail log directory
  12.         /var/log/httpd # Apache access and error logs directory
  13.         /var/log/lighttpd # Lighttpd access and error logs directory
  14.         /var/log/secure # Authentication log
  15.         /var/log/utmp # Login records file
  16.         /var/log/wtmp # Login records file
  17.         /var/log/yum.log # Yum command log file
  18.         /var/log/system.log # System Log
  19.         /var/log/DiagnosticMessages # Mac Analytics Data
  20.         /Library/Logs # System Application Logs
  21.         /Library/Logs/DiagnosticReports # System Reports
  22.         ~/Library/Logs # User Application Logs
  23.         ~/Library/Logs/DiagnosticReports # User Reports
  24. )
  25.  
  26. function isRoot () {
  27.         if [ "$EUID" -ne 0 ]; then
  28.                 return 1
  29.         fi
  30. }
  31.  
  32. function menu () {
  33.         echo
  34.         echo "Welcome to Cover my ass tool !"
  35.  
  36.         echo
  37.         echo "Select an option :"
  38.         echo
  39.         echo "1) Clear logs for user $USER"
  40.         echo "2) Permenently disable auth & bash history"
  41.         echo "3) Restore settings to default"
  42.         echo "99) Exit tool"
  43.         echo
  44.  
  45.         printf "> "
  46.         read -r option
  47.         echo
  48. }
  49.  
  50. function disableAuth () {
  51.         if [ -w /var/log/auth.log ]; then
  52.                 ln /dev/null /var/log/auth.log -sf
  53.                 echo "[+] Permanently sending /var/log/auth.log to /dev/null"
  54.         else
  55.                 echo "[!] /var/log/auth.log is not writable! Retry using sudo."
  56.         fi
  57. }
  58.  
  59. function disableHistory () {
  60.         ln /dev/null ~/.bash_history -sf
  61.         echo "[+] Permanently sending bash_history to /dev/null"
  62.  
  63.         if [ -f ~/.zsh_history ]; then
  64.                 ln /dev/null ~/.zsh_history -sf
  65.                 echo "[+] Permanently sending zsh_history to /dev/null"
  66.         fi
  67.  
  68.         export HISTFILESIZE=0
  69.         export HISTSIZE=0
  70.         echo "[+] Set HISTFILESIZE & HISTSIZE to 0"
  71.  
  72.         set +o history
  73.         echo "[+] Disabled history library"
  74.  
  75.         echo
  76.         echo "Permenently disabled bash log."
  77. }
  78.  
  79. function enableAuth () {
  80.         if [ -w /var/log/auth.log ] && [ -L /var/log/auth.log ]; then
  81.                 rm -rf /var/log/auth.log
  82.                 echo "" > /var/log/auth.log
  83.                 echo "[+] Disabled sending auth logs to /dev/null"
  84.         else
  85.                 echo "[!] /var/log/auth.log is not writable! Retry using sudo."
  86.         fi
  87. }
  88.  
  89. function enableHistory () {
  90.         if [[ -L ~/.bash_history ]]; then
  91.                 rm -rf ~/.bash_history
  92.                 echo "" > ~/.bash_history
  93.                 echo "[+] Disabled sending history to /dev/null"
  94.         fi
  95.  
  96.         if [[ -L ~/.zsh_history ]]; then
  97.                 rm -rf ~/.zsh_history
  98.                 echo "" > ~/.zsh_history
  99.                 echo "[+] Disabled sending zsh history to /dev/null"
  100.         fi
  101.  
  102.         export HISTFILESIZE=""
  103.         export HISTSIZE=50000
  104.         echo "[+] Restore HISTFILESIZE & HISTSIZE default values."
  105.  
  106.         set -o history
  107.         echo "[+] Enabled history library"
  108.  
  109.         echo
  110.         echo "Permenently enabled bash log."
  111. }
  112.  
  113. function clearLogs () {
  114.         for i in "${LOGS_FILES[@]}"
  115.         do
  116.                 if [ -f "$i" ]; then
  117.                         if [ -w "$i" ]; then
  118.                                 echo "" > "$i"
  119.                                 echo "[+] $i cleaned."
  120.                         else
  121.                                 echo "[!] $i is not writable! Retry using sudo."
  122.                         fi
  123.                 elif [ -d "$i" ]; then
  124.                         if [ -w "$i" ]; then
  125.                                 rm -rf "${i:?}"/*
  126.                                 echo "[+] $i cleaned."
  127.                         else
  128.                                 echo "[!] $i is not writable! Retry using sudo."
  129.                         fi
  130.                 fi
  131.         done
  132. }
  133.  
  134. function clearHistory () {
  135.         if [ -f ~/.zsh_history ]; then
  136.                 echo "" > ~/.zsh_history
  137.                 echo "[+] ~/.zsh_history cleaned."
  138.         fi
  139.  
  140.         echo "" > ~/.bash_history
  141.         echo "[+] ~/.bash_history cleaned."
  142.  
  143.         history -c
  144.         echo "[+] History file deleted."
  145.  
  146.         echo
  147.         echo "Reminder: your need to reload the session to see effects."
  148.         echo "Type exit to do so."
  149. }
  150.  
  151. function exitTool () {
  152.         exit 1
  153. }
  154.  
  155. clear # Clear output
  156.  
  157. # "now" option
  158. if [ -n "$1" ] && [ "$1" == 'now' ]; then
  159.         clearLogs
  160.         clearHistory
  161.         exit 0
  162. fi
  163.  
  164. menu
  165.  
  166. if [[ $option == 1 ]]; then
  167.         # Clear logs & current history
  168.         clearLogs
  169.         clearHistory
  170. elif [[ $option == 2 ]]; then
  171.         # Permenently disable auth & bash log
  172.         disableAuth
  173.         disableHistory
  174. elif [[ $option == 3 ]]; then
  175.         # Restore default settings
  176.         enableAuth
  177.         enableHistory
  178. elif [[ $option == 99 ]]; then
  179.         # Exit tool
  180.         exitTool
  181. else
  182.         echo "[!] Option not reconized. Exiting."
  183. fi