elasticpot 2.0.1.dev0__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 (84) 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 +451 -0
  7. core/tools.py +171 -0
  8. elasticpot/__init__.py +26 -0
  9. elasticpot/cli.py +519 -0
  10. elasticpot/data/Dockerfile +56 -0
  11. elasticpot/data/docs/INSTALL.md +424 -0
  12. elasticpot/data/docs/INSTALLWIN.md +435 -0
  13. elasticpot/data/docs/PLUGINS.md +21 -0
  14. elasticpot/data/docs/TODO.md +3 -0
  15. elasticpot/data/docs/datadog/README.md +32 -0
  16. elasticpot/data/docs/discord/README.md +58 -0
  17. elasticpot/data/docs/geoipupdtask.ps1 +270 -0
  18. elasticpot/data/docs/mysql/README.md +176 -0
  19. elasticpot/data/docs/mysql/READMEWIN.md +157 -0
  20. elasticpot/data/docs/mysql/mysql.sql +78 -0
  21. elasticpot/data/docs/postgres/README.md +184 -0
  22. elasticpot/data/docs/postgres/READMEWIN.md +196 -0
  23. elasticpot/data/docs/postgres/postgres.sql +72 -0
  24. elasticpot/data/docs/slack/README.md +68 -0
  25. elasticpot/data/docs/sqlite3/README.md +131 -0
  26. elasticpot/data/docs/sqlite3/READMEWIN.md +123 -0
  27. elasticpot/data/docs/sqlite3/sqlite3.sql +70 -0
  28. elasticpot/data/docs/telegram/README.md +103 -0
  29. elasticpot/data/etc/honeypot.cfg.base +472 -0
  30. elasticpot/data/responses/aliases.json +8 -0
  31. elasticpot/data/responses/banner.json +13 -0
  32. elasticpot/data/responses/cluster.json +17 -0
  33. elasticpot/data/responses/clusterstore.json +21 -0
  34. elasticpot/data/responses/error.json +21 -0
  35. elasticpot/data/responses/index1long.json +12 -0
  36. elasticpot/data/responses/index1short.json +3 -0
  37. elasticpot/data/responses/index2long.json +12 -0
  38. elasticpot/data/responses/index2short.json +3 -0
  39. elasticpot/data/responses/indices.txt +2 -0
  40. elasticpot/data/responses/mapping.json +41 -0
  41. elasticpot/data/responses/nodes.json +37 -0
  42. elasticpot/data/responses/nodes2.json +11 -0
  43. elasticpot/data/responses/nodes2.txt +1 -0
  44. elasticpot/data/responses/pluginhead.html +33 -0
  45. elasticpot/data/responses/search.json +25 -0
  46. elasticpot/data/responses/search2.json +28 -0
  47. elasticpot/data/responses/settings.json +30 -0
  48. elasticpot/data/responses/stats1.json +755 -0
  49. elasticpot/data/responses/stats2.json +163 -0
  50. elasticpot/data/responses/store.json +47 -0
  51. elasticpot/data/test/.gitignore +6 -0
  52. elasticpot/data/test/README.md +36 -0
  53. elasticpot/data/test/baseline +233 -0
  54. elasticpot/data/test/test.py +64 -0
  55. elasticpot/data/test/testurls.txt +39 -0
  56. elasticpot/honeypot.py +134 -0
  57. elasticpot-2.0.1.dev0.dist-info/METADATA +155 -0
  58. elasticpot-2.0.1.dev0.dist-info/RECORD +84 -0
  59. elasticpot-2.0.1.dev0.dist-info/WHEEL +6 -0
  60. elasticpot-2.0.1.dev0.dist-info/entry_points.txt +2 -0
  61. elasticpot-2.0.1.dev0.dist-info/licenses/LICENSE +674 -0
  62. elasticpot-2.0.1.dev0.dist-info/top_level.txt +3 -0
  63. output_plugins/__init__.py +0 -0
  64. output_plugins/couch.py +68 -0
  65. output_plugins/datadog.py +71 -0
  66. output_plugins/discord.py +121 -0
  67. output_plugins/elastic.py +137 -0
  68. output_plugins/hpfeed.py +43 -0
  69. output_plugins/influx2.py +64 -0
  70. output_plugins/jsonlog.py +36 -0
  71. output_plugins/kafka.py +57 -0
  72. output_plugins/localsyslog.py +65 -0
  73. output_plugins/mongodb.py +84 -0
  74. output_plugins/mysql.py +227 -0
  75. output_plugins/nlcvapi.py +125 -0
  76. output_plugins/postgres.py +160 -0
  77. output_plugins/redisdb.py +47 -0
  78. output_plugins/rethinkdblog.py +46 -0
  79. output_plugins/slack.py +79 -0
  80. output_plugins/socketlog.py +40 -0
  81. output_plugins/sqlite.py +158 -0
  82. output_plugins/telegram.py +128 -0
  83. output_plugins/textlog.py +34 -0
  84. output_plugins/xmpp.py +179 -0
core/tools.py ADDED
@@ -0,0 +1,171 @@
1
+
2
+ from sys import version_info
3
+ from os import makedirs, path
4
+ from datetime import datetime
5
+ from ipaddress import ip_address, ip_network
6
+ from socket import socket, AF_INET, SOCK_DGRAM
7
+
8
+ from core.config import CONFIG
9
+
10
+ from pytz import timezone
11
+
12
+ from twisted.python.log import msg
13
+
14
+ try:
15
+ from urllib.request import urlopen
16
+ from urllib.parse import urlsplit, urlunsplit
17
+ except ImportError:
18
+ from urllib import urlopen
19
+ from urlparse import urlsplit, urlunsplit # type: ignore
20
+
21
+
22
+ if version_info[0] >= 3:
23
+ def decode(x):
24
+ return x.decode('utf-8')
25
+ def encode(x):
26
+ return x.encode()
27
+ def unicode(x):
28
+ return x
29
+ def to_bytes(x):
30
+ return bytes(x, 'ascii')
31
+ else:
32
+ def decode(x):
33
+ return x
34
+ def encode(x):
35
+ return x
36
+ def to_bytes(x):
37
+ return bytes(x)
38
+
39
+ def get_utc_time(unix_time):
40
+ return datetime.fromtimestamp(unix_time, tz=timezone('UTC')).isoformat() + 'Z'
41
+
42
+
43
+ def get_public_ip(ip_reporter):
44
+ try:
45
+ if version_info[0] < 3:
46
+ return urlopen(ip_reporter).read().decode('latin1', errors='replace').encode('utf-8')
47
+ else:
48
+ return urlopen(ip_reporter).read()
49
+ except:
50
+ return '127.0.0.1'
51
+
52
+
53
+ def get_local_ip():
54
+ s = socket(AF_INET, SOCK_DGRAM)
55
+ try:
56
+ s.connect(('10.255.255.255', 1))
57
+ ip = s.getsockname()[0]
58
+ except:
59
+ ip = '127.0.0.1'
60
+ finally:
61
+ s.close()
62
+ return ip
63
+
64
+
65
+ def resolve_url(url):
66
+ parts = list(urlsplit(url))
67
+ segments = parts[2].split('/')
68
+ segments = [segment + '/' for segment in segments[:-1]] + [segments[-1]]
69
+ resolved = []
70
+ for segment in segments:
71
+ if segment in ('../', '..'):
72
+ if resolved[1:]:
73
+ resolved.pop()
74
+ elif segment not in ('./', '.'):
75
+ resolved.append(segment)
76
+ parts[2] = ''.join(resolved)
77
+ return urlunsplit(parts)
78
+
79
+
80
+ def write_event(event, cfg):
81
+ ip = event['src_ip']
82
+ for network in cfg['blacklist']:
83
+ if ip_address(unicode(ip)) in ip_network(unicode(network)):
84
+ return
85
+ output_plugins = cfg['output_plugins']
86
+ for plugin in output_plugins:
87
+ try:
88
+ plugin.write(event)
89
+ except Exception as e:
90
+ msg(e)
91
+ continue
92
+
93
+
94
+ def mkdir(dir_path):
95
+ if not dir_path:
96
+ return
97
+ if path.exists(dir_path) and path.isdir(dir_path):
98
+ return
99
+ makedirs(dir_path)
100
+
101
+
102
+ def import_plugins(cfg):
103
+ # Load output modules (inspired by the Cowrie honeypot)
104
+ msg('Loading the plugins...')
105
+ output_plugins = []
106
+ general_options = cfg
107
+ for x in CONFIG.sections():
108
+ if not x.startswith('output_'):
109
+ continue
110
+ if CONFIG.getboolean(x, 'enabled') is False:
111
+ continue
112
+ engine = x.split('_')[1]
113
+ try:
114
+ output = __import__('output_plugins.{}'.format(engine),
115
+ globals(), locals(), ['output'], 0).Output(general_options)
116
+ output_plugins.append(output)
117
+ msg('Loaded output engine: {}'.format(engine))
118
+ except ImportError as e:
119
+ msg('Failed to load output engine: {} due to ImportError: {}'.format(engine, e))
120
+ except Exception as e:
121
+ msg('Failed to load output engine: {} {}'.format(engine, e))
122
+ return output_plugins
123
+
124
+
125
+ def stop_plugins(cfg):
126
+ msg('Stoping the plugins...')
127
+ for plugin in cfg['output_plugins']:
128
+ try:
129
+ plugin.stop()
130
+ except Exception as e:
131
+ msg(e)
132
+ continue
133
+
134
+
135
+ def geolocate(remote_ip, reader_city, reader_asn):
136
+ try:
137
+ response_city = reader_city.city(remote_ip)
138
+ city = response_city.city.name
139
+ if city is None:
140
+ city = ''
141
+ else:
142
+ city = decode(city.encode('utf-8'))
143
+ country = response_city.country.name
144
+ if country is None:
145
+ country = ''
146
+ country_code = ''
147
+ else:
148
+ country = decode(country.encode('utf-8'))
149
+ country_code = decode(response_city.country.iso_code.encode('utf-8'))
150
+ except Exception as e:
151
+ msg(e)
152
+ city = ''
153
+ country = ''
154
+ country_code = ''
155
+
156
+ try:
157
+ response_asn = reader_asn.asn(remote_ip)
158
+ if response_asn.autonomous_system_organization is None:
159
+ org = ''
160
+ else:
161
+ org = decode(response_asn.autonomous_system_organization.encode('utf-8'))
162
+
163
+ if response_asn.autonomous_system_number is not None:
164
+ asn_num = response_asn.autonomous_system_number
165
+ else:
166
+ asn_num = 0
167
+ except Exception as e:
168
+ msg(e)
169
+ org = ''
170
+ asn_num = 0
171
+ return country, country_code, city, org, asn_num
elasticpot/__init__.py ADDED
@@ -0,0 +1,26 @@
1
+ # elasticpot: the installable Python package for the elasticpot honeypot.
2
+ #
3
+ # After `pip install elasticpot`, use the `elasticpot` command:
4
+ #
5
+ # elasticpot init -- scaffold a working directory
6
+ # elasticpot run -- start the honeypot in the foreground
7
+ # elasticpot start -- start the honeypot in the background
8
+ # elasticpot stop -- stop the background honeypot
9
+ # elasticpot restart -- restart the honeypot (stop and start the honeypot in
10
+ # the background)
11
+ # elasticpot status -- show running status
12
+ #
13
+ # NOTE: elasticpot/honeypot.py is generated at build time by the build_py
14
+ # hook in setup.py - it is a copy of the top-level honeypot.py bundled so
15
+ # that the `elasticpot run/start` entry point can locate and run it.
16
+ # It is listed in .gitignore and should not be committed.
17
+ #
18
+ # Contents:
19
+ # cli.py the `elasticpot` console entry point (init/run/start/stop/status)
20
+ # honeypot.py the main honeypot script (copied from repo root at build time)
21
+ # data/ bundled read-only assets copied to the working directory
22
+ # by `elasticpot init`:
23
+ # docs/ documentation and SQL schema files
24
+ # etc/ default configuration templates
25
+ # responses/ MongoDB wire-protocol response stubs
26
+ # test/ test.py for verifying a running honeypot