You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 10.0KB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. [![Build Status](https://travis-ci.org/vstakhov/rspamd.png)](https://travis-ci.org/vstakhov/rspamd)
  2. ## Introduction
  3. Rspamd is an advanced spam filtering system that allows evaluation of messages by a number of
  4. rules including regular expressions, statistical analysis and custom services
  5. such as URL black lists. Each message is analysed by rspamd and given a `spam score`.
  6. According to this spam score and the user's settings rspamd recommends an action for
  7. the MTA to apply to the message- for example to pass, reject or add a header.
  8. Rspamd is designed to process hundreds of messages per second simultaneously and has a number of
  9. features available.
  10. ## Spam filtering features {#features}
  11. Rspamd distribution contains a number of mail processing features, including such techniques as:
  12. * **Regular expressions filtering** - allows basic processing of messages, their textual parts, MIME headers and
  13. SMTP data received by MTA against a set of expressions that includes both normal regular expressions and
  14. message processing functions. Rspamd expressions are the powerful tool that allows to filter messages based on
  15. some pre-defined rules. This feature is similar to regular expressions in spamassassin spam filter.
  16. * **SPF module** that allows to validate a message's sender against the policy defined in the DNS record of sender's domain. You can read
  17. about SPF policies [here](http://www.openspf.org/). A number of mail systems includes SPF support, such as `gmail` or `yahoo mail`.
  18. * **DKIM module** validates message's cryptographic signature against public key placed in the DNS record of sender's domain. Like SPF,
  19. this technique is widely spread and allows to validate that a message is sent from that specific domain.
  20. * **DNS black lists** allows to estimate reputation of sender's IP address or network. Rspamd uses a number of DNS lists including such lists as
  21. `SORBS` or `spamhaus`. However, rspamd doesn't trust any specific DNS list and use a conjunction of estimations instead that allows to
  22. avoid mistakes and false positives. Rspamd also uses positive and grey DNS lists for checking for trusted senders.
  23. * **URL black lists** are rather similar to DNS black lists but uses URLs in a message to make an estimation of sender's reputation.
  24. This technique is very useful for finding malicious or phished domains and filter such mail.
  25. * **Statistics** - rspamd uses bayesian classifier based on five-gramms of input. This means that the input is estimated not based on individual
  26. words, but all input is organized in chains that are further estimated by bayesian classifier. This approach allows to achieve better results than
  27. traditionally used monogramms (or words literally speaking), that is described in details in the following [paper](http://osbf-lua.luaforge.net/papers/osbf-eddc.pdf).
  28. * **Fuzzy hashes** - for checking of malicious mail patterns rspamd uses so called `fuzzy hashes`. Unlike normal hashes, these structures are targeted to hide
  29. small differences between text patterns allowing to find similar messages quickly. Rspamd has internal storage of such hashes and allows to block mass spam sendings
  30. quickly based on user's feedback that specifies messages reputation. Moreover, it allows to feed rspamd with data from [`honeypots`](http://en.wikipedia.org/wiki/Honeypot_(computing)#Spam_versions)
  31. without polluting the statistical module.
  32. Rspamd uses the conjunction of different techniques to make the finall decision about a message. This allows to improve the overall quality of filtering and reduce the number of
  33. false positives (e.g. when a innocent message is badly classified as a spam one). I have tried to simplify rspamd usage by adding the following elements:
  34. * **Web interface** - rspamd is shipped with the fully functional ajax based web interface that allows to observe rspamd statistic; to configure rules, weights and lists; to scan
  35. and learn messages and to view the history of scans. The interface is self-hosted, requires zero configuration and follows the recent web applications standards. You don't need a
  36. web server or applications server to run web UI - you just need to run rspamd itself and a web browser.
  37. * **Integration with MTA** - rspamd can work with the most popular mail transfer systems, such as postfix, exim or sendmail. For postfix and sendmail, there is an [`rmilter` project](https://github.com/vstakhov/rmilter),
  38. whilst for exim there are several solutions to work with rspamd. Should you require MTA integration then please consult with the [integration guide](https://rspamd.com/doc/integration.html).
  39. * **Easy configuration** - rspamd uses [`UCL` language](https://github.com/vstakhov/libucl) for configuration. UCL is a simple and intuitive language that is focused on easy to read configuration files.
  40. You have many choices to write your definitions, so use whatever you like (even a strict `JSON` would be OK).
  41. * **Dynamic tables** - rspamd allows to specify some data as `dynamic maps` that are checked in runtime with updating data when they are changed. Rspamd supports file and HTTP maps.
  42. ## Performance {#performance}
  43. Rspamd was designed to be fast. The core of rspamd is written in `C` and uses event-driven model that allows to process multiple messages simultaenously and without blocking.
  44. Moreover, a set of techniques was used in rspamd to process messages faster:
  45. * **Finite state machines processing** - rspamd uses specialized finite state machines for the performance critical tasks to process input faster than a set of regular expressions.
  46. Of course, it is possible to implement these machines by ordinary `perl regular expressions` but then they won't be compact or human-readable. On the contrary, rspamd optimizes
  47. such actions as headers processing, received elements extraction, protocol operations by builiding the conrete automata for an assigned task.
  48. * **Expressions optimizer** - allows to optimize expressions by exectution of `likely false` or `likely true` expressions in order in the branches. That allows to reduce number of
  49. expensive expressions calls when scanning a message.
  50. * **Symbols optimizer** - rspamd tries to check first the rules that are frequent or inexpensive in terms of time or CPU resourses, which allows to block spam before processing of
  51. expensive rules (rules with negative weights are always checked before other ones).
  52. * **Event driven model** - rspamd is designed not to block anywhere in the code and counting that spam checks requires a lot of network operations, rspamd can process many messages
  53. simultaneously increasing the efficiency of shared DNS caches and other system resources. Moreover, event-driven system normally scales automatically and you won't need to do any
  54. tuning in the most of cases.
  55. * **Threaded expressions and statistics** - rspamd allows to perform computation resources greedy tasks, such as regular expressions or statistics, in separate threads pools, which
  56. allows to scale even more on the modern multi-core systems.
  57. * **Clever choice of data structures** - rspamd tries to use the optimal data structure for each task, for example, it uses very efficient suffix tries for fast matching of a text
  58. against a set of multiple patterns. Or it uses radix bit trie for storing IP addresses information that provides O(1) access time complexity.
  59. ## Extensions {#extensions}
  60. Besides of the `C` core rspamd provides the extensive [LUA](http://lua.org) API to access almost all the features available directly from `C`. LUA is an extremely easy
  61. to learn programming language, though it is powerful enough to implement complex mail filters. In fact, rspamd has a significant amout of code written completely in lua, such as
  62. DNS blacklists checks, or user's settings, or different maps implementation. You can also write your own filters and rules in LUA adopting rspamd functionality to your needs.
  63. Furthermore, LUA programs are very fast and their performance is rather [close](http://attractivechaos.github.io/plb/) to pure `C`. However, you should mention that for the most
  64. of performance critical tasks you usually use the rspamd core functionality than LUA code. Anyway, you can also use `LuaJIT` with rspamd if your goal is maximum performance.
  65. From the LUA API you can do the following tasks:
  66. * **Reading the configuration parameters** - lua code has the full access to the parsed configuration knobs and you can easily modify your plugins behaviour by means of the main
  67. rspamd configuration
  68. * **Registering custom filters** - it is more than simple to add your own filters to rspamd: just add new index to the global variable `rspamd_config`:
  69. ~~~lua
  70. rspamd_config.MYFILTER = function(task)
  71. -- Do something
  72. end
  73. ~~~
  74. * **Full access to the content of messages** - you can access text parts, headers, SMTP data and so on and so forth by using of `task` object. The full list of methods could be found
  75. [here](https://rspamd.com/doc/lua/task.html).
  76. * **Pre- and post- filters** - you can register callbacks that are called before or after messages processing to make results more precise or to make some early decision,
  77. for example, to implement a rate limit.
  78. * **Registering functions for rspamd** - you can write your own functions in lua to extend rspamd internal expression functions.
  79. * **Managing statistics** - lua scripts can define a set of statistical files to be scanned or learned for a specific message allowing to create more complex
  80. statistical systems, e.g. based on an input language. Moreover, you can even learn rspamd statistic from lua scripts.
  81. * **Standalone lua applications** - you can even write your own worker based on rspamd core and performing some asynchronous logic in lua. Of course, you can use the
  82. all features from rspamd core, including such features as non-blocking IO, HTTP client and server, non-blocking redis client, asynchronous DNS, UCL configuration and so on
  83. and so forth.
  84. * **API documentation** - rspamd lua API has an [extensive documentation](https://rspamd.com/doc/lua) where you can find examples, references and the guide about how to extend
  85. rspamd with LUA.
  86. ## References
  87. * Home site: <https://rspamd.com>
  88. * Development: <https://github.com/vstakhov/rspamd>