Skip to content

Commit

Permalink
Add tarpit plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
smfreegard committed Mar 1, 2012
1 parent 787257f commit cc7547f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/tarpit.timeout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
21 changes: 21 additions & 0 deletions docs/plugins/tarpit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tarpit
======

This plugin is designed to introduce deliberate delays on the response
of every hook in order to slow down a connection. It has no
configuration and is designed to be used only by other plugins.

It must be loaded early in config/plugins (e.g. before any plugins
that accept recipients or that return OK) but must be loaded *after*
any plugins that wish to use it.

To use this plugin in another plugin set:

connection.notes.tarpit = <seconds to delay>;

or

connection.transaction.notes.tarpit = <seconds to delay>;

When tarpitting a command it will log 'tarpitting response for Ns' to
the INFO facility where N is the number of seconds.
33 changes: 33 additions & 0 deletions plugins/tarpit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// tarpit

exports.register = function () {
// Register tarpit function last
var self = this;
['connect', 'helo', 'ehlo', 'mail', 'rcpt', 'rcpt_ok', 'data',
'data_post', 'queue', 'unrecognized_command', 'vrfy', 'noop',
'rset', 'quit'].forEach(function (hook) {
self.register_hook(hook, 'tarpit');
});
}

exports.tarpit = function (next, connection) {
var transaction = connection.transaction;
var conn_delay, trans_delay;
if (transaction && transaction.notes) {
trans_delay = transaction.notes.tarpit;
}
if (connection && connection.notes) {
conn_delay = connection.notes.tarpit;
}
var delay = trans_delay || conn_delay;
if (delay) {
connection.loginfo(this, 'tarpitting response for ' + delay + 's');
setTimeout(function () {
// Only return if we still have a connection...
if (connection) return next();
}, (delay*1000));
}
else {
return next();
}
}

0 comments on commit cc7547f

Please sign in to comment.