From 7f17401b6bfa01ee1d35462a11804aca29647f7a Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Fri, 26 Jun 2015 14:28:02 +0200 Subject: [PATCH] Support for shell escape sequences in echo command --- cowrie/commands/base.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cowrie/commands/base.py b/cowrie/commands/base.py index e050dd8..3fb9be2 100644 --- a/cowrie/commands/base.py +++ b/cowrie/commands/base.py @@ -3,6 +3,8 @@ import time import datetime +import functools +import getopt from twisted.internet import reactor from twisted.python import log @@ -100,7 +102,20 @@ commands['/usr/bin/who'] = command_who class command_echo(HoneyPotCommand): def call(self): - self.writeln(' '.join(self.args)) + write_fn = self.writeln + escape_fn = lambda s: s + optlist, args = getopt.getopt(self.args, "eEn") + + for opt in optlist: + if opt[0] == '-e': + escape_fn = functools.partial(str.decode, encoding="string_escape") + elif opt[0] == '-E': + escape_fn = lambda s: s + elif opt[0] == '-n': + write_fn = self.write + + write_fn(escape_fn(' '.join(args))) + commands['/bin/echo'] = command_echo # for testing purposes