mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
@ -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
|
||||
|
||||
73
src/cowrie/output/crashreporter.py
Normal file
73
src/cowrie/output/crashreporter.py
Normal 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))
|
||||
@ -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)+"'")
|
||||
|
||||
Reference in New Issue
Block a user