From cc7547f13da7621bbd7fc3d7c9022a5841f55fd0 Mon Sep 17 00:00:00 2001 From: Steve Freegard Date: Thu, 1 Mar 2012 09:56:31 -0500 Subject: [PATCH] Add tarpit plugin --- config/tarpit.timeout | 1 + docs/plugins/tarpit.md | 21 +++++++++++++++++++++ plugins/tarpit.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 config/tarpit.timeout create mode 100644 docs/plugins/tarpit.md create mode 100644 plugins/tarpit.js diff --git a/config/tarpit.timeout b/config/tarpit.timeout new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/config/tarpit.timeout @@ -0,0 +1 @@ +0 diff --git a/docs/plugins/tarpit.md b/docs/plugins/tarpit.md new file mode 100644 index 000000000..b050d804d --- /dev/null +++ b/docs/plugins/tarpit.md @@ -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 = ; + +or + + connection.transaction.notes.tarpit = ; + +When tarpitting a command it will log 'tarpitting response for Ns' to +the INFO facility where N is the number of seconds. diff --git a/plugins/tarpit.js b/plugins/tarpit.js new file mode 100644 index 000000000..ce91ccc02 --- /dev/null +++ b/plugins/tarpit.js @@ -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(); + } +}