mongopot 2.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. core/__init__.py +0 -0
  2. core/config.py +50 -0
  3. core/logfile.py +74 -0
  4. core/output.py +39 -0
  5. core/paths.py +54 -0
  6. core/protocol.py +550 -0
  7. core/tools.py +171 -0
  8. mongopot/__init__.py +24 -0
  9. mongopot/cli.py +511 -0
  10. mongopot/data/Dockerfile +56 -0
  11. mongopot/data/docs/INSTALL.md +389 -0
  12. mongopot/data/docs/INSTALLWIN.md +400 -0
  13. mongopot/data/docs/TODO.md +8 -0
  14. mongopot/data/docs/datadog/README.md +32 -0
  15. mongopot/data/docs/discord/README.md +58 -0
  16. mongopot/data/docs/geoipupdtask.ps1 +270 -0
  17. mongopot/data/docs/mysql/README.md +175 -0
  18. mongopot/data/docs/mysql/READMEWIN.md +156 -0
  19. mongopot/data/docs/mysql/mysql.sql +87 -0
  20. mongopot/data/docs/postgres/README.md +183 -0
  21. mongopot/data/docs/postgres/READMEWIN.md +185 -0
  22. mongopot/data/docs/postgres/postgres.sql +74 -0
  23. mongopot/data/docs/slack/README.md +68 -0
  24. mongopot/data/docs/sqlite3/README.md +130 -0
  25. mongopot/data/docs/sqlite3/READMEWIN.md +122 -0
  26. mongopot/data/docs/sqlite3/sqlite3.sql +70 -0
  27. mongopot/data/docs/telegram/README.md +103 -0
  28. mongopot/data/etc/honeypot.cfg +427 -0
  29. mongopot/data/etc/honeypot.cfg.base +421 -0
  30. mongopot/data/responses/buildInfo.json +38 -0
  31. mongopot/data/responses/connectionStatus.json +7 -0
  32. mongopot/data/responses/listCommands.json +2359 -0
  33. mongopot/data/test/.gitignore +3 -0
  34. mongopot/data/test/hpfeeds/broker.bat +1 -0
  35. mongopot/data/test/hpfeeds/docker-compose.yml +13 -0
  36. mongopot/data/test/hpfeeds/subscribe.bat +1 -0
  37. mongopot/data/test/kafka/ctest.py +27 -0
  38. mongopot/data/test/kafka/ctest2.py +37 -0
  39. mongopot/data/test/kafka/ptest.py +42 -0
  40. mongopot/data/test/kafka/ptest2.py +47 -0
  41. mongopot/data/test/kafka/ptest3.py +54 -0
  42. mongopot/data/test/mongobleed.py +129 -0
  43. mongopot/data/test/output_plugins/dshield.py +158 -0
  44. mongopot/data/test/output_plugins/graylog.py +52 -0
  45. mongopot/data/test/output_plugins/oraclecloud.py +110 -0
  46. mongopot/data/test/output_plugins/splunk.py +107 -0
  47. mongopot/data/test/redis/redis.bat +2 -0
  48. mongopot/data/test/test.py +52 -0
  49. mongopot/honeypot.py +119 -0
  50. mongopot-2.0.0.dist-info/METADATA +128 -0
  51. mongopot-2.0.0.dist-info/RECORD +77 -0
  52. mongopot-2.0.0.dist-info/WHEEL +6 -0
  53. mongopot-2.0.0.dist-info/entry_points.txt +2 -0
  54. mongopot-2.0.0.dist-info/licenses/LICENSE +674 -0
  55. mongopot-2.0.0.dist-info/top_level.txt +3 -0
  56. output_plugins/__init__.py +0 -0
  57. output_plugins/couch.py +66 -0
  58. output_plugins/datadog.py +77 -0
  59. output_plugins/discord.py +115 -0
  60. output_plugins/elastic.py +109 -0
  61. output_plugins/hpfeed.py +40 -0
  62. output_plugins/influx2.py +62 -0
  63. output_plugins/jsonlog.py +35 -0
  64. output_plugins/kafka.py +54 -0
  65. output_plugins/localsyslog.py +68 -0
  66. output_plugins/mongodb.py +81 -0
  67. output_plugins/mysql.py +201 -0
  68. output_plugins/nlcvapi.py +112 -0
  69. output_plugins/postgres.py +135 -0
  70. output_plugins/redisdb.py +41 -0
  71. output_plugins/rethinkdblog.py +38 -0
  72. output_plugins/slack.py +59 -0
  73. output_plugins/socketlog.py +37 -0
  74. output_plugins/sqlite.py +138 -0
  75. output_plugins/telegram.py +117 -0
  76. output_plugins/textlog.py +44 -0
  77. output_plugins/xmpp.py +47 -0
core/__init__.py ADDED
File without changes
core/config.py ADDED
@@ -0,0 +1,50 @@
1
+
2
+ from configparser import ConfigParser, ExtendedInterpolation
3
+
4
+ from os import environ
5
+
6
+
7
+ def to_environ_key(key):
8
+ return key.upper()
9
+
10
+
11
+ class EnvironmentConfigParser(ConfigParser):
12
+
13
+ def has_option(self, section, option):
14
+ if to_environ_key('_'.join((section, option))) in environ:
15
+ return True
16
+ return super(EnvironmentConfigParser, self).has_option(section, option)
17
+
18
+ def get(self, section, option, **kwargs):
19
+ key = to_environ_key('_'.join((section, option)))
20
+ if key in environ:
21
+ return environ[key]
22
+ return super(EnvironmentConfigParser, self).get(section, option, **kwargs)
23
+
24
+
25
+ def readConfigFile(cfgfile):
26
+ """
27
+ Read config files and return ConfigParser object
28
+
29
+ @param cfgfile: filename or array of filenames
30
+ @return: ConfigParser object
31
+ """
32
+ parser = EnvironmentConfigParser(
33
+ interpolation=ExtendedInterpolation(),
34
+ converters={'list': lambda x: [i.strip() for i in x.split(',')]}
35
+ )
36
+ parser.read(cfgfile)
37
+ return parser
38
+
39
+
40
+ def _config_files():
41
+ # Import here (not at module top) to avoid any circular-import risk.
42
+ from core.paths import workdir_path, bundled
43
+ return [
44
+ bundled('etc', 'honeypot.cfg.base'), # bundled read-only defaults
45
+ workdir_path('etc', 'honeypot.cfg'), # site-local overrides
46
+ workdir_path('honeypot.cfg'), # convenience root-level override
47
+ ]
48
+
49
+
50
+ CONFIG = readConfigFile(_config_files())
core/logfile.py ADDED
@@ -0,0 +1,74 @@
1
+
2
+ from sys import stdout
3
+ from datetime import datetime
4
+
5
+ from pytz import timezone
6
+
7
+ from twisted.python import log, util
8
+ from twisted.python.logfile import DailyLogFile
9
+
10
+
11
+ class HoneypotDailyLogFile(DailyLogFile):
12
+ """
13
+ Overload original Twisted with improved date formatting
14
+ """
15
+
16
+ def suffix(self, tupledate):
17
+ """
18
+ Return the suffix given a (year, month, day) tuple or unixtime
19
+ """
20
+ try:
21
+ return "{:02d}-{:02d}-{:02d}".format(tupledate[0], tupledate[1], tupledate[2])
22
+ except Exception:
23
+ # try taking a float unixtime
24
+ return '_'.join(map(str, self.toDate(tupledate)))
25
+
26
+
27
+ def myFLOemit(self, eventDict):
28
+ """
29
+ Format the given log event as text and write it to the output file.
30
+
31
+ @param eventDict: a log event
32
+ @type eventDict: L{dict} mapping L{str} (native string) to L{object}
33
+ """
34
+
35
+ # Custom emit for FileLogObserver
36
+ text = log.textFromEventDict(eventDict)
37
+ if text is None:
38
+ return
39
+ timeStr = self.formatTime(eventDict['time'])
40
+ fmtDict = {
41
+ 'text': text.replace('\n', '\n\t')
42
+ }
43
+ msgStr = log._safeFormat('%(text)s\n', fmtDict)
44
+ util.untilConcludes(self.write, timeStr + ' ' + msgStr)
45
+ util.untilConcludes(self.flush)
46
+
47
+
48
+ def myFLOformatTime(self, when):
49
+ """
50
+ Log time in UTC
51
+
52
+ By default it's formatted as an ISO8601-like string (ISO8601 date and
53
+ ISO8601 time separated by a space). It can be customized using the
54
+ C{timeFormat} attribute, which will be used as input for the underlying
55
+ L{datetime.datetime.strftime} call.
56
+
57
+ @type when: C{int}
58
+ @param when: POSIX (ie, UTC) timestamp.
59
+
60
+ @rtype: C{str}
61
+ """
62
+ timeFormatString = self.timeFormat
63
+ if timeFormatString is None:
64
+ timeFormatString = '[%Y-%m-%d %H:%M:%S.%fZ]'
65
+ return datetime.fromtimestamp(when, tz=timezone('UTC')).strftime(timeFormatString)
66
+
67
+
68
+ def set_logger(cfg_options):
69
+ log.FileLogObserver.emit = myFLOemit
70
+ log.FileLogObserver.formatTime = myFLOformatTime
71
+ if cfg_options['logfile'] is None:
72
+ log.startLogging(stdout)
73
+ else:
74
+ log.startLogging(HoneypotDailyLogFile.fromFullPath(cfg_options['logfile']), setStdout=False)
core/output.py ADDED
@@ -0,0 +1,39 @@
1
+
2
+ from socket import gethostname
3
+
4
+ from core.config import CONFIG
5
+
6
+
7
+ class Output(object):
8
+ """
9
+ Abstract base class intended to be inherited by output plugins.
10
+ """
11
+
12
+ def __init__(self, general_options):
13
+
14
+ self.cfg = general_options
15
+
16
+ if 'sensor' in self.cfg:
17
+ self.sensor = self.cfg['sensor']
18
+ else:
19
+ self.sensor = CONFIG.get('honeypot', 'sensor_name', fallback=gethostname())
20
+
21
+ self.start()
22
+
23
+ def start(self):
24
+ """
25
+ Abstract method to initialize output plugin
26
+ """
27
+ pass
28
+
29
+ def stop(self):
30
+ """
31
+ Abstract method to shut down output plugin
32
+ """
33
+ pass
34
+
35
+ def write(self, event):
36
+ """
37
+ Handle a general event within the output plugin
38
+ """
39
+ pass
core/paths.py ADDED
@@ -0,0 +1,54 @@
1
+ """
2
+ paths.py - Single source of truth for runtime path resolution.
3
+
4
+ The honeypot needs a "working directory" containing:
5
+ etc/ config files (honeypot-launch.cfg.base, honeypot.cfg.base)
6
+ responses/ MongoDB wire-protocol JSON stubs
7
+ log/ rotating log files (created on demand)
8
+ data/ geolocation databases, SQLite db, etc.
9
+
10
+ Priority for locating the working directory:
11
+ 1. MONGOPOT_WORKDIR environment variable
12
+ 2. Current working directory
13
+
14
+ The bundled read-only defaults (etc/*.cfg.base, responses/*.json)
15
+ are installed inside the `mongopot` package and located via the package's
16
+ own __file__ attribute, which works on all Python versions without
17
+ requiring pkg_resources or importlib.resources.
18
+ """
19
+
20
+ from __future__ import absolute_import
21
+
22
+
23
+ from os import getcwd, environ
24
+ from os.path import abspath, dirname, join
25
+
26
+
27
+ def get_workdir():
28
+ """Return the absolute path to the runtime working directory."""
29
+ env = environ.get('MONGOPOT_WORKDIR', '').strip()
30
+ if env:
31
+ return abspath(env)
32
+ return getcwd()
33
+
34
+
35
+ def workdir_path(*parts):
36
+ """Return an absolute path rooted at the working directory."""
37
+ return join(get_workdir(), *parts)
38
+
39
+
40
+ def bundled(*parts):
41
+ """
42
+ Return the filesystem path to a file bundled inside the installed package.
43
+ Arguments are path components relative to the mongopot/data/ directory,
44
+ passed as separate strings (like os.path.join) to avoid hardcoded separators.
45
+
46
+ Uses the package's own __file__ to locate the data directory, which works
47
+ on all Python versions (2.7+) without requiring pkg_resources or
48
+ importlib.resources.
49
+ """
50
+ # mongopot/data/ lives alongside this module's package (core/ is a sibling
51
+ # of mongopot/), so we go up one level from core/ to find mongopot/data/.
52
+ here = dirname(abspath(__file__))
53
+ package_dir = join(dirname(here), 'mongopot')
54
+ return join(package_dir, 'data', *parts)