Merge pull request #11 from hiviah/echo_escape

Support for shell escape sequences in echo command
This commit is contained in:
Michel Oosterhof
2015-06-26 17:12:11 +04:00

View File

@ -3,6 +3,8 @@
import time import time
import datetime import datetime
import functools
import getopt
from twisted.internet import reactor from twisted.internet import reactor
from twisted.python import log from twisted.python import log
@ -100,7 +102,20 @@ commands['/usr/bin/who'] = command_who
class command_echo(HoneyPotCommand): class command_echo(HoneyPotCommand):
def call(self): 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 commands['/bin/echo'] = command_echo
# for testing purposes # for testing purposes