PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/logs/README.md

https://github.com/glic3rinu/spam-gear
Markdown | 139 lines | 83 code | 56 blank | 0 comment | 0 complexity | 26ce4af921cc075bffd7f46ab96284a3 MD5 | raw file
Possible License(s): WTFPL
  1. # Log analysis tools
  2. ## [postfix-spam-check](postfix-spam-check)
  3. Scans Postfix logs `/var/log/mail.log` looking for SASL authenticated users that make
  4. more than `MAX_CONNECTIONS` per time `PERIOD`. Covering the typical attacks on a mail server setup.
  5. It can disable users based on the number of connections from different and unknown networks. Which is a very distinguishable pattern of mails sent from a botnet.
  6. #### Usage
  7. postfix-spam-check [OPTIONS]
  8. #### Options
  9. -p, --period=PERIOD
  10. A DATE STRING compatible period "1hour" or "10minute" see man date for more.
  11. Defaults to "1hour"
  12. -m, --max-connections=MAX_CONNECTIONS
  13. Threshold value for number of connections beyond a report is made.
  14. Defaults to 90.
  15. -d, --dissable-account=MAX_NETWORKS,MAX_UNKNOWNS
  16. Specifies the boundary conditions for the maximum number of networks and unknown IPs
  17. beyond which the user account is automatically disabled.
  18. A separated e-mail is sent when a user is disabled so you don't miss it.
  19. Dissabling accounts is switched off by default.
  20. -n, --niss=[MASTER_SERVER]
  21. Disables a NIS account rather than a local account.
  22. It usses SSH and NIS MASTER_SERVER defaults to localhost.
  23. h, --help
  24. Shows help message
  25. #### Examples
  26. postfix-spam-check
  27. postfix-spam-check -p 30minutes -m 60
  28. postfix-spam-check -d 10,10
  29. ## [exim-spam-check](exim-spam-check)
  30. Scans Exim4 logs under `/var/log/exim/mainlog` looking for *local users* and *SMTP connections*
  31. that exceed `MAX_CONNECTIONS` during the last `SECONDS`. Covering the typical attacks on a shared hositing web server setup.
  32. #### Usage
  33. exim-spam-check [SECONDS] [MAX_CONNECTIONS]
  34. #### Examples
  35. exim-spam-check 3600
  36. exim-spam-check 3600 60
  37. ## [roundcube-spam-scheck](roundcube-spam-scheck)
  38. TODO
  39. ## [imp-spam-scheck](imp-spam-scheck)
  40. TODO
  41. ## [php-spam-check](php-spam-check)
  42. With PHP ≥ 5.3 there is this feature that you can enable for logging emails sent via PHP. This can be done
  43. by setting `mail.log = /var/log/phpmail.log` on `php.ini`. Don't forget to rotate this new log file.
  44. This script inspects `/var/log/phpmail.log` and returns the PHP scripts that exceed `MAX_DAILY_MAILS`.
  45. Usually you want to run this script combined with `php-shell-scan`.
  46. #### Usage
  47. php-spam-check [MAX_DAILY_MAILS]
  48. #### Examples
  49. php-spam-check
  50. php-spam-check 100
  51. php-spam-check 500 && php-spam-legacy 10 10
  52. ## [php-legacy-spam-check](php-legacy-spam-check)
  53. This script is for legacy versions of PHP (< 5.3), it inspects `/var/log/mail.log` and returns PHP scripts that exceed `MAX_MAILS` over the last number of `MINUTES`.
  54. Usually you want to run this script combined with `php-shell-check`.
  55. #### Usage
  56. php-legacy-spam-check [MINUTES] [MAX_MAILS]
  57. #### Examples
  58. php-legacy-spam-check
  59. php-legacy-spam-check 10 30
  60. php-legacy-spam-check 10 10 && php-spam 500
  61. #### System configuration
  62. PHP prior to 5.3 has no built-in support for logging PHP scripts that send email. However, this can be done by creating a wrapper around sendmail command.
  63. First create a `/usr/local/bin/phpsendmail` file with the following content
  64. ```bash
  65. #!/bin/bash
  66. logger -p mail.info "sendmail-php url=${HTTP_HOST}${REQUEST_URI}, client=${REMOTE_ADDR}, filename=${SCRIPT_FILENAME}, uid=${UID}, user=$(whoami), args=$*"
  67. /usr/lib/sendmail -t -i $*
  68. ```
  69. PHP will have to set the needed environment variables before the sendmail wrapper gets called. Create a `/home/httpd/htdocs/put_environment_variables.php` for that.
  70. ```php
  71. <?php
  72. ob_start();
  73. $vars = array("SCRIPT_FILENAME", "HTTP_HOST", "REMOTE_ADDR", "REQUEST_URI");
  74. foreach ($vars as $var) {
  75. putenv($var . "=" . $_SERVER[$var]);
  76. }
  77. ?>
  78. ```
  79. Finally, tell PHP to use those scripts by configuring `php.ini`.
  80. ```php
  81. sendmail_path = /usr/local/bin/phpsendmail
  82. auto_prepend_file = /home/httpd/htdocs/put_environment_variables.php
  83. ```