* crashreporter uploads crashes to api.cowrie.org
This commit is contained in:
Michel Oosterhof
2019-09-04 16:01:48 +01:00
committed by GitHub
parent 58fcb470be
commit 7a48eda9ec
3 changed files with 84 additions and 3 deletions

View File

@ -957,3 +957,8 @@ topic = cowrie
# It's optional to have API key, so if you don't want to but
# API key then leave this option commented
#api_key = 1234567890
# The crashreporter sends data on Python exceptions to cowrie.org
[output_crashreporter]
enabled = false
debug = false

View File

@ -0,0 +1,73 @@
"""
Cowrie Crashreport
This output plugin is not like the others.
It has its own emit() function and does not use cowrie eventid's
to avoid circular calls
"""
from __future__ import absolute_import, division
import treq
from twisted.internet import defer
from twisted.logger._levels import LogLevel
import cowrie.core.output
from cowrie._version import __version__
from cowrie.core.config import CowrieConfig
COWRIE_USER_AGENT = 'Cowrie Honeypot {}'.format(__version__).encode('ascii')
COWRIE_URL = 'https://api.cowrie.org/v1/crash'
class Output(cowrie.core.output.Output):
"""
Cowrie Crashreporter output
"""
def start(self):
"""
Start output plugin
"""
self.apiKey = CowrieConfig().get('output_cowrie',
'api_key', fallback=None)
self.debug = CowrieConfig().getboolean('output_cowrie',
'debug', fallback=False)
def emit(self, event):
"""
Note we override emit() here, unlike other plugins.
"""
if event.get('log_level') == LogLevel.critical:
self.crashreport(event)
def stop(self):
"""
Stop output plugin
"""
pass
def write(self, entry):
"""
events are done in emit() not in write()
"""
pass
@defer.inlineCallbacks
def crashreport(self, entry):
"""
Crash report
"""
try:
r = yield treq.post(COWRIE_URL,
entry.get('log_text').encode('ascii'),
headers={b'Content-Type':
[b'application/json'],
b'User-Agent':
[COWRIE_USER_AGENT]})
content = yield r.text()
if self.debug:
print("crashreport: "+content)
except Exception as e:
print("crashreporter failed"+repr(e))

View File

@ -58,6 +58,9 @@ class Output(cowrie.core.output.Output):
# Remove twisted 15 legacy keys
if i.startswith('log_') or i == 'time' or i == 'system':
del logentry[i]
try:
json.dump(logentry, self.outfile, separators=(',', ':'))
self.outfile.write('\n')
self.outfile.flush()
except TypeError:
print("jsonlog: Can't serialize: '"+repr(logentry)+"'")