mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
Add text based dblog module, for demonstration purposes or whatever
git-svn-id: https://kippo.googlecode.com/svn/trunk@238 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
@ -159,3 +159,15 @@ interact_port = 5123
|
|||||||
#signal_command = kippo-events
|
#signal_command = kippo-events
|
||||||
#signal_clientversion = kippo-events
|
#signal_clientversion = kippo-events
|
||||||
#debug=true
|
#debug=true
|
||||||
|
|
||||||
|
# Text based logging module
|
||||||
|
#
|
||||||
|
# While this is a database logging module, it actually just creates a simple
|
||||||
|
# text based log. This may not have much purpose, if you're fine with the
|
||||||
|
# default text based logs generated by kippo in log/
|
||||||
|
#
|
||||||
|
# To enable this module, remove the comments below, including the
|
||||||
|
# [database_textlog] line.
|
||||||
|
|
||||||
|
#[database_textlog]
|
||||||
|
#logfile = kippo-textlog.log
|
||||||
|
|||||||
59
kippo/dblog/textlog.py
Normal file
59
kippo/dblog/textlog.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#
|
||||||
|
# this module uses the dblog feature to create a "traditional" looking logfile
|
||||||
|
# ..so not exactly a dblog.
|
||||||
|
#
|
||||||
|
|
||||||
|
from kippo.core import dblog
|
||||||
|
from twisted.enterprise import adbapi
|
||||||
|
from twisted.internet import defer
|
||||||
|
from twisted.python import log
|
||||||
|
import time
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class DBLogger(dblog.DBLogger):
|
||||||
|
def start(self, cfg):
|
||||||
|
self.outfile = file(cfg.get('database_textlog', 'logfile'), 'a')
|
||||||
|
|
||||||
|
def write(self, session, msg):
|
||||||
|
self.outfile.write('%s [%s]: %s\r\n' % \
|
||||||
|
(session, time.strftime('%Y-%m-%d %H:%M:%S'), msg))
|
||||||
|
self.outfile.flush()
|
||||||
|
|
||||||
|
def createSession(self, peerIP, peerPort, hostIP, hostPort):
|
||||||
|
sid = uuid.uuid1().hex
|
||||||
|
sensorname = self.getSensor() or hostIP
|
||||||
|
self.write(sid, 'New connection: %s:%s' % (peerIP, peerPort))
|
||||||
|
return sid
|
||||||
|
|
||||||
|
def handleConnectionLost(self, session, args):
|
||||||
|
self.write(session, 'Connection lost')
|
||||||
|
|
||||||
|
def handleLoginFailed(self, session, args):
|
||||||
|
self.write(session, 'Login failed [%s/%s]' % \
|
||||||
|
(args['username'], args['password']))
|
||||||
|
|
||||||
|
def handleLoginSucceeded(self, session, args):
|
||||||
|
self.write(session, 'Login succeeded [%s/%s]' % \
|
||||||
|
args['username'], args['password'])
|
||||||
|
|
||||||
|
def handleCommand(self, session, args):
|
||||||
|
self.write(session, 'Command [%s]' % (args['input'],))
|
||||||
|
|
||||||
|
def handleUnknownCommand(self, session, args):
|
||||||
|
self.write(session, 'Unknown command [%s]' % (args['input'],))
|
||||||
|
|
||||||
|
def handleInput(self, session, args):
|
||||||
|
self.write(session, 'Input [%s] @%s' % (args['input'], args['realm']))
|
||||||
|
|
||||||
|
def handleTerminalSize(self, session, args):
|
||||||
|
self.write(session, 'Terminal size: %sx%s' % \
|
||||||
|
(args['width'], args['height']))
|
||||||
|
|
||||||
|
def handleClientVersion(self, session, args):
|
||||||
|
self.write(session, 'Client version: [%s]' % (arg['version'],))
|
||||||
|
|
||||||
|
def handleFileDownload(self, session, args):
|
||||||
|
self.write(session, 'File download: [%s] -> %s' % \
|
||||||
|
(args['url'], args['outfile']))
|
||||||
|
|
||||||
|
# vim: set sw=4 et:
|
||||||
Reference in New Issue
Block a user