From 41dc4e93c39b3812ed7a1493d6b0109f245d4dc9 Mon Sep 17 00:00:00 2001 From: Dave Germiquet Date: Wed, 23 Dec 2015 08:16:40 -0500 Subject: [PATCH] Added Redirection code. --- cowrie/core/honeypot.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cowrie/core/honeypot.py b/cowrie/core/honeypot.py index 883b40d..8e9665c 100644 --- a/cowrie/core/honeypot.py +++ b/cowrie/core/honeypot.py @@ -9,6 +9,7 @@ import os import shlex import re import copy +import time from twisted.python import log, failure @@ -24,11 +25,45 @@ class HoneyPotCommand(object): self.protocol = protocol self.args = args self.environ = self.protocol.cmdstack[0].environ - self.writeln = self.protocol.writeln - self.write = self.protocol.terminal.write + self.writeln = self.writeln + self.write = self.write self.nextLine = self.protocol.terminal.nextLine self.fs = self.protocol.fs + def write(self,data): + if ">" in self.args: + try: + self.writeToFile(data,"") + except: + self.protocol.terminal.write(data) + else: + self.protocol.terminal.write(data) + + def writeToFile(self,data,line): + safeoutfile = '%s/%s_%s' % (self.protocol.cfg.get('honeypot', 'download_path'), + time.strftime('%Y%m%d%H%M%S'), + re.sub('[^A-Za-z0-9]', '_', "tmpecho")) + + index = self.args.index(">") + data = data.replace(" > ","") + data = data.replace(self.args[(index+1)],"") + file = open(safeoutfile, "a") + file.write(data + line) + file.close() + outfile = self.fs.resolve_path(str(self.args[(index + 1)]), self.protocol.cwd) + self.fs.mkfile(outfile, 0, 0, len(data), 33188) + self.fs.update_realfile(self.fs.getfile(outfile), safeoutfile) + + def writeln(self, data): + if ">" in self.args: + try: + self.writeToFile(data,"\n") + except: + self.protocol.writeln(data) + else: + self.protocol.writeln(data) + + def start(self): """