diff --git a/utils/asciinema.py b/utils/asciinema.py new file mode 100755 index 0000000..6524b27 --- /dev/null +++ b/utils/asciinema.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python + +import getopt +import json +import os +import sys +import struct + +OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4 +TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3 + +COLOR_INTERACT = '\033[36m' +COLOR_INPUT = '\033[33m' +COLOR_RESET = '\033[0m' + +def playlog(fd, settings): + + thelog = {} + thelog['version'] = 1 + thelog['width'] = 80 + thelog['height'] = 24 + thelog['duration'] = 0.0 + thelog['command'] = "/bin/bash" + thelog['title'] = "Cowrie Recording" + theenv = {} + theenv['TERM'] = "xterm256-color" + theenv['SHELL'] = "/bin/bash" + thelog["env"] = theenv + stdout = [] + thelog["stdout"] = stdout + + ssize = struct.calcsize(' ...' % \ + os.path.basename(sys.argv[0]) + + if verbose: + print ' -c colorify the output based on what streams are being received' + print ' -h display this help' + print ' -o write to the specified output file' + + +if __name__ == '__main__': + + settings = { + 'colorify': 0, + 'output': "" + } + + try: + optlist, args = getopt.getopt(sys.argv[1:], 'hco:' ) + except getopt.GetoptError, error: + sys.stderr.write( '{}: {}\n'.format(sys.argv[0], error)) + help() + sys.exit(1) + + for o, a in optlist: + if o == '-h': help() + if o == '-c': settings['colorify'] = True + if o == '-o': settings['output'] = a + + if len(args)<1: + help() + sys.exit(1) + + for logfile in args: + try: + logfd = open(logfile, 'rb') + playlog(logfd, settings) + except IOError as e: + sys.stderr.write( "{}: {}\n".format(sys.argv[0], e)) +