From f2488b41737e7a13dd39c7ee45d2da2629c7e96e Mon Sep 17 00:00:00 2001 From: desaster Date: Fri, 21 Oct 2011 18:35:41 +0000 Subject: [PATCH] * Write input from the session manager to ttylog with a different ID * playlog.py now able to colorify the output based on which streams the input is coming form git-svn-id: https://kippo.googlecode.com/svn/trunk@211 951d7100-d841-11de-b865-b3884708a8e2 --- kippo/core/honeypot.py | 4 ++-- kippo/core/interact.py | 11 +++++++++-- kippo/core/ttylog.py | 2 +- utils/playlog.py | 22 ++++++++++++++++++---- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/kippo/core/honeypot.py b/kippo/core/honeypot.py index f3c7f403..8385e165 100644 --- a/kippo/core/honeypot.py +++ b/kippo/core/honeypot.py @@ -349,7 +349,7 @@ class HoneyPotProtocol(recvline.HistoricRecvLine): def keystrokeReceived(self, keyID, modifier): if type(keyID) == type(''): ttylog.ttylog_write(self.terminal.ttylog_file, len(keyID), - ttylog.DIR_READ, time.time(), keyID) + ttylog.TYPE_INPUT, time.time(), keyID) recvline.HistoricRecvLine.keystrokeReceived(self, keyID, modifier) # Easier way to implement password input? @@ -418,7 +418,7 @@ class LoggingServerProtocol(insults.ServerProtocol): i.sessionWrite(bytes) if self.ttylog_open and not noLog: ttylog.ttylog_write(self.ttylog_file, len(bytes), - ttylog.DIR_WRITE, time.time(), bytes) + ttylog.TYPE_OUTPUT, time.time(), bytes) insults.ServerProtocol.write(self, bytes) def connectionLost(self, reason): diff --git a/kippo/core/interact.py b/kippo/core/interact.py index d6132dd0..cb8cbe34 100644 --- a/kippo/core/interact.py +++ b/kippo/core/interact.py @@ -1,5 +1,7 @@ from twisted.internet import protocol -from twisted.conch import telnet +from twisted.conch import telnet, recvline +from kippo.core import ttylog +import time class Interact(telnet.Telnet): @@ -61,7 +63,12 @@ class Interact(telnet.Telnet): '\r\n** Interactive session closed.\r\n') return if not self.readonly: - self.interacting.keystrokeReceived(bytes, None) + if type(bytes) == type(''): + ttylog.ttylog_write( + self.interacting.terminal.ttylog_file, + len(bytes), ttylog.TYPE_INTERACT, time.time(), bytes) + recvline.HistoricRecvLine.keystrokeReceived( + self.interacting, bytes, None) def sessionWrite(self, data): buf, prev = '', '' diff --git a/kippo/core/ttylog.py b/kippo/core/ttylog.py index 44c90182..ecd2410e 100644 --- a/kippo/core/ttylog.py +++ b/kippo/core/ttylog.py @@ -6,7 +6,7 @@ import struct, sys OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4 -DIR_READ, DIR_WRITE = 1, 2 +TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3 def ttylog_write(logfile, len, direction, stamp, data = None): f = file(logfile, 'ab') diff --git a/utils/playlog.py b/utils/playlog.py index b49d5a4b..503426f7 100755 --- a/utils/playlog.py +++ b/utils/playlog.py @@ -6,13 +6,15 @@ import os, sys, time, struct, string, getopt OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4 -DIR_READ, DIR_WRITE = 1, 2 +TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3 def playlog(fd, settings): ssize = struct.calcsize(' 0: time.sleep(sleeptime) prevtime = curtime + if settings['colorify'] and color: + sys.stdout.write(color) sys.stdout.write(data) + if settings['colorify'] and color: + sys.stdout.write('\033[0m') + color = None sys.stdout.flush() elif str(tty) == str(currtty) and op == OP_CLOSE: break @@ -62,6 +73,7 @@ def help(brief = 0): ' to the end. (default is 3.0)' print ' -i show the input stream instead of output' print ' -b show both input and output streams' + print ' -c colorify the output stream based on what streams are being received' print ' -h display this help\n' sys.exit(1) @@ -73,10 +85,11 @@ if __name__ == '__main__': 'maxdelay': 3.0, 'input_only': 0, 'both_dirs': 0, + 'colorify': 0, } try: - optlist, args = getopt.getopt(sys.argv[1:], 'fhibm:w:', ['help']) + optlist, args = getopt.getopt(sys.argv[1:], 'fhibcm:w:', ['help']) except getopt.GetoptError, error: print 'Error: %s\n' % error help() @@ -87,6 +100,7 @@ if __name__ == '__main__': elif o == '-i': settings['input_only'] = 1 elif o == '-b': settings['both_dirs'] = 1 elif o in ['-h', '--help']: help() + elif o == '-c': settings['colorify'] = 1 if len(args) < 1: help()