From 6e9f39520f55bf10e2b9138b7431056c6f9d8596 Mon Sep 17 00:00:00 2001 From: fe7ch Date: Tue, 23 May 2017 10:44:48 +0300 Subject: [PATCH] Basic printf (#519) * Implement "printf" command * Remove dbg print --- cowrie/commands/base.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cowrie/commands/base.py b/cowrie/commands/base.py index bbbc1a28..3eb5c17c 100644 --- a/cowrie/commands/base.py +++ b/cowrie/commands/base.py @@ -150,6 +150,23 @@ class command_echo(HoneyPotCommand): commands['/bin/echo'] = command_echo +class command_printf(HoneyPotCommand): + """ + """ + + def call(self): + if not len(self.args): + self.write('printf: usage: printf [-v var] format [arguments]') + else: + if '-v' not in self.args: + if len(self.args) < 2: + escape_fn = functools.partial(str.decode, encoding="string_escape") + self.write(escape_fn(re.sub('(?<=\\\\)x([0-9a-fA-F])(?=\\\\|\"|\'|\s|$)', 'x0\g<1>', + ''.join(self.args[0]).replace('\\\\x', '\\x'))).strip('\"\'')) + + +commands['printf'] = command_printf + class command_exit(HoneyPotCommand): """