mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-18 22:44:29 +01:00
* 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:
@@ -349,7 +349,7 @@ class HoneyPotProtocol(recvline.HistoricRecvLine):
|
|||||||
def keystrokeReceived(self, keyID, modifier):
|
def keystrokeReceived(self, keyID, modifier):
|
||||||
if type(keyID) == type(''):
|
if type(keyID) == type(''):
|
||||||
ttylog.ttylog_write(self.terminal.ttylog_file, len(keyID),
|
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)
|
recvline.HistoricRecvLine.keystrokeReceived(self, keyID, modifier)
|
||||||
|
|
||||||
# Easier way to implement password input?
|
# Easier way to implement password input?
|
||||||
@@ -418,7 +418,7 @@ class LoggingServerProtocol(insults.ServerProtocol):
|
|||||||
i.sessionWrite(bytes)
|
i.sessionWrite(bytes)
|
||||||
if self.ttylog_open and not noLog:
|
if self.ttylog_open and not noLog:
|
||||||
ttylog.ttylog_write(self.ttylog_file, len(bytes),
|
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)
|
insults.ServerProtocol.write(self, bytes)
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from twisted.internet import protocol
|
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):
|
class Interact(telnet.Telnet):
|
||||||
|
|
||||||
@@ -61,7 +63,12 @@ class Interact(telnet.Telnet):
|
|||||||
'\r\n** Interactive session closed.\r\n')
|
'\r\n** Interactive session closed.\r\n')
|
||||||
return
|
return
|
||||||
if not self.readonly:
|
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):
|
def sessionWrite(self, data):
|
||||||
buf, prev = '', ''
|
buf, prev = '', ''
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import struct, sys
|
import struct, sys
|
||||||
|
|
||||||
OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4
|
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):
|
def ttylog_write(logfile, len, direction, stamp, data = None):
|
||||||
f = file(logfile, 'ab')
|
f = file(logfile, 'ab')
|
||||||
|
|||||||
@@ -6,13 +6,15 @@
|
|||||||
import os, sys, time, struct, string, getopt
|
import os, sys, time, struct, string, getopt
|
||||||
|
|
||||||
OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4
|
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):
|
def playlog(fd, settings):
|
||||||
|
|
||||||
ssize = struct.calcsize('<iLiiLL')
|
ssize = struct.calcsize('<iLiiLL')
|
||||||
currtty, prevtime, prefdir = 0, 0, 0
|
currtty, prevtime, prefdir = 0, 0, 0
|
||||||
|
|
||||||
|
color = None
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
(op, tty, length, dir, sec, usec) = \
|
(op, tty, length, dir, sec, usec) = \
|
||||||
@@ -34,8 +36,12 @@ def playlog(fd, settings):
|
|||||||
prefdir = dir
|
prefdir = dir
|
||||||
# use the other direction
|
# use the other direction
|
||||||
if settings['input_only']:
|
if settings['input_only']:
|
||||||
prefdir = DIR_READ
|
prefdir = TYPE_INPUT
|
||||||
if dir == DIR_READ: prefdir = DIR_WRITE
|
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']:
|
if dir == prefdir or settings['both_dirs']:
|
||||||
curtime = float(sec) + float(usec) / 1000000
|
curtime = float(sec) + float(usec) / 1000000
|
||||||
if prevtime != 0:
|
if prevtime != 0:
|
||||||
@@ -45,7 +51,12 @@ def playlog(fd, settings):
|
|||||||
if settings['maxdelay'] > 0:
|
if settings['maxdelay'] > 0:
|
||||||
time.sleep(sleeptime)
|
time.sleep(sleeptime)
|
||||||
prevtime = curtime
|
prevtime = curtime
|
||||||
|
if settings['colorify'] and color:
|
||||||
|
sys.stdout.write(color)
|
||||||
sys.stdout.write(data)
|
sys.stdout.write(data)
|
||||||
|
if settings['colorify'] and color:
|
||||||
|
sys.stdout.write('\033[0m')
|
||||||
|
color = None
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
elif str(tty) == str(currtty) and op == OP_CLOSE:
|
elif str(tty) == str(currtty) and op == OP_CLOSE:
|
||||||
break
|
break
|
||||||
@@ -62,6 +73,7 @@ def help(brief = 0):
|
|||||||
' to the end. (default is 3.0)'
|
' to the end. (default is 3.0)'
|
||||||
print ' -i show the input stream instead of output'
|
print ' -i show the input stream instead of output'
|
||||||
print ' -b show both input and output streams'
|
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'
|
print ' -h display this help\n'
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -73,10 +85,11 @@ if __name__ == '__main__':
|
|||||||
'maxdelay': 3.0,
|
'maxdelay': 3.0,
|
||||||
'input_only': 0,
|
'input_only': 0,
|
||||||
'both_dirs': 0,
|
'both_dirs': 0,
|
||||||
|
'colorify': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
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:
|
except getopt.GetoptError, error:
|
||||||
print 'Error: %s\n' % error
|
print 'Error: %s\n' % error
|
||||||
help()
|
help()
|
||||||
@@ -87,6 +100,7 @@ if __name__ == '__main__':
|
|||||||
elif o == '-i': settings['input_only'] = 1
|
elif o == '-i': settings['input_only'] = 1
|
||||||
elif o == '-b': settings['both_dirs'] = 1
|
elif o == '-b': settings['both_dirs'] = 1
|
||||||
elif o in ['-h', '--help']: help()
|
elif o in ['-h', '--help']: help()
|
||||||
|
elif o == '-c': settings['colorify'] = 1
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
help()
|
help()
|
||||||
|
|||||||
Reference in New Issue
Block a user