mirror of https://github.com/cowrie/cowrie.git
* 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
This commit is contained in:
parent
2bb4a198f8
commit
f2488b4173
|
@ -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):
|
||||
|
|
|
@ -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 = '', ''
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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('<iLiiLL')
|
||||
currtty, prevtime, prefdir = 0, 0, 0
|
||||
|
||||
color = None
|
||||
|
||||
while 1:
|
||||
try:
|
||||
(op, tty, length, dir, sec, usec) = \
|
||||
|
@ -34,8 +36,12 @@ def playlog(fd, settings):
|
|||
prefdir = dir
|
||||
# use the other direction
|
||||
if settings['input_only']:
|
||||
prefdir = DIR_READ
|
||||
if dir == DIR_READ: prefdir = DIR_WRITE
|
||||
prefdir = TYPE_INPUT
|
||||
if dir == TYPE_INPUT: prefdir = TYPE_OUTPUT
|
||||
if dir == TYPE_INTERACT:
|
||||
color = '\033[36m'
|
||||
elif dir == TYPE_INPUT:
|
||||
color = '\033[33m'
|
||||
if dir == prefdir or settings['both_dirs']:
|
||||
curtime = float(sec) + float(usec) / 1000000
|
||||
if prevtime != 0:
|
||||
|
@ -45,7 +51,12 @@ def playlog(fd, settings):
|
|||
if settings['maxdelay'] > 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()
|
||||
|
|
Loading…
Reference in New Issue